akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int c;
    const int n = 39;
    while(cin >> c){
	c %= n;
	if(c==0) c = n;
	printf("3C%02d\n",c);
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Integer output = 0;
		Integer aInteger = new Integer(scanner.next());
		Integer bInteger = new Integer(scanner.next());

		StringBuffer buffer ;
		for(int i = aInteger; i <= bInteger;i++ ) {
			buffer = new StringBuffer(String.valueOf(i));
			if(String.valueOf(i).compareTo(String.valueOf(buffer.reverse()))==0) {
				output++;
			}
		}
		System.out.println(output);
		scanner.close();
	}
}


Measured memory_bytes: 38484
<?php
    $n;
    $ar = array();
    $ans = 1;
    $r = 0;
    $s = -1;
    fscanf(STDIN, "%d", $n);
    for($i = 0; $i < $n; $i++){
        $a;
        fscanf(STDIN, "%d", $a);
        $ar[$a] = 0;
    }
    for($i = 0; $i < $n; $i++){
        $b;
        fscanf(STDIN, "%d", $b);
        $ar[$b] = 1;
    }
    ksort($ar);
    foreach($ar as $v){
        if($v == $s){
            $r++;
        }else if($r == 0){
            $r++;
            $s = $v;
        }else{
            $ans *= $r;
            $ans %= 1000000007;
            $r--;
        }
    }
    echo "$ans\n";
?>


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

