akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

const char* possible = "POSSIBLE";
const char* impossible = "IMPOSSIBLE";

int n;
int p[252521];
vector<int> children[252521];

int cycle[252521];
int m = 0;
bool cycled[252521];

int calcorder[252521];
int calcorderhead = 0;
int calcordertail = 0;

int it = 0;

#define MAX_DEG 19
int val[252521];
bool deg[MAX_DEG+2];
int tmp[252521];
int tmptail = 0;
void calc(int x){
    REP(i,children[x].size()){
        int v = val[children[x][i]];
        deg[v]=true;
        tmp[tmptail++] = v;
    }
    REP(d,MAX_DEG+1)if(!deg[d]){
        val[x] = d;
        break;
    }
    if(tmptail > MAX_DEG+2){
        REP(i,MAX_DEG+2)deg[i]=false;
        tmptail = 0;
    }else{
        while(tmptail--){
            deg[tmp[tmptail]]=false;
        }
        tmptail = 0;
    }
}

int main(void){
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",p+i);
        p[i]--;
        children[p[i]].push_back(i);
    }
    REP(i,n)it = p[it];
    do{
        cycle[m++] = it;
        cycled[it] = true;
        it = p[it];
    }while(cycle[0]!=it);
    REP(i,m){
        int x = cycle[i];
        REP(j,children[x].size()){
            int y = children[x][j];
            if(cycled[y])continue;
            calcorder[calcordertail++] = y;
        }
    }
    while(calcorderhead != calcordertail){
        int x = calcorder[calcorderhead++];
        REP(j,children[x].size()){
            calcorder[calcordertail++] = children[x][j];
        }
    }
    REP(i,n)val[i] = MAX_DEG+1;
    while(calcordertail--){
        int x = calcorder[calcordertail];
        calc(x);
    }
    // first challenge
    REP(i,m)calc(cycle[i]);
    int tst = val[cycle[0]];
    calc(cycle[0]);
    if(tst == val[cycle[0]]){
        puts(possible);
        return 0;
    }
    REP(i,m-1)calc(cycle[i+1]);
    tst = val[cycle[0]];
    calc(cycle[0]);
    if(tst == val[cycle[0]]){
        puts(possible);
    }else{
        puts(impossible);
    }
    return 0;
}


Measured memory_bytes: 15232
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 
#include <bitset>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

bitset <4000001> bt;
int arr[2000];
int n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	bt[0] = 1;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		bt |= (bt << arr[i]);
		sum += arr[i];
	}
	for (int i = (sum + 1) / 2; true; i++) if (bt[i]) {
		cout << i << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1664
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def keyence20_a():
    H, W, N = map(int, readlines())
    lg = max(H, W)
    ans = (N + lg - 1) // lg
    print(ans)

keyence20_a()

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

int main(){
    int n;
    cin>>n;
    double v[n],tmp;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(v[i]>v[j]){
                tmp=v[i];
                v[i]=v[j];
                v[j]=tmp;
            }
        }
    }

    double ans=(v[0]+v[1])/2;

    for(int i=2;i<n;i++){
        ans=(ans+v[i])/2;
    }

    cout<<ans<<endl;

    return 0;

    
    return 0;

}

Measured memory_bytes: 256
#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>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;
 
int N, M, Q, p[509][509];
signed main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) { int L, R; cin >> L >> R; p[L][R]++; }
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i][j - 1]; }
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i - 1][j]; }
 
	for (int i = 1; i <= Q; i++) {
		int L, R; cin >> L >> R;
		cout << p[R][R] + p[L - 1][L - 1] - p[L - 1][R] - p[R][L - 1] << endl;
	}
	return 0;
}


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

long long N;

int main()
{
  scanf("%lld", &N);

  if(N&1) {
    puts("0");
    return 0;
  }

  long long ans = N/10; N /= 10;
  while(N) ans += N/5, N /= 5;
  printf("%lld\n", ans);

  return 0;
}


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

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

vector<LL> dp, dp2;
LL dfs(int f, LL num){
    if(num <= 0) return 0;
    LL ans = 0;
    if(dp[f] <= num) return dp2[f];

    ans += dfs(f - 1, min(num, dp[f] / 2 + 1) - 1);
    if(num > dp[f] / 2) {
        ans += 1;
        ans += dfs(f - 1, num - (dp[f] / 2) - 1);
    }
    return ans;
}

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

    LL n, k;
    cin >> n >> k;

    dp.assign(n+1, 0), dp2.assign(n+1, 0);
    dp[0] = 1;
    dp2[0] = 1;

    REP(i, n){
        dp[i+1] = dp[i] * 2 + 3;
        dp2[i+1] = dp2[i] * 2 + 1;
    }

    cout << dfs(n, k) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
