akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

    int h=0, w=0, H, W, N, i, j, k=1;

    // スペース・改行の手前で一旦代入される。 
    scanf("%d", &H);
    scanf("%d", &W);
    scanf("%d", &N);

    int a[N+1];
    int map[H][W];
    int all = H * W;

    for(i=1; i<N+1; i++) {
        scanf("%d", &a[i]);
    }

    j=1;
    for(i=0; i<all; i++) {
        if(h%2 == 0) {
            map[h][w] = j;
            if(w == W-1) {
                h++;
            }
            else w++;
        }
        else {
            map[h][w] = j;
            if(w == 0) {
                h++;
            }
            else w--;
        }
        if(k==a[j]) {
            k = 1;
            j++;
        }
        else k++;
    }
    for(h=0; h<H; h++) {
        for(w=0; w<W; w++) {
            printf("%d ", map[h][w]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 384
// At Coder :: Beginner Contest 178 :: E - Dist Max
// https://atcoder.jp/contests/abc178/tasks/abc178_e

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<pair<int, int>> points;
    points.reserve(N);
    for (int i{0}; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        points.emplace_back(x, y);
    }
    // Manhattan distance is |x1 - x2| + |y1 - y2|
    // If it is the case that both x1 > x2 and y1 > y2 then
    // |x1-x2| + |y1-y2| = (x1-x2) + (y1-y2) = (x1+y1) - (x2+y2)
    // so we want to find the maximum x1+y1 and the minimum x2+y2
    auto p0{min_element(points.begin(), points.end(), 
                            [](pair<int, int> l, pair<int, int> r) {
                                return l.first + l.second < r.first + r.second;
                            }
                       )};
    auto p1{max_element(points.begin(), points.end(), 
                            [](pair<int, int> l, pair<int, int> r) {
                                return l.first + l.second < r.first + r.second;
                            }
                       )};

    // If it is the case that x1 > x2 but y2 > x2 then
    // |x1-x2| + |y1-y2| = (x1-x2) + (y2-y1) = (x1-y1) + (y2-x2)
    // so we want the maximum x1-y1 point and the maximum y2-x2 point.
    auto p2{max_element(points.begin(), points.end(), 
                            [](pair<int, int> l, pair<int, int> r) {
                                return l.first - l.second < r.first - r.second;
                            }
                       )};
    auto p3{max_element(points.begin(), points.end(), 
                            [](pair<int, int> l, pair<int, int> r) {
                                return l.second - l.first < r.second - r.first;
                            }
                       )};
    
    // The solution is the max of two possible cases.
    int soln{max(((p1->first + p1->second) - (p0->first + p0->second)),
                 ((p2->first - p2->second) + (p3->second - p3->first)))};
    cout << soln << "\n";
    return EXIT_SUCCESS;
}


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

using namespace std;
static const int MAX = 1400;
int G[MAX][MAX], dp[MAX][MAX];
int getLargestSquare( int H, int W ) {
	int maxWidth = 0;

    for( int i = 0; i < H; i++ )
    	for( int j = 0; j < W; j++ ) {
    	   		dp[i][j] = !G[i][j] ;
    	   		maxWidth |= dp[i][j];
    	}
    
    for( int i = 1; i < H; i++ )
    	for( int j = 1; j < W; j++ ) {
    		if( G[i][j] ) dp[i][j] = 0;
    		else {
    			dp[i][j] = min( dp[i -1][j -1], min(dp[i - 1][j], dp[i][j-1]) ) + 1;
    			maxWidth = max( maxWidth, dp[i][j]);
    		}
    	} 
	return maxWidth * maxWidth;
}
int main() {
	int H, W;

	cin >> H >> W;
	for( int i = 0; i < H; i++ )
		for( int j =0; j < W; j++ ) cin >> G[i][j];

	cout << getLargestSquare( H, W ) << endl;

}



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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

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

    int res = -1;
    rep(i, N-1) {
        if (L <= A[i] + A[i+1]) {
            res = i;
            break;
        }
    }

    if (res < 0) {
        puts("Impossible");
        return 0;
    }

    puts("Possible");
    rep(i, res) {
        cout << i + 1 << endl;
    }

    for (int i = N-2; i > res; --i) {
        cout << i + 1 << endl;
    }

    cout << res + 1 << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> m;
  rep(i, N) {
    cin >> A[i];
    m[A[i]]++;
  }

  int ans = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if ((itr->se) % 2)
      ans++;
  }
  cout << ans << endl;
}

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1e18+9
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}


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

    ll x,y; 

    ll mx1=-inf, mn1=inf, mx2=-inf, mn2=inf;
    for(ll i=1;i<=N;i++) {
        cin>>x>>y;
        mx1 = max(mx1,x+y);
        mn1 = min(mn1,x+y);
        mx2 = max(mx2,x-y);
        mn2 = min(mn2,x-y);
    }

    ll ans = max(mx1-mn1,mx2-mn2);
    cout<<ans<<endl;



}






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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M, Q;
    cin >> N >> M >> Q;

    vector<vector<ll>> a(N, vector<ll>(N, 0));
    rep (i, M) {
        ll L, R;
        cin >> L >> R;
        L--;
        R--;
        a[L][R]++;
    }

    vector<vector<ll>> s(N+1, vector<ll>(N+1, 0));
    rep (i, N) {
        rep (j, N) {
            s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + a[i][j];
        }
    }

    rep (i, Q) {
        ll p, q;
        cin >> p >> q;
        p--;
        cout << s[q][q] - s[p][q] - s[q][p] + s[p][p] << endl;
    }
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int vector_finder(std::vector<int> vec, int number) { //数値検索
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
int main(){
  
  int x;
  std::cin >> x;
  std::vector<int> a;
  a.pb(1);
  rrep(i,2,1000){
    rrep(j,2,1000){
      int d=pow(i,j);
      if(d<=x)a.pb(d);
      else break;
    }
  }
  sort(all(a),greater<int>());
  std::cout << a[0] << std::endl;
  
}

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

const int N=5e3+100;
int n,mod,f[2][N],s[N],c[N],Ans;

void Inc(int &x,int y) {x+=y, x>=mod?x-=mod:233;}

int main()
{
	scanf("%d%d",&n,&mod);
	f[1][0]=1; c[2]=1; for(int i=3,j=n;i<=j;++i,--j) c[i]=c[j]=i-1;
	for(int i=2;i<=n;++i)
	{
		int op=(i&1);
		for(int j=0;j<c[i];++j) s[j]=0;
		for(int j=0;j<=n;++j)
			Inc(s[j%c[i]], f[op^1][j]), f[op][j]=s[j%c[i]];
	 }
	 for(int i=0;i<=n;++i)
	 	Inc(Ans, 1ll*(n-i)*f[n&1][i]%mod);
	 printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 384
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1):
        if 10000*i+5000*j+1000*(n-i-j) == y and n-i-j >= 0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int date[10000],i=0,c=1;
    
    while(1){
      if(i>=10000)break;
      scanf("%d",&date[i]);
      if(date[i]==0)break;
      i++;
    }
    i=0;
    while(1){
      if(date[i]==0)break;
      if(date[i]!=0){
	
	printf("Case %d: %d\n",c,date[i]);
	c++;
	i++;
     

      }

      
    }
    return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,i,j,k;
    cin >> n >> k;
    long long int a[n];
    long long int dp[n+1];
    for(i=0;i<n;i++){
        cin >> a[i];
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for(i=2;i<n;i++){
        for(j=1;j<=k;j++){
            if(i-j>=0){
                dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
            }
        }
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#include <algorithm>
#define NMAX (int )1e5+5

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

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

int N,ans = 0,M = -1;
char animal[4][NMAX],truth[NMAX];
char S[NMAX];
string dx[4] = {"SS","SW","WS","WW"};
bool check(int a,int b){
	if(truth[b] == 'o'){
		if(animal[a][b-1] == animal[a][b+1]){
			return true;
		}else{
			return false;
		}
	}else{
		if(animal[a][b-1] != animal[a][b+1]){
			return true;
		}else{
			return false;
		}
	}
}
void made(int a,int b){
	if(truth[b] == 'o'){
		animal[a][b+1] = animal[a][b-1];
	}else{
		if(animal[a][b-1] == 'S'){
			animal[a][b+1] = 'W';
		}else{
			animal[a][b+1] = 'S';
		}
	}
}

int solve(int a){
	animal[a][0] = dx[a][0];
	animal[a][1] = dx[a][1];
	animal[a][N] = animal[a][0];
	for (int i = 0; i < N; ++i)
	{
		if(animal[a][i] == 'S'){
			truth[i] = S[i];
		}else{
			if(S[i] == 'o'){
				truth[i] = 'x';
			}else{
				truth[i] = 'o';
			}
		}
		if(i == N-1){
			if(!check(a,i)){
				return -1;
			}else{
				if((truth[0] == 'o' && animal[a][N-1] != animal[a][1]) 
					|| (truth[0] == 'x' && animal[a][N-1] == animal[a][1])){
					return -1;
				}
			}
		}else if(i != 0){
			made(a,i);
		}
	}
	for (int j = 0; j < N; ++j)
	{
		cout << animal[a][j];
	}
	cout << "\n";
	return 0;
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> S[i];
	}
	for (int i = 0; i < 4; ++i)
	{
		M = max(solve(i),M);
			if(M == 0){
				return 0;
			}
		}
		if(M == -1){
			cout << M << endl;
		}

	#ifdef DEBUG
		debug();
	#endif
	// answer();

		return 0;
	}

Measured memory_bytes: 896
class Combination
  def initialize(n=10000,mod=10**9+7)
    @n,@mod=n,mod
    @fact =  Array.new(n+1)
    @fact[0]=1
    1.upto(n) {|i|@fact[i]=i*@fact[i-1]% @mod}
  end

  def choose(n, r)
    return 0 unless (0 <= r && r <= n)
    return 1 if r == 0 || r == n
    fact(n) * inv( fact(r) * fact(n-r) % @mod ) % @mod
  end

  def mod
    @mod
  end

  def fact(n)
    @fact[n]
  end

  def inv(x)
    pow(x, @mod-2)
  end

  def pow(x, n)
    ans = 1
    while n > 0
      ans = ans * x % @mod if n.odd?
      x = x * x % @mod
      n >>= 1
    end
    ans
  end
end
io = STDIN
n,k=io.gets.split.map(&:to_i)
comb=Combination.new(n)
1.upto(k) do |i|
  p comb.choose(k-1,i-1)*comb.choose(n-k+1,i)%comb.mod
end


Measured memory_bytes: 2044
//
// Created by Tnecesoc on 2017/4/14.
//

#include <stdio.h>
#include <bitset>

using namespace std;

const int MAX_R = 20;
const int MAX_C = 10000 + 10;

int field[MAX_R][MAX_C];

bitset<MAX_C> toast[MAX_R];

void solve(int fr, int r, int c, int &min) {

    if (fr >= r) {

        int sum = 0;

        for (int i = 0; i < c; ++i) {
            int row_sum = 0;
            for (int j = 0; j < r; ++j) {
                if (toast[j][i]) {
                    row_sum++;
                }
            }

            sum += row_sum < r - row_sum ? row_sum : r - row_sum;
        }

        if (min > sum) {
            min = sum;
        }

        return;
    } else {

        solve(fr + 1, r, c, min);

        toast[fr].flip();

        solve(fr + 1, r, c, min);

    }

}

int main() {
    
    int r, c;
    while (~scanf("%d %d", &r, &c), r | c) {
        for (int i = 0; i < r; ++i) {
            for (int j = 0; j < c; ++j) {
                scanf("%d", &field[i][j]);
                toast[i].set((size_t) j, (bool) field[i][j]);
            }
        }

        int ans = 0x7fffffff;
        solve(0, r, c, ans);
        printf("%d\n", r * c - ans);
    }

    return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  while(cin >> n, n) {
    map<char, char> mp;
    REP(i,n) {
      char a,b;
      cin >> a >> b;
      mp[a] = b;
    }
    int m;
    cin >> m;
    string s;
    REP(i,m) {
      char a;
      cin >> a;
      if (mp[a])
        s += mp[a];
      else
        s += a;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1108
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val K = sc.nextLong()

    def a(N: Int, applyCnt: Long): Long = {
      N - 1 + applyCnt * N - K + applyCnt
    }

    val A_MAX = 100000000L * 100000000 + 1000
    def validate(a: Long): Boolean = 0 <= a && a <= A_MAX

    def ok(N: Int): Boolean = {
      val a0 = a(N, K / N)
      val a1 = a(N, K / N + 1)
      if (K % N == 0) validate(a0)
      else validate(a0) && validate(a1)
    }

    val N = ((2 to 50) find ok).get
    val cnt1 = (K % N).toInt
    val cnt0 = N - cnt1
    val a0 = a(N, K / N)
    val a1 = a(N, K / N + 1)

    out.println(N)
    out.println((map(cnt0)(_ => a0) ++ map(cnt1)(_ => a1)).mkString(" "))
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    (0 until n) foreach f
  }

  private def map[@specialized(Int, Long) A](n: Int)(f: Int => A): Seq[A] = {
    (0 until n) map f
  }
}


Measured memory_bytes: 25540
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
	string s;
	cin >> s;
	string ans = "";
	for (int i = 0; i < (int) s.size(); i++){
		if (s[i] == 'B' && ans.size() > 0) ans = ans.substr(0, ans.size()-1);
		else if (s[i] != 'B') ans += s[i];
	}
	cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3604
N = int(input())
A = list(map(int, input().split()))

while True:
    if len(A) == 1:
        print(A[0])
        break
    A.sort()
    A = [A[0]] + [x % A[0] for x in A[1:]]
    A = [x for x in A if x != 0]

Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
#include<string>
#include<climits>
using namespace std;
#define INF INT_MAX
int n;
string ans;
int d[26];
int main(){
	for(int i=0;i<26;i++)d[i]=INF;
	cin>>n;
	for(int i=0;i<n;i++){
		string st;
		cin>>st;
		int nd[26]={};
		for(int j=0;j<st.size();j++){
			nd[st[j]-'a']++;
		}
		for(int j=0;j<26;j++){
			d[j]=min(d[j],nd[j]);
		}
	}
	for(int i=0;i<26;i++){
		if(d[i]==INF)continue;
		for(int j=0;j<d[i];j++)ans+=('a'+i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        boolean [] sit =  new boolean[100000];

        for(int i=0;i<sit.length;i++){
            sit[i] = false;
        }

        for(int i=0;i<n;i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            l--;r--;
            for(int j=l;j<=r;j++){
                sit[j] = true;
            }
        }
        int cnt=0;
        for(int i=0;i<sit.length;i++){
            if(sit[i])cnt++;
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 26212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;
  cin >> n;
  vector<int> d(n);
  for(int i =0;i<n;i++){
    cin>>d[i];
  }
  ans=0;
  for(int i=0;i<n;i++){
  for(int j=i+1;j<n;j++){
    ans+=d[i]*d[j];
  }
  }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	string s[3];cin >> s[0] >> s[1] >> s[2];
	char c = s[0][0];int k;
	char q[3];q[0] = 'A'; q[1] = 'B';q[2] = 'C';
	int a[3];rep(i, 3) a[i] = 0;
	while (true) {
		string t = s[c - 'a'];
		if (t.empty()) {
			k = c - 'a';
			break;
		}
		s[c - 'a'].erase(0,1);
		c = t[0];
	}
	cout << q[k] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

const int N = 2050;

typedef long long LL;

inline int readInt() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}

inline int getBW() {
  int c;
  while (isspace(c = getchar()));
  return c == 'B';
}

int n, ty[N * 2], a[N * 2];
int fb[N * 2][N], fw[N * 2][N];
int f[N][N], pw[N], pb[N];

inline void chk(int &a, int b) { a = std::min(a, b); }

int main() {
  n = readInt();
  for (int i = 1; i <= 2 * n; ++i) {
    ty[i] = getBW();
    a[i] = readInt();
    if (ty[i] == 1) pb[a[i]] = i;
    else pw[a[i]] = i;
  }
  for (int i = 1; i <= 2 * n; ++i) {
    for (int j = 0; j < n; ++j)
      fb[i][j] = fb[i - 1][j] + (ty[i] == 1 && a[i] > j);
    for (int j = 0; j < n; ++j)
      fw[i][j] = fw[i - 1][j] + (ty[i] == 0 && a[i] > j);
  }
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j)
      f[i][j] = 1000000000;
  f[0][0] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) {
      if (i < n) {
        int k = pb[i + 1];
        chk(f[i + 1][j], f[i][j] + fb[k - 1][i] + fw[k - 1][j]);
      }
      if (j < n) {
        int k = pw[j + 1];
        chk(f[i][j + 1], f[i][j] + fb[k - 1][i] + fw[k - 1][j]);
      }
    }
  printf("%d\n", f[n][n]);
  return 0;
}


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

char s[111];
int n;
long long tot;

void dfs(int dep, long long sum, long long cur) {
	if(dep==n) {
		tot += sum + cur;
		return;
	}
	if(cur) dfs(dep+1, sum + cur, s[dep] - '0');
	dfs(dep+1, sum, cur*10+s[dep]-'0');
}

int main() {
	cin>>s;
	n = strlen(s);
	tot = 0LL;
	dfs(0, 0LL, 0LL);
	cout<<tot<<endl;
	
	return 0;
}

Measured memory_bytes: 760
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, sum = 0;
    cin >> n;
    vector<int> h(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        sum += h[i];
    }
    h[n] = 0;

    int cnt = 0, minv = 110;

    while (sum > 0) {
        int pos = 0;
        for (int i = 0; i < n + 1; ++i) {
            if (h[i] == 0) {
                if (minv == 110){
                    ++pos;
                    continue;
                }
                cnt += minv;
                for (int j = pos; j < i; ++j) {
                    h[j] -= minv;
                    sum -= minv;
                }
                minv = 110;
                pos = i + 1;
            } else {
                minv = min(minv, h[i]);
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
def mcm(p,n):
	m=[[0 for x in range(n+1)] for x in range(n+1)]
	for s in range(n):
		for i,j in zip(range(1,n+1),range(s+2,n+1)):
			m[i][j] = 1 << 30
			for k in range(i,j):
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	return m[1][n]

n=int(input())
p=[0]*(n+1)
for i in range(n-1):
	t=list(map(int,input().split()))
	p[i]=t[0];
t=list(map(int,input().split()))
p[n-1]=t[0]
p[n]=t[1]

ans=mcm(p,n)
print(ans)



Measured memory_bytes: 5668
#include <stdio.h>

int main(){
    int a, b, c;
    int ans;
    scanf("%d %d %d", &a, &b, &c);
    
    if(c-(a-b) < 0)ans = 0;
    else ans = c-(a-b);
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
H,W,K=map(int,input().split())
s=[[0 for e in range(W)] for f in range(H)]
for  i in range(H):
 s[i]=[d for d in input()]
ans=[[0 for e in range(W)] for f in range(H)]
iti=0
kazu=[0]*H
for i in range(H):
 if "#" in s[i]:
  kazu[i]=1
 else:
  kazu[i]=0
for  i in range(H):
 if kazu[i]==1:
  iti+=1
  fg=0
  for  j in range(W):
   if s[i][j]=="#" :
    fg+=1
    if fg>1:
     iti+=1
   ans[i][j]=iti
for  i in range(1,H):
 if kazu[i]==0:
  for  j in range(W):
   ans[i][j]=ans[i-1][j]
for  i in range(H-1)[::-1]:
 if kazu[i]==0:
  for  j in range(W):
   ans[i][j]=ans[i+1][j]
for  i in range(H):
 print(*ans[i])

Measured memory_bytes: 50908
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

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

    // cout << 1 + ceil(double(n-k)/(k-1)) << endl;

    int res = 0;
    int right = 0;
    while (true) {
      if (res == 0) right += k;
      else right += k-1;
      ++res;

      if (right >= n) break;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

bool ok(const int& p, const int& n, const int& k, const int w[])
{
    int c = 0, sum = 0;
    for(int i = 0; i < n; i++)
    {
        if(w[i] <= p)
        {
            sum += w[i];
            if(sum > p)
            {
                c++;
                sum = w[i];
            }
        }
        else
            return false;
    }
    return c < k;
}

int main() {
    int n,k;
    cin >> n >> k;
    int w[n];
    for(int i = 0; i < n; i++)
        cin >> w[i];
    int l = 0, h = 2000000000;
    while(l+1 < h)
    {
        int m = (l+h)/2;
        if(ok(m,n,k,w)) h = m;
        else l = m;
    }
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
 
using namespace std;
 
 
int n,m,cnt,sum;
string s;
vector <int> v;
int main (){
	cin >> s;
	for (int i = 0; i < s.size(); i++){
		int r;
		r = (s[i] - '0');
		v.push_back(r);
		r = 0;
	}
	for (int i = 0; i < v.size() - 1; i++){
		if (v[i] == v[i + 1]){
			if (v[i] == 1){
				v[i + 1] = 0;
			}
			else {
				v[i + 1] = 1;
			}
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] != t[i]) ++ans;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3792
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[[float('inf')]*(h+1) for i in range(n+1)]
dp[0][0]=0
# print(dp)
for i in range(n):
    for j in range(h+1):
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])
        tmp=j+ab[i][0]
        if j+ab[i][0]>h:
            tmp=h
        # print(min(dp[i][j]+ab[i][1],dp[i+1][tmp]))
        dp[i+1][tmp]=min(dp[i+1][j]+ab[i][1],dp[i+1][tmp])
        # print(dp[i+1][tmp])
# print(dp)
print(dp[-1][-1])

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

struct union_find {
	int N, M;
	std::vector<int> parent, sz;

	union_find(int n) : N(n), M(n) {
		parent.resize(N);
		for (int i = 0; i < N; i++) parent[i] = i;
		sz.resize(N, 1);
	}

	int root(int i) {
		if (parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}

	bool is_united(int i, int j) {return (root(i) == root(j));}

	int size(int i) {return sz[root(i)];}
	std::pair<int, int> size() {return {N, M};}

	bool unite(int i, int j) {
		if (is_united(i, j)) return false;
		if (size(i) < size(j)) std::swap(i, j);
		i = root(i); j = root(j);
		parent[j] = i;
		sz[i] += sz[j];
		M--;
		return false;
	}
};

int main() {
	int n, m;
	std::cin >> n >> m;
	union_find uf(n);
	while (m--) {
		int a, b;
		std::cin >> a >> b;
		uf.unite(a - 1, b - 1);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) ans = std::max(ans, uf.size(i));
	std::cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 4828
#include<stdio.h>
int sidaikou(int,int);
int main(void)
{
	int n;
	int suu[3];
	int a[10000],b[10000];
	int i,p;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d",&suu[i]);
	}
	suu[0]=saidaikou(suu[0],suu[1]);
	if(n==3)	{
		suu[0]=saidaikou(suu[0],suu[2]);
	}
	p=0;
	for(i=1;i*i<=suu[0];i++)	{
		if(suu[0]%i==0)	{
			a[p]=i;
			b[p]=suu[0]/i;
			p++;
		}
	}
	for(i=0;i<p;i++)	{
		printf("%d\n",a[i]);
	}
	if(a[p-1]==b[p-1])	p--;
	for(i=p-1;i>=0;i--)	{
		printf("%d\n",b[i]);
	}
	return 0;
}
int saidaikou(int a,int b)
{
	int ama,wk;
	if(a<b)	{
		wk=a;
		a=b;
		b=wk;
	}
	while(1)	{
		ama=a%b;
		if(ama==0)	{
			return b;
		}
		else {
			a=b;
			b=ama;
		}
	}
}


Measured memory_bytes: 608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();
        if (n <= 10) {
            System.out.println(r + 100 * (10 - n));
        } else {
            System.out.println(r);
        }
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    int res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;


        y = y>>1;
        x = x*x;
    }
    return res;
}
bool isPalindrome(string str)
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = str.length()- 1;

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            return false;
        }
    }
    return true;
}

signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
int ans1=0,ans2=0;
if(n<2)
    ans1=0;
else
    ans1=(n*(n-1))/2;
if(m<1)
    ans2=0;
else
   ans2=(m*(m-1))/2;
cout<<ans1+ans2<<endl;
}









Measured memory_bytes: 256
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstring>
# include <string>
# include <cstdlib>
# include <algorithm>
# include <stack>
# include <queue>
# include <vector>
# define maxx (103)
# define Pi (3.14159265358979)
# define inf (2147483647)
using namespace std;
int a[200009],n;
int read() {
	int x=0,f=1;
	char ch;
	while(ch<'0'||ch>'9')  {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
int main() {
	
	n=read();
	int i;
	for(i = 1;i <= n;i++){
		a[i]=read();
	}
	
	sort(a+1,a+1+n);
	
	for(i = 1;i <= n;i++){
		if(a[i]==a[i+1]){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    long a,b;
    std::cin >>a >> b;
    if(a<=0 && b>=0){
        std::cout << "Zero" << std::endl;
    }else if(a>0 && b>0){
        std::cout << "Positive" << std::endl;
    }else{
        long c=b-a;
        if(c%2==1){
            std::cout << "Positive" << std::endl;
        }else{
            std::cout << "Negative" << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

rooms = [[] for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    rooms[a].append(b)
    rooms[b].append(a)

from collections import deque
checked = [-1]*N
dirc = [-1]*N
def bfs(v):
    queue = deque()
    queue.appendleft((v, 0))
    while queue:
        v, p = queue.pop()
        if checked[v]==1:
            continue
        dirc[v] = p
        checked[v] = 1
        for i in rooms[v]:
            if checked[i]==-1:
                queue.appendleft((i, v))

bfs(0)
if -1 in dirc:
    print('No')
else:
    print('Yes')
    for d in dirc[1:]:
        print(d+1)

Measured memory_bytes: 99644
#ifndef KHOKHO
//#pragma GCC optimize("O3")
#endif
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define ARRS int(1e6+500)
#define MAX ((long long)(1e18+1))
#define EP ((double)(1e-12))
#define HS1 ((ll)(1000001329))
#define HS2 ((ll)(1000001531))
#define MOD ((long long)1000000007ll)
#define AT9 ((long long)1000000000ll)
#define PI 3.14159265358979323846264338327950288419716939937510
#define LG 20

struct so{
	ll x,y,z;
};

bool c1(so a,so b){
	return (a.y - a.z)>(b.y - b.z);
}

so a[ARRS];
ll ba[ARRS];
int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w+",stdout);
	#endif //KHOKHO
	ll n;
	ll x,y,z;
	cin>>x>>y>>z;
	n=x+y+z;
	for(int i=0; i<n; i++){
		cin>>a[i].x>>a[i].y>>a[i].z;
	}
    sort(a,a+n,c1);
//    for(int i=0; i<n; i++){
//		cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].z<<endl;
//    }
    ll c=0;
    ll sa=0,sm=0;
    multiset<ll> l;
    for(int i=0; i<y; i++){
		l.insert(a[i].x-a[i].y);
		sm+=a[i].y;
    }
    for(int i=y; i<=n-z; i++){
		//cout<<i<<" "<<sm<<endl;
		ba[i]=sm;
		l.insert(a[i].x-a[i].y);
		sm+=a[i].y;
		sm+=*(--l.end());
		l.erase(--l.end());
    }
    l.clear();
    sm=0;
	for(int i=n-1; i>=n-z; i--){
		l.insert(a[i].x-a[i].z);
		sm+=a[i].z;
    }

    ll pas=0;
    for(int i=n-z-1; i>=y-1; i--){
		//cout<<i<<" "<<sm<<endl;
		pas=max(pas,ba[i+1]+sm);
		l.insert(a[i].x-a[i].z);
		sm+=a[i].z;
		sm+=*(--l.end());
		l.erase(--l.end());
    }
    cout<<pas;
	return 0;
}


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


struct Drop{
	Drop( int _x, int _y, int _s ) : x( _x ), y( _y ), size( _s ){}
	int x;
	int y;
	int size;
};

const int DROP_POS_NUM = 13;

int offset[ DROP_POS_NUM ][ 2 ] = {
	{ 0, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 },
	{ 1, -1 }, { 1, 1 }, { -1, 1 }, { -1, -1 },
	{ 0, -2 }, { 2, 0 }, { 0, 2 }, { -2, 0 }
};

const int drop_size[] = {
	0, 5, 9, 13
};

const int drops[] = {
	0,
	( 1 << drop_size[ 1 ] ) - 1,
	( 1 << drop_size[ 2 ] ) - 1,
	( 1 << drop_size[ 3 ] ) - 1,
};

bool solve( vector< vector< int > >& field, vector< vector< int > >& memo, vector< Drop >& ans, int r, int pos, int sum )
{
	if( r == 0 && sum == 0 ){
		return true;
	}

	for( int p = pos; p < 10 * 10; ++p ){
		int x = p % 10 + 2;
		int y = p / 10 + 2;
		if( field[ y ][ x ] == 0 ) continue;
		for( int k = DROP_POS_NUM - 1; k > 0; --k ){
			int dx = x + offset[ k ][ 0 ];
			int dy = y + offset[ k ][ 1 ];
			for( int s = 3; s > 0; --s ){
				if( ( memo[ dy ][ dx ] & drops[ s ] ) == drops[ s ] ){
					vector< vector< int > > f = field;
					vector< vector< int > > m = memo;
					for( int l = 0; l < drop_size[ s ]; ++l ){
						int fx = dx + offset[ l ][ 0 ];
						int fy = dy + offset[ l ][ 1 ];
						f[ fy ][ fx ]--;
						if( f[ fy ][ fx ] == 0 ){
							for( int t = 0; t < DROP_POS_NUM; ++t ){
								int ex = fx + offset[ t ][ 0 ];
								int ey = fy + offset[ t ][ 1 ];
								int bit = 1;
								if( t != 0 ){
									int shift = t + ( ( t + 3 ) % 4 < 2 ? 2 : -2 );
									bit <<= shift;
								}
								m[ ey ][ ex ] &= ~bit;
							}
						}
					}
					if( solve( f, m, ans, r - 1, pos, sum - drop_size[ s ] ) ){
						ans.push_back( Drop( dx - 2, dy - 2, s ) );
						return true;
					}
				}
			}
		}
		return false;
	}

	return false;
}
 
int main()
{
	int n;
	while( cin >> n ){
		vector< vector< int > > field( 10 + 4, vector< int >( 10 + 4, 0 ) );
		int sum = 0;
		for( int i = 0; i < 10; ++i ){
			for( int j = 0; j < 10; ++j ){
				int a;
				cin >> a;
				field[ i + 2 ][ j + 2 ] = a;
				sum += a;
			}
		}

		vector< vector< int > > memo( 10 + 4, vector< int >( 10 + 4, 0 ) );
		for( int i = 2; i < 10 + 2; ++i ){
			for( int j = 2; j < 10 + 2; ++j ){
				int bits = 0;
				for( int k = 0; k < DROP_POS_NUM; ++k ){
					int x = j + offset[ k ][ 0 ];
					int y = i + offset[ k ][ 1 ];
					if( field[ y ][ x ] > 0 ){
						bits |= ( 1 << k );
					}
				}
				memo[ i ][ j ] = bits;
			}
		}

		vector< Drop > ans;
		solve( field, memo, ans, n, 0, sum );

		for( int i = 0; i < n; ++i ){
			cout << ans[ i ].x << " " << ans[ i ].y << " " << ans[ i ].size << endl;
		}
	}
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll k, q;
vector<ll> d;

signed main() {
  cin >> k >> q;
  d.resize(k);
  rep(i, k) {
    cin >> d[i];
  }
  rep(t, q) {
    ll n, x, m;
    cin >> n >> x >> m;
    x %= m;
    vector<ll> dd(k);
    rep(i, k)
      dd[i] = d[i] % m;

    // cout << "x: " << x << endl;
    // cout << "dd: ";
    // rep(i, k){
    //   cout << dd[i] << " ";
    // }
    // cout << endl;

    ll B=0;
    rep(i, k) {
      if (dd[i] != 0)
        continue;
      ll p = (n - (i+1) + (k-1))/k;
      // printf("# i=%d n=%d\n", i, p);
      B += p;
    }

    ll an_1 = x;
    rep(i, k) {
      an_1 += dd[i] * ((n - (i+1) + (k-1))/k);
    }
    ll C = an_1/m - x/m;

    ll ans = (n-1) -B -C;
    // printf("B=%ld C=%ld\n", B, C);
    cout << ans << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b;
    cin >> a >> b;

    if(b%a == 0){
        cout << a+b << endl;
    }else{
        cout << b-a << endl;
    }
    
    return 0;
}

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

#define all(a)  (a).begin(),(a).end()
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define exist(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define range(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define rep(i,n)  range(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef vector<int> vi;
typedef long long ll;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=110;
int value[vmax];
vector<int> graph[vmax];
string item[vmax];
map<string,int> convert;


int dfs(int v){
	if(graph[v].size()==0) return value[v];
	int sum=0;	
	for(auto &v2:graph[v]) sum+=dfs(v2);
	return min(value[v],sum);
}

int main(void){
	int n;
	while(cin >> n,n){
		// reset
		rep(i,vmax) graph[i].clear();
		convert.clear();

		rep(i,n) cin >> item[i] >> value[i];
		rep(i,n) convert[item[i]]=i;
		int m;
		cin >> m;
		rep(i,m){
			string parent;
			cin >> parent;
			int l;
			cin >> l;
			rep(j,l){
				string child;
				cin >> child;
				graph[convert[parent]].push_back(convert[child]);
			}
		}
		string target;
		cin >> target;
		cout << dfs(convert[target]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int N; cin >> N;
    vector<int> A(N+1);
    for(int i=0; i<N+1; i++) A[i] = 0;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        A[a]++;
    }

    bool flg = true;
    if(N%2 == 1){
        if(A[0] != 1) flg = false;

        for(int i=2; i<=N; i+=2){
            if(A[i] != 2) flg = false;
        }    
    }
    else{
        for(int i=1; i<=N; i+=2){
            if(A[i] != 2) flg = false;
        }
    }

    if(flg == false) cout << 0 << endl;
    else{
        ll mod = 1000000007;
        ll ans = 1;
        for(int i=0; i<N/2; i++) ans = ans * 2 % mod;
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;



int main(int argc, const char * argv[]) {
    ll N;
  	cin >> N;
  	ll i;
  	ll difs = 0;
  	ll num;
  for(i=0;i<N;i++){
    cin >> num;
    if(i+1!=num)difs++;
  }
  if(difs==0 || difs == 2){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
  
  
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	vector<long long int>s;
	long long int sum = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
		sum = sum + a;
	}
	long long int ans = 100000000000000000;
	long long int sum1 = 0;
	for (int i = 0; i < n-1; i++) {
		sum1 = sum1 + s[i];

		ans = min(ans, abs(sum-sum1-sum1));
	}
	cout << ans;
}

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

int main() {
  int n, cnt = 1;

  cin >> n;

  vector<int> a(n);

  cin >> a[n / 2];

  if (n % 2 == 0) {
    for (int i = 1; i < n; i++) {
      if (i % 2 != 0) {
        cin >> a[n / 2 - cnt];
      } else {
        cin >> a[n / 2 + cnt];
        cnt++;
      }
    }
  } else {
    for (int i = 1; i < n; i++) {
      if (i % 2 == 0) {
        cin >> a[n / 2 - cnt];
        cnt++;
      } else {
        cin >> a[n / 2 + cnt];
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 2944
n = int(input())
pf={}
for i in range(1,int(n**0.5) + 1):
    if n % i == 0:
      pf[i] = pf.get(i,0) + 1
a = max(pf)
b = int(n/a)
ans = max(len(str(a)), len(str(b)))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] hyo = new int[n];
        int sumVote = 0;
        int count = 0;

        for(int i = 0;i < n;i++){
            hyo[i] = sc.nextInt();
            sumVote += hyo[i];
        }
        double base = sumVote/(4.0*m);
        for(int i = 0;i < n;i++){
            if(hyo[i] >= base){
                count++;
            }
        }
        System.out.println(m <= count?"Yes":"No");
    }
}

Measured memory_bytes: 21844
n,k=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
score_max=max(C)
#スタート地点＝L
for L in range(n):
  score=0
  d=[0]*n
  r=0
  d[L]=1
  #k回移動する
  for _ in range(k):
    r+=1#移動回数をカウント
    L=P[L]-1#移動先の位置
    score+=C[L]
    score_max=max(score,score_max)
    #もしも移動した場所に未到達なら...
    if d[L]==0:
      d[L]=1
    #Cの最小値未満ならスコアは減り続けるのでbreak
    elif score<0:
      break
    else:
      roop=(k//r)-1
      #最後の1周と端数は一個ずつ見る
      h=(k%r)+r
      score*=roop
      score_max=max(score,score_max)

      #あまりの移動回数の処理
      for _ in range(h):
        L=P[L]-1
        score+=C[L]
        score_max=max(score,score_max)
      break
print(score_max)


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

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<long long> dp(n + 1);
	for (int i = 1; i <= n; i++) {
		long long x = a[i] + a[i - 1];
		dp[i] = dp[i - 1];
		if (x > k) {
			long long dx = x - k;
			dp[i] += dx;
			if (a[i] >= dx) {
				a[i] -= dx;
			} 
			else {
				a[i] = 0;
			}
		}
	} 
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 4788
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b,t;
    cin>>a>>b>>t;
    ans=(t/a)*b;


    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256