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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

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

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

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


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


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

    i32 n,m; cin >> n >> m;
    vl x(n), y(n), z(n);
    rep(i,n) cin >> x[i] >> y[i] >> z[i];

    i64 answer = 0;
    maxheap<i64> hp, hp_init;
    for(i32 bit = 0; bit < (1<<3); ++bit) {
        // bitが立っているものを最大化、たっていない物を最小化(符号反転して最大化する)
        hp = hp_init;
        for(i32 i = 0; i < n; ++i) {
            i64 tmp_val = ((bit>>2)&1 ? x[i] : -x[i])
                          + ((bit>>1)&1 ? y[i] : -y[i])
                          + ((bit>>0)&1 ? z[i] : -z[i]);
            hp.push(tmp_val);
        }
        i64 tmp_max = 0;
        rep(i,m) {
            tmp_max += hp.top();
            hp.pop();
        }
        chmax(answer, tmp_max);
    }

    cout << answer << '\n';

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

lint pow_mod(lint base,lint expo) { 
   lint ret = 1;
   for(;expo;) { 
      if(expo&1)  ret = (ret*base)%MOD; 

      expo = (expo>>1);
      base = (base*base)%MOD;
   }
   return ret;
}

/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
      lint N;
      cin >> N;
      lint M;
      cin >> M;

      vector<int> assign(M);
      cin >> assign;

      lint sum = accumulate(ALL(assign),0LL);
      if(sum > N){
          cout << -1 << endl;
      }else
      {
          cout << N - sum << endl;
      }
      
}

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

 return 0;
}


Measured memory_bytes: 3688
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt

data class Pos(val x: Double, val y: Double)

fun main() {
    val builder = StringBuilder()

    val (a, b, h, m) = readInputLine().split(" ").map { it.toDouble() }

    val mDeg = PI * 2L * (m / 60.0)
    val mPos = Pos(b * cos(mDeg), b * sin(mDeg))

    val hDeg = PI * 2L * ((h * 60.0 + m) / 720.0)
    val hPos = Pos(a * cos(hDeg), a * sin(hDeg))

    builder.appendln(sqrt((hPos.x - mPos.x) * (hPos.x - mPos.x) + (hPos.y - mPos.y) * (hPos.y - mPos.y)))

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36668
s = int(input())

a = [s]
last = s

while True:
    if last % 2 == 0:
        last //= 2
    else:
        last = last * 3 + 1

        
    if last in a:
        print(len(a) + 1)
        exit()
    else:
        a.append(last)

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

int main() {
  int A, B, C;
  int K;

  cin >> A >> B >> C;
  cin >> K;

  for (int i = 0; i < K; i++) {
    if (A >= B) {
      B = B * 2;
    }
    else {
      C = C * 2;
    }
  }

  if (A < B && B < C) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  }


Measured memory_bytes: 3628
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=2e6+5;
const ll M=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n,k,a[N],dp[N];

int main()
{
	cin>>n>>k;
	ll xord=0;
	for(ll i=0;i<n;i++){cin>>a[i];}
	sort(a,a+n);
	for(ll i=1;i<=M;i++)
	{
		ll mini=0;
		for(ll j=0;j<n;j++)
		{
			if(i-a[j]<0){break;}
			mini|=(dp[i-a[j]]==0);
		}
		dp[i]=mini;
	}
	if(dp[k]){cout<<"First"<<endl;}
	else{cout<<"Second"<<endl;}
}


Measured memory_bytes: 3072
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
tmp = 0
for i in range(N):
  tmp += A[i]
  a.append(tmp)
tmp = 0
for i in range(M):
  tmp += B[i]
  b.append(tmp)

j = len(b)-1
ans = 0
for i in range(len(a)):
  if a[i] > K:
    break
  while a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i+j)
print(ans)
    
  

Measured memory_bytes: 47360
A, B, C, X, Y = map(int, input().split())
mA = min(A,B)
MB = max(A,B)
mXY = min(X,Y)
if A != mA:
    AX = Y
    BY = X
else:
    AX = X
    BY = Y
A = mA
B = MB
X = AX
Y = BY
ans = 0
if A <= C and B <= C:
    ans = A*X + B*Y
