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

using namespace std;

#define F first
#define S second
#define int long long
#define mpr make_pair 
typedef long long ll;
#pragma GCC optimize("Ofast")

const int maxn = 1e6+10;
const int N = 1e6+5;
const int mod = 998244353;
const int inf = 1e9+10;

int n, m, c[maxn], q;
int mx[maxn];
vector<int> g[maxn];

void dfs(int v, int C)
{
    if(!c[v]) c[v] = C;
    for(auto u : g[v])
        if(mx[u] < mx[v]-1)
        {
            mx[u] = mx[v]-1;
            dfs(u,C);
        }
}

int v[maxn], d[maxn], C[maxn];
signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n >> m;
    memset(mx, -1, sizeof mx);
    for(int i = 1, u, v; i <= m; i++)
    {
        cin>> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    cin>> q;
    for(int i = 1; i <= q; i++) cin>> v[i] >> d[i] >> C[i];
    for(int i = q; i >= 1; i--)
    {
        //cout<< mx[v[i]] <<" "<< d[i] <<" "<< C[i] <<"\n";
        if(mx[v[i]] < d[i])
        {
            mx[v[i]] = d[i];
            dfs(v[i],C[i]);
        }
    }
    for(int i = 1; i <= n; i++) cout<< c[i] <<"\n";
}





Measured memory_bytes: 48372
def main():
	s = input()
	ans = 0
	stock_a = 0
	state = 0 # 0 = prechar is C,B  2 = prestr=("A"*n|n>0)
	ans = 0
	for i in range(len(s)):
		if state == 0:
			if s[i] == "A":
				stock_a = 1
				state = 1
			else:
				stock_a = 0
		elif state == 1:
			if s[i] == "B":
				state = 2
			elif s[i] == "A":
				stock_a += 1
			else:
				stock_a = 0
				state = 0
		elif state == 2:
			if s[i] == "C":
				ans += stock_a
				state = 1
			elif s[i] == "A":
				stock_a = 1
				state = 1
			else:
				state = 0
				stock_a = 0
	print(ans)

main()

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int n;
    cin >> n;
    vector<int> vec;
    while(n--){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.rbegin(),vec.rend());
    int alice = 0;
    int bob = 0;
    for(int i=0; i<vec.size(); i++){
        if(i%2==0){
            alice+=vec[i];
        }else{
            bob += vec[i];
        }
    }
    cout << alice - bob <<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int n,m,q,a1,b1,a2,b2,a[2005][2005],s1[2005][2005],s2[2005][2005],s3[2005][2005];char c[2005];
int gao1(int a1,int b1,int a2,int b2){return s1[a2][b2]-s1[a1-1][b2]-s1[a2][b1-1]+s1[a1-1][b1-1];}
int gao2(int a1,int b1,int a2,int b2){return s2[a2][b2]-s2[a1-1][b2]-s2[a2][b1-1]+s2[a1-1][b1-1];}
int gao3(int a1,int b1,int a2,int b2){return s3[a2][b2]-s3[a1-1][b2]-s3[a2][b1-1]+s3[a1-1][b1-1];}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++){scanf("%s",c+1);for(int j=1;j<=m;j++) a[i][j]=c[j]-'0';}
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) s1[i][j]=a[i][j],s2[i][j]=(a[i][j]&&a[i][j+1]),s3[i][j]=(a[i][j]&&a[i+1][j]);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
        s1[i][j]+=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1];
		s2[i][j]+=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1];
		s3[i][j]+=s3[i-1][j]+s3[i][j-1]-s3[i-1][j-1];
    }
    while(q--) scanf("%d%d%d%d",&a1,&b1,&a2,&b2),printf("%d\n",gao1(a1,b1,a2,b2)-gao2(a1,b1,a2,b2-1)-gao3(a1,b1,a2-1,b2));
}

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

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;

using P = pair<int, int>;

signed main() {
	int n; cin >> n;
	vector<int>a(n), b(n);
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < n - 2; i++) {
		if (a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]) {
			cout << "Yes" << endl; return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    int N;
    cin >> N;
    map<string, int> votes;

    rep(i,N) {
        string S;
        cin >> S;
        votes[S] += 1;
    }

    int maximum = 0;

    for (auto it = votes.begin(); it != votes.end(); it++) {
        maximum = max(maximum, it->second);
    }

    for (auto it = votes.begin(); it != votes.end(); it++) {
       if (maximum == it->second) cout << it->first << endl;
    }

    return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;


const long long  MAX = 200000;
int main() {
    

    stack <int> st;
    long long a,b;
    string s;
    while(cin >> s){
        if(s == "+"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a+b);
        }else if(s == "-"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(b-a);
        }else if(s == "*"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a*b);
        }else{
            st.push(atoi(s.c_str()));
        }
    }
    cout << st.top() << endl;

}


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

