akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 150;
static const int MAX_M = (MAX_N + 1) / 2;
static const int MAX_K = 10;
static const int INF = 1 << 30;

int n, m;
int k[MAX_N], x[MAX_N][MAX_K], d[MAX_N][MAX_K];
int memo[MAX_N][MAX_K][MAX_M + 1];

int abs(int a){
	if(a < 0) return -a;
	else return a;
}

int main(){
	for(;;){
		scanf("%d %d", &n, &m);
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			scanf("%d", &k[i]);
			for(int j = 0; j < k[i]; j++) scanf("%d %d", &x[i][j], &d[i][j]);
		}
		fill(memo[0][0], memo[n][0], INF);
		for(int i1 = 0; i1 < n - 1; i1++){
			for(int i2 = 0; i2 <= m; i2++){
				for(int i3 = 0; i3 < k[i1]; i3++){
					if(i1 == 0 && i2 == 0) memo[i1][i3][i2] = 0;
					if(i1 == 1 && i2 == 1) memo[i1][i3][i2] = 0;
					for(int i4 = 0; i4 < k[i1 + 1]; i4++){
						memo[i1 + 1][i4][i2] = min(memo[i1 + 1][i4][i2], memo[i1][i3][i2] + (d[i1][i3] + d[i1 + 1][i4]) * abs(x[i1][i3] - x[i1 + 1][i4]));
					}
					if(i2 == m) continue;
					if(i1 == n - 2) continue;
					for(int i4 = 0; i4 < k[i1 + 2]; i4++){
						memo[i1 + 2][i4][i2 + 1] = min(memo[i1 + 2][i4][i2 + 1], memo[i1][i3][i2] + (d[i1][i3] + d[i1 + 2][i4]) * abs(x[i1][i3] - x[i1 + 2][i4]));
					}
				}
			}
		}
		int res = INF;
		for(int i1 = 0; i1 < k[n - 1]; i1++){
			for(int i2 = 0; i2 <= m; i2++){
				res = min(res, memo[n - 1][i1][i2]);
			}
		}
		for(int i1 = 0; i1 < k[n - 2]; i1++){
			for(int i2 = 0; i2 <= m - 1; i2++){
				res = min(res, memo[n - 2][i1][i2]);
			}
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 3076
gets.to_i.times {
	out = 0
	run = 0
	base = 0
	loop {
		case gets.chomp
		when 'HIT'
			base |= ((base ^ (base+1)) & base << 1) | 1
			run += base >> 3
			base &= 7
		when 'OUT'
			out += 1
			break if out == 3
		when 'HOMERUN'
			run += 1
			(0..2).each{|i| run += base[i]}
			base = 0
		end
	}
	puts run
}

Measured memory_bytes: 6104
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
D=many_int()

num=998244353


dicts={i:0 for i in range(N)}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True

if keys[0]!=0 or D[0]!=0:
    flg=True
else:
    if dicts[0]!=1:
        flg=True
        
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)

Measured memory_bytes: 21724
n=int(input())
D={}
DD={}
for i in range(1,n+1):
   s=(str(i)[0],str(i)[-1])
   t=(str(i)[-1],str(i)[0])
   if s not in D:
      D[s]=1
   else:
      D[s]+=1
   if t not in DD:
      DD[t]=1
   else:
      DD[t]+=1
ans=0
for i in D:
   if i in DD:
      ans+=D[i]*DD[i]
print(ans)
      

Measured memory_bytes: 40684
N = int(input())
L = [[1]* 201 for _ in range(201)] 

def gcd (a,b):
  if a < b:
    a, b = b, a
  A, B = a, b
  if L[a][b] != 1:
    return L[a][b]
  while b:
    a,b = b, a % b
  L[A][B] = a
  return a

ans = 0
for x in range(1,N+1):
  for y in range(x,N+1):
    for z in range(y,N+1):
      t = gcd(x,y)
      u = gcd(t,z)
      if x==y==z:
        ans += u
      elif x!=y and y!= z:
        ans += u * 6
      else:
        ans += u * 3
      
print (ans)

Measured memory_bytes: 9372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,i,j,l,n;
    long long int sum=0,gc,gc1,gc2;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            for(k=1; k<=n; k++)
            {
                gc=__gcd(j,k);
                gc1=__gcd(gc,i);

                sum=sum+gc1;
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	} 
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int i;
  long a[n];
  int b[n];
  vector<pair<long,int>>p(n);
  for(i=0;i<n;i++){
    cin >> a[i] >> b[i];
    p[i] = make_pair(a[i],b[i]);
  }
  sort(p.begin(),p.end());
  i=0;
  long ans = 0;
  while(m>0){
    if(p[i].second<m){
      m-=p[i].second;
      ans += p[i].second * p[i].first;
    }else{
      ans += m*p[i].first;
      m = 0;
    }
    i++;
  }
  cout << ans;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x, n;
	cin >> x >> n;
	vector<int> a(n);
	map<int,int> m;
	for (int& y: a) {
		cin >> y;
		++m[y-x];
	}
	for (int i = 0; i < n; ++i) {
		if (m.find(-i) == m.end()) {
			cout << -i + x << endl;
			return 0;
		}
		else if (m.find(i) == m.end()) {
			cout << i + x << endl;
			return 0;
		}
	}
	cout << -n + x << endl;
	return 0;
}

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