else:
    if A + B <= 2*C:
        ans = mXY * (A+B)
        if X > Y:
            ans += A*(X - mXY)
        else:
            ans += B*(Y - mXY)
    else:
        ans = mXY * 2 * C
        if X > Y:
            ans += min(A,2*C)*(X-mXY)
        else:
            ans += min(B,2*C)*(Y-mXY)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define LL long long
#define pii pair<int,int>
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
void solve(){
    int n;
    scanf("%d",&n);
    int a[200005];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    LL ans=0;

    for(int i = 1;i<n;i++){
        ans+=max(a[i-1]-a[i],0);
        a[i]=max(a[i],a[i-1]);
    }
    printf("%lld\n",ans);
}
int main()
{
    int t=1;
    //scanf("%d",&t);
    int T=1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 4560
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int n;
ll arr[450],dp[450][450];
int main()
{  fast

cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i];
for(int i=n;i>=1;i--)
{
	for(int j=i;j<=n;j++)
	{
		if(j==i)
		dp[i][j]=0;
		else
		{dp[i][j]=1e15;
		ll x=0;
		for(int k=i;k<=j;k++)
		x+=arr[k];
			for(int k=i;k<j;k++)
			{
				
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+x);
			}
		}
	}
}
cout<<dp[1][n];


}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, t, a;
    cin >> n >> t >> a;

    int ans = 0;
    double minDist = INT_MAX;

    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        double tmp = t - h * 0.006;
        double dist = abs(tmp - a);
        if (dist < minDist) {
            minDist = dist;
            ans = i + 1;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10)



int main() {

	string s1, s2;
	cin >> s1 >> s2;
	int a = 1;
	int n = s1.length();
	for (int i = 0;i < n;i++) {
		if (s1[i] != s2[i])a = 0;
	}
	
	if (a == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3632
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int



ll N,X,T;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  cin>>N;
   ll a[N] , sum = 0 , mx;

   for(ll i = 0 ; i<N ; i++)
    cin>>a[i];

  mx = a[0];

  for(ll i = 1 ; i<N ;i++){
    if(a[i] <= mx){
      sum += (mx - a[i]);
    }

    else
      mx = a[i];
  }


  cout<<sum<<'\n';


}



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
   solve();

  return 0;
}


Measured memory_bytes: 5148
//　　　　　　/＾>》, -―‐‐＜＾}
//　　　 　./:::::/,≠´:::::;:::ヽ
//　　　　/::::::〃:::::::::／:丿ハ
//　　　./:::::::i{l|:::::／  }::::}
//　　 /:::::::::瓜イ-‐  ´‐ ,'::ﾉ
//　 ./:::::::::|ﾉﾍ{､　(ﾌ _ノﾉ:::イ
//　 |:::::::::::|／}｀ｽ/￣￣￣￣￣/
//.　|:::::::::|(_:::つ/　 FMV　 /　ｶﾀｶﾀ
//.￣￣￣￣￣￣￣￣￣＼/＿＿＿＿＿/￣￣￣￣￣￣￣

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)               //repマクロ
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) //多倍長
#define all(x) (x).begin(), (x).end()                              //先頭と最後を渡す
#define SZ(x) ((int)(x).size())                                    //sizeの返り値をunsigned int型からint型にする
//短くするだけ
#define pb push_back
#define mp make_pair
// 名前の変更
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define cauto const auto &                                      //これいる？
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); //なにこれ
#define itn int                                                 //これいる？
// longlong型を省略して
typedef long long lint;

/* 最大値を更新するテンプレート */
template <class T>
bool umax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
/* 最小値を更新するテンプレ */
template <class T>
bool umin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

