akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n, vector<int>(n, -1));
    rep(i, n) {
        int num;
        cin >> num;
        rep(j, num) {
            int x, y;
            cin >> x >> y;
            --x;
            g[i][x] = y;
        }
    }
    int ans = 0;
    rep(i, 1<<n) {
        vector<int> d(n);
        rep(j, n) if ( i & 1<<j ) d[j] = 1;
        bool ok = true;
        rep(j, n ) {
            if (d[j] ) {
                rep(k, n) {
                    if ( g[j][k] == -1 ) continue;
                    if ( g[j][k] != d[k] ) ok = false;
                }
            }
        }
        if ( ok ) {
            ans = max(ans, __builtin_popcount(i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import count

N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w - WV[i][0] >= 0:  # 品物を追加できるとき
            dp[i+1][w] = max(dp[i+1][w], dp[i][w-WV[i][0]] + WV[i][1])
        # できないとき
        dp[i+1][w] = max(dp[i+1][w], dp[i][w])
print(dp[N][W])


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

int main () {

  int a , b , res;

  char op;

  while(1) {

    cin >> a >> op >> b;

    if ( op == '?') break;

    if ( op == '+') {

      res = a + b;

      cout << res << "\n" ;

    }

    if ( op == '-') {

      res = a - b;

      cout << res << "\n" ;

    }

    if ( op == '*') {

      res = a * b;

      cout << res << "\n";

    }

    if ( op == '/') {

      res = a / b;

      cout << res << "\n";

    }

  }

  return 0;

}

Measured memory_bytes: 1164
import math
n = int(input())
dic = {}
def combinations_count(n,r):
    return math.factorial(n) // (math.factorial(n - r)*math.factorial(r))

for index in range(n):
    temp = ''.join(sorted(list(input())))
    #入力された文字列をa-z順にソートし、変数tempに代入
    if temp in dic:
        dic[temp] = dic[temp] + 1
        #すでに同じ文字列の入力があれば、key:tempのvalueに+1
    else:
        dic[temp] = 1
        #新しい文字列の場合は文字列とvalue＝1を辞書に追加
ans = 0

for k in dic.values():
    if k >= 2:
        ans += combinations_count(k,2)
    else:
        ans = ans
print(ans)


Measured memory_bytes: 17932
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll h, n; cin>>h>>n;
    vector<LP> ab(n);
    cin>>ab;

    vvl dp(n + 1, vl(h + 1, LINF));
    rep(i, n + 1) dp[i][0] = 0;
    rep(i, n) rrep(j, 1, h + 1) {
        chmin(dp[i + 1][j], dp[i][j]);
        if (j < ab[i].fi) {
            chmin(dp[i + 1][j], ab[i].se);
            continue;
        }
        chmin(dp[i + 1][j], dp[i + 1][j - ab[i].fi] + ab[i].se);
    }
    cout<<dp[n][h]<<endl;
}

Measured memory_bytes: 78592
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1000000007
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,m,k;
int d[16];
int v[110][110];
int isd[110];

int dp[1<<16];

int dfs(int s){
  if(dp[s]!=-1)return dp[s];
  dp[s]=111111111;
  for(int i=0;i<k;i++){
    int t=0;
    for(int j=0;j<m;j++){
	 if(s>>j&1){
	   if(isd[v[d[j]][i]]>=0&&(t>>isd[v[d[j]][i]]&1)==0){
		t+=(1<<isd[v[d[j]][i]]);
	   }
	 }
    }
    if(s==t)continue;
    dp[s]=min(dp[s],dfs(t)+1);
  }
  return dp[s];
}

signed main(){
  cin>>n>>m>>k;
  fill_n(isd,100,-1);
  for(int i=0;i<m;i++){
    cin>>d[i];
    d[i]--;
    isd[d[i]]=i;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
	 cin>>v[i][j];
	 v[i][j]--;
    }
  }
  fill_n(dp,1<<16,-1);
  dp[0]=0;
  cout<<dfs((1<<m)-1)<<endl;
  return 0;
}



Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int i,a;
    for(i=0; i<n; i++){
        cin >> a;
        if(a%2==0){
            if(a%3!=0 && a%5!=0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = 0;
  REP(i, N){
    if(i != 0){
      ans += min(A[i-1], A[i]);
      A[i] -= min(A[i-1], A[i]);
    }

    ans += A[i]/2;
    A[i] %= 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  s[3] = '8';
  cout << s << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	double a, b, c, d, e, f, x, y;
	double result[10000][2];
	int i, j;
	
	i = 0;
	
	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
		x = ((b * f) + (-1 * e * c)) / ((b * d) + (-1 * a * e));
		
		y = ((a * f) + (-1 * d * c)) / ((a * e) + (-1 * b * d));
		
		result[i][0] = x;
		result[i][1] = y;
		
		if (result[i][0] == -0.000) {
			result[i][0] = 0;
		}
		else if (result[i][1] == -0.000) {
			result[i][1] = 0;
		}
		
		i++;
	}
	
	for (j = 0; j < i; j++) {
		printf("%.3lf %.3lf\n", result[j][0], result[j][1]);
	}
	
	return (0);
}

Measured memory_bytes: 656
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

const int INF = 1 << 30;

typedef pair<int, int> P;

int maxn = 0;
int mind = 0;



int stoi (string s )
{
	stringstream ss (s );
	int res;
	ss >> res;

	return res;
}

int calc_d (P a, P b )
{
	return (abs (a.first - b.first ) + abs (a.second - b.second ) );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.LS", "r", stdin );
	int w, h;
	while (cin >> w >> h  && w && h ){
		int maxn = 0, maxc = 0;
		P g;
		vector <vector <P> > p (10001 );
		for (int i = 0; i < h; i++ ){
			for (int j = 0; j < w; j++ ){
				string c;
				cin >> c;
				if (c[0] == '.' ){
					continue;
				}else
				if (c[0] == 'S' ){
					p[0].push_back (P (i, j ) );
					continue;
				}else
				if (c[0] == 'G' ){
					g = P (i, j );
					continue;
				} // end if
				p[stoi(c)].push_back (P (i, j ) );
				maxn = max (maxn, stoi(c ) );
				maxc = max (maxc, (int)p[stoi(c)].size() );
			} // end for
		} // end for
		p[maxn+1].push_back (g );

		int dp[maxn+2][maxc];
		P minC[maxn+2][maxc];
		for (int i = 0;i < maxn+2; i++ )
			for (int j = 0;j < maxc; j++ )
				dp[i][j] = INF;
		for (int j = 0; j < (int)p[1].size(); j++ ){
			dp[1][j] = calc_d (p[0][0], p[1][j] );
			minC[1][j] = p[1][j];
		} // end for

		for (int i = 2; i < maxn+2; i++ ){
			for (int j = 0; j < (int)p[i].size(); j++ ){
				for (int k = 0; k < (int)p[i-1].size(); k++ ){
					if (dp[i][j] > dp[i-1][k] + calc_d (p[i-1][k], p[i][j] ) ){
						dp[i][j] = dp[i-1][k] + calc_d (p[i-1][k], p[i][j] );
						minC[i][j] = p[i][j];
					} // end if
				} // end for
			} // end for
		} // end for

		cout << dp[maxn+1][0] << endl;		

	} // end loop
	
	return 0;
}

Measured memory_bytes: 2724
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){
  long N,Q;
  vector<long> index(100001,0);
  cin >> N;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    index[tmp]++;
  }
  cin >> Q;
  vector<vector<long>> B(Q, vector<long>(2,0));
  for(int i = 0; i < Q; i++){
    cin >> B.at(i).at(0) >> B.at(i).at(1);
  }
  long sum = 0;
  for(int i = 0; i < 100001; i++){
    sum += i * index[i];
  }

  for(int i = 0; i < Q; i++){
    long tmp1, tmp2;
    tmp1 = B.at(i).at(0);
    tmp2 = B.at(i).at(1);
    sum += (tmp2 - tmp1) * index[tmp1];
    index [tmp2] += index[tmp1];
    index [tmp1] = 0;
    cout << sum << endl;
  }
  
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;

int main(){
	ll d,t,s;
	cin>>d>>t>>s;
	if(d<=t*s)cout<<"Yes";
	else cout<<"No";
}
  
  
  
   


    

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


int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  ll N;
  cin >> N;

  // // 素因数分解
  // vector<pair<ll,ll>> res;
  // for(ll i = 2; i*i < N; i++){
  //   if(N%i != 0) continue;
  //   int count=0;
  //   while(N%i==0){
  //     count++;
  //     N/=i;
  //   }
  //   res.push_back(make_pair(i, count));
  // }
  // if (N != 1) res.push_back(make_pair(N, 1));

  ll result=0;
  for(ll i=2; i*i<=N; i++){
    // if(i > N) break;
    ll count=0;
    ll exp=1;
    while(N%i == 0){
      count++;
      N=N/i;
      if(count>=exp){
        count=0;
        result++;
        exp++;
      }
    }
  }
  if(N!=1) result++;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  ll n;cin >>n;
  vector<ll> h(n);
  for(ll i=0; i< n;++i)cin >> h[i];
  ll max_len = 0;
  ll start =0;
  ll end =0;
  for (ll i=1; i< n;++i){
    if(h[i-1]>=h[i]){
      ++end;
    } else {
      max_len = max(max_len, end - start);
      start =i;
      end = i;
    }
  }
  max_len = max(max_len, end - start);
  cout << max_len << endl;
  return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (B / N < A) {
    cout << B << endl;
  }
  else if (B / N >= A) {
    cout << A * N << endl;
  }
}
    

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

#define int             long long
#define w(x)            int x;  cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,a,b)      for(int i = a; i < b; i++)


int32_t main(){
    FIO;
	  int k,a,b; cin>>k>>a>>b;
      if(a%k == 0 || b%k == 0)
      {
      	cout<<"OK\n";
      	return 0;
      }
      for(int i=a;i<b;i++)
      {
      	if(i%k ==0 ){
        cout<<"OK\n";
        return 0;
        }
        }
        cout<<"NG\n";
    }
    

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    ll h; cin >> h;
    ll count = 0;
    while(h) {
        count++;
        h /= 2;
        h = floor(h);
    }
    ll ans = 0;
    REP(i, count) ans += pow(2, i);
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = np.array([int(a) for a in input().split(" ")])
    F = np.array([int(a) for a in input().split(" ")])
    A = np.sort(A)
    F = np.sort(F)[::-1]
    AF = A * F
    m = np.max(AF)

    if(func(0, AF, F, N, K)):
        print(0)
        return
    a = 0
    b = m
    for aaa in range(m):
        if((b - a) <= 1):
            print(b)
            return
        mid = int((b - a) / 2.) + a
        if(func(mid, AF, F, N, K)):
            b = mid
        else:
            a = mid
    print("???????")


def func(saidai, AF, F, N, K):
    count = np.sum(np.ceil((AF[(AF - saidai) > 0] - saidai) / F[(AF - saidai) > 0]))
    return count <= K


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


Measured memory_bytes: 37240
s = input()
def shrink(char, s):
    if len(set(s)) == 1:
        return 0
    shrinked = "".join((s[i] if s[i+1] != char else s[i+1] for i in range(len(s)-1)))
    return shrink(char, shrinked) + 1

print(min(shrink(char, s) for char in s))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int k;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

void Solve()
{
	cin >> k;
	cout << a[k - 1];
}

int main()
{
	Solve();
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  long int h,w;
  scanf("%ld %ld",&h,&w);
  
  if(h==1||w==1){
    printf("1");
    return 0;
  }
  
  printf("%ld",(h*w+1)/2);
  
  return 0;
  
}

Measured memory_bytes: 128
#include<stdio.h>

main()

{
    int N, max=0, i, sum=0, sum1=0;
    scanf("%d",&N);
    int L[N];

    for(i=0; i<N; i++)
    {
        scanf("%d",&L[i]);
    }
    max = L[0];
    for(i=0; i<N; i++)
    {
        if(L[i] > max)
        {
            max = L[i];
        }
    }

    for(i=0; i<N; i++)
    {
        sum = sum + L[i];
    }

    sum1 = sum - max;

    if(sum1>max)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int a; cin >> a;
    cout << 3 * a * a;
}


Measured memory_bytes: 256
#include <stdio.h>

int result[50];

int i=0;
int a,b;
char op;
//int w,h,x,y,r;

int main(void) {
  while(scanf("%d %c %d",&a,&op,&b) && op!='?'){
  if(op=='+'){
    result[i]=a+b;
  }
  else if(op=='-'){
    result[i]=a-b;
  }
  else if(op=='*'){
    result[i]=a*b;
  }
  else if(op=='/'){
    result[i]=a/b;
  }
  i++;
}

for(int k=0;k<i;k++){
  printf("%d\n",result[k]);
}
	//return 0;

}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

struct City {
    int cityNum;
    int prefNum;
    int year;
    string ID = "";
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    string S;
    ll K;
    cin >> S >> K;
    REP(i, K) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;
    return 0;

}

Measured memory_bytes: 256
N = int(input())
S = [input() for x in range(N)]
M = int(input())
T = [input() for x in range(M)]

KEY = set(S + T)

max_point = 0
max_key = ""
for key in KEY:
	point = S.count(key) - T.count(key)
	if max_point < point:
		max_point = point
		max_key = key
#print(max_key)
print(max_point)


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/


// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i32, i64, isize, u32, u64, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
#[fastout]
fn main() {
    input! {
        n: i64, m: usize,
        a: [i64; m]
    }

    let ans: i64 = n - a.iter().sum::<i64>();

    println!("{}", if ans >= 0 { ans } else { -1 });
}


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

using namespace std;

typedef long long ll;

struct Point {
  int x, y, z;
  Point(){}
  Point(int x, int y, int z):x(x), y(y), z(z){}
};
Point operator + (const Point& a, const Point& b) { return Point(a.x + b.x, a.y + b.y, a.z + b.z); }
Point operator - (const Point& a, const Point& b) { return Point(a.x - b.x, a.y - b.y, a.z - b.z); }
Point operator * (const double& k, const Point& a) { return Point(k*a.x, k*a.y, k*a.z); }
double norm(Point a) { return a.x*a.x + a.y*a.y + a.z*a.z; }
double abs(Point a) { return sqrt(norm(a)); }
double dot(Point a, Point b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
double cross(Point a, Point b) { return sqrt(norm(a)*norm(b) - dot(a, b)*dot(a, b)); }

struct Obstacle {
  Point  p;
  double r;
  ll     l;
};

double getdist(Point a, Point b, Point p)
{
  if(dot(b - a, p - a) < 0.0) return abs(p - a);
  if(dot(a - b, p - b) < 0.0) return abs(p - b);
  return abs(cross(b - a, p - a) / abs(b - a));
}

int main()
{
  int N, Q;
  cin >> N >> Q;
  vector<Obstacle> obs(N);
  for(int i = 0; i < N; i++) {
    cin >> obs[i].p.x >> obs[i].p.y >> obs[i].p.z >> obs[i].r >> obs[i].l;
  }
  for(int i = 0; i < Q; i++) {
    ll ans = 0;
    Point s, d;
    cin >> s.x >> s.y >> s.z >> d.x >> d.y >> d.z;
    for(int j = 0; j < N; j++) {
      double dist = getdist(s, d, obs[j].p);
      if(dist <= obs[j].r + 1e-10) ans += obs[j].l;
    }
    cout << ans << endl;
  }

  return 0;
}

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

bool is_valid(vector<int> a, vector<int> b){
  return (a.at(0) - b.at(0) == a.at(1) - b.at(1)) && (a.at(1) - b.at(1) == a.at(2) - b.at(2));
}

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  
  vector<vector<int>> grid(3, vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> grid.at(i).at(j);
    }
  }

  if(is_valid(grid.at(0), grid.at(1)) && is_valid(grid.at(1), grid.at(2))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  

  return 0;
}

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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  if (s[a] != '-') {
    cout << "No" << endl;
    return 0;
  }
  REP(i, a + b + 1) {
    if (i == a) continue;
    if (s[i] < '0' || '9' < s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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


int main() {
    int N;
    cin>>N;
    if(N%2==0)cout<<N/2<<endl;
    else cout<<N/2+1<<endl;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int l;
    cin >> l;
    Int cnt = 0;
    Int tmp = l;
    while (tmp > 0) {
        cnt++;
        tmp /= 2;
    }
    Int res_n = cnt;
    Int res_m = 0;
    vector<Int> a, b, c;
    for (Int i = 1; i <= cnt - 1; i++) {
        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(0);
        res_m++;
        //print(i, i + 1, 0);
        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(1<<(i - 1));
        res_m++;
        //print(i, i + 1, 1<<(i - 1));
    }
    Int nx = (1<<(cnt - 1));
    for (Int i = cnt - 1; i >= 1; i--) {
        if ((1<<(i - 1)) <= (l - 1 - nx + 1)) {
            res_m++;
            a.push_back(i);
            b.push_back(cnt);
            c.push_back(nx);
            // print(i, cnt, nx);
            nx += (1<<(i - 1));
        }
    }
    print(res_n, res_m);
    for (Int i = 0; i < res_m; i++) {
        print(a[i], b[i], c[i]);
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
const int MAX_N = 1e5;
list<int> G[MAX_N + 1];
VEC<bool> used;
int unused;
VEC<bool> black;
void dfs(int node) {
  if (used[node]) return;
  // DUMP(node, dist);
  used[node] = 1;
  unused--;

  for (auto v : G[node]) {
    dfs(v);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  REP(i, 0, M) {
    int a, b;
    LL c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  used = VEC<bool>(N, 0);
  int cnt = 0;
  unused = N;
  REP(i, 0, N) {
    // DUMP(unused);
    int prev = unused;
    dfs(i);
    if (unused != prev) cnt++;
    if (unused == 0) break;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10**10
def bfs(graph, visited, position, root):
    visited[root] = 1
    position[root] = 0
    deq = deque([root])
    while(deq):
        cur = deq.pop()
        # print(cur)
        for nxt, dist in graph[cur]:
            if position[cur] + dist != position[nxt]:
                if position[nxt] != INF:
                    return False
                else:
                    position[nxt] = position[cur] + dist
            if not visited[nxt]:
                deq.append(nxt)
                visited[nxt] = 1

    return True

def main():
    n, l = getList()
    nums = getList()
    flag = False
    for i in range(n - 1):
        if nums[i] + nums[i + 1] >= l:
            flag = True
            index = 1 + i
            break

    if not flag:
        print("Impossible")
        return

    else:
        print("Possible")
        for i in range(1, index):
            print(i)
        for i in range(n-1, index, -1):
            print(i)
            
        print(index)
if __name__ == "__main__":

    main()

Measured memory_bytes: 59872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll ans=0;
  if(s[0]!=s[s.size()-1]){
      rep(i,s.size()-1){
        int cnt=0;
        while(i<s.size() && s[i]==s[i+1]){
          cnt++;
          i++;
        }
        ans+=(cnt+1)/2*k;
      }
  }
  else{
    int fir=0,en=0,fircnt=0,encnt=0;
    int temp=0;
    while(temp<s.size() && s[temp]==s[0]){
      temp++;
      fir++;
      fircnt++;
    }
    temp=s.size()-1;
    en=temp;
    while(temp>=0 && s[temp]==s[s.size()-1]){
      temp--;
      en--;
      encnt++;
    }
    for(int i=fir;i<=en;i++){
      int cnt=0;
      while(i<=en && s[i]==s[i+1]){
        cnt++;
        i++;
      }
      ans+=(cnt+1)/2*k;
    }
    if(fircnt+encnt==2*s.size()){
      cout << ((k*(ll)s.size())/2) << endl;
      return 0;
    }
    ans+=fircnt/2;
    ans+=encnt/2;
    ans+=(fircnt+encnt)/2*(max((ll)0,k-1));
  }
  cout << ans << endl;
return 0;}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1e9;
const int MAX_LEFT = 500 * 101 + 1;
class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        if(N == 0) return false;
        vector<int> P(N); cin >> P;
        
        vector<vector<pii>> DP(N + 1, vector<pii>(MAX_LEFT, make_pair(0, -INF))); // := (500???, ?????£??????)
        DP[0][0] = make_pair(0, 0);
        rep(n, N) {
            rep(left, MAX_LEFT) {
                int num  = DP[n][left].first;
                int used = DP[n][left].second * -1;
                if(used >= INF) continue;
                
                // ????????????
                set_max(DP[n + 1][left], DP[n][left]);
                
                used += P[n];
                
                int p = P[n] % 1000;
                if(p == 0) {
                    if(left >= 500) {
                        set_max(DP[n + 1][left - 500], pii(num + 1, -1 * used));
                    }
                } else if(p <= 500) {
                    int add = 500 - p;
                    set_max(DP[n + 1][left + add], pii(num + 1, -1 * used));
                    
                } else {
                    int need = p - 500;
                    if(left >= need) 
                        set_max(DP[n + 1][left - need], pii(num + 1, -1 * used));
                    else { // ?°?????????????
                        int add = 1000 - p;
                        set_max(DP[n + 1][left + add], pii(num, -1 * used));   
                    }
                }
            }
        }
        pii ans(-1, 0);
        rep(i, MAX_LEFT) set_max(ans, DP[N][i]);
        cout << ans.first << " " << ans.second * -1 << endl;
        return true;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        Solver s;
        if(!s.solve()) break;
    }
    return 0;
}

Measured memory_bytes: 43104
#include <bits/stdc++.h>
using namespace std;
 
#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;
 
int main(){
    int n;cin >>n;
    int a[n];rep{
        cin >> a[i];
    }
    sort(a,a+n);
    long long ans = 1;
    int i = n-1;int bi = n-1;
    while(i>= 0){
        if(a[i] != bi){
            ans = 0;
        }
        if(i%2==n%2){
            bi -=2;ans *= 2;
        }
        i--;
        ans = ans % MOD;
        //cout << i <<" "<< ans << " " << bi << endl;
    }
    cout << ans << endl;
}

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

long long A[100000];

int main(){
  int N;
  long long K;
  std::cin>>N>>K;
  for(int i=0;i<N;++i){
    std::cin>>A[i];
  }
  long long dp[2][41];
  for(int i=0;i<2;++i)for(int j=0;j<41;++j)dp[i][j]=-(1LL<<60);
  dp[0][40]=0;//0:strict, 1:loose
  for(int i=39;i>=0;--i){
    long long sum=0;
    for(int num=0;num<=1;++num){
      if(dp[1][i+1]<0)continue;
      sum=0;
      for(int j=0;j<N;++j)sum+=((A[j]>>i)&1)^num;
      dp[1][i]=std::max(dp[1][i],dp[1][i+1]+sum*(1LL<<i));
    }
    for(int num=0;num<=(K>>i)%2;++num){
      if(dp[0][i+1]<0)continue;
      sum=0;
      for(int j=0;j<N;++j)sum+=((A[j]>>i)&1)^num;
      if(num<(K>>i)%2)
	dp[1][i]=std::max(dp[1][i],dp[0][i+1]+sum*(1LL<<i));
      else
	dp[0][i]=std::max(dp[0][i],dp[0][i+1]+sum*(1LL<<i));
    }
  }
  std::cout<<std::max(dp[0][0],dp[1][0])<<std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define WHITE 1
#define BLACK 0
#define GLAY 3
#define N 102
int g[N][N],d[N],f[N],color[N],k[N];
int time,u,v,n;
  
void DFSVisit(int u){
  int i;
  color[u] = GLAY;
  d[u] = ++time;
  for(i = 0;i < k[u];i++){
    if(color[g[u][i]] ==  WHITE){
      DFSVisit(g[u][i]);
       }
       }
  color[u] = BLACK;
  f[u] = ++time;
}
  
void DFS(){
  int i;
  for(i = 1;i <=n; i++){
    color[i] = WHITE;
  }
    time = 0;
  for(i = 0; i < n;i++){
    if(color[i] == WHITE){
        DFSVisit(i);
    }
  }
  }
  
int main(){
  int i,j,l;
  scanf("%d",&n);
  
  for(i = 0;i < n; i++){
    scanf("%d",&u);
    scanf("%d",&l);
    k[u] = l;
    for(j = 0;j < k[u];j++){
      scanf("%d",&v);
      g[u][j] = v;
    }
  }
  
  
      DFS();
    for(i = 1; i <=n;i++){
      printf("%d %d %d\n", i,d[i],f[i]);
    }
    return 0;
  }

Measured memory_bytes: 636
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

struct S {
    mint a;
    int size;
};

using F = int;

S op(S l, S r) { return S{l.a * mint(10).pow(r.size) + r.a, l.size + r.size}; }

S e() { return S{0, 0}; }

F id() { return -1; }

S mapping(F f, S x) {
    if (f == id()) return x;
    return S{(mint(10).pow(x.size) - 1) * mint(9).inv() * f, x.size};
}

F composition(F f, F g) {
    if (f == id()) return g;
    return f;
}

int main() {
    int n, q;
    scanf("%d%d", &n, &q);

    vector<S> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = S{1, 1};
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

    for (int i = 0; i < q; i++) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        seg.apply(l - 1, r, d);
        printf("%d\n", seg.all_prod().a.val());
    }
}

Measured memory_bytes: 9856
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
sa = b-a
if sa%2 == 0:
    print(sa//2)
else:
    print(min(a-1, n-b) + 1 + (b-a-1)//2)


Measured memory_bytes: 10384
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    a = in_nl()

    ans = sum(a) - N
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9372
<<NOTE.!
サイコロ I
  次の展開図から得られるサイコロを転がすシミュレーションを行うプログラムを作成してください。
  サイコロの各面には図のとおりに 1 から 6 のラベルが割りあてられています。

  + http://judge.u-aizu.ac.jp/onlinejudge/IMAGE2/ITP1_11_A_1.png
  + http://judge.u-aizu.ac.jp/onlinejudge/IMAGE2/ITP1_11_A_2.png

  入力としてサイコロの各面のラベルに対応する数字と、転がす命令の列が与えられるので、サイコロの上面の数字を出力してください。シミュレーションの初期状態は、図のとおりのラベルの位置でサイコロが置かれているものとします。

Input
  １行目に各面の数字が、図に示すラベルの順番に空白区切りで与えられます。

  ２行目に命令を表す１つの文字列が与えられます。命令はそれぞれ図に示す４方向を表す文字 E、N、S、W を含む文字列です。

Output
  すべての命令を実行した後のサイコロの上面の数を１行に出力してください。

Constraints
    0? 入力されるサイコロの面の数字 ?100
    0? 命令を表す文字列の長さ ?100

Note
  続くシリーズ Dice III, Dice IV では、複数のサイコロを扱うので、サイコロをクラスや構造体で作成しておきましょう。

Sample Input 1
1 2 4 8 16 32
SE

Sample Output 1
8

各面に 1, 2, 4, 8, 16, 32 と書かれたサイコロを S の方向に転がした後、E の方向に転がすと、上面の数字が 8 になります。


Sample Input 2
1 2 4 8 16 32
EESWN

Sample Output 2
32

NOTE

class Dice
  attr_accessor :top, :front, :right, :left, :back, :bottom
  def initialize(faces)
    @top, @front, @right, @left, @back, @bottom = faces
  end

  def move(commands)
    commands.split('').each do |com|
      case com.upcase.to_sym
      when :E
        @top, @right, @bottom, @left = left, top, right, bottom
      when :W
        @top, @right, @bottom, @left = right, bottom, left, top
      when :N
        @top, @front, @bottom, @back = front, bottom, back, top
      when :S
        @top, @front, @bottom, @back = back, top, front, bottom
      end
    end
  end

  def info
    p({ T: @top, F: @front, R: @right, L: @left, Ba: @back, Bt: @bottom })
  end
end

$stdin = DATA if $stdin.eof?

dice = Dice.new(gets.split)
dice.move(gets.strip)

puts dice.top
__END__
1 2 4 8 16 32
EESWN

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

string toString(int n) {
	stringstream ss; ss << n;
	string res; ss >> res;
	return res;
}
int toInt(string s) {
	stringstream ss; ss << s;
	int res; ss >> res;
	return res;
}
string fix(string n, int keta) {
	while (n.size() < keta) {
		n = "0" + n;
	}
	return n;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string a; int L;
	while (cin >> a >> L, a != "0" || L) {
		a = fix(a, L);
		map<string, int> r; r[a] = 0;
		int ans = 0;
		while (++ans) {
			string m = a, M = a;
			sort(ALL(M), greater<char>());
			sort(ALL(m));
			a = fix(toString( toInt(M) - toInt(m) ), L);
			if (r.count(a) > 0) {
				break;
			}
			r[a] = ans;
		}
		cout << r[a] << " " << toInt(a) << " " << ans-r[a] << endl;
	}
}

Measured memory_bytes: 3184
#include<stdio.h>
#include<stdbool.h>
int main(){
  int N,M,i;
  int H[100001],A[100001],B[100001];
  bool t[100001];
  int num=0;
  scanf("%d%d",&N,&M);
  for(int i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  for(int i=0;i<M;i++){
    scanf("%d%d",&A[i],&B[i]);
  }
  for(int i=0;i<N;i++){
    t[i]=true;
  }
  for(int i=0;i<M;i++){
    if(H[A[i]-1]<=H[B[i]-1]){
      t[A[i]-1]=false;
    }
    if(H[A[i]-1]>=H[B[i]-1]){
      t[B[i]-1]=false;
    }
  }
  for(int i=0;i<N;i++){
    if(t[i])
      num++;

  }
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 3000
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+eps)

int x;

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

  string s;
  scan(s);
//  int n = s.size();
  REP(i, 3){
    if(s[i]==s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
//  vint s(n);
//  REP(i, n) scan(s[i]);


  cout << "Good" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1000005;
long long int  dp[N],a[N],n,k;

int main()
{
	cin >> n >> k ;
	
	for(int i = 1 ; i <= n ; i++)  cin >> a[i] ;
	dp[0] = 0;
	dp[1] = 0;
	a[0] = INT_MAX;
	for(int i = 2 ; i <= n ; i++){
		 dp[i] = 1e18;
		 for(int j = 1 ; j <= k ; j++)
		 {
		 	if(i-j >= 0)
		 	dp[i] = min(dp[i] ,dp[i-j]+abs(a[i]-a[i-j]));
		 }
		
	}
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 5152
#include<stdio.h>
#include<stdlib.h>

struct node{

  struct node *right;
  struct node *left;
  struct node *parent;
  int key;

};

typedef struct node * Node;

Node root, NIL;

void insert(int k){

  int H;
  Node y = NIL;
  Node x = root;
  Node z;


  z = malloc(sizeof(struct node));

  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){

    y = x;

    if(z->key < x->key){
      x = x->left;
    }

    else {
      x = x->right;
    }

  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }

  else{
    if(z->key < y->key){
      y->left = z;
    }

    else{
      y->right = z;
    }
    
  }
}

void inorder(Node u){

  if(u == NIL){
    return;

  }

  inorder(u->left);

  printf(" %d",u->key);

  inorder(u->right);

}

void preorder(Node u){

  if(u == NIL){
    return;
  }
  
  printf(" %d", u->key);

  preorder(u->left);
  preorder(u->right);
}


int main(){

  int n, i, x;
  char c[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    
    scanf("%s",c);
    if(strcmp(c,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }

    else if(strcmp(c,"print") == 0){
      
      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");
    }
    
  }

  return 0;

}



Measured memory_bytes: 25184
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sa = b-a;
        int t = 1;
        int x = 0;
        
        for(int i=2;i<sa;i++){
            t += i;
        }
        
        x = t - a;
        
        System.out.println(x);
    }
}


Measured memory_bytes: 35832
s = input()
n = len(s)

rl = []
for i in range(n-1):
    if s[i] != s[i+1] and s[i] == "R":
        rl.append(i)

even = rl[0] + 1
odd = rl[0]
next = 1
ans = [0 for _ in range(n)]

for i in range(n):
    if 0 < i and s[i] == "R" and s[i-1] == "L":
        even = rl[next] + 1
        odd = rl[next]
        next += 1

    if (i % 2 == 0 and even % 2 == 0) or (i % 2 != 0 and even % 2 != 0):
        ans[even] += 1
    else:
        ans[odd] += 1

for i in ans:
    print(i, end=" ")

Measured memory_bytes: 54304
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d\n",(n*3+m)/2);
    return 0;
}


Measured memory_bytes: 128