int main() {
	char a,b;
  		cin>>a>>b;
  int x,y;
  
  if(a=='A') x=1;
  if(a=='B') x=2;
  if(a=='C') x=3;
  if(a=='D') x=4;
  if(a=='E') x=5;
  if(a=='F') x=6;
  
  if(b=='A') y=1;
  if(b=='B') y=2;
  if(b=='C') y=3;
  if(b=='D') y=4;
  if(b=='E') y=5;
  if(b=='F') y=6;
  
  if(x<y) cout<<"<"<<endl;
  else if(x>y) cout<<">"<<endl;
  else cout<<"="<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e];
int n, m;
vector<int>adj[e];
bool vs[e];

//beginner 1999 127

int main()
{
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b;
        return 0;
    }
    if(a >= 6 && a <= 12){
        cout << b/2;
        return 0;
    }
    if(a <= 5){
        cout << 0;
        return 0;
    }
}


Measured memory_bytes: 50424
def f_b():
    s = input()
    e, o, a = "RUD", "LUD", "Yes"
    for i, si in enumerate(s):
        if i%2==0:
            if si not in e:
                a = "No"
                break
        elif i%2==1:
            if si not in o:
                a = "No"
                break

    print(a)

if __name__ == "__main__":
    f_b()

Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{
  public static void main(String[] arigs) throws IOException{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String N = reader.readLine();
    System.out.println(N.contains("7")?"Yes":"No");
    reader.close();
  }
}

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

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

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


Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mod 998244353
#define rep(i,j,k) for(int i=(j),LIM=(k);i<=LIM;i++)
#define per(i,j,k) for(int i=(j),LIM=(k);i>=LIM;i--)
#define LL long long
using namespace std;

int n,m;
int Pow(int b,LL k){ int r=1;for(;k;k>>=1,b=1ll*b*b%mod) if(k&1) r=1ll*r*b%mod;return r; }

int main(){
	scanf("%d%d",&n,&m);
	int Cn=1,Cm=1,ans=0,fc=1;
	rep(i,0,min(n,m)){
		ans = (ans + 1ll * Cn * Cm % mod * (i&1 ? -1ll : 1ll) * fc % mod * Pow(m+1,n-i) % mod * Pow(n+1,m-i)) % mod;
		Cn = 1ll * Cn * (n-i) % mod * Pow(i+1 , mod-2) % mod;
		Cm = 1ll * Cm * (m-i) % mod * Pow(i+1 , mod-2) % mod;	
		fc = 1ll * fc * (i+1) % mod;
	}
	printf("%d\n",(ans+mod)%mod);
}

Measured memory_bytes: 3828
N = int(input())
l = []
for i in range(N):
  X, L = map(int, input().split())
  l.append([X-L, X+L])
  
l.sort(key=lambda x: x[1])
pin = l[0][1]
ans = 1

for i in range(1, N):
  if pin <= l[i][0]:
    ans += 1
    pin = l[i][1]
    
print(ans)

Measured memory_bytes: 25336
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;scanf("%d",&N);
    vector<int> am(N),bm(N);
    rep(i,N)scanf("%d",&am[i]);
    rep(i,N)scanf("%d",&bm[i]);
    ll res = 0;
    for(int k=29;k>=0;k--){
        //vector<int> am(N),bm(N);
        ll T =(1<<k);
        rep(i,N){
            am[i]=am[i]%(2*T);
            bm[i]=bm[i]%(2*T);
        }
        sort(All(bm));

        ll is_one = 0;
        rep(i,N){
            int add = 0;
            if(am[i]<=T){
                add += lower_bound(All(bm),(2*T)-am[i])-lower_bound(All(bm),T-am[i]);
            }else{
                //add += lower_bound(All(bm),(1<<(k+1)))-bm.begin();
                //add -= lower_bound(All(bm),(3*(1<<k))-a[i])-lower_bound(All(bm),(1<<(k+1))-a[i]);
                add+=lower_bound(All(bm),(2*T)-am[i])-bm.begin();
                add+=lower_bound(All(bm),(2*T))-lower_bound(All(bm),(3*T)-am[i]);
            }
            is_one+=add;
        }
        if(is_one&1)res+=T;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	double kq = (w*h)/2;
	if (2*x==w && 2*y==h) {
		printf ("%.6f 1",kq );
	}
	else{
		printf ("%.6f 0",kq );
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>

using namespace std;

#define P(s) cout << s << endl;
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int n, a;
  cin >> n;
  set<int> nums;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (nums.count(a) == 0) {
      nums.insert(a);
    } else {
      nums.erase(a);
    }
  }
  cout << nums.size() << endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 1005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll dp[N][N];
char arr[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  memset(dp, 0, sizeof(dp));

  ll h, w;
  cin >> h >> w;

  for (ll i = 1; i <= h; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < s.length(); j++) {
      arr[i][j + 1] = s[j];
    }
  }

  dp[1][1] = 1;

  for (ll i = 1; i <= h; i++) {
    for (ll j = 1; j <= w; j++) {
      if (i == 1 && j == 1)
        continue;
      if (arr[i][j] == '#')
        continue;
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= mod;
    }
  }

  cout << dp[h][w] << en;

  return 0;
}