int main()
{
  int a[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  if (a[0] > a[1])
  {
    int temp = a[0];
    a[0] = a[1];
    a[1] = temp;
  }
  if (a[0] > a[2])
  {
    int temp = a[0];
    a[0] = a[2];
    a[2] = temp;
  }
  if (a[1] > a[2])
  {
    int temp = a[1];
    a[1] = a[2];
    a[2] = temp;
  }
  if (a[0] == 5 && a[1] == 5 && a[2] == 7)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
}

Measured memory_bytes: 256
import bisect
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print(sum(a[x-d]>0 for d in p[:bisect.bisect(p,x//2)]))


Measured memory_bytes: 7800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = a / 500;
        long c = (a - b * 500) / 5;
        System.out.println(b * 1000 + c * 5);
    }

}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;
int main(void){
    int N, tmp, score[] = {0,0};
    scanf("%d", &N);
    priority_queue<int> A;

    for(int i = 0; i < N; i++){
        scanf("%d", &tmp);
        A.push(tmp);
    }

    tmp = 0;

    while(!A.empty()){
        score[tmp % 2] += A.top();
        A.pop();
        tmp++;
    }

    cout << score[0] - score[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int a;
int b;

void input() {
  cin >> a >> b;
}

void solve() {
  cout << a + b / 2;
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
for i in range(n-1):
    if a[i]+a[i+1]>x:
        a[i+1]=max(0,a[i+1]-(a[i]+a[i+1]-x))
for i in range(n-1):
    if a[i]+a[i+1]>x:
        a[i]=max(0,a[i]-(a[i]+a[i+1]-x))
print(s-sum(a))

Measured memory_bytes: 19988
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define inf 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=10005;

int main(){
	FAST_IO;
	int a;
	int b=0;
	cin >> a;
	for(int i=1;i<=a;i++){
		if(i>=1 && i<=9) b++;
		if(i>=100 && i<=999) b++;
		if(i>=10000 && i<=99999) b++;
	}
	cout << b << endl;
	return 0;
}

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

using namespace std;

int main() {
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    s = min({s, 2 * h, 4 * q});
    d = min(d, 2 * s);

    cout << (n / 2) * d + (n % 2) * s << endl;
    return 0;
}


Measured memory_bytes: 764
import scala.math._

object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toSeq
    println(solve(lines))
  }

  def solve(lines: Seq[String]): String = {
    val Array(a, b) = lines.head.split(" ").map(_.toInt)
    var result = 0
    if (a == b) {
      result = a + b
    } else {
      result = max(a, b) + (max(a, b) - 1)
    }
    result.toString
  }
}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'



// ********** CODE STARTS HERE ****************//

int main()
{
	fastio;
    
    int N,K;
    cin>>N>>K;
    vi p(N);
    fi(N)
        cin >> p[i];
    sort(all(p));
    int ans = 0;
    for(int i=0;i<K;i++)
        ans+=p[i];
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        int M = scan.nextInt();
        long[] A = new long[M];
        for (int i = 0; i < M; i++) {
            A[i] = scan.nextLong();
        }
        long sum = Arrays.stream(A).sum();
        if (N < sum) {
            System.out.println(-1);
        } else {
            System.out.println(N-sum);
        }
    }
}


Measured memory_bytes: 42104
#include <bits/stdc++.h>
#define nmax_def 2200
#define mod_def 1000000007
using namespace std;
typedef long long ll;


ll nCm_array[nmax_def][nmax_def];
void nCm(int N)
{
	ll i, j;
	for (i = 0; i < N; i++)
	{
		for (j = 0; j <= i; j++)
		{
			ll ans;
			if ((j == 0) || (j == i))
				ans = 1;
			else if ((j == 1) || (j == i - 1))
				ans = i;
			else
				ans= nCm_array[i - 1][j] + nCm_array[i - 1][j - 1];
			ans %= mod_def;
			nCm_array[i][j] = ans;
		}
	}
}

int main() {
	ll i, j;
	ll N, K;
	cin >> N >> K;
	nCm(N+10);

	for (i = 1; i <= K; i++)
	{
		ll ans;
		if (N - K + 1 >= i)
			ans = nCm_array[N - K + 1][i] * nCm_array[K - 1][i - 1];
		else
			ans = 0;
		ans %= mod_def;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 33536
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int M;
int color[1010];
bool used[1010];
vector<int>G[1010];
int cnt[2];

bool dfs(int x,int c){
	used[x]=true;
	color[x]=c;
	cnt[c]++;
	REP(i,G[x].size()){
		if(used[G[x][i]]==false){
			bool b=dfs(G[x][i],1-c);
			if(b==false){
				return false;
			}
		}else{
			if(c==color[G[x][i]]){
				return false;
			}
		}
	}
	return true;
}

int main(){
	while(cin>>N>>M,N!=0,M!=0){
		REP(i,N){
			G[i].clear();
			color[i]=-1;
			used[i]=false;
		}
		cnt[0]=0;
		cnt[1]=0;
		REP(i,M){
			int x,y;
			cin>>x>>y;
			x--;y--;
			G[x].push_back(y);
			G[y].push_back(x);
		}
		if(dfs(0,0)==false){
			cout<<0<<endl;
			continue;
		}
		vector<int>ans;
		if(cnt[0]%2==0)ans.push_back(cnt[0]/2);
		if(cnt[1]%2==0&&cnt[0]!=cnt[1])ans.push_back(cnt[1]/2);
		sort(ans.begin(),ans.end());
		cout<<ans.size()<<endl;
		REP(i,ans.size()){
			cout<<ans[i]<<endl;
		}
	}
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
// using std::cin;
// using std::cout;
// using std::endl;
// using std::string;

int main() {
int A=1;

vector <int> vec(5);
for(int k=0; k<5; k++){
    cin >> vec.at(k);
}

for(int k=0; k<5; k++){
    if(vec.at(k) != 0){
        A++;
    }
    else{
        cout << A << endl;
        return 0;
    }
}



}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);i++)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int h, w; cin >> h >> w;
  int a[501][501];
  FOR(i, 1, h+1) {
    FOR(j, 1, w+1) {
      cin >> a[i][j];
    }
  }
  vector<string> ans;

  FOR(i, 1, h+1) {
    FOR(j, 1, w) {
      if(a[i][j]%2 == 1) {
        //ans.pb({i, j, i, j+1});
        ans.pb(to_string(i) + " " +
               to_string(j) + " " +
               to_string(i) + " " +
               to_string(j+1));
        a[i][j]--;
        a[i][j+1]++;
      }
    }
  }

  FOR(i, 1, h) {
    if(a[i][w]%2 == 1) {
      //ans.pb({i, w, i+1, w});
      ans.pb(to_string(i) + " " +
             to_string(w) + " " +
             to_string(i+1) + " " +
             to_string(w));
      a[i][w]--;
      a[i+1][w]++;
    }
  }

  cout << ans.size() << endl;
  REP(i, ans.size()) {
    cout << ans[i] << endl;
  }
  
}


Measured memory_bytes: 13556
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            checked
            {
                string[] s;
#if false
                int N = int.Parse(Console.ReadLine());
#else
                s = Console.ReadLine().Split(' ');
                int N = int.Parse(s[0]);
                int D = int.Parse(s[1]);
#endif

                int[,] v = new int[N,D];

#if true
                for (int i = 0; i < N; i++)
                {
                    s = Console.ReadLine().Split(' ');

                    for (int j = 0; j < D; j++)
                    {
                        v[i, j] = int.Parse(s[j]);
                    }
                }
#else
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(Console.ReadLine());
                }
#endif
                int ans = 0;
                for (int i = 0; i < N; i++)
                {
                    for (int j = i + 1; j < N; j++)
                    {
                        int dist = 0;

                        for (int k = 0; k < D; k++)
                        {
                            dist += (v[i, k] - v[j, k]) * (v[i, k] - v[j, k]);
                        }

                        int distsq = (int)Math.Sqrt(dist);

                        if(distsq * distsq == dist)
                        {
                            ans++;
                        }
                    }
                }

                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 13140
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	queue<ll> coada;

	int k = 0;
	cin >> k;
	if(k <= 9)
	{
		cout << k;
		return 0;
	}
	for(int i = 1; i<= 9; ++i)
	{	
		coada.push(1LL*i);
	}

	int p = 9;

	while(p != k)
	{
		ll x  = coada.front();
		coada.pop();

		ll curr = 0;
		if(x % 10 != 0)
		{
			curr = 1LL*x*10 + (x%10) - 1;
			coada.push(curr);
			p++;
		}
		if(p == k)
		{
			cout << curr;
			return 0;
		}

		p++;
		curr = 1LL*x*10 + (x%10);
		coada.push(curr);
		if(p == k)
		{
			cout << curr;
			return 0;
		}

		if(x % 10 != 9)
		{
			curr = 1LL*x*10 + (x%10) + 1;
			coada.push(curr);
			p++;
		}
		if(p == k)
		{
			cout << curr;
			return 0;
		}
	}


    return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< vector< int > > A(N, vector< int >(N));
	rep(i, N) rep(j, N) cin >> A[i][j];
	vector< int > s(1 << N, 0);
	rep(b, 1 << N) {
		bitset< 16 > bit(b);
		vector< int > g;
		rep(i, N) {
			if (bit[i])
				g.push_back(i);
		}
		M = g.size();
		int tmp = 0;
		rep(i, M) rep(j, M) if (i < j) tmp += A[g[i]][g[j]];
		s[b] = tmp;
	}
	//cout << s;
	vector< int > dp(1 << N, 0);
	rep(b, 1 << N) {
		bitset< 16 > bit(b);
		int nb = b ^ ((1 << N) - 1);
		for (int b2 = nb; b2 > 0; b2 = (b2 - 1) & nb) {
			chmax(dp[b | b2], dp[b] + s[b2]);
		}
	}
	cout << dp[(1 << N) - 1] << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
 
int main(void){
    int i, j, W, H;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0) break;
        for(i=0; i<H; i++){
            for(j=0; j<W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    ll a,b,k;
    cin >> a>>b>>k;
    int total = b-a+1;
    if ((total+(2-1))/2<=k){
        for (int i = 0; i < total; i++)
        {
            cout << a<<endl;
            a++;
        }
    }else{
        for (int i = 0; i < k; i++)
        {
            cout << a<<endl;
            a++;
        }
        for (int i = 0; i < k; i++)
        {
            int cnt = b-k+1+i;
            cout << cnt<<endl;
        }
        
        
    }
}

int main() {
	Main();
	return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

struct edge {
  ll to, cap, rev;
};

vector<vector<edge>> to;
vector<bool> used;
void addE(ll u, ll v, ll w) {
  to[u].push_back({v, w, (ll)to[v].size()});
  to[v].push_back({u, 0, (ll)to[u].size() - 1});
}

ll dfs(ll u, ll t, ll f) {
  assert(f > 0);
  if (u == t) return f;
  used[u] = true;
  for (edge& e : to[u]) {
    if (used[e.to] || e.cap <= 0) continue;
    ll d = dfs(e.to, t, min(f, e.cap));
    if (d == 0) continue;
    e.cap -= d;
    to[e.to][e.rev].cap += d;
    return d;
  }
  return 0;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  while (true) {
    ll m, n;
    cin >> m >> n;
    if (m == 0 && n == 0) break;
    vll bs(m), rs(n);
    rep(i, m) cin >> bs[i];
    rep(i, n) cin >> rs[i];

    to.assign(m + n + 2, vector<edge>());
    rep(i, m) rep(j, n) {
      bool ok = __gcd(bs[i], rs[j]) > 1;
      if (ok) {
        addE(i, m + j, 1);
      }
    }
    rep(i, m) addE(m + n, i, 1);
    rep(j, n) addE(m + j, m + n + 1, 1);

    ll ans = 0;
    while (true) {
      used.assign(m + n + 2, false);
      ll add = dfs(m + n, m + n + 1, INF);
      if (add == 0) {
        cout << ans << endl;
        break;
      } else
        ans += add;
    }
  } // while true

  return 0;
}



Measured memory_bytes: 14420
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	string s;
	int i;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='1') s[i]='9';
		else if(s[i]=='9') s[i]='1';
 	} 
 	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

using namespace std;

int main(int argc, char *argv[]) {
    ll result = 0;
    ll N;
    cin >> N;
    vector<ll> W(N);
    ll sum = 0;
    
    rep(i, N){
        cin >> W[i];
        sum += W[i];
    }
    
    result = sum;
    ll prefix_sum = 0;
    rep(i, N){
        prefix_sum += W[i];
        
        result = min(result, abs(prefix_sum - (sum - prefix_sum)));
    }

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
fn solve() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let (n, m) = (s.len(), t.len());
    let mut memo = vec![vec![0; m + 1]; n + 1];
    for i in 1..n + 1 {
        for j in 1..m + 1 {
            if s[i - 1] == t[j - 1] {
                memo[i][j] = memo[i - 1][j - 1] + 1;
            } else {
                memo[i][j] = max(memo[i][j - 1], memo[i - 1][j]);
            }
        }
    }
    let (mut x, mut y) = (n, m);
    let mut ans = String::new();
    while x != 0 && y != 0 {
        if s[x - 1] == t[y - 1] {
            ans.push(s[x - 1]);
            x -= 1;
            y -= 1;
        } else if memo[x][y] == memo[x - 1][y] {
            x -= 1;
        } else {
            y -= 1;
        }
    }
    println!("{}", ans.chars().rev().collect::<String>());
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 37340
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    ll h, w, m;
    cin >> h >> w >> m;
    vector<P> p(m);
    vector<P> tate(h), yoko(w);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;b--;
        tate[a] = P(tate[a].first + 1, a);
        yoko[b] = P(yoko[b].first + 1, b);
        p[i] = P(a, b);
    }
    sort(ALL(tate), greater<P>());
    sort(ALL(yoko), greater<P>());
    ll res = tate[0].first + yoko[0].first;
    sort(ALL(p));
    for(int i = 0; tate[0].first == tate[i].first; i++){
        for(int j = 0; yoko[0].first == yoko[j].first; j++){
            if(P(tate[i].second, yoko[j].second) != *lower_bound(ALL(p), P(tate[i].second, yoko[j].second))){
                cout << res << endl;
                return 0;
            }
        }
    }
    cout << res - 1 << endl;
}



Measured memory_bytes: 17240
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    ll S = accumulate(arr.begin(), arr.end(), 0LL);
    ll ans = 1e15;
    ll acc = 0;
    for(int i = 0; i < n-1; i++) {
        acc += arr[i];
        ans = min(ans, llabs(S-acc*2));
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1792
n=int(input())
h=list(map(int,input().split()))

count=0
ans=0

for i in range(n-1):
  if h[i]<h[i+1]:
    if ans<count:
      ans=count
      count=0
    else:
      count=0
  else:
    count+=1
    
print(max(ans,count))

Measured memory_bytes: 14252
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	int N;
	cin >> N;
	set<string> S;
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		S.insert(str);
	}
	cout << S.size() << endl;
	return 0;
}

Measured memory_bytes: 19200
#include<stdio.h>
#define N 100

typedef struct{
  int index[1000000];
} NS;

void ISsort(NS *,int,int);

int cnt=0;

int main(){
  int i,n,G[100],m;
  NS ns;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d", &(ns.index[i]) );
  }

  G[0]=1;

  for(i=1; (G[i-1]*3+1)<n ;i++){
    G[i]=G[i-1]*3+1;
  }
  
  m=i;

  for(i=m-1;i>=0;i--) ISsort(&ns,n,G[i] );

  printf("%d\n",m);
  for(i=m-1;i>=0;i--){
    printf("%d",G[i] );
    if(i!=0) printf(" ");
  }
  printf("\n%d\n",cnt);
  for(i=0;i<n;i++) printf("%d\n", ns.index[i] );    

  return 0;
}

