akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w; cin >> h >> w;
  vector<string> grids(h);
  for (int i = 0; i < h; i++) cin >> grids[i];
  
  vector<vector<int>> nums(h, vector<int>(w, 0));
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grids[i][j] == '#') {
        if (i != 0) {
          if (j != 0) nums[i - 1][j - 1]++;
          nums[i - 1][j]++;
          if (j != w - 1) nums[i - 1][j + 1]++;
        }
        if (j != 0) nums[i][j - 1]++;
        if (j != w - 1) nums[i][j + 1]++;
        if (i != h - 1) {
          if (j != 0) nums[i + 1][j - 1]++;
          nums[i + 1][j]++;
          if (j != w - 1) nums[i + 1][j + 1]++;
        }
      }
    }
  }
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grids[i][j] == '.') {
        cout << nums[i][j];
      } else {
        cout << grids[i][j];
      }
    }
    cout << endl;
  }   
}

Measured memory_bytes: 256
minEvenity=29
N=int(input())
A=[0]*N
A=list(map(int,input().split()))
for i in range(N):
    evenity=0
    while A[i]%2==0:
        A[i]/=2
        evenity+=1
    minEvenity=min(evenity,minEvenity)
print(minEvenity)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int  long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 998244353
// order_of_key and *find_by_order
#define N 200001
int32_t main() {
	fast;
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int su = 0;
	sort(a, a + n);
	for (int i = 0; i < k; i++) {
		su += a[i];
	}
	cout << su;









}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<ll>());

    ll ans = 0;
    REP(i, n){
        ans += a[i/2];
    }
    ans -= a[0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> ABC(3);//0がA、1がB、2がC
  for (int i = 0; i < 3; i++){
    cin >> ABC.at(i);
  }
  vector<int> l(N);
  for (int i = 0; i < N; i++){
    cin >> l.at(i);
  }
  vector<int> bamboo(N);
  int MP = pow(10, 5);
  for (int i = 0; i < pow(4, N); i++){
    vector<int> abc(3);//仮の長さ
    vector<int> num(3, -1);
    int MPnow = 0;
    int now = i;
    for (int j = 0; j < N; j++){
      bamboo.at(j) = now % 4;
      now /= 4;
    }
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < N; k++){
        if (bamboo.at(k) == j){
          abc.at(j) += l.at(k);
          num.at(j)++;
        }
      }
      int MPabc = pow(10, 5);
      if (!(num.at(j) == -1)){
        MPabc = abs(ABC.at(j) - abc.at(j)) + num.at(j) * 10;
      }
      MPnow += MPabc;
    }
    MP = min(MP, MPnow);
  }
  cout << MP << endl;
  return 0;
}

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

int num[256];
int sum[256];
string str[108];
bool leading[256];
int n;
vector<char> chars;
int to_num(string str){
	int l  = str.size();
	if(l > 1 && num[str[0]] == 0)return -3141;
	int b = 1, res = 0;
	for(int i = l-1;i >= 0;i--){
		res += num[str[i]] * b;
		b *= 10;
	}
	return res;
}

bool solve(){
	cin >> n;
	int cnt = 0;
	if(n == 0)return false;
	chars.clear();
	for(int i = 0;i < 256;i++){
		sum[i] = 0;
		leading[i] = 0;
	}

	for(int i = 0;i < n;i++){
		cin >> str[i];
		int l = str[i].size();
		int b = 1;
		for(int j = l-1;j >= 0;j--){
			sum[str[i][j]] += b * ((i==n-1)?-1:1);
			chars.push_back(str[i][j]);
			b *= 10;
		}
		if(l > 1)leading[str[i][0]] = true;
	}	
	sort(chars.begin(), chars.end());
	chars.erase(unique(chars.begin(), chars.end()), chars.end());
	while(chars.size() < 10)chars.push_back('[');
	do{
		int res = 0;
		if(leading[chars[0]])continue;
		for(int i = 0;i < 10;i++){
			res += sum[chars[i]] * i;
		}
		cnt += res == 0;
	}while(next_permutation(chars.begin(),chars.end()));
	cout << cnt << endl;
	return true;
}

int main(){
	while(solve());
	return 0;
}