string ans,a,b;
int n,m;
vvi dp;
void Path(int r,int c){
    if(r == 0 || c == 0) return;
    if(dp[r][c] == dp[r-1][c])
        Path(r-1,c);
    else if(dp[r][c] == dp[r][c-1])
        Path(r,c-1);
    else{
        ans += a[r-1];
        Path(r-1,c-1);
    }
}
int main(){
    cin >> a >> b;
    n = a.length(),m = b.length();
    dp.resize(n+1,vi(m+1,0));
    rep(i,0,n-1){
        rep(j,0,m-1){
            if(a[i] == b[j])
                dp[i+1][j+1] = 1 + dp[i][j];
            else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }
    Path(n,m);
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 38584
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    int n = t%10;
    if(n == 2 || n == 5 || n == 4 || n == 7 || n == 9){
        cout << "hon";
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon";
    }else{
        cout << "bon";
    }
}


Measured memory_bytes: 3616
nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)

Measured memory_bytes: 6728
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define SZ(c) int(c.size())
#define pb push_back
#define loop(i,start,n)  for(int i=start;i<n;i++)
#define rloop(i,start,n)  for(int i=start;i>n;i--)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
const ll inf = 2e9+3;

void solve(){
    int tc=1 ;
    //cin >> tc;
    while(tc--) {
        ll n,m,k,res=0;
        cin >> n >> m >> k;
        vll va(n+1) , vb(m+1);
        ll A=0, B=0;
        loop(i,1,n+1) { cin >> va[i]; va[i] = va[i]+va[i-1]; }
        loop(i,1,m+1) { cin >> vb[i]; vb[i] = vb[i]+vb[i-1]; }
        ll b = m , a = n;
        loop(i,1,n+1) if(va[i]<=k) a = i;
        loop(i,1,m+1) if(vb[i]<=k) b = i;
        loop(i,0,a+1){
            if(vb[b]+va[i] <= k) res = max(res,i+b);
            else b--;
            /*loop(j,0,b+1) {
                if (va[i] + vb[j] <= k) res = max(res,(ll)(i+j));
            }*/
        }
        cout << res;
    }
}

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

Measured memory_bytes: 6340
n = str(input())
N = n[-1]

if N == "3":
  print("bon")
elif N == "0" :
  print("pon")
elif N == "1" :
  print("pon")
elif N == "6":
  print("pon")
elif N == "8":
  print("pon")
else:
  print("hon")

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
using ll = long long int;
int main()
{
    int x, y;
    cin >> x >> y;

    int prize = 0;

    if (x <= 3) {
        prize += (4-x) * 100000;
    }
    if (y <= 3) {
        prize += (4-y) * 100000;
    }
    if (x == 1 && y == 1) {
        prize += 400000;
    }
    cout << prize << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int a = scan.nextInt();

		if(h % a != 0) {
			System.out.println(h / a + 1);
		}else {
			System.out.println(h / a);
		}
	}
}

Measured memory_bytes: 21972
#include<stdio.h>

int main(){
	int num[2], n;
	int i, j;
	for(i=0;i<200;i++){
		if(scanf("%d %d",&num[0],&num[1])==EOF){
			break;
		}
		j = 0;
		n = num[0] + num[1];
		while(n>0){
			n = n/10;
			j++;
		}
		printf("%d\n",j);
	}
	return 0;
}

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

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

  cout << accumulate(D.begin(), D.end(), 0) << endl;
  
  return 0;
}

Measured memory_bytes: 1152
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

ll factor(ll x) {
	ll ret = 1;
	ll tmp = 0;
	for (ll p = 2;;p++) {
		if (x == 1) {
			ret *= tmp + 1;
			break;
		}
		if (x % p == 0) {
			tmp += 1;
			x /= p;
			p--;
			continue;
		}
		ret *= tmp + 1;
		tmp = 0;
	}
	return ret;
}

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

	ll N;
	cin >> N;
	ll ans = 0;

	for (ll i = 1; i <= N; i++) {
		ll ret = factor(i);
		ll tmp = ret;
		ans += i * tmp;
	}

	cout << ans << endl;



EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}


*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

	int A, B, K;
	cin >> K >> A >> B;

	for (int i = A; i <= B; i++) {
		if (i % K == 0) {
			cout << "OK" << endl;;
			goto EndPoint;
		}
	}
	cout << "NG" << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3128
#include <iostream>
#include <stdio.h>

#include <string>

#include <vector>
#include <list>
#include <map>

#include <algorithm>
#include <utility>

using namespace std;