void ISsort(NS *ns,int n,int g){
  int i,j,swap;

  for(i=g;i<n;i++){
    swap=ns->index[i];
    j=i-g;
    while(j >= 0 && ns->index[j] > swap){
      ns->index[j+g]=ns->index[j];
      j-=g;
      cnt++;
    }
    ns->index[j+g]=swap;
  }
  
}



Measured memory_bytes: 5764
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        h: usize, w: usize, d: usize,
        a: [[usize; w]; h],
        q: usize,
        lr: [(usize, usize); q],
    }

    let mut i2pos = vec![(0, 0); h*w + 1];
    for y in 0..h {
        for x in 0..w {
            let i = a[y][x];
            i2pos[i] = (x as i64, y as i64);
        }
    }

    let mut cum = vec![0; h*w + 1];
    for i in d+1..=h*w {
        let (x1, y1) = i2pos[i];
        let (x2, y2) = i2pos[i-d];
        cum[i] = cum[i-d] + (x1-x2).abs() + (y1-y2).abs();
    }

    for (l, r) in lr {
        println!("{}", cum[r] - cum[l]);
    }

}


Measured memory_bytes: 8004
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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

int main(){
	
	string s;
	int cnt=0;
	while(cin>>s){
		s=s+'#';
		int now = 0;
		rep(i,s.size()){
			if('0'<=s[i]&&s[i]<='9'){
				now*=10;
				now+=(s[i]-'0');
			}else{
				cnt+=now;
				now=0;	
			}
		}
		
		
	}
	printf("%d\n",cnt);
	
	
}

