akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <limits>
using namespace std;
template <typename T, bool directed>
class Dinic
{
public:
  Dinic(int n) : n(n), capacity(n, vector<T>(n)) {}
  void add_edge(int src, int dst, T cap)
  {
    capacity[src][dst] = cap;
    capacity[dst][src] = directed ? 0 : cap;
  }

  T max_flow(int s, int t)
  {
    T flow = 0;
    while (bfs(s, t))
    {
      start.assign(n, 0);
      flow += dfs(t, s, numeric_limits<T>::max());
    }
    return flow;
  }

private:
  int n;
  vector<int> level, start;
  vector<vector<T>> capacity;
  bool bfs(int s, int t)
  {
    level.assign(n, -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty())
    {
      int v = que.front();
      que.pop();
      for (int nv = 0; nv < n; ++nv)
        if (capacity[v][nv] > 0 && level[nv] < 0)
        {
          level[nv] = level[v] + 1;
          que.push(nv);
        }
    }
    return level[t] != -1;
  }

  T dfs(int v, int s, T limit)
  {
    if (v == s)
      return limit;

    T res = 0;
    for (int &nv = start[v]; nv < n; ++nv)
    {
      if (capacity[nv][v] > 0 && level[v] == level[nv] + 1)
      {
        T d = dfs(nv, s, min(limit, capacity[nv][v]));
        if (d > 0)
        {
          capacity[nv][v] -= d;
          capacity[v][nv] += d;
          res += d;
          limit -= d;
          if (limit == 0)
            break;
        }
      }
    }
    return res;
  }
};