#define INF 1930000000
int main(){
    int n;
    cin >> n;
    vector<int> arr(n,0);
    for(int d = 0; d < n; d++) cin >> arr[d];
    sort(arr.begin(),arr.end());

    //cout << arr[0] << "," << arr[1] << endl;
    //return 0;
    int ans = INF;
    int res = 0;
    if(arr[0] == arr[n-1]){
        cout << 0 << endl;
        return 0;
    }
    for(int i = arr[0]; i < arr[n-1]; i++){
        for(int j = 0; j < n; j++){
            res += (i-arr[j])*(i-arr[j]);
        }
        //cout << res<< endl;
        if(ans > res) ans = res;//最小値を更新する。
        res = 0;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    string out = "Yes";
    ll t = A/D;
    if(A%D!=0) t++;
    ll a = C/B;
    if(C%B!=0) a++;
    if(a>t) out = "No";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iostream>
#include<cstdlib>
#include  <string.h>
using namespace std;
long long x,y,z,a,b,c,k,have1[11111],have2[11111],have3[11111],have12[11111],have123[11111];
int main(){
  cin>>x>>y>>z>>a>>b>>c>>k;
  memset(have1,0,sizeof (have1));
  memset(have2,0,sizeof (have2));
  memset(have3,0,sizeof (have3));
  for (int i=0;i<x;i++)  have1[abs(i-a)%k]++;
  for (int i=0;i<y;i++)  have2[abs(i-b)%k]++;
  for (int i=0;i<z;i++)  have3[abs(i-c)%k]++;
  memset(have12,0,sizeof (have12));
  for (int i=0;i<k;i++)
    for (int j=0;j<k;j++)
      have12[(i+j)%k]+=have1[i]*have2[j];
  memset(have123,0,sizeof (have123));
  for (int i=0;i<k;i++)
    for (int j=0;j<k;j++)
       have123[(i+j)%k]+=have12[i]*have3[j];
   for (int i=0;i<k-1;i++)
        cout<<have123[i]<<" ";
   cout<<have123[k-1]<<endl;

}

Measured memory_bytes: 3504
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main() {
    string str;
    string x,y;
    int a;
    int b,c;
    cin >> str;
    cin >> a;
    for (int i=0; i<a; i++) {
        cin >> x >> b >> c;
        if(x=="replace"){
            cin >> y;
            str.replace(b,c-b+1,y);
        }
        if(x=="reverse"){
            reverse( str.begin() + b, str.begin() + c + 1);
        }
        if(x=="print"){
            cout <<str.substr(b,c-b+1) <<endl;
        }
    }
}



Measured memory_bytes: 3188
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        
        int cnt = 0;
        for(int i=0; i<=A; i++){
            for(int j=0; j<=B; j++){
                int c = (X - i*500 - j*100)/50;
                if(c>=0 && c<=C){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>


using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };


#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll m, n, p[10010], e[510], c[510], rui[10010], ans;
ll dp[510][10100];

int main() {
	cin >> m >> n;
	for (int i = 1;i <= m;i++)cin >> p[i];
	for (int i = 0;i < n;i++) {
		cin >> c[i] >> e[i];
	}
	sort(p, p + m);
	for (int i = 1;i <= m;i++) {
		rui[i] = rui[i - 1] + p[i];
	}
	dp[0][0] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j <= m;j++) {
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			dp[i + 1][min(m, j + c[i])] = max(dp[i + 1][min(m, j + c[i])], dp[i][j] + rui[min(m, j + c[i])] - rui[j] - e[i]);
		}
	}
	for (int i = 0;i <= m;i++) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 42784
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define MAX_V 100010

using namespace std;
vector<long long> G[MAX_V],a;
bool used1[MAX_V],used2[MAX_V];
int V,E,k=0;
long long b[MAX_V];
pair<int,long long> p[MAX_V];

void dfs(int s){
	if(a[b[k]]>a[s]){
		b[k] = s;
	}
	used1[s] = true;
	int i = 0;
	while(true){
		int e = G[s][i];
		if(e==-1){
			break;
		}
		i++;
		if(!used1[e]){
			dfs(e);
		}
	}
}

int main(){
	int i,j;
	long long x,ans=0;
	cin >> V >> E;
	for(i=0;i<V;i++){
		cin >> x;
		a.push_back(x);
		p[i] = make_pair(x,i);
		used1[i] = false;
		used2[i] = false;
		b[i] = V;
	}
	a[V] = 1000000000;
	for(i=0;i<E;i++){
		int s,t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	for(i=0;i<V;i++){
		G[i].push_back(-1);
	}
	
	for(i=0;i<V;i++){
		if(!used1[i]){
			dfs(i);
			used2[b[k]] = true;
			ans += a[b[k]];
			k++;
		}
	}
	if(k==1){
		cout << 0 << endl;
		return 0;
	}
	int cnt = k;
	if(V<2*(k-1)){
		cout << "Impossible" << endl;
		return 0;
	}
	
	sort(p,p+V);
	for(i=0;i<V;i++){
		if(cnt==2*(k-1)){
			break;
		}
		if(!used2[p[i].second]){
			ans += p[i].first;
			cnt++;
		}
	}
	cout  << ans << endl;
}
	


Measured memory_bytes: 10868
N = int(input())
#A = [int(i) for i in input().split()]
A = [int(input()) for _ in range(N)]

idx1, ma1 = A.index(max(A)), max(A)

tmp = A[idx1]
A[idx1] = 0
idx2, ma2 = A.index(max(A)), max(A)

A[idx1] = tmp

for i in A:
	if i == ma1:
		print(ma2)
	else:
		print(ma1)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll ans = 0;
  for(int i = 1; i < N; ++i) {
    if(A[i - 1] > A[i]) {
      ans += (A[i - 1] - A[i]);
      A[i] += (A[i - 1] - A[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N <= K) cout << N * X << endl;
    else cout << K * X + (N - K) * Y << endl;
    return 0;
}


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

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

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    if(n * a <= b){
        cout << n*a << endl;
    }else{
        cout << b << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>

#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,i;
    cin >> N >> i;
    cout << N-i+1 << endl;
    return 0;
}

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

int main() {
	int l,r,d;
		cin >> l >> r >> d;
		int ans =  r/d-l/d;
		if(l%d==0)ans++;
		cout << ans <<endl;
	return 0;
}


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

int main(){
    long long h, w;
    cin >> h >> w;
    long long sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    sh--, sw--, gh--, gw--;

    char maze[h][w];

    for(long long i = 0; i < h; i++){
        for(long long j = 0; j < w; j++){
            cin >> maze[i][j];
        }
    }

    vector<vector<long long> > cost(h, vector<long long>(w, 1e12));

    cost[sh][sw] = 0;
    deque<pair<long long, long long> > q;//dequeを使用 前後からpush, popができる 01-bfs

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

    q.push_front(make_pair(sh, sw));

    while(!q.empty()){
        pair<long long, long long> top;
        top = q.front();
        q.pop_front();
        
        for(long long i = 0; i < 4; i++){
            if(0 <= top.first+dy[i] and top.first+dy[i] < h and 0 <= top.second+dx[i] and top.second+dx[i] < w and maze[top.first+dy[i]][top.second+dx[i]] == '.' and cost[top.first+dy[i]][top.second+dx[i]] > cost[top.first][top.second]){
                cost[top.first+dy[i]][top.second+dx[i]] = cost[top.first][top.second];
                q.push_front(make_pair(top.first+dy[i], top.second+dx[i]));
            }
        }

        for(long long i = -2; i <= 2; i++){
            for(long long j = -2; j <= 2; j++){
                if(i == 0 and j == 0) continue;

                if(0 <= top.first+i and top.first+i < h and 0 <= top.second+j and top.second+j < w and maze[top.first+i][top.second+j] == '.' and cost[top.first+i][top.second+j] > cost[top.first][top.second] + 1){
                    cost[top.first+i][top.second+j] = cost[top.first][top.second] + 1;
                    q.push_back(make_pair(top.first+i, top.second+j));
                }
            }
        }
    }

    if(cost[gh][gw] == 1e12) cost[gh][gw] = -1;
    printf("%lld\n", cost[gh][gw]);
    return 0;
}

Measured memory_bytes: 12692
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    ll a[n][26];
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        cin>>s;
        int m=s.length();
        for(int j=0;j<m;j++){
            a[i][(s[j]-'a')]++;
        }
    }
    string t="";
    ll num;
    for(int i=0;i<26;i++){
        num=1e9;
        for(int j=0;j<n;j++){
            num=min(num,a[j][i]);
        }
        for(int j=0;j<num;j++){
            t+=('a'+i);
        }
    }
    cout << t<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void) {
    int n,i,j,sieve[10001]={0};
    sieve[1]=1;
    for (i=2; i<=sqrt(10000); i++) {
        if (sieve[i]==0) {
            for (j=i*2; j<=10000; j+=i) sieve[j]=1;
        }
    }
    while (scanf("%d",&n)!=EOF) {
        int count=0;
        if (n%2==0) {
            for (i=2; i<=n/2; i++) {
                if (sieve[i]==0&&sieve[n+1-i]==0) count++;
            }
            printf("%d\n",count*2);
        } else {
            for (i=2; i<=n/2; i++) {
                if (sieve[i]==0&&sieve[n+1-i]==0) count++;
            }
            if (sieve[n/2+1]==0) {
                printf("%d\n",count*2+1);
            } else {
                printf("%d\n",count*2);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[1010];
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        printf("%d\n",a[n-1]-a[0]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int a[3];
    rep(i,3){
        cin>>a[i];
    }
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
    
}


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

int main(){
  long long int N,P;

  long long int pans = 0,ans = 0;

  cin >>N>>P;

  if(N == 1){
    cout <<P<<endl;
    return 0;
  }

  while(pow(pans,N) <= P ){
    pans++;
    /*cout <<pans<<endl;
    cout <<pow(pans,N)<<' '<<P<<endl;
    cout <<(double)P/pow(pans,N)<<' '<<(long long int)(P/pow(pans,N))<<endl;
    /*if (pans == 210)break;*/
    if((P % (long long int)pow(pans,N)) == 0)ans = pans;
  }

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


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long[10^^5] AS, BS;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        auto ab = readln.split.to!(long[]);
        AS[i] = ab[0];
        BS[i] = ab[1];
    }

    long r;
    foreach_reverse (i; 0..N) {
        AS[i] += r;
        r += AS[i] % BS[i] == 0 ? 0 : BS[i] - AS[i] % BS[i];
    }
    writeln(r);
}

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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;


int main()
{
    string s;
    cin>>s;
    int sum=0;
    int flag=0;
    rep(i,0,s.size())
    {
        if(s[i]=='R'&&flag==0)
        {
            while(s[i]=='R'&&i<s.size())
            {
                sum++;
                i++;
            }
            flag=1;
            i--;
        }
    }
    cout<<sum;
return 0;
}

Measured memory_bytes: 3640
import numpy as np
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
fact = factorization(n)
vals = []
for f in fact:
  for e in range(1, f[1]+1):
    vals.append(f[0]**e)
vals.sort()
if n==1:
  print(0)
else:
  ans = 0
  for d in vals:
    if n%d == 0:
      ans += 1
      n /= d
  print(ans)

Measured memory_bytes: 27164
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').ToArray();
        string a = input[0];
        string b = input[1];
        bool useA = a.CompareTo(b) < 0;
        
        if (useA)
        {
            for (int i = 0; i < int.Parse(b); i++)
            {
                Console.Write(a);
            }
        }
        else
        {
            for (int i = 0; i < int.Parse(a); i++)
            {
                Console.Write(b);
            }
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 13408
#include<stdio.h>

int main(){
	char s1[21], s2[21];
	int i, j;
	scanf("%s",s1);
	for(i=0;s1[i]!='\0';i++){}
	i--;
	j=0;
	for(;i>=0;i--){
		s2[j++]=s1[i];
	}
	s2[j]='\0';
	printf("%s\n",s2);
	return 0;
}

Measured memory_bytes: 524
#include<iostream>

using namespace std;

int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    cout << ((A == 7 && B == 5 && C == 5) || (A == 5 && B == 7 && C == 5) || (A == 5 && B == 5 && C == 7) ? "YES" : "NO") << endl;
}

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

int main(){
  int n;cin>>n;
  vector<int> a(n),b(n);
  int s=0,s_,ans;
  rep(i,n){
    cin>>a.at(i);
    s+=a.at(i);      
  }
  rep(i,n){cin>>b.at(i);}
  s+=b.at(n-1);
  ans=s;
  for(int i=n-1; i>0; i--){
    s_=s;
    s=s-a.at(i)+b.at(i-1);
    ans=max(ans,s);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const int maxn=1e5+10;
#define LL long long
LL n,ans;
LL a[maxn],b[maxn];
int main()
{
	LL i,j;
    scanf("%d",&n);
	for(i=1;i<=n;i++)
            scanf("%lld%lld",&a[i],&b[i]);
	for(i=n;i>=1;i--)
	{
		a[i] += ans;
		for(j=a[i]/b[i];;j++)
			if(j*b[i]>=a[i])
				break;
		LL comm = j*b[i] - a[i];
		ans += comm;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1664
N = int(input())
X = list(map(int,input().split()))
d = [0]*(max(X)+1-min(X))
for i in range(min(X),max(X)+1):
  for x in X:
    d[i-min(X)] += (x-i)**2
  if i > min(X) and d[i-min(X)] >= d[i-1-min(X)]:
    print(d[i-1-min(X)])
    exit(0)    
print(min(d))

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

bool dfs(int node, vector<vector<pair<int, int> > >& adj, vector<ll>& vals, vector<int>& seen)
{
  seen[node] = 1;
  for (int i = 0; i < (int)adj[node].size(); ++i) {
    pair<int, int> p = adj[node][i];
    int next = p.first, d = p.second;
    if (seen[next] and vals[next] != vals[node] + d) { return false; }
    if (seen[next]) { continue; }
    vals[next] = vals[node]+ d;
    if (not dfs(next, adj, vals, seen)) { return false; }
  }
  return true;
}

bool is_ok(vector<vector<pair<int, int> > >& adj)
{
  int n = adj.size();
  vector<ll> vals(n);
  vector<int> seen(n, 0);
  for (int i = 0; i < n; ++i) {
    if (not seen[i]) {
      vals[i] = 0;
      if (not dfs(i, adj, vals, seen)) {
        return false;
      }
    }
  }
  return true;
}

int main()
{
  int N, M;
  scanf("%d %d", &N, &M);
  vector<vector<pair<int, int> > > adj(N);
  for (int i = 0; i < M; ++i) {
    ll l, r, d;
    scanf("%lld %lld %lld", &l, &r, &d);
    adj[l - 1].push_back(make_pair(r - 1, -d));
    adj[r - 1].push_back(make_pair(l - 1, d));
  }

  string ans = is_ok(adj) ? "Yes" : "No";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13696
from collections import Counter

N = int(input())
*A, = map(int, input().split())
c = Counter(A)

ans = 0
for i in c.values():
    ans += i*(i-1)//2

for i in A:
    b = ans
    b -= c[i]*(c[i]-1)//2
    b += (c[i]-1)*(c[i]-2)//2
    print(b)

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

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

using namespace std;

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

  int result=1;
  rep(i,x-1){
    int t = 2;
    int c=i+2;
    int pct;
    while((pct=pow(c,t))<=x){
      result = max(result,pct);
      t++;
    }
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[101];
void solve() {
	int n;
	cin >> n;
	int s = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	if (s % 10 == 0) {
		int mn = s;
		for (int i = 0; i < n; i++) {
			if (a[i] % 10 != 0) {
				mn = min(mn, a[i]);
			}
		}
		s -= mn;
	}
	cout << s;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

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

int main() {
	int N;
	cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
      cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    int count=0;
    for(int i=0;i<N;i++){
      if(i+1<N && d.at(i) == d.at(i+1)){
        count++;
      }
    }
    cout << N-count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n, W;
	cin>>n>>W;
	ll w[n], v[n];
	for(ll i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}
	vector<vector<ll>>dp(n+1, vector<ll>(W+1, 0));
	for(ll i = 0; i <= n; i++){
		for(ll j = 0; j<=W; j++){
			if(i==0 || j==0) dp[i][j] = 0;
			else if(w[i-1] <= j) dp[i][j] = max(v[i-1] + dp[i-1][j-w[i-1]], dp[i-1][j]);
			else dp[i][j] = dp[i-1][j];
			
			//cout<<dp[i][j]<<" ";
		}
		//cout<<"\n";
	}

	cout<<dp[n][W];
}

Measured memory_bytes: 80256
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    N = input_int()
    ans = ""
    while N:
        r = N % 2
        if r < 0:
            r += 2
        N = (N - r) // (-2)
        ans += str(r)
    ans = ans[::-1]
    if ans:
        print(ans)
    else:
        print(0)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61364
#include <stdio.h>

int main() {
    char c = getchar();
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        printf("vowel\n");
    } else {
        printf("consonant\n");
    }
    return 0;
}


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

bool judge(int num) {
    for(int i = 2; i < num; i++) {
        if(num % i == 0)
            return false;
    }
    return true;
}
int main() {
    int x;
    cin >> x;
    int num = x;
    while(1) {
        if(judge(num)) {
            cout << num << endl;
            ;
            break;
        }
        num++;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vii vector<int>
#define vcc vector<char>
#define pll pair<long long, long long>
#define mem memset
#define sof sizeof
#define PB push_back
#define MP make_pair
#define TS to_string
#define F first
#define S second
#define endl '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c=0,d,e,f,i,j,k,m,n,o,x,y;
    string s, t;
    cin>>s>>t; 
    n=s.size();
    for(i=0;i<n;i++){
        if(s[i]!=t[i]) c++;
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 3844
using System;
using System.Linq;

class Program
{
  static void Main()
  {
    uint N = uint.Parse(Console.ReadLine());
    uint n = N;
    uint sum = 0;
    while (n > 0) {
      sum += n % 10;
      n /= 10;
    }
    bool res = N % sum == 0;
    Console.WriteLine(res ? "Yes" : "No");
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a,b;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
    	cin>>a>>b;
    	v.pb(make_pair(b,a));
    }
    sort(be(v));
    ll num=0;
    for(int i=0;i<n;i++){
    	num+=v[i].second;
    	if(num>v[i].first){
    		cout << "No" <<endl;
    		return 0;
    	}
    }
    cout <<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 	int a,b,c;
 	cin >> a >> b >> c;
 	swap(a,b);
 	swap(a,c);
 	cout << a << ' ' << b << ' ' << c << '\n';   
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(N);
    map<int,int> list;
    FOR(i,N){
        GI(a);
        list[a]++;
    }
    ll ans=0;
    for(P p:list){
        if(p.first<p.second){
            ans+=p.second-p.first;
        }else if(p.first>p.second){
            ans+=p.second;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin>>N;
  vec<int>a(N);
  REP(i,N){
    cin>>a[i];
    a[i]-=i+1;
  }
  sort(ALL(a));
  int b=a[N/2];
  int ans=0;
  REP(i,N){
    ans+=abs(a[i]-b);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

#define inf 0x3f3f3f3f; 

int d[21000];

int gh[1100][1100];
bool v[1100][1100]={0};
int lowcost[2100];
int n,m;
bool vis[2100]={0};
queue<int>q;                              

int main()
{
     int i,j,k,l,x,p,flag=0;
     long long ans;
     cin>>n;
     for (i=1;i<=n;i++)
       for (j=1;j<=n;j++)
         cin>>gh[i][j];
     
     for (k=1;k<=n;k++)
       for (i=1;i<=n;i++)
         for (j=1;j<=n;j++)
         if (i!=k && j!=k && i!=j)
         {
         
           if (gh[i][k]+gh[k][j]<gh[i][j]) flag=1;
           if (gh[i][k]+gh[k][j]==gh[i][j]) v[i][j]=1;
         } 
     ans=0;
     
     if (flag==1)
       cout<<"-1"<<endl;
     else
     {
         for (i=1;i<=n;i++)
           for (j=i+1;j<=n;j++)
              if  (!v[i][j]) 
              {
  
                ans=ans+gh[i][j];
                }
        cout<<ans<<endl;      
     }
     
   return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
int s1[maxn],s2[maxn],s3[maxn];
int main()
{
    int n;
    ll a,b;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&s1[i]);
    sort(s1+1,s1+1+n);
    for(int i=1;i<=n;i++) scanf("%d",&s2[i]);
    sort(s2+1,s2+1+n);
    for(int i=1;i<=n;i++) scanf("%d",&s3[i]);
    sort(s3+1,s3+1+n);
    ll ans=0;
    for(int i=1;i<=n;i++){
        a=lower_bound(s1+1,s1+1+n,s2[i])-(s1+1);
        b=upper_bound(s3+1,s3+1+n,s2[i])-(s3+1);
       ans+=1ll*a*(n-b);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

#define N 10000

int main()
{
  int n,tmpmin,tmpmax,a[N];
  long long int i,sum=0;
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

  tmpmin=a[0];
  tmpmax=a[0];
  sum=a[0];
  for(i=1;i<n;i++){
    sum+=a[i];
    
    if(tmpmax<a[i])
      tmpmax=a[i];
    if(tmpmin>a[i])
      tmpmin=a[i];
  }

  printf("%d %d %lld\n",tmpmin,tmpmax,sum);
  
  return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int n,q;
    string s;
    cin >> n >> s >> q;
    set < int > v[26];
    for( int i = 0; i < (int)s.size(); i++ ){
        v[s[i] - 'a'].insert(i);
    }
    for( int i = 1; i <= q; i++ ){
        int tp;
        cin >> tp;
        if( tp == 1 ){
            int p;
            char c;
            cin >> p >> c;
            p--;
            v[s[p] - 'a'].erase(p);
            s[p] = c;
            v[s[p] - 'a'].insert(p);
        }else{
            int l,r;
            cin >> l >> r;
            l--,r--;
            int ans = 0;
            for( int j = 0; j < 26; j++ ){
                auto p = v[j].lower_bound(l);
                if( p != v[j].end() && *p <= r )ans++;
            }
            cout << ans << "\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 24220
// AOJ ITP 1_4_B
#include<cstdio>
#include<cmath>

const double pi = acos( -1 );

int main()
{
	double r;
	scanf( "%lf", &r );
	printf( "%.6f %.6f\n", pi*r*r, 2*pi*r );

	return 0;
}

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

int main(){
  int n; cin >> n;
  int a[n];
  for(int i = 0; i < n; ++i) cin >> a[i];
  int b[n];
  for(int i = 0; i < n; ++i) b[i] = a[i] - (i + 1);
  sort(b,b + n);
  int mid = b[n/2];
  ll ans = 0;
  for(int i = 0; i < n; ++i){
    ans += (ll)abs(b[i] - mid);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 5200
from math import gcd
import sys
input = sys.stdin.readline

mod = 1000000007


def fpow(x, power, mod):
    x %= mod
    ans = 1
    while power != 0:
        if (power & 1) == 1:
            ans = ans * x % mod
        power >>= 1
        x = x * x % mod
    return ans


def fac(x):
    A = []
    i = 1
    while i * i <= x:
        if x % i == 0:
            A.append(i)
            if (x // i) != i:
                A.append(x // i)
        i += 1
    return A


n, k = map(int, input().split())
ans = 0
# print(fpow(n,k,mod))
A = [0] * (k + 2)
ans = 0
for i in range(k, 0, -1):
    #print(i,A[i],fpow(k // i, n, mod))
    A[i] += fpow(k // i, n, mod)
    while A[i] < 0:
        A[i] += mod
    A[i] %= mod
    ans = ans + A[i] * i
    ans %= mod
    B = fac(i)
    for b in B:
        if b!=i:
            A[b] -= A[i]

print(ans)


Measured memory_bytes: 74976
#include <bits/stdc++.h>
using namespace std;
class binary_indexed_tree {
  public:
    int n;
    vector<int> tree;
    binary_indexed_tree (int size) {
      n = size;
      tree.resize(n + 1, 0);
    }
    int sum (int i) {
      int ret = 0;
      while (i) {
        ret += tree[i];
        i -= i & -i;
      }
      return ret;
    }
    void add (int i, int x) {
      while (i <= n) {
        tree[i] += x;
        i += i & -i;
      }
    }
};
int n;
vector<int> a;
bool medianOrLess (int x) {
  vector<int> acm(n + 1, n + 1);
  for (int i = 0; i < n; i++) {
    acm[i + 1] = acm[i];
    if (a[i] >= x) {
      acm[i + 1]++;
    } else {
      acm[i + 1]--;
    }
  }
  long long inv = 0;
  binary_indexed_tree bit(2 * n + 1);
  for (int i = 0; i <= n; i++) {
    inv += bit.sum(acm[i]);
    bit.add(acm[i], 1);
  }
  if (inv >= (long long) n * (n + 1) / 2 - (long long) n * (n + 1) / 4) {
    return true;
  } else {
    return false;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int lb = 0;
  int ub = 1e9 + 1;
  while (ub - lb > 1) {
    int md = (lb + ub) / 2;
    if (medianOrLess(md)) {
      lb = md;
    } else {
      ub = md;
    }
  }
  cout << lb << '\n';
  return 0;
}

Measured memory_bytes: 1808
import numpy as np
from numba import njit


@njit('(f8[:,:,:],i4,i4,i4,i4,)')
def solve(dp, N, n1, n2, n3):

    if dp[n1][n2][n3] >= 0.0:
        return dp[n1][n2][n3]
    if n1 == n2 == n3 == 0:
        return 0.0

    cnt = n1 + n2 + n3
    ret = 0
    if n3 >= 1:
        ret += solve(dp, N, n1, n2 + 1, n3 - 1) * n3
    if n2 >= 1:
        ret += solve(dp, N, n1 + 1, n2 - 1, n3) * n2
    if n1 >= 1:
        ret += solve(dp, N, n1 - 1, n2, n3) * n1

    ret = (ret + N) / cnt
    dp[n1][n2][n3] = ret
    return ret


def main():
    N = int(input())
    A = list(map(int, input().split()))

    dp = np.full((N + 1, N + 1, N + 1), -1, dtype=np.float64)

    a1, a2, a3 = 0, 0, 0
    for i in range(N):
        if A[i] == 1:
            a1 += 1
        elif A[i] == 2:
            a2 += 1
        elif A[i] == 3:
            a3 += 1

    print(solve(dp, N, a1, a2, a3))


if __name__ == '__main__':
    main()


Measured memory_bytes: 330216
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int n;
string s;

int main(){
	while(cin>>n && n != -1){
		s="";
		int d=1;
		while(d*4<=n)d*=4;
		//cout<<n<<" "<<d<<endl;
		for(int i=d; i>0; i/=4){
			s+=(n/i+'0');
			n%=i;
		}
		//s+=(n+'0');
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1188
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	h,w,k = IN()
	ss=0
	ret=[]
	kv=1
	for i in range(h):
		wd = input()
		if ss >= 0 and wd == '.'*w:
			ss+=1
		elif wd == '.'*w:
			al=ret[-1][:]
			ret.append(al)
		else:
			al=[]
			stf=True
			for c in wd:
				if stf and c == '#':
					stf = False
				elif c == '#':
					kv+=1
				al.append(kv)
			else:
				kv+=1
			if ss >= 0:
				for i in range(ss+1):
					ret.append(al)
				ss=-1
			else:
				ret.append(al)
	for l in ret:
		print(*l)
		
		
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    
    int max=0;
    int semi=0;
    for(int i=0;i<n;i++){        
        if(max<a.at(i)){
            //cout<<1<<endl;
                semi=max;
            
            max=a.at(i);
        }
        else{
            //cout<<0<<endl;
            if(semi<a.at(i)){
                semi=a.at(i);
            }
        }
    }
    //cout<<max<<" "<<semi<<endl;
    for(int i=0;i<n;i++){
        if(a.at(i)<max){
            cout<<max<<endl;
        }
        else{
            cout<<semi<<endl;
        }
    }
}

Measured memory_bytes: 2432
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N;
	string S;
	cin >> N >> S;

	int x = 0;
	int ans = 0;
	FOR(i, 0, S.length()) {
		if (S[i] == 'I')
			x++;
		else
			x--;
		ans = max(ans, x);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanInit()

	n := nextInt()
	m := map[int]int{}
	sum := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		m[tmp]++
		sum += tmp
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		from := nextInt()
		to := nextInt()

		fromcnt := m[from]
		delete(m, from)
		m[to] += fromcnt
		sum -= from * fromcnt
		sum += to * fromcnt

		fmt.Println(sum)
	}

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 8672
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static int[] ans;
	static Map<Integer, Integer> map;

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

		int N = sc.nextInt();
		int Q = sc.nextInt();
		ans = new int[N];

		map = new HashMap<>();
		for (int i = 0; i < N - 1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (map.get(b) == null) {
				map.put(b, a);
			}
		}

		for (int i = 0; i < Q; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			ans[a - 1] += b;
		}

		for (int i = 2; i <= N; i++) {
			int p = map.get(i);
			ans[i - 1] += ans[p - 1];
		}
		for (int i = 0; i < N; i++) {
			if (i < N - 1) {
				System.out.print(ans[i]);
				System.out.print(" ");
			} else {
				System.out.println(ans[i]);
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 190204
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }


const long long MOD = 1000000007;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a -= t*b; swap(a, b);
        u -= t*v; swap(u, v);
    }
    return mod(u, m);
}

const int MAX_R = 510000;
long long Com1[MAX_R];
long long Com2[MAX_R];

void calc_Dcom(long long a, long long b) {
    memset(Com1, 0, sizeof(Com1));
    memset(Com2, 0, sizeof(Com2));
    long long s = 1, t = 1;
    Com1[0] = s, Com2[0] = t;
    for (int i = 1; i < MAX_R; ++i) {
        s = mod(s * (a-i+1), MOD);
        s = mod(s * inv(i, MOD), MOD);
        Com1[i] = s;
        
        t = mod(t * (b-i+1), MOD);
        t = mod(t * inv(i, MOD), MOD);
        Com2[i] = t;
    }
}

int main() {
    int n, m, A, B;
    while (cin >> n >> m >> A >> B) {
        --n; --m;
        calc_Dcom(n - A + B, m + A - B);
        
        long long res = 0;
        for (long long i = 0; i < max(n+1, m+1); ++i) {
            long long tmp = mod(Com1[B+i] * Com2[A+i], MOD);
            res += tmp;
            res %= MOD;
        }
        cout << res << endl;
    }
}























Measured memory_bytes: 8192
// ConsoleApplication72.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

// ConsoleApplication71.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include<algorithm>
#include<iomanip>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int a[100500];
int main()
{
	int n,lala=0;
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	if (a[n / 2] == a[n / 2 - 1])
	{
		cout << "0\n";
		return 0;
	}
	else
	{
		lala = abs(a[n / 2] - a[n / 2 - 1]);
	}
	cout << lala << "\n";
	return 0;
}


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

typedef long long ll;
using namespace std;
//using namespace atcoder;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _reps(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _reps, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

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

	cout << s;
	if(s[s.length()-1] == 's')	cout << "es" << endl;
	else						cout << "s" << endl;

	return 0;
}


Measured memory_bytes: 3624