akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <queue>

struct vertex
{
  long long x;
  long long y;
  long long r;
};

int main()
{
  long long sx, sy, tx, ty;
  int n;
  scanf("%lld%lld%lld%lld%d", &sx, &sy, &tx, &ty, &n);
  vertex vs[1002];
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld%lld%lld", &vs[i].x, &vs[i].y, &vs[i].r);
  }
  vs[n] = vertex{sx, sy, 0};
  vs[n + 1] = vertex{tx, ty, 0};

  double edges[1002][1002];
  edges[n + 1][n + 1] = 0;
  for (int i = 0; i < n + 1; ++i)
  {
    edges[i][i] = 0;
    for (int j = i + 1; j < n + 2; ++j)
    {
      double dist = std::max(0., std::sqrt((vs[i].x - vs[j].x) * (vs[i].x - vs[j].x) + (vs[i].y - vs[j].y) * (vs[i].y - vs[j].y)) - (vs[i].r + vs[j].r));
      edges[i][j] = dist;
      edges[j][i] = dist;
    }
  }
  using pair = std::pair<double, int>;
  std::priority_queue<pair, std::vector<pair>, std::greater<pair>> q;
  double dist[1002];
  std::fill(dist, dist + n + 2, 1e18);
  q.emplace(0, n);
  while (q.size() > 0)
  {
    pair p = q.top(); q.pop();
    for (int i = 0; i < n + 2; ++i)
    {
      if (p.first + edges[p.second][i] < dist[i])
      {
        dist[i] = p.first + edges[p.second][i];
        q.emplace(p.first + edges[p.second][i], i);
      }
    }
  }
  printf("%.12f\n", dist[n + 1]);
}

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

const int Maxn = 1000005;

int n;
char a[Maxn];

int Has(int r, int c)
{
    while (r) {
        if (c % 2 > r % 2) return 0;
        c /= 2; r /= 2;
    }
    return 1;
}

int main()
{
    scanf("%d", &n);
    scanf("%s", a);
    for (int i = 0; i < n; i++)
        a[i]--;
    bool was1 = false;
    bool odd = false;
    for (int i = 0; i < n; i++)
        if (a[i] == '1') { odd ^= Has(n - 1, i); was1 = true; }
    if (odd) { printf("1\n"); return 0; }
    if (was1) { printf("0\n"); return 0; }
    for (int i = 0; i < n; i++)
        if (a[i] == '2') odd ^= Has(n - 1, i);
    printf("%d\n", odd? 2: 0);
    return 0;
}


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

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (ll i=0; i<n; i++)
#define	Rep1(i, n)	for (ll i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N, K;
	cin >>N >>K;
	vector<ll> NN(K+1, 0);
	Rep1(i, K) {
		ll n=K/i;
		NN.at(i)=myPow(n, N);
	}
	for (ll i=K; i>0; i--) {
		for (ll j=2; i*j<=K; j++) {
			NN.at(i) -=NN.at(i*j);
			NN.at(i)+=MOD;
			NN.at(i)%=MOD;
		}
	}
	ll SS=0;
	Rep1(i, K) {
		SS +=NN.at(i)*i;
		SS %=MOD;
	}
	cout <<SS <<endl;
	return 0;
}



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

int main() {
  ll N,Q,sum=0,cnt[100001]={};
  cin >> N;
  rep(i,N) {
    int a;
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  cin >> Q;
  rep(i,Q){
    ll b,c;
    cin >> b >> c;
    sum += cnt[b]*(c-b);
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
  
  return 0;
}

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

bool check(string s){
    if(s.size() & 1) return false;
    if(s.substr(0, s.size() / 2) == s.substr(s.size() / 2)) return true;
    return false;
}


int main(){string S;
cin >> S;
int ans;
for(long i = 1; i < S.size(); i++){
    if(check(S.substr(0, S.size() - i))){
        ans = S.size() - i;
        break;
    }
}






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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans=0;
  cin >>N;
  vector<int> L(N);
for(int i=0;i<N;i++){
   cin >> L.at(i);
}
  if(N>2){
   for(int i=0;i<N-2;i++){
     for(int j=i+1;j<N-1;j++){
        for(int k=j+1;k<N;k++){
       //  cout <<L[i]<<" "<<L[j]<<" "<<L[k]<<endl;
          if(L[i]+L[j]>L[k]&&L[i]+L[k]>L[j]&&L[k]+L[j]>L[i]){
          ans++;

          if(L[i]==L[j]||L[j]==L[k]||L[i]==L[k]) ans--; 
         }
       }  
    }
  }
 }
cout << ans;
}

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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

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

	ll ans = 0;
	rep(bit,60LL){
		ll one=0,zero=0;
		rep(i,n){
			if(a[i] & (1LL<<bit))one++;
			else zero++;
		}
		ll res = one*zero;
		res %=mod;
		ans += res*((1LL<<bit)%mod);
		ans %= mod;
		// cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
		for(int i=a ; i<=b; i++) {
			if(i < a+k || i > b-k) System.out.println(i);
		}
	}
}


Measured memory_bytes: 21972
#include <stdio.h>

int main(void){
    int n, m, c;
    scanf("%d %d %d", &n, &m, &c);
    int b[m];
    for(int i = 0;i < m;i++){
        scanf("%d", &b[i]);
    }
    int a[n][m];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            scanf("%d", &a[i][j]);
        }
    }
    int count = 0;
    for(int i = 0;i < n;i++){
        int sum = c;
        for(int j = 0;j < m;j++){
            sum += a[i][j] * b[j];
        }
        if(sum > 0)count++;
    }
    printf("%d\n", count);
    return 0;
}

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