int main()
{
  int N;
  cin >> N;
  long a[111], sum = 0;
  for (int i = 1; i <= N; ++i)
  {
    cin >> a[i];
    if (a[i] > 0)
      sum += a[i];
  }

  Dinic<long, true> dn(N + 3);
  for (int i = 1; i <= N; ++i)
    if (a[i] < 0)
      dn.add_edge(N + 1, i, -a[i]);
    else
      dn.add_edge(i, N + 2, a[i]);

  for (int i = 1; i <= N; ++i)
    for (int j = i * 2; j <= N; j += i)
        dn.add_edge(i, j, numeric_limits<long>::max());
  cout << sum - dn.max_flow(N + 1, N + 2) << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;

int main(void)
{
    string S;
    cin >> S;
    int count0 = 0;
    int count1 = 0;
    rep (i,S.length()){
        if (S.substr(i,1) == "0") {
            count0++;
        } else {
            count1++;
        }
    }

    cout << min(count0,count1)*2 << endl;

    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

N = input()

odd_list = N[0:len(N):2]
even_list = N[1:len(N):2]


def a():
    if len(even_list) == 0:
        print(0)
        return


def calc_one_and_zero(arr):
    zero_count = arr.count('0')
    one_count = arr.count('1')
    return zero_count, one_count


odd_zero,  odd_one = calc_one_and_zero(odd_list)
even_zero, even_one = calc_one_and_zero(even_list)

if odd_zero + even_one > odd_one + even_zero:
    print(odd_one + even_zero)
else:
    print(odd_zero + even_one)

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

int ind(int i){
	if (i < 0) return 0;
	return i;
}

int main(){
	char bord[1000002];
	int i = 0, result = 0;

	scanf("%s", bord);

	while(bord[i] == 'W' || bord[i] == 'B'){
		if (bord[ind(i)] != bord[ind(i-1)]){
			result++;
		}
		i++;
	}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


void  bubbleSort(char number[], int length);

int main() {

	char S[30];
	scanf("%s", S);

	bubbleSort(S, strlen(S));

	for (int i = 0; i < strlen(S) - 1; i++) {
		if (S[i] == S[i + 1]) {
			printf("no");
			return 0;
		}

	}

	printf("yes");



}


void  bubbleSort(char number[], int length) {
	for (int i = 0; i < length; i++)
		for (int j = i + 1; j < length; j++)
			if ((int)number[i] > (int)number[j]) {
				char tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()

	var p []int
	for i := 0; i < n; i++ {
		p = append(p, nextInt())
	}

	sort.Ints(p)

	var sum int
	for _, v := range p[:k] {
		sum += v
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1804
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int n, m, v[100100];
vector<int> G[100100];

int main()
{
	scanf ("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		int x, y; scanf ("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for (int i = 1; i <= n; i++) v[i] = -1;
	queue<int> q; q.push(1);
	while (!q.empty()){
		int x = q.front(); q.pop();
		for (auto& y : G[x]) if (v[y] == -1){
			q.push(y); v[y] = x;
		}
	}

	
	puts("Yes");
	for (int i = 2; i <= n; i++) printf ("%d\n", v[i]);
	return 0;
}


Measured memory_bytes: 10084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define pb push_back
#define en "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define asort(arr,n) sort(arr,arr+n)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(),greater<int>())
#define ff first
#define ss second
#define aout(a) for (auto u:a) {cout<<u<<" ";}cout<<en;

 
#define out(x1) cout << x1 << en
#define out2(x1,x2) cout << x1 << " " << x2 << en
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << en

 
#define in(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
 
#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << en;
 

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("oput.txt", "w", stdout);
#endif

ios_base::sync_with_stdio(false);
    cin.tie(NULL);


ll n;
in(n);
ll arr[n];
arrin(arr,n);
ll dp[n];
dp[0]=0;
dp[1]=abs(arr[1]-arr[0]);
for (ll i = 2; i < n; i++)
{
	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));

}
// arrout(dp,n);
out(dp[n-1]);





    return 0;
}


Measured memory_bytes: 5168
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;
const double PI=3.14159265358979323846;

int main() {
  int n,m;
  cin >> n >> m;
  int a[m];
  long long sum = 0;
  for(int i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if(n >= sum) {
    cout << n-sum << endl;
  }else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3660
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  string s;
  cin >> s;
  cout << s.front() << SZ(s) - 2 << s.back() << endl;
  return 0;
}

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

int main() {
    int A, B, C, D, res, upper, lower;
    cin >> A >> B >> C >> D;

    if (A > C) {
        lower = A;
    } else {
        lower = C;
    }

    if (B > D) {
        upper = D;
    } else {
        upper = B;
    }

    res = upper - lower;

    if (res < 0) res = 0; 

    cout << res << endl;
}

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

int main(){
    int A, B; cin >> A >> B;
    bool ans=false;
    int price;
    for(price=1; price<=1000; price++){
        if(A==(int)(price*0.08) && B==(int)(price*0.1)){
            ans=true;
            break;
        }
    }
    if(ans) cout << price << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main()
{
    int N, D, X, A, choco = 0;
    cin >> N >> D >> X;
    for (int i=0; i<N; i++){
        cin >> A;
        for(int i=0; i*A+1<=D; i++) choco++;
    }
    cout << choco + X << endl;
    return 0;
}

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MD=998244353;
class Segment_Tree{
private:
    vector<int> seg;
    int n;
public:
    Segment_Tree(int n){
        this->n=n;
        seg.resize(4*n,0);
    }
    void update(int idx, int l, int r, int f, int g){
        if(l>f || r<f) return;
        seg[idx]=max(seg[idx],g);
        if(l==r) return;
        int m=(l+r)/2;
        update(2*idx,l,m,f,g);
        update(2*idx+1,m+1,r,f,g);
    }
    int find(int idx, int l, int r, int fl, int fr){
        if(fr<l || r<fl) return 0;
        if(fl<=l && r<=fr) return seg[idx];
        int m=(l+r)/2;
        return max(find(2*idx,l,m,fl,fr),find(2*idx+1,m+1,r,fl,fr));
    }
};
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    vector<pii> arr(n);
    vector<int> ord(n);
    for(int i=0;i<n;i++){
        int x,d; cin>>x>>d;
        arr[i]={x,d};
        ord[i]=x;
    }
    sort(arr.begin(),arr.end());
    sort(ord.begin(),ord.end());
    vector<int> rr(n+5,0);
    vector<int> memo(n+5,0);
    for(int i=0;i<n;i++){
        auto low=lower_bound(ord.begin()+i+1,ord.end(),arr[i].first+arr[i].second);
        rr[i]=low-1-ord.begin();
    }
    Segment_Tree seg=Segment_Tree(n);
    for(int i=n-1;i>=0;i--){
        memo[i]=seg.find(1,0,n-1,i+1,rr[i]);
        memo[i]=max(memo[i],rr[i]);
        seg.update(1,0,n-1,i,memo[i]);
    }
    vector<int> dp(n+5,0);
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        dp[i]=(dp[i+1]+dp[memo[i]+1])%MD;
    }
    cout<<dp[0];
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
ll combi(ll n){
  return n*(n-1)/2;
}
int main(){
  ll N, M;
  cin >> N >> M;
  ll ans = 1;

  if(N>=2) ans *= N-2;

  if(M>=2) ans *= M-2;

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
	class Program
	{
		static void Main(string[] args)
		{

			string[] values = Console.ReadLine().Split(' ');
			long a = long.Parse(values[0]);
			long b = long.Parse(values[1]);
			long c = long.Parse(values[2]);
			long d = long.Parse(values[3]);

			long m = Lcm(c, d);

			long divisible = b / c - (a - 1) / c + b / d - ( a - 1 ) / d - ( b / m - ( a - 1 ) / m );	

			long solution = b - (a - 1) - divisible;
		
			Console.WriteLine(solution.ToString());
				
		}



		public static long Lcm(long a, long b) {

			return (a * b )/ Gcd(a, b);

		}
		public  static long Gcd(long a, long b)
		{
			if (a < b)
			{
				Gcd(b, a);
			}
			while (b != 0)
			{
				long remeinder = a % b;
				a = b;
				b = remeinder;
			}

			return a;

	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;

ll N, M;
vector<vector<int>> G;
vector<int> C;
vector<bool> V;

bool is_bigraph(int n) {
  for (int next_n : G[n]) {
    // if adjacent node has same color.
    if (C[next_n] == C[n])
      return false;
    // if adjacent node doesn't have color.
    else if (C[next_n] == 0) {
      C[next_n] = C[n] * -1;
      if (!is_bigraph(next_n))
        return false;
    }
  }
  return true;
}

int main(void) {
  cin >> N >> M;
  G.resize(N);
  C.assign(N, 0);
  V.assign(N, false);

  int a, b;
  rep(i, M) {
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }

  C[0] = 1;
  if (is_bigraph(0)) {
    ll B = 0, W = 0;
    rep(i, N) {
      B += (C[i] == 1);
      W += (C[i] == -1);
    }
    cout << B * W - M << endl;
  } else {
    cout << N * (N - 1) / 2 - M << endl;
  }

  return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vector<vector<int>>G;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  ll n,m;
  cin >> n >> m;
  vector<P>vec(m);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    vec[i]=P(b,a);   
  }
  sort(vec.begin(),vec.end());
  int now=0,cnt=0;
  rep(i,m){
    if(vec[i].second<now)continue;
    else{
      cnt++;
      now=vec[i].first;
    }
  }
  cout << cnt << endl;
  
}


Measured memory_bytes: 13824
#include<iostream>

using namespace std;


int main()
{
	int cnt[16][16];
	bool chk[16][16];

	for(int a,b;cin>>a>>b,a||b;){
		for(int i=0;i<b;i++)for(int j=0;j<a;j++)cnt[i][j]=0,chk[i][j]=false;

		int n;	cin>>n;
		for(int i=0;i<n;i++){
			int x,y;	cin>>x>>y;
			chk[y-1][x-1]=true;
		}

		cnt[0][0]=1;
		for(int i=0;i<b;i++)for(int j=0;j<a;j++){
			if(i+j>0 && !chk[i][j])	cnt[i][j]=(i>0?cnt[i-1][j]:0)+(j>0?cnt[i][j-1]:0);
		}

		cout<<cnt[b-1][a-1]<<endl;
	}
	return 0;
}

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

typedef pair<int,int>P;
typedef pair<int,P>P2;

int dp[111][1111],H,W,N,ans=1e9;
int x[111],y[111],man[111][111];

int main(){

  for(int i=0;i<111;i++)
    for(int j=0;j<1111;j++)dp[i][j]=1e8;

  x[0]=y[0]=1;

  cin>>W>>H>>N;N++;
  for(int i=1;i<N;i++)cin>>x[i]>>y[i];
  x[N]=W;
  y[N]=H; N++;

  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      man[i][j]=man[j][i]=(abs(x[i]-x[j])+abs(y[i]-y[j]));
    }
  }
  
  priority_queue<P2,vector<P2>,greater<P2> >q;
  q.push(P2(0,P(0,0)));
  dp[0][0]=0;

  while(!q.empty()){
    P2 p=q.top();q.pop();
    int cost = p.first;
    int now = p.second.first;
    int ran = p.second.second;
    if(now==N-1){
      cout<<cost<<endl;
      return 0;
    }
    if(dp[now][ran]<cost)continue;
    for(int i=0;i<N;i++)if(now!=i){
      int next;
      if(now==0)next=max(0,man[i][now]-ran);
      else if(i==N-1)next=max(0,man[i][now]-ran);
      else next=max(0,man[i][now]-ran-1);
      int cost2 = cost+next;     
      if(cost2>=dp[i][next])continue;
      dp[i][next]=cost2;
      q.push(P2(cost2,P(i,next)));
    }
  }
}


Measured memory_bytes: 4336
//2020.2.17
//s1270188 xxxmk2
//alds1_14a

#include<stdio.h>
#define N 1000

//global
char a[N+1], b[N+1];

//function
int cnt(int n){
  int i;

  for(i=0;b[i]!='\0';i++){
    if(a[n+i]!=b[i]) return -1;
  }
  
  return 1;
}

int main(){
  int i;
  
  //input
  scanf("%s %s",a,b);

  //output
  for(i=0;a[i]!='\0';i++){
    if(cnt(i)>0) printf("%d\n",i);
  }
  
  return 0;
}



Measured memory_bytes: 2124
#include<stdio.h>
 
static const int N = 1000;
 
void trace(int A[], int n){
    int i;
    for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
    }
    printf("\n");
}
 
int main(){
    int n, i, j;
    int key;
    int A[N+1];
    scanf("%d", &n);
 
    for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
    /* trace(A, n); */
    for(i=1; i<n+1; i++){
        key = A[i];
        j = i - 1;
        while(j >= 0 && A[j]>key){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        trace(A, n);
    }
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll solve() {
    ll H, W;
    cin >> H >> W;
    string S[H];
    for ( int i = 0; i < H; i++ ) {
        cin >> S[i];
    }
    int b0 = 0;
    for ( int i = 0; i < H; i++ ) {
        for ( int j = 0; j < W; j++ ) {
            if ( S[i][j] == '#' ) b0++;
        }
    }
    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0};
    int INF = 1e9;
    vector<vector<int>> d(H, vector<int>(W, INF));
    d[0][0] = 1;
    queue<pii> q;
    q.push(pii(0,0));
    while ( !q.empty() ) {
        pii p = q.front();
        q.pop();
        for ( int i = 0; i < 4; i++ ) {
            int h = p.first + dh[i];
            int w = p.second + dw[i];
            if ( h < 0 || h >= H ) continue;
            if ( w < 0 || w >= W ) continue;
            if ( d[h][w] < INF ) continue;
            if ( S[h][w] == '#' ) continue;
            d[h][w] = d[p.first][p.second] + 1;
            if ( h == H-1 && w == W-1 ) break;
            q.push(pii(h,w));
        }
    }
    if ( d[H-1][W-1] == INF ) return -1;
    return H * W - d[H-1][W-1] - b0;

}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

struct result
{
    int errors = 0;
    bool cleared = false;
};

int main(void)
{
    int problems_count;
    int submits_count;

    map<int, struct result> results;

    cin >> problems_count >> submits_count;

    for(int i = 0; i < submits_count; i++){
        int p;
        string s;

        cin >> p >> s;

        auto current_result = results.find(p);
        if(current_result == results.end()){
            struct result res;
            if(s == "AC"){
                res.cleared = true;
                res.errors = 0;
            }else if(s == "WA" && !res.cleared){
                res.errors = 1;
            }
            results[p] = res;
        }else{
            if(s == "AC"){
                results[p].cleared = true;
            }else if(s == "WA" && !results[p].cleared){
                results[p].errors += 1;
            }
        }
    }

    long long errors_sum = 0;
    long long clears_sum = 0;

    for(auto result = results.begin(); result != results.end(); result++){
        struct result res = result->second;

        if(res.cleared){
            clears_sum += 1;
            errors_sum += res.errors;
        }
    }

    cout << clears_sum << " " << errors_sum << endl;

    return 0;
}

Measured memory_bytes: 6528
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    y=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i!=j and j!=k and k!=i and i+j+k==x:
                    y+=1
    print(y)


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {
    
    int m,n,sum=0;
    cin>>n>>m;
    Vec vec(n);
    for(int i=0;i<n;i++){
    cin>>vec[i];
    sum+=vec[i];
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    

    int last=vec[m-1];
    if(last*4*m<sum){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
   


}

Measured memory_bytes: 3588
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: Vec<char> = sc.chars();
    let N = S.len();
    let mut ans = 0;
    for bit in 0..1<<(N-1) {
        let mut num = (S[0] as u8 - b'0') as usize;
        for i in 0..N-1 {
            if (bit>>i) & 1 != 0 {
                ans += num;
                num = (S[i+1] as u8 - b'0') as usize;
            } else {
                num = num * 10 + (S[i+1] as u8 - b'0') as usize;
            }
        }
        ans += num;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
ll f(ll x, ll y, ll z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}
int main() {
  int n;
  cin >> n;
  vector<int> ans(n + 1);

  rep(x, n + 1) {
    rep(y, n + 1) {
      rep(z, n + 1) {
        ll res = f(x + 1, y + 1, z + 1);
        if (res > n) break;
        ans[res]++;
      }
    }
  }

  rep(i, n) printf("%d\n", ans[i + 1]);
}

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

int main()
{

	int n = 1;
	
	while (cin >> n) {
		if (n == 0)
			break;
		int a[1000];
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
                
                int ans = 1000001;
		
                for (int i = 0;i < n - 1;i++) {
			for (int j = i + 1;j < n;j++) {
				if (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
	        cout << ans << endl;

	}
	return 0;
}

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

def insertionSort(A,N):
    for i in range(1,N):
        print(" ".join(map(str, A)))
        v = A[i]
        j = i -1
        
        while (j >= 0) & (A[j]>v):
            A[j+1] = A[j]
            j -= 1
            
        A[j+1] = v
    print(" ".join(map(str, A)))
    
insertionSort(A, N)

Measured memory_bytes: 7776
#include <stdio.h>

int S[2000000], n = 0;

void maxHeapify(int i){
  int l, r, largest, a;

  l = i * 2;
  r = i * 2 + 1;

  if(l <= n && S[l] > S[i])
    largest = l;
  else
    largest = i;

  if(r <= n && S[r] > S[largest])
    largest = r;

  if(largest != i){
    a = S[i];
    S[i] =  S[largest];
    S[largest] = a;
    maxHeapify(largest);
  }
}
int extractMax(){
  int i, e;
  if(n < 1) return -10000000;
  e = S[1];
  S[1] = S[n--];
  maxHeapify(1);
  return e;
}

void increk(int i, int k){
  int a;
  if(k < S[n]) return;
  S[n] = k;
  while(i > 1 && S[i / 2] < S[i]){
    a = S[i];
    S[i] = S[i / 2];
    S[i / 2] = a;
    i = i / 2;
  }
}

void insert(int k){
  n++;
  S[n] = -10000000;
  increk(n, k);
}

int main(){
  int key;
  char a[10];

  while(1){
    scanf("%s", a);
    if(a[0] == 'e' && a[1] == 'n') break;
    if(a[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    }
    else printf("%d\n", extractMax());
  }

  return 0;
}

Measured memory_bytes: 4696
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

naive0 [x] = x
naive0 xs = maximum [sub k xs | k <- [0..length xs - 1]]
  where
    sub k xs | k == 0 = naive0 (tail xs)
             | k == (length xs) - 1 = naive0 (init xs)
             | otherwise = naive0 ((init ys) ++ ((last ys) + z) : zs)
               where (ys, (_:z:zs)) = splitAt k xs

solve :: Int -> [Int] -> (Int, [Int])
solve n as | as_max <= 0 = noPlus n as_max as
           | otherwise   = somePlus n as
  where as_max = maximum as

noPlus n as_max as = (as_max, replicate k 1 ++ [n-k,n-k-1..2])
  where k = length $ takeWhile (< as_max) as

somePlus n as = (bVal, opList)
  where
    eLen = (n+1) `div` 2
    oLen = n `div` 2
    (es, os) = f $ partition fst $ zip (cycle [True,False]) as
      where f (x,y) = (map snd x, map snd y)
    (eVal, eMax) = myScan es
    (oVal, oMax) = myScan os
    initCut | odd n && eVal > oVal = []
            | odd n                = [n, 1]
            |          eVal > oVal = [n]
            | otherwise            = [1]
    (seq, bVal, bMax) = if eVal > oVal then (es, eVal, eMax)
                                       else (os, oVal, oMax)
    (part1, part2a) = span (<= 0) seq
    (part3r, part2r) = span (<= 0) $ reverse part2a
    part2 = reverse part2r
    opList = initCut ++ replicate (2 * k1) 1 ++ zs ++ [2*k3+1,2*k3..2]
      where
        k1 = length part1
        k3 = length part3r
        zs = map (\x -> if x <= 0 then 3 else 2) (tail part2)

myScan as = (sum (map (max 0) as), maximum as)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> (Int, [Int])
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

outAnswer :: (Int, [Int]) -> IO ()
outAnswer (bVal, opList) = do
  putStrLn $ show $ bVal
  putStrLn $ show $ length $ opList
  putStr $ unlines $ map show opList

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 1020
n = int(input())

XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        xy.append(list(map(int, input().split())))
    
    XY.append(xy)

"""
    矛盾したらFalse
    矛盾しなければTrue
    正直者と仮定した者の証言
        正直&正直者と仮定されている
        不親切&不親切と仮定されている
"""
def check(i, xiyj, HoU):
    # XOR
    if HoU ^ ((i >> xiyj) & 1):
        return False

    return True

max_honest = 0
for i in range(2 ** len(XY)):
    count = 0
    is_contradiction = True
    for j in range(len(XY)):
        # 正直者と仮定したときだけ採用
        if not ((i >> j) & 1): continue
        count+=1
        for k in range(len(XY[j])):
            xiyj = XY[j][k][0] - 1
            HoU = XY[j][k][1]
            
            if not check(i, xiyj, HoU):
                is_contradiction = False
                break # TLE対策
                
        if not is_contradiction:
            break # TLE対策

    # 矛盾がなく、正直者の数が更新できれば更新
    if is_contradiction and (count > max_honest):
        max_honest =count
            
print(max_honest)

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(m);
    vector<int> Z = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    copy_n(istream_iterator<int>(cin), m, A.begin());
    vector<int> T(8, -1);
    for (const auto &a: A)
        T[Z[a]] = max(T[Z[a]], a);
    vector<pair<int, char>> B;
    for (int i = 0; i < 8; i++){
        if (T[i] > 0)
            B.push_back({i, T[i] + '0'});
    }

    const int INF = 1e8;
    vector<int> DP(n + 1, -INF);
    DP[0] = 0;
    for (int i = 0; i < n; i++){
        for (const auto &b: B){
            const int& j = b.first;
            if (i + j <= n){
                DP[i + j] = max(DP[i + j], DP[i] + 1);
            }
        }
    }

    sort(A.begin(), A.end(), greater<int>());

    int i = n;
    while(i > 0){
        for (const auto &a: A){
            if (i - Z[a] >= 0 and DP[i - Z[a]] == DP[i] - 1){
                i -= Z[a];
                cout << a;
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main (String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        for(int i = 0; i < n; i++)
            b[i] = sc.nextInt();
        long r2 = 0, r1 = 0;
        for(int i = 0; i < n; i++){
            if(a[i] > b[i])
                r1 += a[i] - b[i];
            else{
                r2 += (b[i] - a[i]) / 2;
                if((b[i] - a[i]) % 2 == 1){
                    r2++;
                    r1++;
                }
            }
        }
        if(r2 >= r1)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 26068
#include<stdio.h>
int main()
{

   int A,B,x,y,z;
   scanf("%d %d",&A,&B);
   x=A+B;
   y=A-B;
   z=A*B;
   if(x>=y&&x>=z)
   printf("%d",x);
   else if(y>=x&&y>=z)
   printf("%d",y);
   else
       printf("%d",z);


}


Measured memory_bytes: 128
#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;
#define ll  long long
#define PI  acos(-1)
#define pb  push_back
#define ins insert
#define INF 5000000000000000007 //1e18+7
#define mk  make_pair
#define ff  first
#define ss  second
#define endl "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a) (ll)a.size()
#define double long double
#define coud(a,b) cout << fixed << setprecision((b)) << (a)
#define mset(x,y)  memset(x,y,sizeof(x))
#define all(x)   (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bp(n)  __builtin_popcountll(n)
#define mxt(a)  *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end()))
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define trav(a, x)    for(auto &a : x)

const double eps=1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int d8x[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int d8y[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int d4x[4]={1, 0, 0, -1};
int d4y[4]={0, -1, 1, 0};
ll power(ll x,ll y){ll ans=1;x=x;while(y>0){if(y&1)ans=(ans*x);y=y>>1;x=(x*x);}return ans;}
ll sqr(ll x) { return x * x;}

template <typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template <class T> inline void chmax(T &x,T y){ x = max((x), (y));}
template <class T> inline void chmin(T &x,T y){ x = min((x), (y));}
template <class T> T abs(T x) { return x>0 ? x : -x;}
template <typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0) { if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
typedef pair<int,int>  pii;
typedef pair<ll,ll>  pll;
typedef vector<pll>  vpll;
typedef vector<pii>  vpii;
typedef vector<ll>   vll;
typedef vector<int>  vii;
#define minpq priority_queue<T,vector<T>,greater<T> >;
// #define T int
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
//*X.find_by_order(k) returns the kth largest element (0-based).
//X.order_of_key(val) returns the no. of values less than val.
ll ncr(ll n,ll r) {ll ans=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){ans*=(n-i);ans/=(i+1);}return ans;}
const int MOD = 1000000007;   
const int N = 200010;

struct compare{
    bool operator() (const int &a,const int &b) const {
        return a>b;
    }
};
// 🎲

int32_t main() {
  cin.sync_with_stdio(0);cin.tie(0);
  cin.exceptions(cin.failbit);
  
  string s;
  cin >> s;
  int ok = 0;
  for (int i=0; i<3; ++i) {
    if(s[i] == 'R') ok++;
  }
  if(ok == 0) {
    cout << 0;
    return 0;
  }else if(ok==3) {
    cout << 3 << endl;
    return 0;
  }
  if(ok==1) {
    cout << 1 << endl;
    return 0;
  }
  if((s[0] == 'S' or s[2] == 'S') and ok ==2) {
    cout << 2;
    return 0;
  }
  cout << 1;
  return 0; 
}

/* 
    stuff you shoulds look for
    * int overflow,array bounds.
    * special cases (n=1?).
    * N,MOD value.
*/

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

int main(){
    int R;
    scanf("%d", &R);
    if (R < 1200){
        printf("ABC\n");
    }else if (R < 2800){
        printf("ARC\n");
    }else {
        printf("AGC\n");
    }
    return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input

    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}

int a[N];
int main(void){
    int n;
    scanf("%d",&n);
    ll ans=0;
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]),ans+=a[i];
    cout << ans-n << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split(' ')))

broken = [False] * (n + 1)
for i in range(m):
    broken[int(input())] = True

mod = 1000000007

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 0 if broken[1] else 1

for i in range(2, n + 1):
    if broken[i]:
        dp[i] = 0
    else:
        c = dp[i - 1] + dp[i - 2]
        if c > mod:
            c = c % mod
        dp[i] = c

print(dp[n])


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;
typedef pair<ll, ll> pll;

int main()
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	sort(all(a));

	ll ans = 0;
	int j = 3  * n - 1;
	for (int i = 0; i < n; ++i) {
		--j;
		ans += a[j];
		--j;
	}

	cout << ans << "\n";

}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;  cin >> h >> w;
    char pi[h + 2][w + 2];
    rep(i, h + 2) {
      rep(j, w + 2) {
        if ((0 < i && i < h + 1) && (0 < j && j < w + 1)) {
          cin >> pi[i][j];
        } else {
          pi[i][j] = '#';
        }
      }
    }
    rep(i, h + 2) {
      rep(j, w + 2) {
        cout << pi[i][j];
      }
      cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int n;
    ll ans = 0;
    scanf("%d", &n);
    vector< pair<int, int> > d(n);
    for (int i = 0; i < n; ++i) scanf("%d%d", &d.at(i).first, &d.at(i).second);
    sort(d.begin(), d.end(), [](const pair<int, int>& i, const pair<int, int>& j) { return i.first + i.second > j.first + j.second; });
    for (int i = 0; i < n; ++i) {
        if (i % 2) ans -= d.at(i).second;
        else ans += d.at(i).first;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#C - Otoshidama
N, Y = map(int, input().split())

x_ans = -1
y_ans = -1
z_ans = -1
flg = 0

for x in range(N+1):
    for y in range(N+1-x):
        otoshidama = 10000*x + 5000*y + 1000*(N-x-y)
        if otoshidama == Y :
            flg = 1
            x_ans = x
            y_ans = y
            z_ans = N-x-y
print(x_ans, y_ans, z_ans)
                

Measured memory_bytes: 3064
#include<stdio.h>
 
int main(){
	int n, a, max = 0, min = 500, score = 0, i, j;
	while(scanf("%d", &n) != 0){
		if(n == 0) break;
		for(i = 0; i < n; i++){
			for(j = 0; j < 5; j++){
				scanf("%d", &a);
				score += a;
			}
			if(max < score) max = score;
			if(min > score) min = score;
			score = 0;
		}
		printf("%d %d\n", max, min);
		max = 0;
		min = 500;
	}
	return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
#include<string.h>
int main(void)
{
	int len,len2,n,i,j,k,cnt,l,flg;
	char s[11],a[100][11];
	scanf("%s",s);
	len=strlen(s);
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%s",a[i]);
	cnt=0;
	for(i=0;i<n;i++){
		len2=strlen(a[i]);
		for(j=0;j<10;j++){
			l=j;
			flg=1;
			for(k=0;k<len;k++){
				if(l>=10) l=0;
				if(s[k]!=a[i][l]){
					flg=0;
					break;
				}
				l++;
			}
			if(flg==1) break;
		}
		if(flg==1) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#define N 500

using namespace std;

int main() {
  int n, c[N], s[N], f[N];
  int i, time;

  cin >> n;
  for (i = 1; i < n; i++) cin >> c[i] >> s[i] >> f[i];

  for (i = 1; i < n - 1; i++) {
    time = 0;
    time = s[i] + c[i];
    for (int j = i; j < n - 1; j++) {
      if (time < s[j+1]) time += s[j+1] - time;
      else if (time % f[j+1] != 0) time += f[j+1] - (time % f[j+1]);
      time += c[j+1];
    }
    cout << time << endl;
  }
  cout << s[i] + c[i] << endl;
  cout << 0 << endl;

  return 0;
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

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

	int n, m; cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 3628
S = list(input())
l = len(S)
a = 1
for i in range(l) :
    del S[-1]
    ll = len(S)
    if ll % 2 == 0 :
        for j in range((ll)//2) :
            if S[j] == S[(ll)//2 + j] :
                continue
            else :
                a = 0
                break
    else :
        a = 0
    if a == 1 :
        break
    a = 1
print(len(S))

Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = 998244353;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt(), s = sc.nextInt();
        int[] as = new int[n];

        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        long[] dp = new long[s + 1];
        dp[0] = 1;

        for (int i = 0; i < n; i++) {
            for (int j = s; j >= 0; j--) {
                if (j - as[i] >= 0) {
                    dp[j] = 2 * dp[j] + dp[j - as[i]];
                } else {
                    dp[j] = 2 * dp[j];
                }
                dp[j] %= MOD;
            }
        }

        out.println(dp[s]);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

Measured memory_bytes: 40676
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
#define fr first
#define sc second
#define mpr make_pair
#define pb push_back
#define ppb pop_back()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define ins insert
const int mod = 1e9 + 7;
const ll INF = 1e18;
const int N = 3e5 + 1, N2 = 5001;

int n;
ll a[N], b[N], cnt;
int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n; ++ i){
        cin >> a[i] >> b[i];
    }
    for(int i = n;i >= 1; -- i){
        a[i] += cnt;
        cnt += ((a[i] + b[i] - 1) / b[i]) * b[i] - a[i];
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define INF 1000000;

using namespace std;

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

    int five_hd, five, remain;

    five_hd = x/500;
    
    remain = x - 500*five_hd;
    five = remain/5;

    int happy;
    happy = 1000*five_hd + 5*five;

    cout << happy << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool T=false;
int main(){
    string S,T;cin>>S>>T;
    long long cnt=0;
    for (int i = 0; i < S.size(); i++)
    {
        if(S[i]!=T[i])cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<pair<int, int> > va(N);
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        va[i] = make_pair(a, i);
    }

    // 昇順にソート
    sort(va.begin(), va.end(), greater<pair<int, int> >());

    for(int j = 0; j < N; j++) {
        // もしjがva[j].secondに等しかったらその次の要素が最大の要素
        if (j == va[0].second) cout << va[1].first << endl;

        // それ以外はva[0].firstが最大
        else {
            cout << va[0].first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200