Measured memory_bytes: 9088
#include <iostream>                                                                                                                                                                                         
#include <cmath>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int x;  
    x = to_string(b).length();
    int temp; 
    temp = pow(10, x)*a + b;
    
    for(int i =0; i <= sqrt(temp); i++){
        if(i * i == temp){
            cout << "Yes" << endl;
            return 0;
        }   
    }   
    cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) max_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int H, W,N;
int field[305][305];
int field2[305][305];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};


void dfs(int x, int y, int h) {
    field[x][y] = 0;
    rep(i,4){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(0 <= nx and nx < H and 0 <= ny and ny < W and field[nx][ny] > h) dfs(nx, ny, h);
    }
    return ;
}

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

    int h, w;
    while(cin >> h >> w) {
        if(h == 0 and w == 0) return 0;
        rep(i,h) {
            rep(j,w) cout << '#';
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3144
s = list(input())
n = len(s)
if s == s[::-1] and s[:(n-1)//2] == s[:(n-1)//2][::-1] and s[(n+3)//2-1:n] == s[(n+3)//2-1:n][::-1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    set<int> S;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        if (!S.count(A[i])) {
            S.insert(A[i]);
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 10368
import sys
input = sys.stdin.readline
def print_ans(input_line):
    """Test Case
    >>> print_ans("10")
    5
    >>> print_ans("50")
    13
    >>> print_ans("10000000019")
    10000000018
    """
    N = int(input_line)
    min_ans = N - 1
    for i in range(1,int(N ** 0.5) + 1):
        q, mod= divmod(N,i)
        if mod == 0:
            min_ans = min(min_ans, q + i -2 )
    print(min_ans)

if __name__ == '__main__':
    print_ans(input())


Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	string S;
	cin >> S;
	int len = S.length();
	int ind = -1;
	int point = -1;
	bool modeR = false;
	vector<int> res(len,0);
	for (int i = 0; i < S.length(); ++i) {
		if (S[i] == 'R') {
			modeR = true;
		}
		else {
			if (modeR) {
				res[i-1] += (i-ind)/2;
				res[i] += (i-ind+1)/2;
				ind = i;
				point = i;
			}
			else {
				++res[point-((i-point)%2)];
				++ind;
			}
			modeR = false;
		}
	}
	for (int i = 0; i < len; ++i) {
		cout << res[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

bool is_prime(int x)
{
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
            return false;
    return true;
}

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

    int n;
    cin >> n;
    while (1)
    {
        if (is_prime(n))
        {
            cout << n << endl;
            return 0;
        }
        n++;
    }
}


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

int main()
{
  int a,b,c,ans=1000;
  cin>>a>>b>>c;
  ans=min(ans,abs(a-b)+abs(b-c));
  ans=min(ans,abs(a-c)+abs(b-c));
  ans=min(ans,abs(a-b)+abs(a-c));
  cout<<ans<<endl;
}


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

int main() {
  int n;
  cin >> n;
  long long x[5] = {0};
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[0] == 'M') x[0]++;
    else if (s[0] == 'A') x[1]++;
    else if (s[0] == 'R') x[2]++;
    else if (s[0] == 'C') x[3]++;
    else if (s[0] == 'H') x[4]++;
  }
  long long ans = x[0]*x[1]*x[2] + x[0]*x[1]*x[3];
  ans += x[0]*x[1]*x[4] + x[0]*x[2]*x[3];
  ans += x[0]*x[2]*x[4] + x[0]*x[3]*x[4];
  ans += x[1]*x[2]*x[3] + x[1]*x[2]*x[4];
  ans += x[1]*x[3]*x[4] + x[2]*x[3]*x[4];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
function Main(input) {
  input = input.trim().split(" ");
  var N = parseInt(input[0], 10);
  var K = parseInt(input[1], 10);
 
  var sum = K;
 
  for (var i = 1; i < N; i++) {
    sum *= K - 1;
  }
 
  console.log(sum);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n = in();
    vector<int> num(n);
    REP(i, n){
        int tmp = in();
        if(i == 0) num[i] = tmp;
        else num[i] = num[i - 1] + tmp;
    }
    int ans = 2 * 10e14;
    REP(i, n - 1) ans = min(ans, abs(num[i] - (num[n - 1] - num[i])));
    cout << ans << endl;

}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    Scanner reader=new Scanner(System.in);
    int a =reader.nextInt();
    int b =reader.nextInt();
    int c =reader.nextInt();
	
    if((b-a)==(c-b)) {
    	System.out.println("YES");
    }
    else {
    	System.out.println("NO");
    }
	}
	

}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <algorithm>

using s64 = int64_t;

enum BAMBOO_STATE {
	NOT_USED = 0,
	USED_4_A = 1,
	USED_4_B = 2,
	USED_4_C = 3
};

bool next_bamboo_state(std::vector<BAMBOO_STATE>& bs){
	for(size_t i = 0 ; i < bs.size() ; ++i){
		if(bs[i] != USED_4_C){
			switch(bs[i]){
			case NOT_USED:
				bs[i] = USED_4_A;
				break;
			case USED_4_A:
				bs[i] = USED_4_B;
				break;
			case USED_4_B:
				bs[i] = USED_4_C;
				break;
			case USED_4_C:
				bs[i] = NOT_USED;
				break;
			}
			if(i){
				for(size_t j = 0 ; j < i ; ++j){
					bs[j] = NOT_USED;
				}
			}
			return true;
		}
	}
	return false;
}

s64 min3(s64 A, s64 B, s64 C, std::vector<s64> bamboos){
	std::vector<BAMBOO_STATE> status(bamboos.size());
	std::fill(status.begin(), status.end(), NOT_USED);
	
	constexpr s64 MAX_MP = std::numeric_limits<s64>::max() >> 2;

	s64 min_MP = MAX_MP;
	do{
		s64 Alen = 0;
		s64 Blen = 0;
		s64 Clen = 0;
		s64 Acnt = 0;
		s64 Bcnt = 0;
		s64 Ccnt = 0;
		for(size_t i = 0 ; i < status.size() ; ++i){
			switch(status[i]){
			case NOT_USED:
				break;
			case USED_4_A:
				Acnt++;
				Alen += bamboos[i];
				break;
			case USED_4_B:
				Bcnt++;
				Blen += bamboos[i];
				break;
			case USED_4_C:
				Ccnt++;
				Clen += bamboos[i];
				break;
			}
		}
		s64 MP = MAX_MP;
		if(Acnt && Bcnt && Ccnt){
			MP = std::abs(A - Alen) + std::abs(B - Blen) + std::abs(C - Clen)
			         + (Acnt - 1) * 10  +	(Bcnt - 1) * 10 + (Ccnt - 1) * 10;
			min_MP = std::min(min_MP,  MP);
		}
	}while(next_bamboo_state(status));
	return min_MP;
}

int main(int argc,char *argv[]){
	s64 N, A, B, C;
	std::cin >> N >> A >> B >> C;
	std::vector<s64> l;
	for(s64 i = 0 ; i < N ; ++i){
		s64 tmp;
		std::cin >> tmp;
		l.push_back(tmp);
	}
	std::cout << min3(A,B,C,l);
	
	return 0;
}



Measured memory_bytes: 256
h,w=map(int,input().split())
s,t=[list(input()) for i in range(h)],[[0 for j in range(w+2)] for i in range(h+2)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			continue
		for p in range(9):
			t[i+p//3][j+p%3]+=1
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			s[i][j]=str(t[i+1][j+1])
	print("".join(s[i]))


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

int main(){
  int64_t N;
  cin >> N;
  const int64_t mod=1e9+7;
  int64_t x=1;
  int64_t y=1;
  int64_t z=1;
  for(int i=0;i<N;i++){
    x*=10;
    y*=9;
    z*=8;
    x%=mod;
    y%=mod;
    z%=mod;
  }
  int64_t ans=(x-2*y+z)%mod;
  if(ans<0){
    ans+=mod;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 998244353;

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

  int n,m;
  cin >> n >> m;
  
  vvi mp(n,vi());

  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }

  queue<int> q;
  q.push(0);

  vector<pii> ret(n,make_pair(0,0)); //ans, cnt

  while(!q.empty()){
    int cur = q.front();
    q.pop();
    if(ret[cur].second)continue;

    pii tmp(0,INT_MAX);
    if(cur){
      rep(i,mp[cur].size()){
        if(ret[mp[cur][i]].second && tmp.second > ret[mp[cur][i]].second + 1){
          tmp = make_pair(mp[cur][i],ret[mp[cur][i]].second+1);
        }
      }
    }

    ret[cur] = tmp;

    rep(i,mp[cur].size()){
      q.push(mp[cur][i]);
    }
  }

  cout << "Yes" << endl;
  rep(i,n-1){
    cout << ret[i+1].first + 1 << endl;
  }
}

Measured memory_bytes: 11500
#include "bits/stdc++.h"
using namespace std;
pair<int,int> Coor[105];
int Array[105] , MAX = 1100000000;
map<int,int> M;

int main(){
	int N , H;
	scanf( "%d" , &N );
	int i , j , k , Temp;

	for( i = 1 ; i <= N ; ++i )
		scanf( "%d%d%d" , &Coor[i].first , &Coor[i].second , Array + i );

	int limit;

	for( i = 0 ; i <= 100 ; ++i ){
		for( j = 0 ; j <= 100 ; ++j ){
			limit = MAX;
			H = 0;
			Temp = Array[1] + abs( i - Coor[1].first ) + abs( j - Coor[1].second );
			
			if( Array[1] == 0 ) limit = Temp;
			else H = Temp;

			for( k = 2 ; k <= N ; ++k ){
				Temp = Array[k] + abs( i - Coor[k].first ) + abs( j - Coor[k].second );
				
				if( Array[k] == 0 ) limit = min( limit , Temp );
				else{ 
					if( H == 0 ) H = Temp;					
					else if( H != Temp ) break;
				}
			}

			if( k <= N || H > limit ) continue;
			if( H == 0 ){
				if( limit > 0 ){ 
					printf( "%d %d %d\n" , i , j , limit );
					return 0;
				}
			}
			else{ 
				printf( "%d %d %d\n" , i , j , H );
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int n,m,tot;
ll ans;
char s1[maxn],s2[maxn];
int main()
{
    cin>>s1>>s2;
    if(strlen(s1)!=strlen(s2))
    {
        printf("No\n");
        return 0;
    }
    int len=strlen(s1);
    while(tot<len)
    {
        if(strcmp(s1,s2)==0)
        {
            printf("Yes\n");
            return 0;
        }
        char ch=s1[0];
        for(int i=0;i<len-1;i++)
        {
            s1[i]=s1[i+1];
        }
        s1[len-1]=ch;
        tot++;

    }
    printf("No\n");
}


Measured memory_bytes: 256
def main():
    H, W, K = map(int, input().split())
    chocolate = [list(map(int,list(input()))) for _ in range(H)]
    choco = [[0]*W for _ in range(H)]
    ids = [0] * H
    ans = 10 ** 9
    for bit in range(1<<(H-1)):
        group_id = 0
        for i in range(H):
            ids[i] = group_id
            if (bit>>i)&1:
                group_id += 1
        group_id += 1
        
        for i in range(group_id):
            for j in range(W):
                choco[i][j] = 0

        for i in range(H):
            for j in range(W):
                choco[ids[i]][j] += chocolate[i][j]
        
        if any(choco[i][j] > K for i in range(group_id) for j in range(W)):
            continue
        
        num = group_id - 1
        now = [0] * group_id
        def add(j):
            for i in range(group_id):
                now[i] += choco[i][j]
            if any(now[i] > K for i in range(group_id)):
                return False
            else:
                return True

        for j in range(W):
            if not add(j):
                num += 1
                now = [0] * group_id
                add(j)
        ans = min(ans, num)
    print(ans)


if __name__ == "__main__":
    main()

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

int main(void){ 
    int N,X[101],Y[101],i,j;
    int minh=100000000;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&X[i]);
    }
    for(i=1;i<=100;i++){
        Y[i]=0;
    }
    for(i=1;i<=100;i++){
        for(j=0;j<N;j++){
            Y[i]=Y[i]+(X[j]-i)*(X[j]-i);
        }
    }
    for(i=1;i<100;i++){
        if(minh>Y[i]){
            minh=Y[i];
        }
    }
    printf("%d",minh);
    return 0;
}

Measured memory_bytes: 128
grade m f r
    | m == (-1) || f == (-1) = "F"
    | m+f >= 80 = "A"
    | m+f >= 65 = "B"
    | m+f >= 50 || r >= 50 = "C"
    | m+f >= 30 = "D"
    | otherwise = "F"

main = do
    str <- getLine
    let (m:f:r:_) = map read $ words str
    if ((m,f,r) == (-1,-1,-1)) then
        return ()
    else do
        putStrLn $ grade m f r
        main

Measured memory_bytes: 4068
#include <iostream>
#include <cmath>

typedef long long LL;
using namespace std;

const int X = 1000001;
bool Find[X];

void init(){
  for(int i=0;i<X;i++){
    Find[i] = false;
  }
  for(int i=2;i<=sqrt(X);i++){
    if(Find[i])continue;
    for(int j=i+1;j<X;j++){
      if(Find[j])continue;
      if(j%i==0)Find[j]=true;
    }
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=2;i<n+1;i++){
      if(!Find[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 1840
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1000000007;
	static int N, total;
	static long[] pow10 = new long[801];
	static long[] fact = new long[201];
	static long[][] binom = new long[201][201];

	public static void main(String[] args) {
		pow10[0] = fact[0] = 1;
		for (int i = 1; i < pow10.length; ++i) {
			pow10[i] = pow10[i - 1] * 10 % MOD;
		}
		for (int i = 1; i < fact.length; ++i) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		for (int i = 0; i <= 200; ++i) {
			binom[i][i] = binom[i][0] = 1;
		}
		for (int i = 0; i <= 200; ++i) {
			for (int j = 1; j < i; ++j) {
				binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % MOD;
			}
		}
		N = sc.nextInt();
		int[] A = new int[N];
		int zi = -1;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			if (A[i] == 0) zi = i;
		}
		int ans = solve(A);
		if (zi != -1) {
			int[] B = new int[N - 1];
			int idx = 0;
			for (int i = 0; i < N; ++i) {
				if (i == zi) continue;
				B[idx++] = A[i];
			}
			ans += MOD - solve(B);
			ans %= MOD;
		}
		System.out.println(ans);
	}

	static int solve(int[] A) {
		int[] digits = new int[5];
		for (int i = 0; i < A.length; ++i) {
			digits[(A[i] + "").length()]++;
		}
		total = digits[1] + digits[2] * 2 + digits[3] * 3 + digits[4] * 4;
		int[][][] comb = new int[5][][];
		for (int i = 1; i <= 4; ++i) {
			if (digits[i] > 0) {
				comb[i] = calcComb(digits, i);
			}
		}
		long ret = 0;
		for (int i = 0; i < A.length; ++i) {
			int len = (A[i] + "").length();
			for (int j = 0; j < A.length; ++j) {
				long add = 0;
				for (int k = 0; k <= A.length - 1 - j; ++k) {
					add += binom[A.length - 1 - j][k] * fact[k];
					add %= MOD;
				}
				add *= A[i];
				add %= MOD;
				add *= fact[j];
				add %= MOD;
				for (int k = 0; k < total && k <= j * 4; ++k) {
					long addElem = add * pow10[k] % MOD;
					addElem *= comb[len][j][k];
					addElem %= MOD;
					ret += addElem;
				}
				ret %= MOD;
			}
		}
		return (int) ret;
	}

	static int[][] calcComb(int[] digits, int cur) {
		digits[cur]--;
		int[][] dp = new int[N][total + 1]; // dp[i][j] : j digits with i cards
		dp[0][0] = 1;
		for (int i = 1; i <= 4; ++i) {
			for (int j = 0; j < digits[i]; ++j) {
				for (int k = N - 1; k > 0; --k) {
					for (int l = total; l >= i; --l) {
						dp[k][l] += dp[k - 1][l - i];
						if (dp[k][l] >= MOD) dp[k][l] -= MOD;
					}
				}
			}
		}
		digits[cur]++;
		return dp;
	}
}

Measured memory_bytes: 28308
#include <iostream>
#include <utility>
#include <stdint.h>
#include <set>

using namespace std;

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

  set<int> A;

  bool ans = true;
  
  for (int n=0; ans && n<N; ++n) {
    int a;
    cin >> a;
    if (A.count(a))
      ans = false;
    else
      A.insert(a);
  }

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

  return 0;
}


Measured memory_bytes: 9600
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

bool f(){
	int N;
	cin >> N;
	vector<int> revx(N*N+1);
	vector<int> xs(1+N);
	vector<int> buf0;
	vector<int> buf1;
	for(int i=1;i<=N;i++){
		int x;
		cin >> x;
		if(revx[x]){
			return false;
		}
		revx[x]=i;
		xs[i]=x;
	}
	for(int x=N*N;x>=1;x--){
		if(revx[x]){
			for(int i=1;i<revx[x];i++){
				buf0.push_back(revx[x]);
			}
			for(int i=revx[x]+1;i<=N;i++){
				buf1.push_back(revx[x]);
			}
		}
	}

	vector<int> ret;
	for(int x=1;x<=N*N;x++){
		if(revx[x]){
			ret.push_back(revx[x]);
		}
		else if(buf0.size()){
			int i=buf0.back();
			if(xs[i]<x){
				return false;
			}
			buf0.pop_back();
			ret.push_back(i);
		}
		else if(buf1.size()){
			int i=buf1.back();
			if(x<xs[i]){
				return false;
			}
			buf1.pop_back();
			ret.push_back(i);
		}
	}
	cout << "Yes" << endl;
	auto sp="";
	for(int r:ret){
		cout << sp << r;
		sp=" ";
	}
	cout << endl;

	return true;
}
int main() {
	if(!f()){
		cout << "No" << endl;
	}
}



Measured memory_bytes: 4212
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(void)
{

    char a[21],b[21];
    int x,i,j;
    scanf("%s",a);
    x=strlen(a);

    for(i=0;i<=x;i++){

        if(i==x){
            b[i]=a[i];
        }

        else{
            b[x-i-1]=a[i];
        }

    }
    printf("%s\n",b);
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void print_int(int n)
{
    printf("%d\n",n);
    
}

void sort(int a[], int n)
{
    int h, i, j;

    for(h = 1; h < n / 9; h = h * 3 + 1)
        continue;

    for(; h > 0; h /= 3)
    {
        for(i = h; i < n; i++)
        {
            j = i;
            while(j >= h && a[j] < a[j-h])
            {
                swap(&a[j], &a[j-h]);
                j -= h;
            }
        }
    }
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
}

void intcpy(int a[], const int b[], int count)
{
    for(int i = 0; i < count; i++)
    {
        a[i] = b[i];
    }
}

int list_sum(int a[], int n)
{
    int sum = 0;

    for(int i = 0; i < n; i++)
    {
        sum += a[i];
    }

    return sum;
}


void permutate(int s[], int count, int n)
{
    if(n == count)
        return;

    for(int i = n; i < count; i++)
    {
        swap(&s[i], &s[n]);

        if(i != n)
        {
            //intcpy(result[j++], s, count);
        }
        
        permutate(s, count, n+1);
        swap(&s[i], &s[n]);
    }
}



int main(void)
{
    int n;
    scanf("%d", &n);
    if(n <= 999)
    {
        printf("%s\n", "ABC");
    }
    else
    {
        printf("%s\n", "ABD");
    }
    
    
    return 0;
}



Measured memory_bytes: 128
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	ll  n, k;
	cin >> n >> k;
	ll ret = 0;
	ll cnt1 = 0;
	for (int i = k; i <= n; i += k) {
		cnt1++;
	}
	ll cnt2 = 0;
	if (!(k & 1)) {
		for (int i = k/2; i <= n; i += k) {
			cnt2++;
		}
	}
	ret = cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2;
	cout << ret << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3636
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String data = sc.nextLine();
      
      	char[] letter = new char [data.length()];
      
      	for (int i = 0; i < data.length(); i++ ) {
          letter[i] = data.charAt(i);
        }
    
    if (letter[2] == letter[3] && letter[4] == letter[5] ) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
      
    }
}


Measured memory_bytes: 22868
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,m:usize,s:usize,
    uvab : [(Usize1,Usize1,usize,usize);m],// city,city,fee, transit time
    cd:[(usize,usize);n],// money, time
    }
    let mut G = vec![Vec::new(); n + 1];
    for &(u, v, a, b) in uvab.iter() {
        G[u].push((v, a, b));
        G[v].push((u, a, b));
    }
    let mut s = s;
    /**
     * 銀貨は最大でも2500枚あればよい -> 制約ゆるくなる
     * */
    let MAX = 2500usize;
    if s >= MAX {
        s = MAX;
    }
    // [頂点, 金]への最大値
    let mut dp = vec![vec![INF as usize; MAX + 1]; n];
    let mut que = BinaryHeap::new();
    // let mut qq = BTreeSet::new();
    dp[0][s] = 0;
    // ダイクストラの拡張
    que.push((0 as i64, 0 as i64, -(s as i64)));
    // qq.insert((0, 0, s));
    while let Some(tp) = que.pop() {
        // dbg!(que.len());
        let time = (-tp.0) as usize;
        let v = (-tp.1) as usize;
        let ss = (-tp.2) as usize;
        // 最大より時間がかかるなら無視
        if time > dp[v][ss] {
            continue;
        }
        // 両替する
        if ss + cd[v].0 <= MAX {
            let ns = ss + cd[v].0;
            let ntime = time + cd[v].1;
            if dp[v][ns] > ntime {
                dp[v][ns] = ntime;
                que.push((-(ntime as i64), -(v as i64), -(ns as i64)));
            }
        }
        for &e in G[v].iter() {
            if ss < e.1 {
                continue;
            }
            let nv = e.0;
            let ns = ss - e.1;
            let ntime = time + e.2;
            if dp[nv][ns] > ntime {
                dp[nv][ns] = ntime;
                que.push((-(ntime as i64), -(nv as i64), -(ns as i64)));
            }
        }
    }
    for v in 1..n {
        let mut res = INF as usize;
        for s in 0..=MAX {
            res = min(res, dp[v as usize][s as usize]);
        }
        println!("{}", res);
    }
}

const INF: usize = 1 << 55;


Measured memory_bytes: 4652
#include <utility>
#include <bitset>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ios>
#include <iomanip>
#include <sstream>
#include <climits>
#include <cmath>

using namespace std;

#ifdef USE_LOG
#define LOG(str)  cout << str << endl
#define DMP(var)  cout << #var << " = " << var << endl
#else
#define LOG(...)
#define DMP(...)
#endif

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define RFOR(v, b, e)  for (int v = (e) - 1; (b) <= v; --v)
#define REP(v, n)      FOR(v, 0, n)
#define RREP(v, n)     RFOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

typedef long long           ll;
typedef unsigned long long  ull;

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

	int H, W;
	cin >> H >> W;

	vector<vector<int>> m(H, vector<int>(W));

	const int kWall = -1;
	const int kRoad = 1000000;
	int wall = 0;

	REP (i, H)
	REP (j, W) {
		char c;
		cin >> c;
		if (c == '.') {
			m[i][j] = kRoad;
		} else {
			m[i][j] = kWall;
			++wall;
		}
	}

	m[0][0] = 1;
	stack<pair<int, int>> s;
	s.push(make_pair(0, 0));

	while (!s.empty()) {
		auto p = s.top();
		s.pop();

		int i = p.first;
		int j = p.second;
		int c = m[i][j] + 1;

		bool u = i > 0;
		bool d = i < (H - 1);
		bool l = j > 0;
		bool r = j < (W - 1);

		if (u && (m[i - 1][j] > c)) {
			m[i - 1][j] = c;
			s.emplace(i - 1, j);
		}

		if (d && (m[i + 1][j] > c)) {
			m[i + 1][j] = c;
			s.emplace(i + 1, j);
		}

		if (l && (m[i][j - 1] > c)) {
			m[i][j - 1] = c;
			s.emplace(i, j - 1);
		}

		if (r && (m[i][j + 1] > c)) {
			m[i][j + 1] = c;
			s.emplace(i, j + 1);
		}
	}

	int g = m[H - 1][W - 1];
	if ((kWall < g) && (g < kRoad)) {
		cout << (((W * H) - wall) - g) << endl;
	} else {
		cout << "-1" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
//ll const mod=1e9+7;
const ll MAX=300000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


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


int main(){
    string s;
    cin>>s;
    string t;
    cin>>t;
    int ns=s.size();
    vvi d(26);
    rep(i,ns){
      d[s[i]-'a'].push_back(i);
    }
    ll ans=0;
    int nt=t.size();
    int index=-1;
    rep(i,nt){
      if(d[t[i]-'a'].size()==0){
        cout<<-1<<endl;
        return 0;
      }
      auto it=upper_bound(all(d[t[i]-'a']),index);
      if(it==d[t[i]-'a'].end()){
        ans+=ns;
        i--;
        index=-1;
      }
      else{
        index=*it;
      }
    }
    ans+=index+1;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;



public class Main {

	
	static int max=0;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		//超时过不了
		Scanner scan =new Scanner(System.in);
		StringBuilder builder=new StringBuilder();
		int n=scan.nextInt();
		int[] A=new int[n];
		
		for(int i=0;i<n;i++){
			A[i]=scan.nextInt();
			max=Math.max(max,A[i]);
		}
		int[] B=new int[n];
		int[] C=new int[max+1];
		countSort(A,B,C,n);
		builder.append(B[0]);
		for(int i=1;i<n;i++){
			builder.append(" ").append(B[i]);
		}
		System.out.println(builder);
	}

	private static void countSort(int[] A, int[] B,int[] C, int n) {
		// TODO Auto-generated method stub
		for(int i=0;i<n;i++){
			C[A[i]]++;
		}
		
		for(int i=1;i<=max;i++)
			C[i]=C[i-1]+C[i];
		
		
		for(int j=n-1;j>=0;j--){
			B[C[A[j]]-1]=A[j];
			C[A[j]]--;
		}
	}

}



Measured memory_bytes: 508492
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> P;

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k, tmp = 10000, s, m;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        s += k + i;
        if (abs(k + i) < abs(tmp)) {
            tmp = k + i;
        }
    }
    s -= tmp;
    cout << s << "\n";
    //system("pause");
    return 0;
}

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

#define MOD 1000000007
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795

const int INF = ~(1<<31);
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int32 N;
	cin>>N;
	int32 A[N+1];
	int32 B[N];
	for(int i=0; i<=N; i++){
		cin>>A[i];
	}
	for(int i=0; i<N; i++){
		cin>>B[i];
	}
	int32 monDef = 0;
	for(int i=0; i<N; i++){
		if(B[i] >= A[i]){
			monDef += A[i];
			if(A[i+1] >= (B[i]-A[i])){
				monDef += (B[i]-A[i]);
				A[i+1] = A[i+1]-(B[i]-A[i]);
			}
			else{
				monDef+= A[i+1];
				A[i+1] = 0;
			}
		}
		else{
			monDef += B[i];
		}
	}
	cout<<monDef<<"\n";
	return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int N,M,Q; cin>>N>>M>>Q;

    vector<vector<int>> station(N,vector<int>(N,0));

    int l,r;
    for (int i = 0; i < M; ++i) {
        cin>>l>>r; l--; r--;
        station[l][r]++;
    }

    vector<vector<int>> ruiseki(N+1,vector<int>(N+1,0));

    for (int i = 0; i <N; ++i) {
        for (int j = 0; j < N; ++j) {
            ruiseki[i+1][j+1]=ruiseki[i][j+1]+ruiseki[i+1][j]-ruiseki[i][j]+station[i][j];
        }
    }

    int p,q;
    for (int i = 0; i < Q; ++i) {
        cin>>p>>q; p--; q--;
        cout<<ruiseki[q+1][q+1]-ruiseki[p][q+1]-ruiseki[q+1][p]+ruiseki[p][p]<<endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    string s,t;
    cin>>s;
    cin>>t;
    long long x,i;
    x=0;
    for (i=0;i<s.length();i++)
    {
    	if (s[i]==t[i])
    	{
    		continue;
		}
		x++;
	}
	cout<<x<<endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
 
int main(){
    int N;
    long long int A=0,B=0;
    int f=0;
    long long int a[14514],b[14514];
    long long int C=0;
    long long int j=0,k=0;
    cin >> N ;
    REP(i,N){
        cin >> a[i];
        A+=a[i];
    }
    REP(i,N){
        cin >> b[i];
        B+=b[i];
        if(a[i]!=b[i]){
            f=1;
        }
    }
    if(A>=B){
        if(f==1){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
        return 0;
    }
    B=B-A;
    REP(i,N){
        if(a[i]>b[i]){
            k+=a[i]-b[i];
        }else{
            if((b[i]-a[i])%2==1){
                k++;
                b[i]++;
            }
            j+=(b[i]-a[i])/2;
        }
    }
    //cout << j << " " << k << endl;
    C+=min(j,k);
    j-=C;k-=C;
    if(j>0){
        C+=j*2;
    }else if(k>0){
        cout << "No" << endl;
        return 0;
    }
    //cout << C << endl;
    if(C<=B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){
    int W,H;
    int x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(H<y+r) puts("No");
    else if(0>y-r) puts("No");
    else if(W<x+r) puts("No");
    else if(0>x-r) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100, MAX_V = 100000;
int N, W;
int w[MAX_N+1], v[MAX_N+1];
ll dp[MAX_N+1][MAX_V+1];

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

  cin >> N >> W;
  repa(i, 1, N) cin >> w[i] >> v[i];

  fill(dp[0], dp[0]+(MAX_N+1)*(MAX_V+1), INFINT);
  dp[0][0] = 0;
  for (int i = 1; i <= N; ++i) {
      for (int j = 0; j <= MAX_V; ++j) {
          if (v[i] <= j) dp[i][j] = dp[i-1][j-v[i]] + w[i];
          dp[i][j] = min(dp[i][j], dp[i-1][j]);
      }
  }

  ll ans = 0;
  for (int i = 0; i <= MAX_V; ++i) {
      if (dp[N][i] <= W) ans = i;
  }

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


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


Measured memory_bytes: 128