if N == 2 or M == 2:
    print(0)
elif N == 1 and M == 1:
    print(1)
elif N == 1 and M > 2:
    print(M - 2)
elif N > 2 and M == 1:
    print(N - 2)
else:
    print((N - 2) * (M - 2))

Measured memory_bytes: 3060
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] a = new int[H][W];
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                a[i][j] = sc.nextInt();
            }
        }
        sc.close();
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
        int i = 0, j = 0;
        int cnt = 0;
        while(cnt < H*W-1){
            if(a[i][j]%2 == 1){
                ArrayList<Integer> list1 = new ArrayList<>();
                list1.add(i+1);
                list1.add(j+1);
                if(i%2 == 0){
                    if(j != W-1){
                        a[i][j+1]++;
                        j++;
                    } else {
                        a[i+1][j]++;
                        i++;
                    }
                } else {
                    if(j != 0){
                        a[i][j-1]++;
                        j--;
                    } else {
                        a[i+1][j]++;
                        i++;
                    }
                }
                list1.add(i+1);
                list1.add(j+1);
                list.add(list1);
            } else {
                if(i%2 == 0){
                    if(j != W-1){
                        j++;
                    } else {
                        i++;
                    }
                } else {
                    if(j != 0){
                        j--;
                    } else {
                        i++;
                    }
                }
            }
            cnt++;
        }
        System.out.println(list.size());
        for(int k = 0; k < list.size(); k++){
            System.out.println(list.get(k).get(0) + " " + list.get(k).get(1) + " " + 
            list.get(k).get(2) + " " + list.get(k).get(3));
        }
    }
}

Measured memory_bytes: 127140
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    printf("%lld\n", (ll)n*(n-1)/2);


    return 0;
}


Measured memory_bytes: 128
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,k = li()
xs = []
ys = []
points = []
for _ in range(n):
    x,y = li()
    xs.append(x)
    ys.append(y)
    points.append((x,y))
    
xs.sort()
ys.sort()

rank_x = {}
rank_y = {}
for i, x in enumerate(xs):
    rank_x.update({x:i+1})
for i, y in enumerate(ys):
    rank_y.update({y:i+1})

field = [[0 for _ in range(n+1)] for _ in range(n+1)]
for px,py in points:
    field[rank_y[py]][rank_x[px]] = 1
    
for row in range(n+1):
    field[row] = list(accumulate(field[row]))
    
for col in range(n+1):
    for row in range(n):
        field[row+1][col] += field[row][col]

ans = float("inf")
for xst in range(n):
    for xed in range(xst+1,n):
        for yst in range(n):
            for yed in range(yst+1,n):
                if field[yed+1][xed+1] + field[yst][xst] \
                    -field[yed+1][xst] - field[yst][xed+1]>= k:
                    ans = min(ans, (xs[xed]-xs[xst])*(ys[yed]-ys[yst]))

print(ans)

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