Measured memory_bytes: 1180
# N, X, T = map(int, input().split())
from functools import reduce
stringN = input()
if len(stringN) == 1:
  sum = int(stringN)
else:
  sum = reduce(lambda a, b: int(a)+int(b), stringN)
if sum % 9 == 0:
  print('Yes')
else:
  print('No')


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


long long calc(string s)
{
     int len = s.length();
     long long sum ;

     sum = stoll(s);
  
    for(int i=1;i<len;i++)
    {
        string left =s.substr(0,i);
        sum += stoll(left) * pow(2,len-i-1);
        
        string right = s.substr(i,len-i);
       
         sum += calc(right);
    
    }

   return sum;
}



int main()
{
    string s;
    cin>>s;
  
  long long sum = calc(s);
  
  cout<<sum<<endl;

}



//standlineさん参考


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

int main(){
    int A, B;
    std::cin >> A >> B;

    int r = ((B - 1) % (A - 1) > 0)? 1 : 0;
    int nums = (B - 1) / (A - 1) + r;

    std::cout << nums << std::endl;
}

Measured memory_bytes: 3604
mod = 998244353
S,K = input().split()
a = []
c = 0
for i in range(len(S)):
    if S[i]=='0':
        a.append(c)
        c = 0
    else:
        c += 1