Measured memory_bytes: 3000
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	int[] A;
	int ans = 0;
	String[] op; 
	boolean flag = false;
	
	
	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = new char[4];
		op = new String[3];
		c = s.toCharArray();
		A = new int[4];
		A[0] = c[0] - '0';
		A[1] = c[1] - '0';
		A[2] = c[2] - '0';
		A[3] = c[3] - '0';
		dfs(0);
		sc.close();
	}
	
	void dfs(int pos) {
		if(pos == 3) {
			ans = A[0];
			for(int i = 0; i < 3; i++) {
				if(op[i] == "+") ans += A[i+1];
				else if(op[i] == "-") ans -= A[i+1];
			}
			if(ans == 7) {
				System.out.print(A[0] + op[0] + A[1] + op[1] + A[2] + op[2] + A[3]);
				System.out.println("=7");
				flag = true;
			}
			return;
		}
		if(!flag) {
			op[pos] = "+";
			dfs(pos+1);
		}
		if(!flag) {
			op[pos] = "-";
			dfs(pos+1);	
		}
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,r;
    cin>>a>>b>>c;

    if((a!=b)&&(b!=c)&&(c!=a)){
       cout<<3<<endl;
    }
    else if((a==b)&&(b==c)&&(c==a)){
        cout<<1<<endl;
    }
    else{
        cout<<2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int X;

int main() {
    cin >> X;

    int c = X / 100;
    int r = X % 100;
    cout << (r <= 5 * c ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;

int dist[100005][3];
    int n,m,x;
signed main(){

    cin >> n >> m >> x;
    int a[n][m];
    vector<int> c(n);
    rep(i,n) {
        int ca;
        cin >> ca;
        c[i] = ca;
        rep(j,m) {
            int aa;
            cin >> aa;
            a[i][j] = aa;
        }
    }
    int ma = inf;
    for (int bit = 0; bit < (1<<n); ++bit) {
        bool f = true;
        int total = 0;
        vector<int> S(m);
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                total += c[i];
                rep(j,m) S[j] += a[i][j];
            }
        }
        for(auto s: S) {
            if(s<x) f = false;
        }
        if(f) ma = min(ma, total);
    }
    if(ma==inf) ma = -1;
    cout << ma << endl;
    return 0;
}

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

#define ll long long int
#define endl "\n"
#define mod 1000000007
#define maxN 100005


int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	//vector<ll> v[100001];
	ll n, m, a, c, cnt = 0;
	cin >> n >> m;
	vector<ll> b(n + 1);
	vector<ll> v[n + 1];
	for (ll i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (ll i = 0; i < m; i++) {
		cin >> a >> c;
		v[a].push_back(b[c]);
		v[c].push_back(b[a]);
	}
	for (ll i = 1; i <= n; i++) {
		if (v[i].size() == 0) {
			cnt++;
		} else {
			if (b[i] > *max_element(v[i].begin(), v[i].end())) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main()
{
    double a, b, x;
    cin >> a >> b >> x;

    double maximum = a * a * b;
    double y;
    double ans;
    if (maximum / 2 > x)
    {
        y = 2 * x / (a * b);
        ans = atan2(b, y);
    }
    else
    {
        y = 2 * (maximum - x) / (a * a);
        ans = atan2(y, a);
    }
    ans = ans / 2 / M_PI * 360;
    cout << fixed << setprecision(7) << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  unsigned long long int arr[n];
  unsigned long long int pro=1,temp;
  int flag=0,flag1=0;
  for(int a=0;a<n;a++)
  {
    cin>>arr[a];
    if(arr[a]==0)
    {
        flag=1;
        cout<<"0";
        break;
     }
  }
  if(flag==0)
  {
  	for(int a=0;a<n;a++)
  	{
  		temp=pro;
  		pro*=arr[a];
  		if(pro>1000000000000000000 || (pro/arr[a])!=temp)
  		{
	  		 cout<<"-1";
	  		 flag1=1;
	  		 break;
  		}
  	}
  	if(flag1==0)
  	cout<<pro;
  }
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
const int inf = 1000000000;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338; // double PI = 4*atan(1);

int n,a[3][3], b[10];
bool appear[3][3];	 

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
    for(int i=0; i<3; i++){
    	for(int j=0; j<3; j++){
    		cin >> a[i][j];
    	}
    }
    cin >> n;
    for(int i=0; i<n; i++)cin >> b[i];

    for(int i=0; i<n; i++){
    	for(int j=0; j<n; j++){
    		appear[i][j]=false;
    		for(int k=0; k<n; k++){
    			if(a[i][j] == b[k]) appear[i][j]=true;
    		}
    	}
    }
    string ans = "No";
    for(int i=0; i<3; i++){
    	if(appear[0][i] and appear[1][i] and appear[2][i]) ans="Yes";
    }
    for(int i=0; i<3; i++){
    	if(appear[i][0] and appear[i][1] and appear[i][2]) ans="Yes";
    }
    if(appear[0][0] and appear[1][1] and appear[2][2]) ans="Yes";
    if(appear[0][2] and appear[1][1] and appear[2][0]) ans="Yes";
    cout << ans << "\n";
    return 0;	
}





Measured memory_bytes: 3624
#include<cstdio>
bool isprime[55556];
int main() {
	int n, i, j, a[5];
	scanf("%d", &n);
	for (i = 0; i <= 55555; i++)isprime[i] = true;
	isprime[0] = false;
	isprime[1] = false;
	for (i = 2; i < 236; i++) {
		for (j = 2; i*j <= 55555; j++) {
			isprime[i*j] = false;
		}
	}
	j = 0;
	for (i = 11; j < n; i += 5) {
		if (isprime[i]) {
			printf("%d ", i);
			j++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)
const long long INF = 1LL << 60;
int main()
{
	int N;
  cin >> N;
  vector<ll> v(N+1);
  rep(i,N){
    cin >> v[i] ;
  }
  v[N]=INF;
  ll ans=0;
  rep(i,N){
    if(v[i]>v[i+1]){
      ans+=v[i]-v[i+1];
      v[i+1]+=v[i]-v[i+1];
    }
  }
	cout<<ans << endl;
}

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

int main(){
	int n, i;
	double a, sum, c, average;

	for(;;){
		int s[1001]={};
		sum = 0;
		cin >> n;
		if(n == 0)
		break;

		for(i = 0;i < n;i++){
			cin >> s[i];
			sum += s[i];
		}
		average = (double)sum / n;
		sum = 0;

		for(i = 0;i < n;i++)
			sum += pow(s[i] - average,2);

			c = (double)sum / n;
			a = sqrt(c);

			printf("%7lf\n", a);
		}
	return 0;
}

Measured memory_bytes: 1196
import sys
import fractions
import numpy as np
x,y = map(int,input().split())
A = list(map(int,input().split()))
B = [0]*len(A)
for i in range(x-1):
	if format(A[i], 'b')[::-1].find('1') != format(A[i+1], 'b')[::-1].find('1'):
		print(0)
		sys.exit()
for i in range(x):
    B[i] = A[i]//2

def lcm(h, g):
    return (h * g) // fractions.gcd(h, g)
for i in range(1,len(B)):
    B[i]=lcm(B[i-1], B[i])

if int(B[x-1])>y:
    print(0)
else:
  print((y-int(B[x-1]))//(2*int(B[x-1]))+1)

Measured memory_bytes: 27652
import sys
readline = sys.stdin.readline

N, X, M = map(int, readline().split())

table = [0]*M
for x in range(M):
    table[x] = x*x%M

if N <= M:
    ans = 0
    x = X
    for _ in range(N):
        ans += x
        x = table[x]
    
else:
    ans = 0
    x = X
    for _ in range(M):
        ans += x
        x = table[x]
    N -= M
    res = 0
    vx = x
    st = []
    for loop in range(1, M+1):
        st.append(x)
        x = table[x]
        if x == vx:
            break
    
    ans += sum(st)*(N//loop) + sum(st[:N%loop])
print(ans)

Measured memory_bytes: 70096
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll x[500010], y[500010];
char d[500010][10];
vector <ll> v1, v2;
ld val(ld xx){
    ld mx1=-1e9, mn1=1e9, mx2=-1e9, mn2=1e9, tmp;
    for(int i=0; i<v1.size(); ++i){
        if(d[v1[i]][0]=='L'){
            tmp=x[v1[i]]-xx;
        }
        else{
            tmp=x[v1[i]]+xx;
        }
        mx1=max(mx1, tmp);
        mn1=min(mn1, tmp);
        mx2=max(mx2, (ld)y[v1[i]]);
        mn2=min(mn2, (ld)y[v1[i]]);
    }

    for(int i=0; i<v2.size(); ++i){
        if(d[v2[i]][0]=='D'){
            tmp=y[v2[i]]-xx;
        }
        else{
            tmp=y[v2[i]]+xx;
        }
        mx2=max(mx2, tmp);
        mn2=min(mn2, tmp);
        mx1=max(mx1, (ld)x[v2[i]]);
        mn1=min(mn1, (ld)x[v2[i]]);
    }
    return (mx1-mn1)*(mx2-mn2);
}
int main(){
    ll n;
    while(cin>>n){
        ld ans=0;
        for(ll i=0; i<n; ++i){
            scanf("%lld%lld%s",x+i,y+i,d+i);
            if(d[i][0]=='L'||d[i][0]=='R'){
                v1.push_back(i);
            }
            else{
                v2.push_back(i);
            }
        }
        ld st=0, nd=3e8, t1, t2, tmp1, tmp2;
        int t=200;
        while(t--){
            t1=st+(nd-st)/3.0;
            t2=nd-(nd-st)/3.0;
            tmp1=val(t1);
            tmp2=val(t2);
            if(tmp1>tmp2){
                st=t1;
            }
            else{
                nd=t2;
            }
        }
        ans=val(nd);
        cout<<fixed<<setprecision(12)<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 6264
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            switch (Console.ReadLine())
            {
            case "Sunny":
                Console.WriteLine("Cloudy");
                break;
            case "Cloudy":
                Console.WriteLine("Rainy");
                break;
            case "Rainy":
                Console.WriteLine("Sunny");
                break;
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;
    
#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long
    
typedef long long ll;
typedef pair<int,int> Pair;

int A,B,C,ans;
    
signed main(){
    cin >> A >> B >> C;
    if(B/A > C) ans = C;
    else ans = B/A;
    cout << ans << endl;
}

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

int gcd(int a, int b){
    int temp;
    while (b != 0){
        temp = a % b;
        a = b;
        b = temp;
    }
    return a;
}

int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n],i;
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    if(n==1){
        if(k!=a[0]) printf("IMPOSSIBLE\n");
        else printf("POSSIBLE\n");
        return 0;
    }
    int max=a[0];
    for(i=1;i<n;i++) if(a[i]>max) max=a[i];
    if(k>max){
        printf("IMPOSSIBLE\n");
        return 0;
    }
    int small=-1;
    small=gcd(a[0],a[1]);
    for(i=2;i<n;i++) small=gcd(small,a[i]);
    if(k%small==0) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void) {
	int N; cin >> N;
	ll lst = 0;
	ll res = 0;
	for (int i = 0; i < N; ++i) {
		ll ai; cin >> ai;
		ll tmp = max(lst, ai);
		lst = tmp;
		res += tmp - ai;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
}


Measured memory_bytes: 23764
use std::collections::LinkedList;

fn main() {
    let mut s: LinkedList<char> = read::<String>().chars().collect();
    let q: usize = read();

    let mut reverse = false;
    for _ in 0..q {
        let query: Vec<char> = read::<String>().chars().collect();

        if query[0] == '1' {
            reverse = !reverse;
        } else {
            if (!reverse && query[2] == '1') || (reverse && query[2] == '2') {
                s.push_front(query[4]);
            } else {
                s.push_back(query[4]);
            }
        }
    }
    let ans: String = if reverse {
        s.iter().rev().map(|c| *c).collect()
    } else {
        s.iter().map(|c| *c).collect()
    };

    println!("{}", ans);
}
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 12796
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    long sum = 0;
    long fra[10000];
    int n;
     
    //??????'n'?????\???
    cin >> n;
     
    //??????fra[]???????????£??\???????¨????sum?????????
    for(int i = 0; i < n; i++){
        cin >> fra[i];
        sum = sum + fra[i];
    }
     
    while(1){
        int flag = 0;
    //???????????¬???
        for(int i = 0; i < n; i++){
            if(fra[i-1] > fra[i] && i > 0 && i < n){
                swap(fra[i-1],fra[i]);
            }
        }
    //???????????????
        int count = 0;
        for(int i = 0; i < n; i++){
            if(fra[i-1] <= fra[i] && i > 0 ){
                count++;
            } 
            if(count == n-1){
                flag = 1;
            }
        }
         
        if(flag == 1)break;
    }
     
    cout << fra[0] << " " << fra[n-1] << " " << sum << endl;
     
    return 0;
}

Measured memory_bytes: 3176
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
        x:chars,
    }
    let x = x
        .iter()
        .map(|&c| if c == '1' { 1 } else { 0 })
        .collect::<Vec<_>>();
    let pc: isize = x.iter().fold(0, |s, v| s + v);
    let mut ans = vec![0; n];
    for b in 0..2 {
        let npc = if b == 0 { pc + 1 } else { pc - 1 };
        if npc <= 0 {
            continue;
        }
        let mut r0 = 0;
        for xi in x.iter() {
            r0 = (r0 * 2) % npc;
            r0 += xi;
        }
        let mut k = 1;
        for (i, &xi) in x.iter().enumerate().rev() {
            if xi == b {
                let r = if b == 0 {
                    (r0 + k) % npc
                } else {
                    (r0 + npc - k) % npc
                };
                ans[i] = f(r as u32) + 1;
            }
            k = (k * 2) % npc;
        }
    }

    let mut out = String::with_capacity(n * 2);
    for a in ans.iter() {
        out.push_str(&format!("{}\n", a));
    }
    out
}

fn f(x: u32) -> u32 {
    if x > 0 {
        f(x % popcount(x)) + 1
    } else {
        0
    }
}

fn popcount(x: u32) -> u32 {
    x.count_ones()
}
test! {
    include_str!("d1_in.txt") => include_str!("d1_out.txt"),
    include_str!("d2_in.txt") => include_str!("d2_out.txt"),
    include_str!("d3_in.txt") => include_str!("d3_out.txt"),
}


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

int main () {
  int N;
  cin >> N;
  long long cash = 1000;
  long long stake = 0;
  vector <int> rate(N);
  for (int i = 0; i < N; i++) cin >> rate.at(i);
  for (int i = 0; i < N-1;i++){
    if (rate.at(i) <= rate.at(i+1)) {
      stake += cash/rate.at(i);
      cash %= rate.at(i);
    }
    else {
      cash += stake*rate.at(i);
      stake = 0;
    }
  }
  cash += stake*rate.at(N-1);
  cout << cash << endl;
} 

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X,Y; cin>>X>>Y;
    bool ok=true;
    int B = Y-2*X;
    if (B%2!=0) ok=false;
    B/=2;
    if (!(0<=B && B<=X)) ok=false;

    if (ok){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3652
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,m,a[710],s1,s2;
bool can[710][710],f[710][710];
int cnt,head[710],to[500010],nxt[500010];
vector<int> v1,v2;
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x)
{
	if (a[x]==1)
	{
		s1++;
	}
	else if (a[x]==-1)
	{
		s2++;
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (!a[y])
		{
			a[y]=-a[x];
			dfs(y);
		}
		else
		{
			if (a[x]==a[y])
			{
				puts("-1");
				exit(0);
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		can[x][y]=can[y][x]=true;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			if (can[i][j])
			{
				continue;
			}
			add(i,j);
			add(j,i);
		}
	}
	int s3=n;
	for (int i=1;i<=n;i++)
	{
		if (head[i])
		{
			if (!a[i])
			{
				a[i]=1;
				s1=s2=0;
				dfs(i);
				s3-=s1+s2;
				v1.push_back(s1);
				v2.push_back(s2);
			}
		}
	}
	f[0][0]=true;
	int sz=v1.size();
	for (int i=0;i<sz;i++)
	{
		for (int j=v1[i];j<=n;j++)
		{
			f[i+1][j]|=f[i][j-v1[i]];
		}
		for (int j=v2[i];j<=n;j++)
		{
			f[i+1][j]|=f[i][j-v2[i]];
		}
	}
	s1=n/2;
	while (s1>0 && !f[sz][s1])
	{
		s1--;
	}
	s2=n-s1-s3;
	/*
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			s1++;
		}
		else if (a[i]==-1)
		{
			s2++;
		}
	}
	
	*/
	if (s1>s2)
	{
		swap(s1,s2);
	}
	if (s1+s3>s2)
	{
		s3-=(s2-s1);
		s1=s2;
		s1+=s3/2;
		s2=n-s1;
	}
	else
	{
		s1+=s3;
	}
	printf("%d\n",s1*(s1-1)/2+s2*(s2-1)/2);
    return 0;
}
/*
5 7
1 3
1 4
1 5
2 4
2 5
3 4
3 5
*/

Measured memory_bytes: 4352
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastScanner sc=new FastScanner();
		int n=sc.nextInt();
	int m=n%1000;
	int ans= (m==0)? 0:(1000-m);
	
	System.out.println(ans);
	
		
		
	}
		static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
}
}


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

int solve(ll X,ll A,ll B){
  ll INC,DEC;
  if(X%2==1){
    INC=max(1LL,(X+1)/2-2),DEC=min(X,(X+1)/2+2);
  }else{
    INC=max(1LL,X/2-3),DEC=min(X,X/2+1+3);
  }
  if(A<INC) INC++;
  if(B>DEC) DEC--;
  rep(i,10){
    if(INC==A) INC++;
    if(DEC==B) DEC--;
    if(INC*DEC>=A*B) return 0;
    INC++,DEC--;
  }
  return 1;
}

int main(){
  int Q; cin>>Q;
  rep(i,Q){
    ll A,B; cin>>A>>B;
    if(A>B) swap(A,B);
    ll ok=2*A-2,ng=2*B;
    while(abs(ok-ng)>1){
      ll mid=(ok+ng)/2;
      if(solve(mid,A,B)) ok=mid;
      else ng=mid;
    }
    cout<<(ok-1)<<endl;
  }
  return 0;
}


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

using namespace std;
using ull = unsigned long long;

int main() {
    int N;
    cin >> N;
    vector<ull> A(N), S(N + 1);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    S[0] = 0;
    for (int i = 0; i < N; ++i) S[i + 1] = S[i] + A[i];

    ull ans = 0;
    for (int i = 1; i < N; ++i) {
        // cout << A[i] << ' ' << S[i] << endl;

        // 色iが残るか
        if (A[i] <= 2 * S[i]) ++ans;
        else ans = 0;
    }
    ++ans;
    cout << ans << endl;
}


Measured memory_bytes: 1920
change [] n = []
change (d:dx) n =
    case d of
        'A' -> [n] ++ change dx (n + 1)
        'T' -> [n] ++ change dx (n + 1)
        'C' -> [n] ++ change dx (n + 1)
        'G' -> [n] ++ change dx (n + 1)
        _ -> [0] ++ change dx 1

solve s = maximum (change s 1)

main::IO()
main=do
    s <- getLine
    print $ solve s


Measured memory_bytes: 380
n=gets.to_i
h=gets.split.map(&:to_i)
ans="Yes"
i=n-1
flg=0
while i>0
  d=h[i]-h[i-1]
  if d==-1
    h[i-1]-=1
  elsif d<-1
    ans="No"
    break
  end
  i-=1
end
puts ans

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

using namespace std;

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

int main()
{
    int a, b;
    while (cin >> a >> b) {
        cout << gcd(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    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);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

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

ll three_gcd(ll a,ll b,ll c){
    return gcd(gcd(a,b),c);
}

int main(){
    int K;cin >> K;
    ll ans = 0;
    Rep(i,K)Rep(j,K)Rep(k,K){
        ans += three_gcd(i,j,k);
    }
    cout << ans << endl;
    return 0;
}

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

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

  int ans = 0;
  int count = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      count = 1;
      for (int j = i + 1; j < S.length(); j++) {
        if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
          count++;
        }
        else {
          ans = max(ans, count);
          count = 0;
          break;
        }
        ans = max(ans, count);
      }
    }
    ans = max(ans, count);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int ll;

int main()
{
    ll s, c;
    scanf("%lld%lld", &s, &c);
    if(c<=(s*2)) printf("%lld\n", c/2);
    else printf("%lld\n", s+(c-s*2)/4);
    return 0;
}


Measured memory_bytes: 256
#define ma(a,b)(a>b?a:b)
T[1000],X[1000],q,n,A,a,B,b,h,m,p;N(){if(~T[0])for(q=1;q<1000;q++)if(~T[q])X[q]+=1440-ma(T[q],T[0]),T[q]=-1;T[0]=-1;}
main(){for(;scanf("%d",&n),n;printf("%d\n",m)){
	for(memset(T,0xff,4000),memset(X,0,4000),A=0;n--;){
		if(scanf("%d/%d%d:%d%s%d",&a,&b,&h,&m,&p,&p),A-a||B-b)N(),A=a,B=b;
		if(h=h*60+m,~T[p]){
			if(p==0){for(q=1;q<1000;q++)if(~T[q])X[q]+=h-ma(T[q],T[0]);}
			else if(~T[0])X[p]+=h-ma(T[p],T[0]);
		T[p]=-1;}else T[p]=h;
	}for(N(),m=0,p=1;p<1000;p++)if(m<X[p])m=X[p];
}exit(0);}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct node {
	int key;
	node* prev, * next;
};

node* nil;

node* listsearch(int key) {
	node* cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (node*)malloc(sizeof(node));
	nil->next = nil;
	nil->prev = nil;
}

void printlist() {
	node* cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deletenode(node* t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deletefirst() {
	deletenode(nil->next);
}

void deletelast() {
	deletenode(nil->prev);
}

void deletekey(int key) {
	deletenode(listsearch(key));
}

void insert(int key) {
	node* x = (node*)malloc(sizeof(node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil -> next = x;
	x->prev = nil;
}

int main()
{
	int key, n;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
			np++;
			size++;
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deletefirst();
				else if (com[6] == 'L') deletelast();
			}
			else {
				deletekey(key);
				nd++;
			}
			size--;
		}
	}
	printlist();

	return 0;
}


Measured memory_bytes: 34384
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

ans = [0] * (N + 1)
for i in range(N - 1):
    if L[i] >= L[i + 1]:
        ans[i + 1] += ans[i] + 1

print(max(ans))

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
#include <queue>
#include <set>
using namespace std;


void printNumber(int r, int l){
    for (int j = 0; j < r - 1; j++)
        cout << "0 ";
    if ((r + l) % 2 == 0)
        cout << (r + l) / 2 << " " << (r + l) / 2 << " ";
    else if ((r > l && r % 2 == 0) || (r < l && l % 2 == 1))
        cout << (r + l - 1) / 2 << " " << (r + l + 1) / 2 << " ";
    else
        cout << (r + l + 1) / 2 << " " << (r + l - 1) / 2 << " ";
    for (int j = 0; j < l - 1; j++)
        cout << "0 ";
}


int main(){
    string s;
    cin >> s;
    int r = 1, l = 0;
    for (int i = 1; i < s.length(); i++){
        if (s[i] == 'R' && s[i - 1] == 'L'){
            printNumber(r, l);
            r = 0;
            l = 0;
        }
        if (s[i] == 'R') r++;
        else l++;
    }
    printNumber(r, l);
    cout << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int n,d[100];
void ck() {
	for (int i=1;i<=n;i++)
		if (d[i]!=i) return;
	printf("YES\n");
	exit(0);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(d[i]);
	ck();
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++) {
		swap(d[i],d[j]);
		ck();
		swap(d[i],d[j]);
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
 int n , i;
 cin >> n >> i;
 cout << n - i + 1 << endl;
}

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

void main() {
  int n = readln.chomp.to!int;
  int[int] chie;
  auto b = map!(x => x.to!int)(readln.chomp.split);
  int res = 0;
  foreach (x; b) {
    ++chie[x];
  }
  foreach (x, cnt; chie) {
    if (cnt >= x) {
      res += min(cnt - x, cnt);
    } else {
      res += cnt;
    }
  }
  writeln(res);
}


Measured memory_bytes: 10200
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>

using namespace std;
typedef long long ll;
int p[5001];
ll c[5001];
ll d[5001][5001];
bool check[5001];
pair<ll, pair<ll, ll>> a[5001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i]; p[i] -= 1;
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < n; i++) {
		memset(check, false, sizeof(check));
		int t = i;
		ll sum = 0;
		int cnt = 0;
		ll cnt2 = 0;
		bool f = false;
		for (int j = 1; j <= n; j++) {
			int next = p[t];
			if (check[next])break;
			check[next] = true;
			sum += c[next];
			if (!f)cnt2 = sum;
			else cnt2 = max(cnt2, sum);
			d[i][j] = cnt2;
			f = true;
			cnt += 1;
			t = p[t];
		}
		a[i].first = sum;
		a[i].second.first = cnt;
		a[i].second.second = cnt2;
	}

	ll ans = 0;
	bool f = false;

	for (int i = 0; i < n; i++) {
		ll sum = (ll)0;
		ll tmp = k;
		bool fff = false;
		if (a[i].first > (ll)0 && k / a[i].second.first > (ll)0) {
			sum = a[i].first * (k / a[i].second.first - (ll)1) + d[i][a[i].second.first];
			if (!f || ans < sum) {
				f = true;
				ans = sum;
			}
			sum = a[i].first * (k / a[i].second.first);
			tmp -= ((k / a[i].second.first) * a[i].second.first);
			sum += d[i][tmp];
			if (!f || ans < sum) {
				f = true;
				ans = sum;
			}
		}
		else {
			int m = min(a[i].second.first, k);
			if (!f || ans < d[i][m]) {
				f = true;
				ans = d[i][m];
			}
		}
	}

	cout << ans << '\n';
}

Measured memory_bytes: 198688
#include <iostream>
#include <string>

using namespace std;

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

    for(int i = s.size()-2;i >= 0;i-=2){
        string t,u;
        t = s.substr(0,i/2);
        u = s.substr(i/2,i/2);
        if(t.compare(u)==0){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = longList().sorted()
    var total = 0L
    var unreachableIndex = -1
    0.until(n - 1).forEach { i ->
        total += a[i]
        if (total * 2 < a[i + 1]) {
            unreachableIndex = i
        }
    }
    println((n - (unreachableIndex + 1)).toString())
}


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

int main() {
  int N, K;
  cin >> N >> K;
  priority_queue<int> pq;
  int n;
  for (int i = 0; i < N; i++) {
    cin >> n;
    pq.push(n);
  }
  for (int i = 0; i < K; i++) {
    pq.pop();
    if (pq.empty()) break;
  }
  int64_t r = 0;
  while (!pq.empty()) {
    r += pq.top();
    pq.pop();
  }
  cout << r << endl;
}

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

int getnum() {
  char C;
  while(!isdigit(C = getchar()));
  int n = C - '0';
  while(isdigit(C = getchar())) n = n * 10 + C - '0';
  return n;
}

int main() {
  int N = getnum();
  string S;
  map<string,int> ans{};
  for (int i = 0; i < N; i++) {
    cin >> S;
    ans[S] += 1;
  }
  N = getnum();
  for (int i = 0; i < N; i++) {
    cin >> S;
    ans[S] -= 1;
  }
  int maxans = 0;
  for(auto itr = ans.begin(); itr != ans.end(); ++itr) maxans = max(maxans, ans[itr->first]);
  printf("%d\n", maxans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int a,b,c,d,e,f;
int main()
{
	read(a);
	read(b);
	read(c);
	read(d);
	read(e);
	read(f);
	a*=100;
	b*=100;
	int mxa=12345;
	int mxb=0;
	for(int i=0;i*a<=f;i++)
		for(int j=0;j*b+i*a<=f;j++)
			for(int k=0;i*a+j*b+k*c<=f;k++)
				for(int l=0;i*a+j*b+k*c+l*d<=f;l++)
				{
					if(i==0 && j==0)	break;
					if((k*c+l*d)*100>e*(i*a+j*b))	break;
					if((k*c+l*d)*mxa>=(mxb)*(i*a+j*b+k*c+l*d))
					{
						mxa=i*a+j*b+k*c+l*d;
						mxb=k*c+l*d;
					}
				}
	cout<<mxa<<' '<<mxb<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int digit(int i){
    int res = 0;
    while(i){
        res += i % 10;
        i /= 10;
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    int ans = N;
    for (int a = 1; a < N/2; ++a){
        int b = N - a;
        int sum = digit(a) + digit(b);
        if (ans > sum) ans = sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
ll dp[3005][3005][2];
ll a[3005];
ll solve(int l,int r,int turn)
{
    if(l==r)
    return dp[l][l][turn] = a[l]*turn;

    if(dp[l][r][turn]!=-1)return dp[l][r][turn];

    if(turn==1)
        return dp[l][r][1] = max(solve(l+1,r,0)+a[l],solve(l,r-1,0)+a[r]);
    return dp[l][r][0] = min(solve(l+1,r,1),solve(l,r-1,1));
}
int main()
{
    fastio;
    int n;
    cin>>n;
    ll sum = 0;
    set_ar(dp,-1);
    for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];}
    solve(1,n,1);
    cout<<(dp[1][n][1]-(sum-dp[1][n][1]))<<endl;
    return 0;
}


Measured memory_bytes: 141568
import java.util.Scanner;

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 cnt = 0;
		
		for (; a <= b; a++)
			if (c % a == 0) cnt++;
		
		System.out.println(cnt);
		
		sc.close();
	}

}

Measured memory_bytes: 26304
const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let k: usize = sc.read();
    let n: usize = sc.read();

    let combination = Combination::new(k + n, MOD);
    for sum in 2..(2 * k + 1) {
        println!("{}", solve(sum, k, n, &combination));
    }
}

fn solve(sum: usize, max_value: usize, num_dice: usize, combination: &Combination) -> usize {
    let mut pairs = 0;
    for i in 1.. {
        if i * 2 > sum {
            break;
        }
        let other = sum - i;
        if other > max_value {
            continue;
        }
        pairs += 1;
    }

    let mut ans = combination.h(max_value, num_dice);
    for used_pairs in 1..(pairs + 1) {
        if num_dice < used_pairs * 2 {
            break;
        }

        let num_other_dice = num_dice - used_pairs * 2;
        let mut invalid_moves = combination.get(num_other_dice + max_value - 1, num_other_dice)
            * combination.get(pairs, used_pairs);
        invalid_moves %= MOD;
        if used_pairs % 2 == 1 {
            ans += MOD - invalid_moves;
        } else {
            ans += invalid_moves;
        }
        ans %= MOD;
    }
    ans
}

pub struct Combination {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    modulo: usize,
}

impl Combination {
    pub fn new(max: usize, modulo: usize) -> Combination {
        let mut inv = vec![0; max + 1];
        let mut fact = vec![0; max + 1];
        let mut inv_fact = vec![0; max + 1];
        inv[1] = 1;
        for i in 2..(max + 1) {
            inv[i] = inv[modulo % i] * (modulo - modulo / i) % modulo;
        }
        fact[0] = 1;
        inv_fact[0] = 1;
        for i in 0..max {
            fact[i + 1] = fact[i] * (i + 1) % modulo;
        }
        for i in 0..max {
            inv_fact[i + 1] = inv_fact[i] * inv[i + 1] % modulo;
        }
        Combination {
            fact: fact,
            inv_fact: inv_fact,
            modulo: modulo,
        }
    }

    pub fn get(&self, x: usize, y: usize) -> usize {
        assert!(x >= y);
        self.fact[x] * self.inv_fact[y] % self.modulo * self.inv_fact[x - y] % self.modulo
    }

    pub fn h(&self, n: usize, r: usize) -> usize {
        self.get(n + r - 1, r)
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
  int N, sum=1;
  string s;
  cin >> N >> s;
  for(int i=0; i<N-1; i++) {
     if(s.at(i) != s.at(i+1)) {
       sum++; 
     }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512