typedef long long ll;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    ll minn = 1LL<<60;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        minn = min(minn,a[i]);
    }
    if(minn!=1){
        cout << -1 << endl;
        return 0;
    }
    ll num = 1,ans = 0;
    for(ll i=0;i<n;i++){
        if(a[i]!=num) ans++;
        else num++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
x,y,z,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
ab=[]
for i in range(x):
    for j in range(y):
        ab+=[a[i]+b[j]]
ab.sort(key=lambda x: -x)
c.sort(key=lambda x: -x)
ans=[]
ct=[0]
ansc=[ab[0]+c[0]]
while (len(ans)<k):
    if(ct[-1]!=0 and len(ct)<z):
        ansc+=[ab[0]+c[len(ct)]]
        ct+=[0]
    ans+=[max(ansc)]
    tmp=ansc.index(max(ansc))
    if(ct[tmp]==len(ab)-1):
        ansc[tmp]=0
    else:
        ct[tmp]+=1
        ansc[tmp]=ab[ct[tmp]]+c[tmp]
for i in ans:
    print(i)

Measured memory_bytes: 99812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

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

	int N;
	vector<int> vd;

	cin >> N;
	for(int i=0; i<N; i++){
		int d;
		cin >> d;
		vd.push_back(d);
	}

	sort(vd.begin(), vd.end());

	int r = N / 2 ;
	int l = r - 1;
	int ans = vd[r] - vd[l];
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int n, m;
int res = 0;
int G[8][8];

void rec(int a, vector<int> flag){
    flag[a] = 1;
    if(accumulate(all(flag), 0) == n) res++;
    rep(i, n){
        if(G[a][i] == 0 or flag[i] or a == i) continue;
        rec(i, flag);
    }
}

int main(int argc, char *argv[]){
    cin >> n >> m;
    rep(i, 8) rep(j, 8) G[i][j] = 0;
    int a, b;
    rep(i, m){
        cin >> a >> b;
        a--; b--;
        G[a][b] = G[b][a] = 1;
    }
    v flag(n);
    rec(0, flag);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    while(cin>>n)
    {
        ll ret = sqrt(n);
        ll x = 1e9;
        if(ret *ret == n)
        {
            cout << ret << " 0 0 " << ret << " 0 0\n";
        }
        else
        {
            int xx=(x-n%x)%x;
            int yy=(n+xx)/x;
            cout << x << " " << 1 << " " << xx << " " << yy << " 0 0\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define tezz std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() {
    tezz
   int n;
   cin>>n;
   vector<int> a(n);
   vector<int> b(n);
   for(int i=0;i<n;i++){  cin>>a[i];}
    for(int i=0;i<n;i++){
        b[a[i]-1]=i+1;
    }
    for(int i=0;i<n;i++) cout<<b[i]<<" ";
    cout<<endl;
   return 0; 

}

Measured memory_bytes: 1664
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec  6 02:10:17 2018
//
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)

	grid := make([]string, H)
	for i := range grid {
		fmt.Scan(&grid[i])
	}

	for i := range grid {
		hide := true
		for col := 0; col < W; col++ {
			if grid[i][col] == '#' {
				hide = false
			}
		}
		if hide {
			continue
		}

		for j := range grid[i] {
			hide := true
			for row := 0; row < H; row++ {
				if grid[row][j] == '#' {
					hide = false
				}
			}
			if hide {
				continue
			}
			fmt.Print(string(grid[i][j]))
		}
		fmt.Println()
	}
}


Measured memory_bytes: 768
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
  exit(0)
MOD = k
n = 0
l = []
root = 1
for i in range(1000000):
  n += 7 * root
  n %= k
  if n == 0:
    print(i + 1)
    exit(0)
  root *= 10
  root %= k
print(-1)

Measured memory_bytes: 63452
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define MAXN 100010
struct node
{
	int v,s;
};
int vis[MAXN];
int d[MAXN];
int l,r,f=1,x=-1;
vector<node>G[MAXN];
void DFS(int u,int fa)
{
	for(int i=0;i<G[u].size();i++)
	{
		node e=G[u][i];
		if(!vis[e.v])
		{
			d[e.v]=e.s-d[u];
			if(vis[u]==1)
			{
				vis[e.v]=-1;
				r=min(r,d[e.v]);
			}
			else
			{
				vis[e.v]=1;
				l=max(l,-d[e.v]);
			}
			if(l>r)
			{
				f=0;
				return;
			}
			DFS(e.v,u);
			if(!f) return;
		}
		else
		{
			if(vis[u]==vis[e.v])
			{
				if((e.s-d[u]-d[e.v])&1)
				{
					f=0;
					return;
				}
				else
				{
					int tmp=vis[u]*(e.s-d[u]-d[e.v])/2;
					if(x==-1) x=tmp;
					if(x!=tmp||x<=0)
					{
						f=0;
						return;
					}
				}
			}
			else if(d[u]+d[e.v]!=e.s)
			{
				f=0;
				return;
			}
		}
	}
}
int main()
{
	int n,m,u,v;
	node a;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&u,&v,&a.s);
		a.v=v;G[u].push_back(a);
		a.v=u;G[v].push_back(a);
		r=max(r,a.s);
	}
	vis[1]=1;
	DFS(1,0);
	if(f)
	{
		if(x==-1)
			printf("%d\n",r-l-1);
		else if(x<=r&&x>=l)
			printf("1\n");
		else printf("0\n");
	}
	else printf("0\n");
}

Measured memory_bytes: 11136
import java.io.*;
import java.util.*;

public class Main {

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