if S[-1]=='1':
    a.append(c)
a = a[::-1]
K = min(sum(a),int(K))
N = len(a)
dp = [[[0]*(K+1) for _ in range(K+1)] for _ in range(N+1)]
dp[0][0][0] = 1
for i in range(N):
    for j in range(K+1):
        for k in range(j+1):
            for l in range(a[i]+1):
                if j+l>K:
                    break
                dp[i+1][j+l][k+l] += dp[i][j][k]
                dp[i+1][j+l][k+l] %= mod
            for l in range(1,k+1):
                dp[i+1][j][k-l] += dp[i][j][k]
                dp[i+1][j][k-l] %= mod
                
ans = 0
for k in range(K+1):
    ans += dp[N][k][0]
    ans %= mod
print(ans)

Measured memory_bytes: 102772
n,m=map(int,input().split())
a=[0]*n
ans=0
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if a[p]!=1:
    if s=='WA':a[p]-=1
    else:
      ans-=a[p]
      a[p]=1
for i in range(n):
  a[i]=max(a[i],0)
print(sum(a),ans)

Measured memory_bytes: 9636
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var digsum = 0;
        for (int i = 1; i <= 100000; i *= 10)
        {
            if (n == i)
            {
                Console.WriteLine(10);
                return;
            }

            digsum += n / i % 10;
        }

        Console.WriteLine(digsum);
    }
}


Measured memory_bytes: 11220
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
int main(){
    CPPinput;
    int n,k; cin>>n>>k;
    for(int i=1;i<=n;++i)cin>>a[i];
    int x=-1;
    for(int i=1;i<=n;++i)if(a[i]==1)x=i;
    int l=x,r=x,ans=0;
    while(l>1 || r<n){
        if(l>1){
            int ext=(l-1);
            int t=(ext-1)/(k-1)+1;
            int more=t*(k-1)-ext;
            ans+=t;
            l=1;
            r+=more;
        }
        else{
            ++ans;
            r+=k-1;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
#define INF 10000000000000000
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef pair<pii, pii> piiii;

const int MAXN = 1000100, MAXK = 35;
const ll MOD = 1e9+7;

int main()
{
    FAST_IO;

    ll n; cin >> n;
    ll ans = n*(n-1)/2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256