int main(const int argc, const char **argv){
  int A, B;
  scanf("%d %d", &A, &B);

  if(B % A == 0){
    printf("%d", A + B);
  }else{
    printf("%d", B - A);
  }

  return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> town(N);
  vector<int> road1(M);
  vector<int> road2(M);
  
  for (int i = 0; i < M; i++) {
    cin >> road1.at(i) >> road2.at(i);
    town.at(road1.at(i)-1)++;
    town.at(road2.at(i)-1)++;
  }
  for (int i = 0; i <N; i++){
    cout << town.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      char c;
      cin>>c;
      if(c=='A')
        cout<<"T\n";
      else if(c=='T')
        cout<<"A\n";
      else if(c=='G')
        cout<<"C\n";
      else
        cout<<"G\n";
      return 0;
    }

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n;
vector<int> a,b,c;

signed main() {
    rep1(i,30000) {
        if (i%2 == 0 && i%3 == 0) c.pb(i);
        else if (i%2 == 0) a.pb(i);
        else if (i%3 == 0) b.pb(i);
    }
    cin >> n;
    if (n == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    rep(i,min(n-2-n%2, (int)a.size())) cout << a[i] << " ";
    n -= min(n-2-n%2, (int)a.size());
    rep(i,min(n-n%2, (int)b.size())) cout << b[i] << " ";
    n -= min(n-n%2, (int)b.size());
    rep(i,n) cout << c[i] << " ";
    cout << endl;

}




Measured memory_bytes: 640
(let* ((n (read))
       (arr (make-array n
                        :element-type 'fixnum
                        :initial-element 0))
       (ans 0))

  (loop for i from 0 to (1- n)
        do (setf (aref arr i) (1- (read))))

  (defun f (k)
    (cond ((< n ans) (princ "-1"))
          ((= k 1) (princ ans))
          (t (incf ans)
             (f (aref arr k)))))

  (f 0))


Measured memory_bytes: 68192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n){
        cin >> a.at(i);
        a.at(i)--;
    }
    rep(i,n){
        cin >> b.at(i);
    }
    rep(i,n-1){
        cin >> c.at(i);
    }

    int sum = 0;
    rep(i,n){
        sum += b.at(a.at(i));
        if(i > 0 && a.at(i) == a.at(i-1)+1){
            sum += c.at(a.at(i-1));
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3604
<?php
$num = trim(fgets(STDIN)); //数字や文字列
for($i=0;$i<$num;++$i){
    fscanf(STDIN,"%d",$moti[$i]);
}
$uniqueMoti = array_unique($moti);

$countMoti = count($uniqueMoti);

echo $countMoti."\n";
?>


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

int main() {
    int64_t A, B, N;
    cin >> A >> B >> N;
    if(A == 1 or B == 1) {
        cout << 0 << '\n';
        return 0;
    }
    auto f = [&](int64_t x) -> int64_t {
        return (A * x / B) - A * (x / B);
    };
    if(B <= N) cout << f(B - 1) << '\n';
    else cout << f(N) << '\n';
    return 0;
}


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

int main() {
  int N,M;
  vector<int> vec(M);
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> vec.at(i);
  }
  for(int j=0;j<M;j++){
    N-=vec.at(j);
  }
  if(N>=0)cout << N << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	int sum = 0;
	for (int i = 0; i < S.length(); i++) {

		if (S[i] == 'x') sum++;

	}

	if (sum < 8) cout << "YES" << "\n";
	else cout << "NO" << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)

ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
ll intpoint(ll x1, ll y1, ll x2, ll y2) { return ( __gcd(abs(x1-x2),abs(y1-y2))+1); }
bool isvalid(ll x,ll y,ll n,ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int pp = uniform_int_distribution<int>(0, kk-1)(rng);
// ---------------------///////////////---------------------------------
// ---------------------///////////////----------------------------------
// -------------/////////////////---------------------------------///////
vector<ll>v[100011];
ll dist[100011],visited[100011];

void dfs(ll s,ll p){

	visited[s] = 1;

	for(auto x:v[s]){
		if(!visited[x]){
			dfs(x,s);
			dist[s] = max(dist[s],dist[x] + 1);
		}else{
			dist[s] = max(dist[s], dist[x] + 1);
		}
	}
}

struct gg{
	ll first;
	ll second;
};
gg ap[100000+11];

bool fun(gg x, gg y){
	return x.first>y.first;
}


int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
    ll t,i,j,l,r,q,k,kk,m,n,p;
    
    cin>>n>>m;

    for(i=0;i<m;i++){
    	cin>>l>>r;
    	v[l].push_back(r);
    }

    for(i=1;i<=n;i++){
    	ap[i-1].first = v[i].size();
    	ap[i-1].second = i;
    }

    sort(ap,ap+n,fun);

    for(i=0;i<n;i++){
    	if(!visited[ap[i].second]){
    		// cout<<ap[i].second<<" ";
    		dfs(ap[i].second,0);
    	}
    }
    ll ans = 0;
    for(i=1;i<=n;i++){
    	ans = max(ans,dist[i]);
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n, T, A;
   cin >> n >> T >> A;
   vector<int> h(n);
   int ans = 0;
   rep(i, 0, n) {
      cin >> h[i];
      if (abs(T * 1000 - h[i] * 6 - A*1000) < abs(T * 1000 - h[ans] * 6 - A*1000))
         ans = i;
   }
   ans++;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;

#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=(0);i<(n);++i)
#define fill(a,b) memset(a,b,sizeof a);

const int maxn = 510;
char s[maxn][maxn],a[maxn][maxn],b[maxn][maxn];
int n,m;

int main()
{
//	freopen("test.txt","r",stdin);
	scanf("%d %d",&n,&m);
	R(i,n)
	{
	   	scanf("%s",s[i]);
		R(j,m) a[i][j] = b[i][j] = '.';
		if(i&1)
		{
		   	R(j,m-1) a[i][j] = '#';
			R(j,m-1) if(s[i][j] == '#') b[i][j] = '#';
			b[i][m-1] = '#';
		}
		else
		{
		   	F(j,1,m-1) b[i][j] = '#';
			R(j,m-1) if(s[i][j] == '#') a[i][j] = '#';
			a[i][0] = '#';
		}
	}
	R(i,n) puts(a[i]);
	puts("");
	R(i,n) puts(b[i]);
	return 0;
}

Measured memory_bytes: 1536
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	ll N, M, i, ans=0;
	cin >> N >> M;
	i = 1;
	while (i <= sqrt(M)) {
		if (M%i == 0) {
			if (i*N <= M)
				ans = max(ans, i);
			if (M / i * N <= M)
				ans = max(ans, M / i);
		}
		i = i + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long int n,i,ans=0;
  scanf("%ld",&n);
  for(i=1;i<=n;i++){
    if(ans<i*i&&i*i<=n){
      ans=i*i;
    }
  }
  printf("%ld\n",ans);
  return(0);
}
	


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

using namespace std;
int main(){
  int N;
  cin >> N;
  
  int count = 0;
  
  int a = 1;
  while(a*a < N){
    int c = N-a*a;
    if(c%a == 0) count = count +c/a;
    else count = count + c/a + 1;
    a++;
  }
  
  //A<=Bの場合を足す
  count *=2;
  //A==Bの場合を減らす
  count -= (a-1);
  
  cout << count << endl;
    
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
	int N;
	int p[20]={0};
	int i,j,temp,s;
	int ba=0;
	char c[200];
	while(1){
		scanf("%d",&N);
		if(N==0){
			break;
		}
		ba=0;
		for(i=0;i<10;i++){
			p[i]=0;
		}
		scanf("%s",c);
		for(j=0;j<100;j++){
			s=j%N;
			if(c[j]=='M'){
				p[s]++;
			}
			else if(c[j]=='S'){
				ba=ba+p[s];
				p[s]=0;
				ba++;
			}
			else if(c[j]=='L'){
				p[s]=p[s]+ba;
				ba=0;
				p[s]++;
			}
		}
		for(i=0;i<N;i++){
			for(j=N-1;j>i;j--){
				if(p[i]>p[j]){
					temp=p[i];
					p[i]=p[j];
					p[j]=temp;
				}
			}
		}
		for(i=0;i<N;i++){
			printf("%d ",p[i]);
		}
		printf("%d\n",ba);
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
  REP(M){
    --p[i];
  }
  ll ac=0,wa=0;
  map<ll,ll> was;
  set<ll> s;
  REP(M){
    if(S[i]=="AC"&&s.find(p[i])==s.end()){
      s.insert(p[i]);
      ++ac;
      wa+=was[p[i]];
    }else if(S[i]=="WA"&&s.find(p[i])==s.end()){
      if(was.count(p[i])){
        ++was[p[i]];
      }else{
        was[p[i]]=1;
      }
    }
  }
  cout<<ac<<" "<<wa<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m];
    rep(i,n)rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,m) a[i][j]--;
    int ans = n;
    vector<int> nowselect(n);
    vector<int> nowpeople(m);
    rep(i,n) nowselect[i]=0;
    set<int> sports;
    rep(i,m) sports.insert(i);
    while(!sports.empty()){
        int maxsports = -1;
        int maxpeople = -1;
        fill(All(nowpeople),0);
        rep(i,n) nowpeople[a[i][nowselect[i]]]++;
        rep(i,m){
            if(maxpeople<nowpeople[i]){
                maxpeople = nowpeople[i];
                maxsports = i;                
            }
        }
        ans = min(ans,maxpeople);
        sports.erase(maxsports);
        if(sports.empty()) break;
        rep(i,n){
            if(a[i][nowselect[i]]==maxsports){
                int now = nowselect[i];
                while(sports.count(a[i][now])==0) now++;
                nowselect[i]=now;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
    int n; scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

    auto Check = [&](int k) {
        map<int, int> prv;
        for (int i = 1; i < n; ++i) {
            if (a[i] > a[i - 1]) continue;
            if (k == 1) return false;
            int pos = a[i];
            while (!prv.empty() && prv.rbegin()->first > a[i]) prv.erase(prev(prv.end()));
            while (pos > 0 && prv.find(pos) != prv.end() && prv[pos] == k) pos--;
            if (pos == 0) return false;
            if (prv.find(pos) == prv.end()) prv[pos] = 2;
            else prv[pos]++;
            while (!prv.empty() && prv.rbegin()->first > pos) prv.erase(prev(prv.end()));
        }
        return true;
    };

    int ans = n;
    for (int d = 20; d >= 0; --d) {
        if (ans - (1 << d) <= 0) continue;
        if (Check(ans - (1 << d))) ans -= (1 << d);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
package main

import (
  "fmt"
  "sort"
)

func main() {
  var N, A, B int
  fmt.Scan(&N)
  a := make([]int, N)
  for i := range a {
    fmt.Scan(&a[i])
  }
  sort.Sort(sort.Reverse(sort.IntSlice(a)))
  for i := range a {
    if i % 2 == 0 {
      A += a[i]
    } else {
      B += a[i]
    }
  }
  fmt.Println(A - B)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

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

int main(){
    int k; cin >> k;
    ll ans = 0;
    for(int i = 1; i<= k; i++) for(int j = 1; j<= k; j++) for(int l = 1; l<= k; l++){
        ans += gcd(i,gcd(j,l));
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a < b)
	{
		ans += b;
		b--;
	}
	else
	{
		ans += a;
		a--;
	}
	if (a < b)
	{
		ans += b;
		b--;
	}
	else
	{
		ans += a;
		a--;
	}
	cout << ans << endl;
}

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

template<class T>
class segtree {
private:
  ll n=1;
  T unit;
  std::vector<T> dat;
  std::function<T(T,T)> func;
public:
  segtree(){}
  segtree(std::vector<T>& a,T v,std::function<T(T,T)> f){
    build(a,v,f);
  }
  void build(std::vector<T>& a,T v,std::function<T(T,T)> f){
    ll sz=a.size();
    unit=v;
    func=f;
    while(n<sz)n<<=1LL;
    dat.resize(2*n-1,unit);
    for(int i=0;i<sz;++i)dat[i+n-1]=a[i];
    for(int i=n-2;i>=0;--i){
      dat[i]=func(dat[i*2+1],dat[i*2+2]);
    }
  }
  void update(ll idx,ll val){
    idx+=n-1;
    dat[idx]=val;
    while(idx){
      idx--;idx>>=1LL;
      dat[idx]=func(dat[idx*2+1],dat[idx*2+2]);
    }
  }
  T query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
    if(r<0)r=n;
    if( b<=l || r<=a )return unit;
    if( a<=l && r<=b )return dat[k];
    else{
      auto left=query(a,b,2*k+1,l,(l+r)/2);
      auto right=query(a,b,2*k+2,(l+r)/2,r);
      return func(left,right);
    }
  }
};
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
constexpr long long INF = (1LL<<60);
main(){

  ll n;
  string s;
  cin>>n>>s;

  vector<ll> a(n),b(n);
  rep(i,n){
    if(s[i]=='E')a[i]++;
    else if(s[i]=='W')b[i]++;
  }
  function<ll(ll,ll)> sum = [](ll a,ll b)->ll{return a+b;};
  segtree<ll> e(a,0,sum);
  segtree<ll> w(b,0,sum);

  ll ans=INF;
  // left w + right e
  rep(i,n){
    ll tmp = w.query(0,i)+e.query(i+1,n+1);
    chmin(ans,tmp);
  }
  cout<<(ans)<<endl;

}

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

#define o_max(a, b) ((a>b)?a:b)

int main()
{
    int n;
    int x[1000];
    int y[1000];
    double p1=0.0, p2=0.0, p3=0.0, p4=0.0;

    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%d", &x[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d", &y[i]);
        p1 += fabs(x[i] - y[i]);
        p2 += fabs(x[i] - y[i])*fabs(x[i] - y[i]);
        p3 += fabs(x[i] - y[i])*fabs(x[i] - y[i])*fabs(x[i] - y[i]);
        p4 = o_max(p4, abs(x[i]-y[i]));
    }

    p2 = sqrt(p2);
    p3 = pow(p3, 1/3.0);


    printf("%lf\n", p1);
    printf("%lf\n", p2);
    printf("%lf\n", p3);
    printf("%lf\n", p4);



    return 0;
}


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

template<typename T> class Weighted_UnionFind {
public:
  int n;
  vector<int> par, nrank;
  vector<T> wd;
  Weighted_UnionFind(int node_size) : n(node_size), par(n), nrank(n, 0), wd(n, 0) {
    iota(par.begin(), par.end(), 0);
  }
  int root(int x) {
    if (par.at(x) == x) {
      return x;
    } else {
      int parent = root(par.at(x));
      wd.at(x) += wd.at(par.at(x));
      return par.at(x) = parent;
    }
  }
  T weight(int x) {
    root(x);
    return wd.at(x);
  }
  void unit(int x, int y, T w) {
    w += weight(x), w -= weight(y);
    x = par.at(x), y = par.at(y);
    if (x == y) return;
    if (nrank.at(x) < nrank.at(y)) {
      swap(x, y);
      w = -w;
    }
    nrank.at(x) += (nrank.at(x) == nrank.at(y));
    par.at(y) = x;
    wd.at(y) = w;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  T diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  Weighted_UnionFind<int> WU(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    if (WU.same(a, b)) {
      if (WU.diff(a, b) != c) return cout << "No" << "\n", 0;
    } else {
      WU.unit(a, b, c);
    }
  }
  cout << "Yes" << "\n";
}

Measured memory_bytes: 1536
A,B=list(map(int,input().split(" ")))
from collections import defaultdict
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a=prime_factorize(A)
b=prime_factorize(B)
count1=defaultdict(lambda:0)
count2=defaultdict(lambda:0)
for i in range(len(a)):
    count1[a[i]]+=1
for i in range(len(b)):
    count2[b[i]]+=1

c=count1.keys()
d=count2.keys()
num=0
for i in c:
    if i in d:
        num+=1
print(num+1)



Measured memory_bytes: 3316
import sys

N, T = sys.stdin.readline().strip().split()
N = int(N)
T = int(T)

min_cost = 99999999999
for line in sys.stdin.readlines():
    c, t = line.strip().split()
    c = int(c)
    t = int(t)
    if t <= T:
        if c < min_cost:
            min_cost = c

if min_cost > 1000:
    print("TLE")
else:
    print(min_cost)


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

int main(void) {
	int  N,i,j;
	unsigned long  t=0;

	scanf("%d",&N);
	int d[N];
	for(i=0;i<N-1;i++)
	    scanf("%d ",&d[i]);
	scanf("%d",&d[i]);

	for(i=0;i<N;i++)
		for(j=i+1;j<N;j++) 
		  t+=(unsigned long)(d[i]*d[j]);	
	
    printf("%lu",t);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 888

int defX[4] = {-1, 1, 0, 0};
int defY[4] = {0, 0, -1, 1};

int n, m, k, i, j;
char tp[maxN][maxN];
int dist[maxN][maxN];
queue<pair<int, int> > Q;
int best;

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%d%d%d\n", &n, &m, &k);
    for (i = 1; i <= n; i++) scanf("%s\n", tp[i] + 1);

    for (i = 1; i <= n; i++)
        tp[i][0] = tp[i][m + 1] = '#';

    for (i = 1; i <= n; i++)
        tp[0][i] = tp[n + 1][i] = '#';

    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            if (tp[i][j] == 'S')
                Q.push(mp(i, j));

    best = n;

    while (!Q.empty()) {
        int x = Q.front().first;
        int y = Q.front().second;
        Q.pop();

        if (dist[x][y] > k) break;
        best = min(best, x - 1);
        best = min(best, y - 1);
        best = min(best, n - x);
        best = min(best, m - y);

        for (int i = 0; i < 4; i++) {
            int xx = x + defX[i];
            int yy = y + defY[i];

            if (tp[xx][yy] != '.') continue;
            tp[xx][yy] = '#';
            dist[xx][yy] = dist[x][y] + 1;
            Q.push(mp(xx, yy));
        }
    }

    cout << 1 + (best + k - 1) / k;


    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstdlib>
#include<list>
using namespace std;

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

int main()
{
	int n,m,s,g1,g2;
	int i,j,k;
	int M=10000000;
	
	while(1){
		cin >> n >> m >> s >> g1 >> g2;
		if(n==0 && m == 0 && s ==0 && g1 ==0 &&g2==0) break;
		int a[101][101];
		int c[101][101];
		
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				a[i][j]=M;
				c[i][j]=M;
				if(i==j) c[i][j]=0;
			}
		}
		for(i=0;i<m;i++){
			int in1,in2,in3;
			cin >> in1 >> in2 >> in3;
			c[in1][in2] = in3;
		}
		
		for(k=1;k<=n;k++){
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
				}
			}
		}
		
		int mn=M;
		for(i=1;i<=n;i++){
			mn= min(mn, c[s][i] + c[i][g1] + c[i][g2]);
		}
		
		cout << mn << endl;
				
		
	}
	return 0;	
}

Measured memory_bytes: 908
list = []
max_value = 0
sum_value = 0
n = int(input())

for i in range(n):
    value = int(input())
    list.append(value)
    if max_value < value:
        max_value = value
    sum_value = sum_value + list[i]

print(sum_value - int(max_value / 2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    ll MX = 1e18;
    int n,k;
    cin >> n >> k;
    vector<int> neg,pos;
    rep(i,n){
        int temp;cin >> temp;
        if(temp == 0) k--;
        else if(temp < 0) neg.push_back(temp);
        else pos.push_back(temp);
    }
    sort(neg.begin(),neg.end(),greater<int>());
    if(k <= 0){
        cout << 0 << endl;
        return 0;
    }
    int s = pos.size();
    int t = neg.size();
    ll ans = MX;
    ll total = 0;

    if(s >= k){
        total = pos[k-1];
        ans = min(ans,total);
    }
    if(t >= k){
        total = abs(neg[k-1]);
        ans = min(ans,total);
    }

    for(int i = max(0,k-t-1);i<=min(s-1,k-2);i++){
        total = 2*abs(neg[k-i-2]) + pos[i];
        ans = min(ans,total);
    }
    for(int i = max(0,k-s-1);i<=min(t-1,k-2);i++){
        total = 2*pos[k-i-2] + abs(neg[i]);
        ans = min(ans,total);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4056
#include <iostream>
using namespace std;
int main() {
    int N,X;
    int L[1000];
    cin>>N;
    cin>>X;
    for(int i=1;i<=N;i++)
    {
        cin>>L[i];
    }
    int D[1000];
    D[1]=0;
    int count =1;
    for(int i=2;i<=N+1;i++)
    {
        D[i]=D[i-1]+L[i-1];
       
        if(D[i]<=X)
        {
            count++;
        }
    }
    
    cout<<count;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
mods=[0]*k
mods[0]=n//k
for i in range(1,k):
    mods[i]=(n-i)//k+1
# print(mods)
ans=0

for i in range(k):
    if (k-i)%k == i:
        ans+=mods[i]*mods[(k-i)%k]*mods[i]
print(ans)

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

int sum_digit(int x) {
  int sum = 0;
  while (x) {
    div_t q = div(x, 10);
    sum += q.rem;
    x = q.quot;        
  }
  return sum;
}

int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  
  int sum = 0;
  
  for (int i = 1; i <= N; i++) {
  	int n = sum_digit(i);

    if (A <= n && n <= B) sum += i;    
  }
  
  printf("%d\n", sum);
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
void solve()
{
   long long n;
   cin>>n;
   vector<long long> v(n);
   for(int i=0;i<n;i++)
   {
      cin>>v[i];
   }
   vector<int> pref(n);
   pref[0]=v[0];
   for(int i=1;i<n;i++)
   {
   	   pref[i]=v[i]+pref[i-1];
   }

   int ans=INT_MAX;
   for(int i=0;i<n-1;i++)
   {
   	   int temp=abs(pref[i]-(pref[n-1]-pref[i]));

   	   ans=min(ans,temp);
   }
 cout<<ans;

}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,k,ans=0,su=0;
    cin >> n >> k;
    map<ll,ll> a;
    vector<ll> b(n),r(n);
    rep(i,n) {
        r[i]=su;
        cin >> b[i];
        b[i]%=k;
        ll u=(b[i]-1+k)%k;
        if (i+1>=k) a[(k-r[i+1-k])%k]--;
        if (u==0) ans++;
        ans+=a[abs(2*k-u-su)%k];
        a[(k-su)%k]++;
        su=(su+u)%k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15872
a=int(input())
b=sorted([list(map(int,input().split())) for i in range(a)],key=lambda x:x[1])
sofar=0
flag=True
for i in b:
    sofar+=i[0]
    if sofar>i[1]:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

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

int main(){
  vector<vector<int>> c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c.at(i).at(j);
    }
  }
  bool a=false;
  if(c.at(0).at(0)-c.at(0).at(1)==c.at(1).at(0)-c.at(1).at(1)&&c.at(0).at(0)-c.at(0).at(1)==c.at(2).at(0)-c.at(2).at(1)){
    if(c.at(0).at(1)-c.at(0).at(2)==c.at(1).at(1)-c.at(1).at(2)&&c.at(0).at(1)-c.at(0).at(2)==c.at(2).at(1)-c.at(2).at(2)){
      if(c.at(0).at(0)-c.at(1).at(0)==c.at(0).at(1)-c.at(1).at(1)&&c.at(0).at(0)-c.at(1).at(0)==c.at(0).at(2)-c.at(1).at(2)){
        if(c.at(1).at(0)-c.at(2).at(0)==c.at(1).at(1)-c.at(2).at(1)&&c.at(1).at(0)-c.at(2).at(0)==c.at(1).at(2)-c.at(2).at(2)){
          a=true;
        }
      }
    }
  }
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
          
  
  
  
}

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

using namespace std;

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

typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;

int n; ll a, b;

bool f(ll md, const vector<ll>& h){
	auto wh = h;
	rep(i,n) wh[i] -= b * md;
	//b-a * md
	rep(i,n){
		if(wh[i] >0){
			ll su = (wh[i] + a-b-1) /(a-b);
			if(su <= md) md -= su;
			else return false;
		}
	}
	return true;
}



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	cin >>n >> a >>b;
	vector<ll> h(n);
	rep(i,n) cin >> h[i];
	
	sort(all(h));reverse(all(h));
	
	ll hi=h[0]/b+100, lw=0;
	while(hi - lw > 1){
		ll md= (hi + lw) >> 1;
		if( f(md, h))  hi = md;
		else lw = md;
	}

	
	cout << hi << endl;
	return 0;
}



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

int main()
{
 int x,y;
 for(int i=1; i<10; i++)
 {
   for(int j=1; j<10; j++)
   {
     cout<<i<<"x"<<j<<"="<<i*j<<endl;
   }
 }
 return 0;
}

Measured memory_bytes: 1116
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	string s;
	string t = "NWSE";
	vector<int>NWSE(4);
	cin >> s;
	rep(i, s.size()) {
		rep(j, 4) {
			if (s[i] == t[j]) {
				NWSE[j]++;
			}
		}
	}
	bool ans = true;
	if (NWSE[0] > 0 && NWSE[2] == 0) {
		ans = false;
	}
	else if (NWSE[0] == 0 && NWSE[2] > 0) {
		ans = false;
	}
	else if (NWSE[1] > 0 && NWSE[3] == 0) {
		ans = false;
	}
	else if (NWSE[1] == 0 && NWSE[3] > 0) {
		ans = false;
	}

	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	        ArrayList<Integer> a=new ArrayList<>();
	        a.add(1);
	        a.add(3);
	        a.add(5);
	        a.add(7);
	        a.add(8);
	        a.add(10);
	        a.add(12);
	        ArrayList<Integer> b=new ArrayList<>();
	        ArrayList<Integer> c=new ArrayList<>();
b.add(4);
b.add(6);
b.add(9);
b.add(11);
c.add(2);
int x=sc.nextInt();
int y=sc.nextInt();
if((a.contains(x)&&a.contains(y))||(b.contains(x)&&b.contains(y))||(c.contains(x)&&c.contains(y))){
 System.out.println("Yes"); 
}else {
  System.out.println("No");
}
}

	      static long gcd(long a, long b) 
	      { 
	          if (a == 0) 
	              return b; 
	          return gcd(b % a, a); 
	      } 

static long nCr(int n,int r) {
  int dp[][]=new int[2001][2001];
  for(int i=0;i<2001;i++) {
    dp[0][i]=0;
  }
  for(int i=0;i<2001;i++) {
    dp[i][0]=1;
  }
  for(int i=1;i<2001;i++) {
    for(int j=1;j<2001;j++) {
      if(i==j) {
        dp[i][j]=1;
      }else {
        dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
      }
    }
  }
  return dp[n][r];
}


      
}
class pair {
  int src;
 int  des;
 long val;
  pair(int src,int des,long val){
    this.src=src;
    this.des=des;
    this.val=val;
    
  }

//  @Override
//  public int compareTo(pair o) {
//   
//    return this.wt-o.wt;
//  }
}

Measured memory_bytes: 35780
fun main(args: Array<String>) {
    val N = nextInt()
    val A = Array(N) {
        val (x, l) = listOfInt()
        val L = x - l
        val R = x + l
        Pair(L, R)
    } .sortedBy { it.second }
    var max = Int.MIN_VALUE
    var ans = 0
    for (n in 0 until N) {
        if (max <= A[n].first) {
            ans += 1
            max = A[n].second
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 83116
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int w, n;
	cin >> w >> n;
	VI a(w);
	rep(i, w)a[i] = i + 1;
	rep(i, n) {
		int x, y;
		scanf("%d,%d", &x, &y);
		swap(a[x - 1], a[y - 1]);
	}
	rep(i, w) cout << a[i] << endl;
}


Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string ToString(char val);
string ToBase26(unsigned long long self);

int main()
{
	unsigned long long n;
	cin >> n;
	cout << ToBase26(n) << endl;
	return 0;
}

string ToString(char ascii)
{
	return string { ascii };
}

string ToBase26(unsigned long long self)
{
	unsigned long long n = self % 26;
	if (n == 0) n = 26;
	string s = ToString((char)(n + 96));
	if (self == n) return s;
	return ToBase26((self - n) / 26) + s;
}


Measured memory_bytes: 3572