    static class Question {
        public void solve(Scanner sc) {
            long n = sc.nextLong();
            long m = sc.nextLong();
            long i = n / m;
            long j = i + 1;
            System.out.println(Math.min(Math.abs(i * m - n), Math.abs(j * m - n)));
        }
    }
}


Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
char	s[30001];
int		num[1000] = { 0 };
int main()
{
	int		a,c,i,j,k,n,m,x,y,z,ans = 0;
	int		b[3];
	
	scanf("%d", &n);
	scanf("%s", s);
	
	
	for(i=0;i<1000;i++) {
		b[0] = i / 100 + '0';
		b[1] = (i % 100 ) / 10 + '0';
		b[2] = i % 10 + '0';
		a = 0;
		for(j=0;j<n;j++) {
			if (s[j] == b[a]) a++;
		}
		if (a == 3) ans++;
	}
	
	/*
	for(i=0;i<n-2;i++) {
		x = s[i] - '0';
		for(j=i+1;j<n-1;j++) {
			y = s[j] - '0';
			for(k=j+1;k<n;k++) {
				z = s[k] - '0';
				num[ x*100 + y*10 + z ] = 1;
			}
		}
	}
	
	for(i=0;i<1000;i++) {
		ans += num[i];
	}
	*/

	printf("%d\n",ans);


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

class segtree2{
public:
	static const int N=1<<17;
	int dp[1<<18];
	segtree2(){
		for(int i=0;i<N*2;i++){
			dp[i]=INF;
		}
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=min(dp[k*2+1],dp[k*2+2]);
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return INF;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return min(vl,vr);
	}
};

segtree2 seg2;
int n;
ll t;
ll a[100001];
vector<ll> vec;
vector<int> xid[100001];
P p[500001];
map<P,int> mp;

int main(void){
	scanf("%d%lld",&n,&t);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		vec.push_back(a[i]);
		p[i]=P(a[i],i);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	sort(p,p+n);
	ll ans=0;
	for(int i=0;i<n;i++){
		a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
		xid[a[i]].push_back(i);
	}
	for(int i=0;i<n;i++){
		seg2.update(p[i].second,p[i].first);
		int mi=seg2.query(0,p[i].second);
		if(mi>=p[i].first)continue;
		int g=lower_bound(vec.begin(),vec.end(),mi)-vec.begin();
		int g2=lower_bound(vec.begin(),vec.end(),p[i].first)-vec.begin();
		int ct=lower_bound(xid[g].begin(),xid[g].end(),p[i].second)-xid[g].begin();
		mp[P(p[i].first,vec[g])]=min((int)ct,(int)xid[g2].size());
	}
	ll biggest=0;
	for(map<P,int>::iterator it=mp.begin();it!=mp.end();it++){
		P p=(*it).first;
		if(p.first-p.second>biggest){
			ans=0;
			biggest=p.first-p.second;
		}
		if(p.first-p.second==biggest){
			ans+=(*it).second;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 17780
s = input()
K = int(input())

for i,c in enumerate(s):
	x = (ord('z')-ord(c)+1)%26
	if x <= K:
		s = s[:i]+'a'+s[i+1:]
		K -= x

print(s[:-1]+chr((ord(s[-1])-ord('a')+K)%26+ord('a')))

Measured memory_bytes: 178740
#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>;

const int Q = 7 + 1e9;

ll exp( ll n, ll m ){
    if( m == 0 ) return 1;
    if(m%2==0) return ( exp(n,m/2)*exp(n,m/2) )%Q;
    else return ( n*exp(n,m-1) )%Q;
}

int main(){
    int N;
    cin >> N;
    ll w_all = exp(10,N); // 0...9
    ll w_wo_0 = exp(9,N); // 1..9 ( = 0..8)
    ll w_wo_09 = exp(8,N); // 1...8
    ll ans = ( ( w_wo_09 - (2*w_wo_0)%Q + w_all )%Q + Q )%Q;
    // we take the remainder so w_all - 2*w_wo0 + w_wo_09 can <0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1
fn main() {
    input! { n:usize, mut ans: chars, k: usize }
    let target = ans[k-1];
    for i in 0..n {
        if target != ans[i] { ans[i] = '*' }
    }
    println!("{}", ans.into_iter().collect::<String>());
}

Measured memory_bytes: 4352
import collections 
a=[]
n=int(input())
for i in range(n):
  S=input()
  s=list(S)
  s.sort()
  b="".join(s)
  a.append(b)
c=collections.Counter(a)
ans=0
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

Measured memory_bytes: 24076
/*input
116
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	lld n;
	cin >> n;
	while(n>0){
		if(n%10 == 7){
			cout << "Yes" << endl;
			return ;
		}
		n/=10;
	}
	cout << "No" << endl;
	return;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3532
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n 10^16
 */
string s;
int n[20];
int dp[20][2];

int main(){
  cin>>s;
  int l = s.size();
  REP(i,l){
    n[i] = s[i] - '0';
  }

  REP(i,l){
    REP(j,2){
      REP(j2,2){
        int x;
        if(j) i==0 ? 0 : x=9;
        else if(j2) x=n[i]-1;
        else x=n[i];
        
        dp[i+1][j||j2] = max(dp[i+1][j||j2], dp[i][j] + x);
        LOG("i=%d, j=%d, j2=%d, dp=%d\n", i,j,j2,dp[i+1][j||j2]);
      }
    }
  }

  cout<<max(dp[l][0], dp[l][1])<<endl;  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,dp[100009],a[100009],mx=1e9+8;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)dp[i]=mx;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n&&j<=i+k;j++)
        {
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
import numpy as np

if __name__=='__main__':
    N,Max_w = map(int,input().split())
    v,w = [],[]
    for _ in range(N):
        a,b = map(int,input().split())
        w.append(a)
        v.append(b)
    
    sum_v = sum(v)+1
    dp = [10**10 for _ in range(sum_v + 1)]
    dp[0] = 0
    dp = np.array(dp)
    
    for a,b in zip(w,v):
        x = dp[:-b]+a
        y = dp[b:]
        np.minimum(x,y,out=dp[b:])


    ans = np.where( dp <= Max_w )
    print(np.max(ans))


Measured memory_bytes: 15544
n, q = map(int, input().split())
l = []
for i in range(n):
  t = []
  for j in input().split():
    t += [j]
  t[1] = int(t[1])
  l += [t]
 
c = 0
while len(l) > 0:
  if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0)


Measured memory_bytes: 13784
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto prev = 0ll;
	vector<ll> h(N, INT_MAX);
	vector<ll> T(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> T[i];
		if (T[i] > prev)
		{
			h[i] = 0;
		}
		else
		{
			h[i] = min(h[i], T[i]);
		}
		prev = T[i];
	}

	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	prev = 0;
	for (auto i = N - 1; i >= 0; --i)
	{
		if (A[i] > prev)
		{
			if (h[i] == 0)
			{
				if (A[i] != T[i])
				{
					h[i] = -1;
				}
			}
			else
			{
				if (A[i] <= T[i])
				{
					h[i] = 0;
				}
				else
				{
					h[i] = -1;
				}
			}
		}
		else
		{
			h[i] = min(h[i], A[i]);
		}
		prev = A[i];
	}

	auto result = 1ll;
	auto mod = (ll)1e9 + 7;
	for (auto i = 0; i < N; ++i)
	{
		if (h[i] < 0)
		{
			result = 0;
			break;
		}
		else if (h[i] == 0)
		{
			continue;
		}

		result = (result * h[i]) % mod;
	}

	cout << result << endl;

	return 0;
}

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


void solve(long long N, std::vector<long long> W){
  long long acc = 0;
  long long mymin = LLONG_MAX;
  for(long long i = 0; i < N; i++){
    acc += W[i];

    long long twoacc = 0;
    for(long long j = (i+1); j < N; j++){
      twoacc += W[j];
    }

    mymin = min(mymin, abs(acc - twoacc));
  }

  cout << mymin << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> W(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&W[i]);
  }
    solve(N, std::move(W));
    return 0;
}


Measured memory_bytes: 3724
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,x,y,z;
LL k;
char a[1010][1010];

bool check1()
{
    repu(i,1,m)
        if (a[1][i]=='#' && a[n][i]=='#')
            return 1;
    return 0;
}

bool check2()
{
    repu(i,1,n)
        if (a[i][1]=='#' && a[i][m]=='#')
            return 1;
    return 0;
}

int power(int x,LL k)
{
    int ret=1;
    for (; k; k>>=1,x=LL(x)*x%p)
        if (k&1)
            ret=LL(ret)*x%p;
    return ret;
}

int calc(int x,int q,LL n)
{
    if (q==1)
        return n%p*x%p;
    return LL(power(q,n)-1)*x%p*power(q-1,p-2)%p;
} 

int main()
{
    scanf("%d%d%lld",&n,&m,&k);
    repu(i,1,n)
        scanf("%s",a[i]+1);
    bool flag1=check1(),flag2=check2();
    if (k<=1 || flag1 && flag2)
    {
        puts("1");
        return 0;
    }
    if (flag1)
    {
        repu(i,1,max(n,m))
            repu(j,1,i)
                swap(a[i][j],a[j][i]);
        swap(n,m);
    }
    repu(i,1,n)
        repu(j,1,m)
            if (a[i][j]=='#')
                ++x,z+=j<m && a[i][j+1]=='#';
    repu(i,1,n)
        y+=a[i][1]=='#' && a[i][m]=='#';
    int ans=power(x,k-1);
    if (y)
        ans=(ans+p-LL(z)*calc(power(y,k-2),LL(x)*power(y,p-2)%p,k-1)%p)%p;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  int num,count=0,count_2=0;
  
  cin >> S;
  cin >> T;
  
  num = int(S.size()) - int(T.size()) + 1;
  
  for(int i=0;i<num;i++){
    count_2 = 0;
  	for(int j=0;j<int(T.size());j++){
      if(T.at(j) != S.at(i+j)){
        count_2 += 1;
      }  
    } 
    if(i==0){
      count = count_2;
    }
    if((i != 0) and (count_2 < count)){
      count = count_2;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 3556
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{
    int c, a, b;
    cin >> c >> a >> b;
    cout << c * a / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 36


typedef struct{
  int value;
  char wd;
}card;


int main(){

  int i,j,n,minj,c=0,a,b;
  card B[N],C[N],D[N],temp;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %c%d",&C[i].wd,&C[i].value);
    D[i]=B[i]=C[i];
  }
  
  for (i = 0 ;i<=n-1;i++){
    for (j = n-1;j>= i+1;j--){
      if (C[j].value < C[j-1].value){
	temp=C[j];
        C[j]=C[j-1];
        C[j-1]=temp;
      }
      
    }
  }

  for(i=0;i<n;i++){
    printf("%c%d",C[i].wd,C[i].value);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  
  for(i=0;i<=n-1;i++){
    for(j=i+1;j<=n-1;j++){
      for(a=0;a<=n-1;a++){
	for(b=a+1;b<=n-1;b++){
	  if(B[i].value==B[j].value && (B[i].value==C[b].value && B[i].wd==C[b].wd) && (B[j].value==C[a].value && B[j].wd== C[a].wd)){
	    printf("Not stable\n");
	    c=1;
	  }
	}
      }
    }
  }
  if(c==0)printf("Stable\n");
 
  for(i = 0;i<=n-1;i++){
    minj = i;
    for (j = i;j<= n-1;j++){
      if(D[j].value < D[minj].value)
	minj = j;
    }
    temp=D[i];
    D[i]=D[minj];
    D[minj]=temp;
  }

  for(i=0;i<n;i++){
    printf("%c%d",D[i].wd,D[i].value);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  
  c=0;
  for(i=0;i<=n-1;i++){
    for(j=i+1;j<=n-1;j++){
      for(a=0;a<=n-1;a++){
	for(b=a+1;b<=n-1;b++){
	  if(c==0 && B[i].value==B[j].value &&( B[i].value==D[b].value &&B[i].wd==D[b].wd )&&( B[j].value==D[a].value && B[j].wd==D[a].wd)){
	    printf("Not stable\n");
	    c=1;
	  }
	}
      }
    }
  }
  if(c==0)printf("Stable\n");
  
  return 0;
}





Measured memory_bytes: 2104
from itertools import accumulate
n,m=map(int,input().split())
dp=[0]*(n+1)
List=[int(input()) for i in range(m)]
List.sort()
step=0

dp[0]=1
dp[1]=1

if(m>0 and List[0]==1):
    dp[1]=0
    step+=1
for i in range(2,n+1):
    # print(i,step)
    if(step<m and i==List[step]):
        step+=1
        dp[i]=0
    else:
        dp[i]=dp[i-2]+dp[i-1]
# print(List)
# print(dp)
print(dp[n]%((10**9)+7))

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

using namespace std;

int main()
{
	int N, R;
	int minvalue;
	int maxprofit = -2000000000;
	cin >> N;

	cin >> minvalue;
	for (int i = 1;i < N;i++)
	{
		cin >> R;

		maxprofit = max(maxprofit, R - minvalue);
		minvalue = min(minvalue, R);
	}

	cout << maxprofit << endl;

	return 0;
}

Measured memory_bytes: 3096
S = input().strip()
N = len(S)
C = {"a":0,"b":0,"c":0}
for i in range(N):
    C[S[i]] += 1
na = C["a"]
nb = C["b"]
nc = C["c"]
if max(na,nb,nc)-min(na,nb,nc)<=1:
    print("YES")
else:
    print("NO")

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long K){
    for(long long i = 0; i <= K; ++i){
        if(C > B && B > A){
            cout << YES << endl;
            return;
        }

        if(B - A <= 0) B *= 2;
        else{
            if(C - B <= 0) C *= 2;
        }
    }
    cout << NO << endl;
    return;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3684
import itertools
import math

n=int(input())
a=list()
for i in range(n):
    a.append(list(map(int,input().split())))
p=0
pp=0
for i,j in itertools.combinations(range(n),2):
    p+=math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
    pp+=1
print('{:.10f}'.format(p/pp*(n-1)))

Measured memory_bytes: 3064
#include<cstdio>
#define maxn 100005
int main(){
	int n;
	char s[maxn];
	scanf("%d",&n);
	scanf("%s",s);
	int count = 0 ;
	for(int i = 0;i<n;i++){
		if(s[i]!=s[i+1]){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 256
n, y = gets.split.map(&:to_i)
y = y / 1000

def calc(n, y)
  result = "-1 -1 -1"
  (0..n).reverse_each do |c|
    n_tmp = n - c
    b = (0..n_tmp).reverse_each.select do |b|
      c * 10 + b * 5 + (n_tmp - b) == y
    end
    unless b.empty?
      result = "#{c} #{b[0]} #{n_tmp - b[0]}"
      break
    end
  end
  result
end

result = calc(n, y)

puts result


Measured memory_bytes: 13564
#include<stdio.h>
#define INF 1000000000

int dp[(1<<17)-1]={INF};

void init(int dp[],int n){
	int i;
	for(i=0;i<(1<<n);i++){
		dp[i]=INF;
	}
	dp[0]=0;
}
	

int best_arm(int stage,int ad,int data[][17],int n){
	int i,min=data[stage][0];	
	for(i=0;i<n;i++){
		if(ad&(1<<i)){
			if(min>data[stage][i+1]){
				min=data[stage][i+1];
			}
		}
	}
	return min;
}

int update(int ad,int data[][17],int n){
	if(dp[ad]!=INF){
		return dp[ad];
	}
	int i,min=INF,tmp;
	for(i=0;i<n;i++){
		if(ad&(1<<i)){
			tmp=update(ad-(1<<i),data,n)+best_arm(i,ad-(1<<i),data,n);
			if(min>tmp){
				min=tmp;
			}
		}
	}
	dp[ad]=min;
	return dp[ad];
}

int main(void){
	int n,i,j,data[16][17];
	while(scanf("%d",&n)!=0 && n!=0){
		for(i=0;i<n;i++){
			for(j=0;j<n+1;j++){
				scanf("%d",&data[i][j]);
			}
		}
		init(dp,n);
		printf("%d\n",update((1<<n)-1,data,n));
	}
	return 0;
}
		
	

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

string s;
int gu(int size){
	bool flag = true;
	for(int i = 0; i < size/2; i++){
		if(s[i] != s[size/2 + i])flag = false;
	}
	if(flag == true && size != s.size())return size;
	else gu(size - 2);
}

int main(){
	cin >> s;
	int ans = gu(s.size());
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>　　　 //STL 通用算法
#include <bitset>　　　　　//STL 位集容器
#include <cctype>         //字符处理
#include <cerrno> 　　　　 //定义错误码
#include <cfloat>　　　　 //浮点数处理
#include <ciso646>         //对应各种运算符的宏
#include <climits> 　　　　//定义各种数据类型最值的常量
#include <clocale> 　　　　//定义本地化函数
#include <cmath> 　　　　　//定义数学函数
#include <complex>　　　　 //复数类
#include <csignal>         //信号机制支持
#include <csetjmp>         //异常处理支持
#include <cstdarg>         //不定参数列表支持
#include <cstddef>         //常用常量
#include <cstdio> 　　　　 //定义输入／输出函数
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理
#include <ctime> 　　　　　//定义关于时间的函数
#include <cwchar> 　　　　 //宽字符处理及输入／输出
#include <cwctype> 　　　　//宽字符分类
#include <deque>　　　　　 //STL 双端队列容器
#include <exception>　　　 //异常处理类
#include <fstream> 　　　 //文件输入／输出
#include <functional>　　　//STL 定义运算函数（代替运算符）
#include <limits> 　　　　 //定义各种数据类型最值常量
#include <list>　　　　　　//STL 线性列表容器
#include <locale>         //本地化特定信息
#include <map>　　　　　　 //STL 映射容器
#include <memory>         //STL通过分配器进行的内存分配
#include<new>            //动态内存分配
#include <numeric>         //STL常用的数字操作
#include <iomanip> 　　　 //参数化输入／输出
#include <ios>　　　　　　 //基本输入／输出支持
#include <iosfwd>　　　　　//输入／输出系统使用的前置声明
#include <iostream> 　　　//数据流输入／输出
#include <istream>　　　　 //基本输入流
#include <iterator>        //STL迭代器
#include <ostream>　　　　 //基本输出流
#include <queue>　　　　　 //STL 队列容器
#include <set>　　　　　　 //STL 集合容器
#include <sstream>　　　　 //基于字符串的流
#include <stack>　　　　　 //STL 堆栈容器
#include <stdexcept>　　　 //标准异常类
#include <streambuf>　　　 //底层输入／输出支持
#include <string>　　　　　//字符串类
#include <typeinfo>        //运行期间类型信息
#include <utility>　　　　 //STL 通用模板类
#include <valarray>        //对包含值的数组的操作
#include <vector>　　　　　//STL 动态数组容器
using namespace std;

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

const int MAXN=2e5+10;
const int MOD=998244353;
const int INF=0x3f3f3f3f;

inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0;int f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)) x=(x<<3ll)+(x<<1ll)+1ll*(c-'0'),c=getchar();
	return x*f;
}
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x;
}

int n,a[MAXN];
string s;

int main(){
	n=read();
	cin>>s;
	for(int i=1;i<=n;i++) a[i]=a[i-1]+(s[i-1]=='R');
	cout<<a[n]-a[a[n]]<<'\n';
	return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,s1;
   cin>>s>>s1;
   int L1=s.length();
   int L2=s1.length();

   for(int i=0;i<L1;i++)
   {
       cout<<s[i];
       if(i<L2) cout<<s1[i];
   }
   cout<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int h, w;
string s[410];
bool used[410][410];
int bnum;

int dfs(int i, int j, bool a)
{
    used[i][j] = true;

    int res = 0;

    if (s[i][j] == '.')
        res++;
    else
        bnum++;

    REP(k, 4)
    {
        int ni = i + di[k];
        int nj = j + dj[k];

        if (ni < 0 || h <= ni ||
            nj < 0 || w <= nj)
            continue;

        if (s[ni][nj] != (a ? '.' : '#'))
            continue;

        if (used[ni][nj])
            continue;

        res += dfs(ni, nj, !a);
    }

    return res;
}

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

    cin >> h >> w;
    REP(i, h)
    cin >> s[i];

    ll res = 0;

    REP(i, h)
    REP(j, w)
    {
        if (s[i][j] == '.')
            continue;

        //memset(used, 0, sizeof(used));

        bnum = 0;

        res += (ll)dfs(i, j, true) * (ll)bnum;

        /*

        queue<P> q;

        bool used[410][410] = {false};

        used[i][j] = true;

        q.push(make_pair(i, j));

        while (q.size())
        {
            P p = q.front();
            q.pop();

            used[p.first][p.second] = true;

            REP(k, 4)
            {
                if (p.first + di[k] < 0 || h <= p.first + di[k] ||
                    p.second + dj[k] < 0 || w <= p.second + dj[k])
                    continue;

                if (s[p.first + di[k]][p.second + dj[k]] == '#')
                    continue;

                if (used[p.first + di[k]][p.second + dj[k]])
                    continue;

                used[p.first + di[k]][p.second + dj[k]] = true;

                res++;

                REP(l, 4)
                {
                    if (p.first + di[k] + di[l] < 0 || h <= p.first + di[k] + di[l] ||
                        p.second + dj[k] + dj[l] < 0 || w <= p.second + dj[k] + dj[l])
                        continue;

                    if (s[p.first + di[k] + di[l]][p.second + dj[k] + dj[l]] == '.')
                        continue;

                    if (di[k] + di[l] == 0 && dj[k] + dj[l] == 0)
                        continue;

                    if (used[p.first + di[k] + di[l]][p.second + dj[k] + dj[l]])
                        continue;

                    q.push(make_pair(p.first + di[k] + di[l], p.second + dj[k] + dj[l]));
                }
            }
        }
        */
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 18048
# Acceptance of input

import sys

f_i = sys.stdin

V, E = map(int, f_i.readline().split())

adj = [[] for i in range(V)]

for l_i in f_i:
    s, t = map(int, l_i.split())
    adj[s].append(t)
    adj[t].append(s)


# dfs traverse

prenum = [1] + [None] * (V - 1)
parent = [0] * V
lowest = [V] * V

import collections

path = collections.deque()
path.append(0)

cnt = 1

while path:
    u = path[-1]
    adj_v = adj[u]
    for v in adj_v:
        if not prenum[v]:
            parent[v] = u
            path.append(v)
            cnt += 1
            prenum[v] = cnt
            adj[u].remove(v)
            adj[v].remove(u)
            break
    if u == path[-1]:
        for v in adj_v:
            lowest[u] = min(lowest[u], prenum[v])
            adj[u].remove(v)
            adj[v].remove(u)
        p = parent[u]
        lowest[p] = min(lowest[u], lowest[p])
        path.pop()


# output

ans = set()

for u in range(1, V):
    p = parent[u]
    if prenum[p] <= lowest[u]:
        ans.add(p)

if parent.count(0) >= 3:
    ans.add(0)
else:
    ans.discard(0)

ans = list(ans)
ans.sort()

if ans:
    print(*ans, sep = '\n')

Measured memory_bytes: 13284
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1)
        cout << "No";
    else
    {
        rep(i, 0, n / 2)
        {
            if (s[i] != s[i + n / 2])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

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

int main(){
	char * ch = new char(205);
	cin >> ch;
	int i = 0;
	while(ch[i] != '\0'){
		i++;
	}
	int N = i;
	//cout << i << endl;

	
	for(;i >= 0; i--){
		if(i%2 == 1) {continue;}
		else {
			int flag = 1;
			for(int t = i; t >= i/2+1; t--){
				if(ch[t-1] != ch[t-i/2-1]) flag = 0;
				//cout << ch[t-1] << endl;
				//cout << ch[t-i/2-1] << endl;
			}
			if(flag == 1 && i != N) break;
			//cout << i << endl;
		}
	}

	cout << i << endl;
}

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

using namespace std;
long int d[1000000];
const long int INF = 5000000000;
int main()
{
    map<pair<int, int>, int > mymap;
    map<pair<int, int>, int >::iterator it;
    int v;
    int e;
    int r;
    cin >> v >> e >> r;
    for(int a1 = 0; a1 < e; a1++){
        int v1;
        int v2;
        int cost;
        cin >> v1 >> v2 >> cost;
        mymap[make_pair(v1,v2)] = cost;
    }
      if (v == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < v;i++)
        d[i] = INF;
    d[r] = 0;
    for(int a = 0; a < v; a++)
    {
        bool check = false;
        for (it = mymap.begin(); it != mymap.end();it++)
        {
            if (d[it->first.first] != INF && d[it->first.second] > d[it->first.first] + it->second)
            {
                d[it->first.second] = d[it->first.first] + it->second;
                check = true;
            }

        }
        if (a == v - 1){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
        if (check == false) break;
    }
    for (int i = 0; i < v; i++)
    {
        if (d[i] != INF)
            cout << d[i] << endl;
        else
            cout << "INF" << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <utility>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <tuple>
using namespace std;
using ll=long long;
ll gcd(ll a,ll b){return (b==0?a:gcd(b,a%b));}
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,n) for(int i=a;i<n;i++)
constexpr ll INF=1000000011;

int main (){
    int n, a, b;
    int sum,ans=0;

    cin >> n >> a >> b;

    rep (i,n+1){
        sum = i/10000 + i/1000%10 + i/100%10 + i/10%10 + i%10;
        if(sum>=a && sum<=b){
            ans += i;
        }
    }
    cout << ans << endl;




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<vector>
//#include<queue>
//#include<sstream>
//#include<cmath>
//#include<set>
//#include<algorithm>
//#include<map>
#define mp make_pair
#define pii pair<int,int>
#pragma GCC optimize ("O3")
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 1e5+9;
const double pi=acos(-1.0);
const int inf = 1e9+9;
const int mod = 10007;

int main()
{
    ios::sync_with_stdio(false);
    int a=0,b=0,c=0,d=0;
    int n;
    cin>>n;
    while(n--){
        string tmp;
        cin>>tmp;
        if(tmp[0]=='A') ++a;
        else if(tmp[0]=='W') ++b;
        else if(tmp[0]=='T') ++c;
        else ++d;
    }
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<b<<"\n";
    cout<<"TLE x "<<c<<"\n";
    cout<<"RE x "<<d<<"\n";

    return 0;
}


Measured memory_bytes: 3656