void solve(string, string);
int main(){
  string s, t;
  cin >> s >> t;

  solve(s, t);

  return 0;
}

void solve(string s, string t){
  int m=s.length(), n=t.length();
  s = " "+s; t = " "+t;

  int dp[m+1][n+1];
  for(int i=0; i<=m; i++) dp[i][0] = i;
  for(int i=0; i<=n; i++) dp[0][i] = i;

  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      int ins=dp[i-1][j]+1;
      int del=dp[i][j-1]+1;
      int rep;
      if(s[i]==t[j]){
        rep = dp[i-1][j-1];
        dp[i][j] = min(ins, min(del, rep));
      }
      else{
        rep = dp[i-1][j-1]+1;
        dp[i][j] = min(ins, min(del, rep));
      }
    }
  }

  cout << dp[m][n] << endl;
}



Measured memory_bytes: 7076
/*input
4
2 1 4 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int a[maxn];
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) a[i]--;
	int cnt=0;
	REP(i,n) if(a[a[i]]==i) cnt++;
	cout<<cnt/2;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;


int main()
{
    int n;scanf("%d",&n);
    for (int i=1;i*100<=n;++i){
        if (i*100<=n && i*105>=n){
            printf("1\n");return 0;
        }
    }
    printf("0");
}





Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int H,W;
    while(true)
    {
        scanf("%d%d",&H,&W);
        if(H==0&&W==0)
            break;
        for(int i=0;i<W;i++)
            printf("#");
        printf("\n");
        for(int i=1;i<H-1;i++)
        {
            printf("#");
            for(int j=1;j<W-1;j++)
                printf(".");
            printf("#\n");
        }
        if(H>1)
        {
            for(int i=0;i<W;i++)
                printf("#");
        printf("\n");
        }
        printf("\n");
    }
   }


Measured memory_bytes: 2544
//Sum of Three Integers
#include <bits/stdc++.h>
using namespace std;

int main(){
    int K,S;
    cin>>K>>S;

    int count=0;
    /*for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            for(int z=0;z<=K;z++){
                if(x+y+z==S)    count++;
            }
        }
    }*/
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int z=S-x-y;
            if(0<=z&&z<=K)  count++;
        }
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    string p;
    cin>>p;
    if(p=="ABC")
    cout<<"ARC";
    else
    {
        cout<<"ABC";
    }
    

return 0;
}

Measured memory_bytes: 3624
N = int(input())
cnt = 0
Cnt = 0
for i in range(1, N + 1):
    if i % 2 != 0:
        for j in range(1, i + 1):
            if i % j == 0:
                cnt += 1
        if cnt == 8:
            Cnt += 1
        cnt = 0

print(Cnt)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[102];
bool ans[3];
int main(){
	int i;
	ans[2]=false;
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		if(s[i]=='C'){
			ans[1]=true;
		}
		if(s[i]=='F'&&ans[1]){
			cout<<"Yes";
			return 0;
		}
	}
	if(!ans[2]){
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int counter = 0;
  if(s[0]=='1') ++counter;
  if(s[1]=='1') ++counter;
  if(s[2]=='1') ++counter;
  cout << counter << endl;
}

Measured memory_bytes: 3632
using System;

class ITP1_7_B
{
    public static void Main()
    {
        string[] Input;
        int n, target;
        int count = 0;

        while (true)
        {
            Input = Console.ReadLine().Split(' ');
            n = int.Parse(Input[0]);
            target = int.Parse(Input[1]);
            count = 0;

            if (n == 0 && target == 0) break;

            for (int i = 1; i <= n - 2; i++)
                for (int j = i + 1; j <= n - 1; j++)
                    for (int k = j + 1; k <= n; k++)
                        if (i + j + k == target) count++;

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9152
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, d, ans = 0; cin >> n >> d;

    for(long long i = 0; i < n; i++){
        long long x, y, z = 0; cin >> x >> y;
        z = x * x + y * y;
        if(z > 0){
            if(d * d >= z){
               ans++;
            }
        }
        else {
            ans++;
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e5 + 5;

vector<int> adj[2][N];

int comp[N];

void dfs(int node, int id) {
  if (comp[node] == id) return;
  comp[node] = id;
  for (int x : adj[0][node]) {
    dfs(x, id);
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, q;
  Long m;
  cin >> n >> m >> q;

  bool type_1_appeared = false;
  while (q--) {
    int u, v, c;
    cin >> u >> v >> c;
    ++u, ++v;
    adj[c][u].push_back(v);
    adj[c][v].push_back(u);
    type_1_appeared |= (c == 1);
  }

  int cnt_comps = 0;
  for (int i = 1; i <= n; ++i) {
    if (comp[i] == 0) {
      dfs(i, i);
      ++cnt_comps;
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int x : adj[1][i]) {
      if (comp[i] == comp[x]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  int mn = n;
  Long mx = n - cnt_comps + 1LL * cnt_comps * (cnt_comps - 1) / 2;
  if (!type_1_appeared) {
    mn = n - 1;
  }
  if (cnt_comps == 2 && type_1_appeared) {
    cout << "No" << endl;
    return 0;
  }

  if (mn <= m && m <= mx) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}



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

int main() {
  ll N,K;
  cin >> N >> K;
  
  //while(N>K){N = N - K; }
  if(N>K){
    N = N-(((N-K)/K)+1)*K;
  }
  
  //min(N,abs(N-K))
 
  cout << min(N,abs(N-K)) << endl;
  
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int T = s.nextInt();
        int [] arr = new int[T];
        for(int i=0;i<T;i++){
            arr[i]=0;
        }
        for(int i=0;i<T-1;i++){
            arr[s.nextInt()-1]+=1;
        }
        for(int i=0;i<T;i++){
            System.out.println(arr[i]);
        }
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

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

}

Measured memory_bytes: 51632
#include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int mx[4] = {-1, 0, 1, 0};
int my[4] = {0, -1, 0, 1};

PII s;

int bfs(vector<vector<char> > f, int H, int W, int n, PII sp){
  int res = 0;
  vector<VI > cost(H, VI(W, INF));
  int ini_y = sp.fst, ini_x = sp.snd;
  cost[ini_y][ini_x] = 0;

  queue<pair<PII, int> > q;
  q.push(MP(MP(ini_y, ini_x), 0));

  while(!q.empty()){
    pair<PII, int> p = q.front();
    q.pop();
    int y = p.fst.fst, x = p.fst.snd, c = p.snd;
    if(f[y][x] == (char)('0' + n)){
      res = c;
      s.fst = y;
      s.snd = x;
      break;
    } else {
      REP(i, 0, 4){
        int ny = y + my[i], nx = x + mx[i];
        if(ny >= 0 && ny < H && nx >= 0 && nx < W &&
           f[ny][nx] != 'X' && cost[ny][nx] > c + 1){
          cost[ny][nx] = c + 1;
          q.push(MP(MP(ny,nx), c + 1));
        }
      }
    }
  }

  return res;
}

int solve(vector<vector<char> > f, int H, int W, int N, PII p){
  int ans = 0;
  s = p;

  REP(i, 1, N+1){
    ans += bfs(f, H, W, i, s);
  }
  return ans;
}

int main(){
  int H, W, N;
  cin >> H >> W >> N;

  vector<vector<char> > f(H, vector<char>(W));
  int y, x;
  REP(i, 0, H){
    REP(j, 0, W){
      cin >> f[i][j];
      if(f[i][j] == 'S'){
        y = i;
        x = j;
      }
    }
  }

  cout << solve(f, H, W, N, MP(y, x)) << endl;
  return 0;
}

Measured memory_bytes: 9680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main(){
	cin>>n;
	for(ll i=1;i<=3500;i++){
		for(ll j=1;j<=3500;j++){
			ll m=4*i*j-n*i-n*j;
			ll k=n*i*j;;
			if(m>0&&k%m==0){
				printf("%lld %lld %lld\n",i,j,k/m);
				return 0;
			}
		} 	
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int D;
int c[26];
int s[365][26];
int last[26] = {};  // 各コンテストを最後に開催した日
int t[365] = { 0 };  // 各日に開催するコンテスト
int M;
vector<int> d;
vector<int> q;
vector<int> ds[26];  // 各コンテストの開催日

void Setds() {
    rep(i, D) {
        ds[t[i] - 1].push_back(i+1);
    }
}

int CalcScore() {
    int res = 0;
    int last_[26] = { 0 };
    rep(i, D) {
        res += s[i][t[i] - 1];
        last_[t[i] - 1] = i + 1;
        rep(j, 26) {
            res -= c[j] * (i+1 - last_[j]);
        }
    }
    return res;
}

int Disatisfaction(int c, int pre, int d, int post) {
    return c * ((post - pre)* (post - pre - 1) - (d - pre) * (d - pre - 1) - (post - d) * (post - d - 1)) / 2;
}

int Disatisfaction2(int c, int pre, int d, int post) {
    return c * (- (post - pre) * (post - pre - 1) + (d - pre) * (d - pre - 1) + (post - d) * (post - d - 1)) / 2;
}

void Query(int d, int q) {
    t[d - 1] = q;
}

//int Query(int d, int q) {
//    int res = 0;
//    int old = t[d - 1];  // 前回値保存
//    t[d - 1] = q;  // 入れ替え
//
//    // 満足度上昇分
//    res -= s[d - 1][old - 1];
//    res += s[d - 1][q - 1];
//
//    // oldについて満足度減少分
//    int pre = 0;
//    int post = D + 1;
//    for (int i = 1; i < ds[old-1].size(); i++) {
//        if (ds[old - 1][i] == d) {
//            pre = ds[old - 1][i - 1];
//            if (i != ds[old - 1].size() - 1) {
//                post = ds[old - 1][i+1];
//            }
//        }
//    }
//    res -= Disatisfaction(c[old - 1], pre, d, post);
//
//    // qについて満足度減少分
//    pre = 0;
//    post = D + 1;
//    for (int i = 1; i < ds[q - 1].size(); i++) {
//        if (ds[q - 1][i] == d) {
//            pre = ds[q - 1][i - 1];
//            if (i != ds[q - 1].size() - 1) {
//                post = ds[q - 1][i + 1];
//            }
//        }
//    }
//    res -= Disatisfaction2(c[q - 1], pre, d, post);
//    return res;
//}

int main()
{
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];

    rep(i, D) {
        int max_v = -INF;
        rep(j, 26) {
            int v = 0;
            v += s[i][j];
            rep(k, 26) {
                if (k == j) continue;
                v -= c[k] * (i + 1 - last[k]);
            }
            if (v > max_v) {
                max_v = v;
                t[i] = j + 1;
            }
        }
        last[t[i] - 1] = i + 1;
    }
    rep(i, D) cout << t[i] << endl;
    return 0;
}


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

int64_t f(int64_t H1){
  
  if (H1 > 1){
    int64_t  s = f( int64_t (H1)/2) ; 
    return  2*s + 1; 
  }
  else if (H1 == 1){
    return 1 ; 
  }
  
}



int main (){
  int64_t H1  ;
  cin >> H1  ;
  
  cout << f(H1) << endl ; 
  
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	set<pair<int,int>> memo[n];
	int p,y;
	for (int i = 0; i < m; ++i)
	{
		cin>>p>>y;
		--p;
		memo[p].insert(make_pair(y,i));
	}
	long long ans[m];
	for (int i = 0; i < n; ++i)
	{
		long long j=0LL;
		for (auto v:memo[i])
		{
			++j;
			ans[v.second]=(long long)(i+1LL)*1000000LL+j;
		}
	}
	for (int i = 0; i < m; ++i)
	{
		printf("%012Ld\n", ans[i]);
	}
	return 0;
}


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

int main(){
	int a, sum;
	sum = 0;
	for(int i=0; i<3; i++){
		cin >> a;
		sum += a;
	}
	if(sum >= 22){
		cout << "bust" << endl;
	}else{
		cout << "win" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    ll n;
    cin >> n;
    ll pmax = 4 * n;
    for(ll p = 1; p < pmax; p++){
        if (4*p - n <= 0) continue;
        for(ll q = p; q <= 3500; q++){
            if (4*p*q - n*p - n*q <= 0) continue;
            for(ll r = q; r <= 3500; r++){
                if (4*p*q*r == n * (p*q + q*r + r*p)){
                    cout << p << " " << q << " " << r << endl;
                    return 0;
                }
            }
        }
    }
}

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

int main()
{
    int n;
    char s[10000];
     cin >> n >> s;
     for(int i = 0; s[i] >= 65 && s[i] <= 90; i++)
     {

         s[i] += n;
         if(s[i] > 90) s[i] = 65 + (s[i] - 90) - 1;
         cout << s[i];
     }

    return 0;
}


Measured memory_bytes: 256
extern crate num;

use std::collections::HashMap;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let s = get_one!(String);
    let s_rev = s.chars().rev();

    // 10^n を 2019 で割ったときの余り
    let mut res_pow_10 = 1;
    // s を右から数えて n 桁とってきたときの数字を 2019 で割ったときの余り
    let mut res = 0;
    // res を格納していく
    let mut v_res = vec![0];
    for c in s_rev {
        let num = c.to_digit(10).unwrap();
        res = (res + res_pow_10 * num) % 2019;
        res_pow_10 = (res_pow_10 * 10) % 2019;
        v_res.push(res);
    }
    dbg!(&v_res);

    let mut map_count: HashMap<u32, u32> = HashMap::new();
    for res in v_res {
        map_count.entry(res)
            .and_modify(|e| {*e += 1})
            .or_insert(1);
    }

    let ans: u32 = map_count.into_iter().map(|(_, v)| v * (v - 1) / 2).sum();

    println!("{}", ans);

}


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


int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for(int i = 0; i < N; i++){
		cin >> H.at(i);
	}
	bool ans = true;
	for(int i = N - 1; i >= 1; i--){
		if(H.at(i - 1) - 1 > H.at(i)){
			ans = false;
			break;
		}
		else if(H.at(i - 1) - 1 == H.at(i)){
			H.at(i - 1)--;
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
n = int(input())
l = []
for _ in range(n):
  x,y = map(int, input().split())
  l.append([x+y,x-y])
l=sorted(l)
 
tmp = l[0][0]
count = n
for p in l[1:]:
  if tmp <= p[1]:
    tmp = p[0]
  else:
    tmp = min(tmp,p[0])
    count -= 1
print(count) 

Measured memory_bytes: 20872
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	final long b1 = 401;
	final long b2 = 397;
	final long h = 1000000007l;
	final int MAX_SIZE = 1000;

	int N, M, T, P, Q;
	char[][] field, pattern;
	long[][] hash, tmp;
	void computeHash(char[][] a, int n, int m) {
		long t1 = 1;
		for (int j = 0; j < Q; j++) t1 = (t1 * b1) % h;
		
		for (int i = 0; i < n; i++) {
			long e = 0;
			for (int j = 0; j < Q; j++) e = (e * b1 + a[i][j]) % h;
			
			for (int j = 0; j + Q <= m; j++) {
				tmp[i][j] = e;
				if (j + Q < m) e = (e * b1 - t1 * a[i][j] + a[i][j + Q]) % h;
				e = (e < 0) ? e + h : e;
			}
		}
		
		long t2 = 1;
		for (int i = 0; i < P; i++) t2 = (t2 * b2) % h;
		
		for (int j = 0; j + Q <= m; j++) {
			long e = 0;
			
			for (int i = 0; i < P; i++) e = (e * b2 + tmp[i][j]) % h;
			
			for (int i = 0; i + P <= n; i++) {
				hash[i][j] = e;
				if (i + P < n) e = (e * b2 - t2 * tmp[i][j] + tmp[i + P][j]) % h;
				e = (e < 0) ? e + h : e;
			}
		}
	}
	void run() {
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		field   = new char[MAX_SIZE][MAX_SIZE];
		pattern = new char[MAX_SIZE][MAX_SIZE];
		hash = new long[MAX_SIZE][MAX_SIZE];
		tmp  = new long[MAX_SIZE][MAX_SIZE];
		N = scan.nextInt();
		M = scan.nextInt();
		for (int i = 0; i < N; i++) {
			char[] line = scan.next().toCharArray();
			for (int j = 0; j < M; j++)
				field[i][j] = line[j];
		}
		P = scan.nextInt();
		Q = scan.nextInt();
		for (int i = 0; i < P; i++) {
			char[] line = scan.next().toCharArray();
			for (int j = 0; j < Q; j++)
				pattern[i][j] = line[j];
		}
		computeHash(pattern, P, Q);
		long pHash = hash[0][0];
		
		computeHash(field, N, M);
		for (int i = 0; i + P <= N; i++)
			for (int j = 0; j + Q <= M; j++)
				if (hash[i][j] == pHash)
					sb.append(i + " " + j + "\n");
		
		System.out.print(sb.toString());
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 97272
import java.util.*;
import java.lang.*;
import java.io.*;

public final class Main
{
    public static void main (String[] args) throws java.lang.Exception {
        Scanner in = new Scanner(System.in);
        String  s = in.next();
        if(s.charAt(s.length()-1)=='s') {
           System.out.println(s+"es");
        } else
          System.out.println(s+"s");


    }
}

Measured memory_bytes: 38524
#include <stdio.h>

int h[105];

int main() {
	
	int N;

	scanf("%d",&N);
	
	int i;
	
	for(i=0;i<N;i++){
		scanf(" %d",&h[i]);
	}
	
	int l,r;
	
	int tmp1,tmp2,tmp3;
	
	int section;
	
	int ans=0;
	
	while(1){
		
		for(i=0;i<N;i++){
			if(h[i]!=0){break;}
		}
		if(i==N){break;}
		
	section=0;
	
	for(l=0;l<N;l++){
		if(h[l]>0){
			int mini=114514;
		for(r=l;r<N;r++){
			if(h[r]>0 && mini>h[r]){mini=h[r];}
			if(h[r]<=0){break;}
		}
		if(r-l+1>section){section=r-l+1;tmp1=mini;tmp2=l;tmp3=r;}
		}
	}
	ans+=tmp1;
	if(tmp2==tmp3){h[tmp2]=h[tmp2]-tmp1;}
	else{
	for(i=tmp2;i<tmp3;i++){
		h[i]=h[i]-tmp1;
	}
	}
	}

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


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

ll solve() {
    ll N, R;
    cin >> N >> R;
    if ( N < 10 ) return R + 100*(10-N);
    else return R;
}

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

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    map<char, int> mp;
    REP( i, N - 1 ){
        mp[s[i]]++;

        int t = 0;
        map<char, int> tmp;
        FOR( j, i + 1, N ){
            if( tmp[s[j]] == 0 && mp[s[j]] > 0 ){
                tmp[s[j]]++;
                t++;
            }
        }
        chmax( ans, t );
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
//#define random_shuffle(r...) random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}
ll prime[1000000];bool visprime[10000000];
void sieve(){ll k=0;for(ll i=2;i*i<=1000000;i++){for(ll j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(ll i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}
int myrandom (int i) { return std::rand()%i;}

bool checkbit(int mask,int bit) {return (mask & (1<<bit));}

int main()
{

    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<POW(2,n);i++)
    {
        string x;
        for(int j=n-1;j>=0;j--)
        {
            if(checkbit(i,j)) x+='1';
            else x+='0';
        }
        v.pb(x);
       // x.clear();

    }
    vector<pair<int,int>>contra[18];
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        while(x--)
        {
            int a,b;
            cin>>a>>b;
            a--;
            contra[i].pb({a,b});
        }
    }


   int mx=-1;
    for(int i=0;i<POW(2,n);i++)
    {

        bool flag=true;
        for(int j=n-1;j>=0;j--)
        {

            if(checkbit(i,j))
            {
                for(int k=0;k<contra[j].size();k++)
                {
                    pair<int,int> p=contra[j][k];
                    int a,b;
                    a=p.first; b=p.second;
                    if(checkbit(i,a)!=b)  {flag=false; break;}
                }
                if(flag==false) break;
            }

        }

        if(flag==true)
        {
            int x= __builtin_popcount(i);
            mx=max(mx,x);
        }



    }
    cout<<mx<<endl;

}
















Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int o(int a,int b,int c,int d){
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}

int main(){
    int x,X,y,Y;cin>>x>>y>>X>>Y;
    int dx=(x-X);
    int dy=(y-Y);
    o(X+dy,Y-dx,x+dy,y-dx);
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    string S; cin>>S;
    if(S.at(0)=='M')A[0]++;
    if(S.at(0)=='A')A[1]++;
    if(S.at(0)=='R')A[2]++;
    if(S.at(0)=='C')A[3]++;
    if(S.at(0)=='H')A[4]++;
  }
  cout<<A[0]*A[1]*A[2]+A[0]*A[1]*A[3]+A[0]*A[1]*A[4]+A[0]*A[2]*A[3]+A[0]*A[2]*A[4]+A[0]*A[3]*A[4]+A[1]*A[2]*A[3]+A[1]*A[2]*A[4]+A[1]*A[3]*A[4]+A[2]*A[3]*A[4]<<endl;
}

Measured memory_bytes: 3940
# Refer to:
# https://qiita.com/mochizukikotaro/items/c335e6dcc5020ead0b92
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| push(a)}
  end

  def push(element)
    @data.push(element)
    bottom_up
  end
  
  # added by univ
  def top
    if size == 0
      return nil
    else
      @data[0]
    end
  end

  def pop
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end
  
  # added by univ
  def sum
    @data.inject(:+)
  end
  
  def size
    @data.size
  end
  
  # added by univ
  def empty?
    @data.size == 0
  end
  
  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def parent_idx(target_idx)
    (target_idx - (target_idx.even? ? 2 : 1)) / 2
  end

  def bottom_up
    target_idx = size - 1
    return if target_idx == 0
    parent_idx = parent_idx(target_idx)
    while (@data[parent_idx] > @data[target_idx])
      swap(parent_idx, target_idx)
      target_idx = parent_idx
      break if target_idx == 0
      parent_idx = parent_idx(target_idx)
    end
  end

  def top_down
    target_idx = 0

    # child がある場合
    while (has_child?(target_idx))

      a = left_child_idx(target_idx)
      b = right_child_idx(target_idx)

      if @data[b].nil?
        c = a
      else
        c = @data[a] <= @data[b] ? a : b
      end

      if @data[target_idx] > @data[c]
        swap(target_idx, c)
        target_idx = c
      else
        return
      end
    end
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end
end

mod = 10 ** 9 + 7
def an(n,d=0) Array.new(n,d)end
def an2(n,m,d=0) Array.new(n){an(m,d)}end
def an3(n,m,l,d=0) Array.new(n){an2(m,l,d)}end

n, m = gets.split.map(&:to_i)

t = Array.new(10**5+1){[]}
n.times do |i|
  a, b = gets.split.map(&:to_i)
  t[a].push(b)
end

ans = 0
pq = PriorityQueue.new()
(1..m).each do |d|
  t[d].each{|b| b*=-1; pq.push(b) }
  if pq.size > 0
    ans -= pq.pop
  end
end

puts ans

Measured memory_bytes: 11516
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nvu = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nvu[0];
        var v = nvu[1] - 1;
        var u = nvu[2] - 1;

        List<int>[] tree = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            tree[st[0]].Add(st[1]);
            tree[st[1]].Add(st[0]);
        }
        int res = 0;
        var takDists = tree.CalcDists(v);
        var aokDists = tree.CalcDists(u);
        for (int i = 0; i < takDists.Length; i++)
        {
            var tak = takDists[i];
            var aok = aokDists[i];
            if (tak < aok) res = Math.Max(res, aok - 1);
        }
        Console.WriteLine(res);
    }
    
    static int[] CalcDists(this List<int>[] tree, int v)
    {
        var res = new int[tree.Length];
        Stack<int> stack = new Stack<int>();
        stack.Push(v);
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            foreach (var item in tree[elem])
            {
                if (res[item] != 0 || item == v) continue;
                res[item] = res[elem] + 1;
                stack.Push(item);
            }
        }
        return res;
    }
}


Measured memory_bytes: 30424
import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.IO

main = do
  [n,x] <- map read . words <$> getLine :: IO [Int]
  as <- listArray (0,n-1) . map read . words <$> getLine :: IO (UArray Int Int)

  m <- newArray ((0,0),(n-1,n-1)) 0 :: IO (IOUArray (Int,Int) Int)

  forM_ [0..n-1] $ \i -> writeArray m (i,0) (as!i)
  forM_ [1..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      writeArray m (i,k) =<< min (as!((i-k+n)`mod`n)) <$> readArray m (i,k-1)
        
  print =<< minimum <$> (forM [0..n-1] $ \k -> (+k*x) . sum <$> (forM [0..n-1] $ \i -> readArray m (i,k)))


Measured memory_bytes: 208252
from collections import defaultdict
N = int(input())
D = defaultdict(int)


# 素因数分解
def prime_factorization(n):
    table = []
    for x in range(2, int(n**0.5)+2):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


for n in range(2, N + 1):
    T = prime_factorization(n)
    for t in T:
        D[t] += 1


def num(m):
    return len([i for i in D.values() if i >= m - 1])


ans = num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) // 2
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>


int main() {
	int n, k, s; std::cin >> n >> k >> s;
	std::vector<int> result(n);
	if (s == 1000000000) {
		std::fill(result.begin(), std::next(result.begin(), k), s);
		std::fill(std::next(result.begin(), k), result.end(), s - 1);
	}
	else {
		std::fill(result.begin(), std::next(result.begin(), k), s);
		std::fill(std::next(result.begin(), k), result.end(), s + 1);
	}
	for (auto i = 0; i < n; ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << result[i];
	}
	std::cout << std::endl;
}


Measured memory_bytes: 1664
n = gets.chomp.to_i
v = gets.chomp.split().map {|v| v.to_i}
c = gets.chomp.split().map {|v| v.to_i}

sum = 0
n.times do |i|
  diff = v[i] - c[i]
  if 0 < diff
    sum += diff
  end
end

puts(sum)



Measured memory_bytes: 1788
#include <stdio.h>
int main(){
    int S;
    int h,m,s;
    scanf("%d",&S);
    h=(S/3600);
    m=(S%3600)/60;
    s=S-3600*h-60*m;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair

int main() {
    int n;
    cin>>n;
    double r=0;double b,c=1;
    for(int i=0;i<n;i++)
    {

        cin>>b;
        r+=c/b;
    }
    r=c/r;
    printf("%.10f",r);
    return 0;
}
// ABAB
//


Measured memory_bytes: 256
// In The Name Of Allah
// Mehrkish Makuei

#include <bits/stdc++.h>

#define pb push_back
#define debug1(x) cerr << #x << " : " << x << endl;
#define debug2(x, y ) cerr << #x << " : " << x << "  " << #y << " : " << y << endl;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector <ll> vll;
typedef set <char> sch;
typedef set <ll> sll;

const ll MOD = 1e9 + 7;
const ll MAXN = 1e5 + 19;

ll n, a[MAXN], dp[MAXN];

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for ( int i = 0; i < n; i++ )
		cin >> a[i];
	dp[1] = abs( a[1] - a[0] );
	for ( int i = 2; i < n; i++ ){
		dp[i] = min( abs( a[i] - a[i - 1] ) + dp[i - 1], abs( a[i] - a[i - 2] ) + dp[i - 2] );
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
)
type point struct {
	row int
	col int
	stable bool
}
var N = 8
var col []bool
var dpos []bool
var dneg []bool
var stay []point
var out = bufio.NewWriter(os.Stdout)
func main() {
	var in = bufio.NewReader(os.Stdin)
	var n, r, c int
	col = make([]bool, N)
	dpos = make([]bool, 2*N-1)
	dneg = make([]bool, 2*N-1)
	fmt.Fscanf(in, "%d\n", &n)
	stay = make([]point, N)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &r, &c)
		//row[r] = c
		stay[r] = point{r, c,true}
		makeNotFree(r, c)
	}
	putQueen(0)
}
func putQueen(r int) {
	if r == N {
		printBoard()
		return
	}else if stay[r].stable {
		putQueen(r + 1)
	}else{
		for c := 0; c < N; c++ {
			if col[c] != true && dpos[c+r] != true && dneg[r-c+N-1] != true{
					makeNotFree(r, c)
					putQueen(r + 1)
					makeFree(r, c)
			}
		}
	}
}
func makeNotFree(r, c int) {
		col[c], dpos[r+c], dneg[r-c+N-1] = true, true, true
	if !stay[r].stable {
		stay[r].col = c
		stay[r].row = r
	}
}
func makeFree(r, c int)    {
	if !stay[r].stable {
		col[c], dpos[r+c], dneg[r-c+N-1] = false, false, false
	}
}
func printBoard() {
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if stay[i].row == i && stay[i].col == j {
				fmt.Fprint(out, "Q")
			} else {
				fmt.Fprint(out, ".")
			}
			out.Flush()
		}
		fmt.Fprintf(out, "\n")
		out.Flush()
	}
}



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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

vi sub(vector<bool> fin,ll n) {
  vi ret;
  REP(i,n) {
    if(fin.at(i))continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vi result = sub(cp,n);
    ret.insert(ret.end(),result.begin(),result.end());
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  vi a(n);
  REP(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  REP(i,n-1) if(a.at(i)==a.at(i+1)) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
}


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

bool is_war(const vector<int> & x,const vector<int> & y){
  for(int Z=-100;Z<=100;Z++){
    bool is_ok= true;
    for(int i=0;i<x.size();i++){
      if(x[i]>=Z)is_ok=false;
    }
    for(int i=0;i<y.size();i++){
      if(y[i]<Z)is_ok=false;
    }
    if ( is_ok ) return false ;
  }
  return true;
}



int main() {
  int N,M;cin >>N >> M;
  vector<int> x(N+1),y(M+1);
  cin >> x[0] >> y[0];
  rep(i,N) cin >> x[i+1];
  rep(i,M) cin >> y[i+1];
  if ( is_war (x , y )) {
    cout << "War " << endl ;
  }
  else {
    cout << "No War " << endl ;
    }
  return 0;
}

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

int main (void){
  int N,K;

  int t = 'a' - 'A';
  cin >> N >>K;
  char *A = new char[N];
  for(int i = 0;i < N; i++){
    cin >> A[i];
  }

  A[K-1] =  A[K-1] + 32;

  for(int j = 0;j < N; j++){
    printf("%c",A[j]);
  }
  printf("\n");
  delete[] A;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int NMAX = (int)1e5+1;

int max(int a,int b){
  return a>b ? a : b;
}

int main(){
  int n,a[NMAX],i,j,k,ans=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  sort(a,a+n);
  
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n;k++)
        if(a[i]+a[j] <= a[k])break;
      ans += k-j-1;
    }
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
void isl(int in[50][50],int x,int y){
in[x][y]=0;
loop(i,-1,2){
loop(j,-1,2){
if(x-i>=0&&x-i<50&&y-j>=0&&y-j<50&&in[x-i][y-j])isl(in,x-i,y-j);
}
}
}
int main(){
int n,m;
while(cin>>n>>m,n||m){
int in[50][50]={0};
int co=0;
rep(i,m)
rep(j,n)
cin>>in[i][j];

rep(i,m){
rep(j,n){
if(in[i][j]){co++;isl(in,i,j);}
}
}
cout<<co<<endl;
}
}

Measured memory_bytes: 1356