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

int main(){

    uint64_t n;
    cin >> n;

    uint64_t d = n;
    for(uint64_t i = 2; i*i <= n; ++i){
        if(!(n%i)) d = i;
    }

    cout << n/d+d-2 << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;

vector<PL> v; 
LL dp[2020][2020];
int main()
{
	LL n,ans=0;
	cin>>n;
	for(LL i=0;i<n;i++)
	{
		LL x;cin>>x;
		v.push_back(PL(x,i));
	}
	sort(v.begin(),v.end(),greater<PL>());
	for(LL i=0;i<=n;i++)
	{
		for(LL j=0;j<=n-i;j++)
		{
			LL I=0,J=0;
			if(i>=1)I=dp[i-1][j]+v[i+j-1].first*abs(v[i+j-1].second-(i-1));
			if(j>=1)J=dp[i][j-1]+v[i+j-1].first*abs(v[i+j-1].second-(n-j));
			dp[i][j]=max(I,J);
			if(i+j==n)ans=max(ans,dp[i][j]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<"\n";
		
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 26372
# https://atcoder.jp/contests/abc127/tasks/abc127_c



N, M = gets.split.map(&:to_i)
left_max = 1
right_min = N
M.times do |i|
  left, right = gets.split.map(&:to_i)
  left_max = left if left_max < left
  right_min = right if right_min > right
end

puts (left_max..right_min).size


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector>

std::vector<int> A;

int main(void){
    int n; scanf("%d", &n);
    A.resize(n); for(int i = 0; i < n; ++i){scanf("%d", &A[i]); A[i] -= i+1;}
    std::sort(A.begin(), A.end());
    long long int result = 0;
    int medium = (n & 1) ? A[n/2] : (A[n/2-1]+A[n/2]) >> 1;
    for(int i = 0; i < n; ++i) result += abs(A[i] - medium);
    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<ctime>
#include<set>
#include<queue>
#define MAX 105
int map[MAX][MAX];
int a[MAX*MAX+10],n;
int h,w;
using namespace std;
int main()
{
	int count=0,num=1;
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=h;i++)
	{
		if(i%2==0)
		{
			for(int j=w;j>0;j--)
			{
				if(count>=a[num])
				{
					count=0;
					num++;
				}
				map[i][j]=num;
				count++;
			}
		}
		else
		{
			for(int j=1;j<=w;j++)
			{
				if(count>=a[num])
				{
					count=0;
					num++;
				}
				map[i][j]=num;
				count++;
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			printf("%d ",map[i][j]);
		}
		printf("\n");
	} 
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <list>

using namespace std;

int main(){
	int n, q;
	int cnt = 0;
	cin >> n;
	list<int> A;
	list<int>::iterator it;
	for(int i; i < n; i++){
		int x;
		cin >> x;
		A.push_front(x);
	}
	cin >> q;
	int B[q];
	for(int i = 0; i < q; i++){
		cin >> B[i];
		for(it = A.begin(); it != A.end();it++){
			if(B[i] == *it){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3392
#include <stdio.h>
int main(void){
    int w,b;
    
    while(1){
        scanf("%d",&w);
        if(w==-1)break;
        b=0;
        switch(w/10){
            case 0 : b=1150;break;
            case 1 : b=1150+125*(w-10);break;
            case 2 : b=1150+1250+140*(w-20);break;
            default : b=1150+1250+1400+160*(w-30);break;
        }
        printf("%d\n",4280-b);
    }
    return 0;
}

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

L = len(bin(max(K, max(A)))) - 2
X = 0
ans = 0
table = [0]*L

for x in A:
    for i in range(L):
        if (x >> i) % 2 == 1:
            table[i] += 1

table = [(2**i * (N - table[i]), 2**i, table[i], table[i] > N - table[i])
         for i in range(L)]
table.sort(reverse=True)
ans = 0
tmp = 0
# print(table)
for x, y, z, flag in table:
    if flag or tmp + y > K:
        ans += (y*z)
        continue
    else:
        tmp += y
        ans += x
    #print(tmp, y, ans)
print(ans)


Measured memory_bytes: 15144
#include<bits/stdc++.h>
using namespace std ;
#define Fors(n) for(int i=1;i<=n;i++)
#define For(n) for(i=0;i<n;i++)
#define ll long long
#define vint(s) vector<int> s
#define pb(x)  push_back(x)
#define mpair(x,y) make_pair(x,y)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll x=0,y=0,n=0,i=0;

int main(){
    IOS;
    string s;
    cin >> n;
    cin >> s;
    if (n<3200){
    	cout <<"red";
    }
    else{
    	cout << s;
    	
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream> 
#include <algorithm>
#include <math.h>
#include <map>  
#include <string.h> 

using namespace std;

const int INF=100000000;
                             
int dS[201][201],dL[201][201],dp[1001][201],z[1001];

int main() {
  
  while(1){
    
   int N,M;
    
   cin>>N>>M;
   
   if(N==0) break;
   
   fill(dL[0],dL[201],INF);
   fill(dS[0],dS[201],INF);
   
   for(int i=0; i<M; i++){
     
     int s,t,v; char u;
     
     cin>>s>>t>>v>>u;
     
     if(u=='L'){
     dL[s][t]=min(dL[s][t],v);  
     dL[t][s]=min(dL[t][s],v);  
     }else{
     dS[s][t]=min(dS[s][t],v);  
     dS[t][s]=min(dS[t][s],v); 
     }
    
    }
    
    int R; cin>>R;
    
    for(int i=1; i<=R; i++){
      cin>>z[i];
      }
     
     
    for(int k=1; k<=N; k++){
     for(int i=1; i<=N; i++){
       for(int j=1; j<=N; j++){ 
       if(i==j) {dL[i][j]=0; dS[i][j]=0;}
       dL[i][j]=min(dL[i][j],dL[i][k]+dL[k][j]);
       dS[i][j]=min(dS[i][j],dS[i][k]+dS[k][j]);
        }
       }
      } 

   fill(dp[0],dp[1001],INF);
    
    for(int i=1; i<=N; i++){
      dp[1][i]=dS[i][z[1]]+dL[z[1]][i];
      }
   
     for(int i=2; i<=R; i++){
       for(int j=1; j<=N; j++){
         for(int k=1; k<=N; k++){
           if(j!=k) dp[i][k]=min(dp[i][k],dp[i-1][j]+dL[z[i-1]][j]+dS[j][k]+dL[k][z[i]]);
           else dp[i][j]=min(dp[i][j],dp[i-1][j]+dL[z[i-1]][z[i]]);
             }
           }
         }
         
         int ans=INF;
         
         for(int i=1; i<=N; i++){
           if(ans>dp[R][i]) ans=dp[R][i];
           }
           
           cout<<ans<<endl;
     
   }
}

Measured memory_bytes: 2264
a,b,c = map(int,input().split())
if a>=b:
    if a>=c:
        print(a*10+b+c)
    else:
        print(c*10+a+b)
else:
    if b>=c:
        print(b*10+a+c)
    else:
        print(c*10+a+b)

Measured memory_bytes: 2940
n=int(input())
abc=[[int(i) for i in input().split()] for j in range(n)]
dp=[[0 for i in range(3)] for j in range(n+1)]

for i in range(3):
    dp[1][i]=abc[0][i]
    
for i in range(1,n):
    dp[i+1][0]=max(dp[i][1],dp[i][2])+abc[i][0]
    dp[i+1][1]=max(dp[i][2],dp[i][0])+abc[i][1]
    dp[i+1][2]=max(dp[i][1],dp[i][0])+abc[i][2]
    
print(max(dp[-1]))
    

Measured memory_bytes: 47008
#include <stdio.h>

int main(void) {
	int i = 0;

	int n = 0;

	int maxv = 0;	//?????§??????.
	int minv = 0;	//????°????.

	int buf = 0;

	scanf("%d", &n);

	scanf("%d", &minv);

	for (i = 1; i < n; i++) {
		scanf("%d", &buf);

		if (i == 1)
			maxv = buf - minv;

		maxv = maxv > buf - minv ? maxv : buf - minv;
		minv = minv < buf ? minv : buf;
	}

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

	return 0;
}

Measured memory_bytes: 596
N, M = map(int, input().split())
C = [[0, 0, 0] for i in range(M)] # Cities
for i in range(M):
    P, Y = map(int, input().split())
    C[i] = [i, P, Y]

C.sort(key=lambda x: x[2])

I = [[0, 0] for i in range(M)]
Num = [0]*N

for i in range(M):
    P = C[i][1]
    Num[P-1] += 1
    I[i] = [C[i][0], "%06d%06d" % (P, Num[P-1])]

I.sort(key=lambda x: x[0])
for i in range(M):
    print(I[i][1])

Measured memory_bytes: 42180
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int X = NextInt();
        int A = NextInt();
        Console.WriteLine(X < A ? 0 : 10);

    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}


public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13268
#include<stdio.h>

#define M 100000
#define N 100000000

typedef struct {
  char suit;
  int value;

}C;

C L[M /2 +2],R[M/2+2];

void merge(C *,int,int,int,int);
void mergesort(C *,int,int,int);
int partition(C *,int,int,int);
void quickSort(C *,int,int,int);

int main(){
  int n,i,value,stable=1;
  C a[M],b[M];
  char suit[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",suit,&value);
    a[i].suit = suit[0];
    b[i].suit = suit[0];
    a[i].value = value;
    b[i].value = value;
  }

  mergesort(a,n,0,n);
  quickSort(b,n,0,n-1);


for(i=0;i<n;i++){
  if(a[i].suit != b[i].suit) stable = 0;


  }

if(stable==1) printf("Stable\n");
else printf("Not stable\n");

for(i=0;i<n;i++){
  printf("%c %d\n",b[i].suit,b[i].value);
 }

return 0;


}

void merge(C *a,int n,int left,int mid,int right){
  int i,j,k;
  int n1 = mid -left;
  int n2 = right - mid;

  for(i=0;i<n1;i++) L[i] = a[left + i];
  for(i=0;i<n2;i++) R[i] = a[mid + i];
  L[n1].value = N;
  R[n2].value = N;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i].value <= R[j].value){
      a[k] = L[i++];
    }else{
      a[k] = R[j++];
    }
  }
}


void mergesort(C *a,int n,int left,int right){
  int mid;
  if(left + 1<right){
    mid = (left+right)/2;
    mergesort(a,n,left,mid);
    mergesort(a,n,mid,right);
    merge(a,n,left,mid,right);
  }
}

int partition(C *a,int n,int p,int r){
  int i,j;
  C t,x;
  x =a[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(a[j].value<=x.value){
      i++;
      t=a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  t = a[i+1];
  a[i+1] = a[r];
  a[r] = t;

  return i+1;
}


void quickSort(C *a,int n,int p,int r){
  int q;

  if(p<r){
    q= partition(a,n,p,r);
    quickSort(a,n,p,q-1);
    quickSort(a,n,q+1,r);
  }
}



Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

ll x,t,c=100,y=1;

int main()
{

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

    cin >> x;

    while( c < x ){
        c+=(ll)(c/100);
        t++;
    }

    cout << t; return 0;

    while( c < x ){
        cout << c << " " << y << " " << t << "\n";
        if( c <= x-y*100 ){
            c+=y*100;
            y++;
            t+=100;
        }else{
            while( c < x ) c+=y , t++;
        }
    }

    cout << t;

    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<vector<int>> card(3, vector<int>(3));
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> card[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++)
    cin >> b[i];
  vector<vector<bool>> res(3, vector<bool>(3));
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        if (b[k] == card[i][j])
          res[i][j] = true;
      }
    }
  }
  bool bingo = false;
  if ((res[0][0] && res[1][1] && res[2][2]) or (res[0][2] && res[1][1] && res[2][0]))
    bingo = true;
  for (int i = 0; i < 3; i++)
  {
    if (res[i][0] && res[i][1] && res[i][2])
      bingo = true;
  }
  for (int j = 0; j < 3; j++)
  {
    if (res[0][j] && res[1][j] && res[2][j])
      bingo = true;
  }
  if (bingo)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5;
int a[N+5];
struct ft{
	int ft[2*N+10];
	void init(){
		memset(ft, 0, sizeof(ft));
	}
	void update(int i, int v){
		for(;i<=2*N+5;i+=(i&-i)){
			ft[i] += v;
		}
	}
	int query(int i){
		int res = 0;
		for(;i>0;i-=(i&-i)) res+=ft[i];
		return res;
	}
}ft;
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	LL tot = (LL)n*(n+1)/2;
	LL m = tot/2+1;

	int lo = 1, hi = 1e9, ans = 0;
	while(lo <= hi){
		int mid = (lo+hi)/2;

		int cnt = 100001;
		LL res = 0;
		ft.init();
		for(int i=1;i<=n;i++){
			ft.update(cnt, 1);
			if(a[i] <= mid) cnt++;
			else cnt--;
			res += ft.query(cnt-1);
		}

		if(res >= m) ans = mid, hi = mid-1;
		else lo = mid+1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1408
import math
a, b, x = list(map(int,input().split()))

if 2*x < a*a*b:
    hatena = 2*x/a/b
    print(math.degrees(math.atan(b/hatena)))
else:
    hatena = 2*x/a/a - b
    print(math.degrees(math.atan((b-hatena)/a)))
    

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

map<ll, ll> insu; //問題として、n=1を代入してしまった時のみmapに1がはいる。
void bunkai(ll n)
{
    ll a = 2; //割る数
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            insu[a] = (insu[a] + 1) % 1000000007;
            n /= a;
        }
        else
        {
            a++;
        }
    }
    // 最後に残った n は素因数
    insu[n] += 1;
}
int main()
{
    ll n;
    cin >> n;
    //素因数分解するだけ
    for (int i = 2; i <= n; i++)
    {
        bunkai(i);
    }
    ll count = 1;
    for (auto x : insu)
    {
        count = (count * (x.second + 1)) % 1000000007;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;

int main() {
  	int n, k;
  	string s;
  	cin >> n >> k;
  	cin >> s;
    vector<int> vec1(n);
    vector<pair<int,int>> vec0;
    string start_str = s.substr(0,1);
    int start_id = 0;
    int end_id = 0;
  	for (int i = 1; i < n; ++i) {
      auto sub = s.substr(i,1);
      if(start_str != sub){
        if(start_str == "0") vec0.push_back(make_pair(start_id,end_id));
        if(start_str == "1") {
          vec1[start_id] = end_id;
          vec1[end_id] = start_id;
        }
        start_str = sub;
        start_id = i;
      }
      end_id = i;
      if(i==n-1){
        if(start_str == "0") vec0.push_back(make_pair(start_id,end_id));
        if(start_str == "1") {
          vec1[start_id] = end_id;
          vec1[end_id] = start_id;
        }
      }
    }
    int max_out = 0;
    for(int j=0;j<vec0.size();++j){
      int zero_start = vec0[j].first;
      int str_start = zero_start;
      if(zero_start > 0){
        str_start = vec1[zero_start-1];
      }
      int vec0_endid = min(j+k-1, (int)vec0.size()-1);
      int zero_end = vec0[vec0_endid].second;
      int str_end = zero_end;
      if(zero_end < n-1){
        str_end = vec1[zero_end+1];
      }
      max_out = max(max_out, str_end - str_start + 1);
    }
    if(vec0.size()==0) max_out = n;
    cout << max_out << endl;
	return 0;
}


Measured memory_bytes: 1404
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false; 
 }
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vb dp(k+10,false);
  
  for(int i=1;i<=k;i++){
    rep(j,n){
      if(i>=a[j]){
        if(!dp[i-a[j]]){
          dp[i]=true;
        }
      }
    }
  }
  if(dp[k]){
    COUT("First");
  }
  else COUT("Second");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
		if ((a >= 1 && a <= 9) && (b >= 1 && b <= 9))
		{

			cout << a * b << endl;
		}
		else
		{
			cout << "-1" << endl;
		}
	return 0;
}

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

using namespace std;

int main() {
	string a;
	char abc[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int aaa[26] = {0};
	while (cin >> a) {
		for (int i = 0; i < a.size(); i++) {
			if (isupper(a[i])) {
				a[i] = tolower(a[i]);
			}
			for (int j = 0; j < 26; j++) {
				if (a[i] == abc[j]) {
					aaa[j]++;
					break;
				}
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		cout << abc[i] << " : " << aaa[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);
	vector<string> str = { "AC","WA","TLE","RE" };
	int n;
	int cnt[4] = { 0, };

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		char input[10];
		string verd;

		scanf("%s", input);
		verd = input;

		for (int j = 0; j < 4; j++)
		{
			if (verd == str[j])
			{
				cnt[j]++;

				break;
			}
		}
	}

	for (int i = 0; i < 4; i++)
	{
		printf("%s x %d\n", str[i].c_str(), cnt[i]);
	}

	return 0;
}

Measured memory_bytes: 3312
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
int64 A, B, N;

int64 F(int64 X) {
    return A * X / B - A * (X / B);
}

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

    cin >> A >> B >> N;

    if (B - 1 <= N) {
        cout << F(B - 1) << "\n";
    } else {
        cout << F(N) << "\n";
    }
    // int MAX_DIM = 100;
    // for (int a = 1; a <= MAX_DIM; a++) {
    //     for (int b = 1; b <= MAX_DIM; b++) {
    //         for (int n = 1; n <= MAX_DIM; n++) {
    //             int64 bst = 0;
    //             A = a, B = b, N = n;
    //             for (int x = 1; x <= n; x++) {
    //                 auto cur = F(x);
    //                 bst = max(cur, bst);
    //             }

    //             int64 ans = 0;
    //             if (b - 1 <= n) {
    //                 ans = F(b-1);
    //             } else {
    //                 ans = F(n);
    //             }

    //             if (ans != bst) {
    //                 cerr << a << " " << b << " " << n << "\n";
    //                 cerr << ans << " " << bst << "\n";
    //             }
    //         }
    //     }
    // }

    return 0;
}


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

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

  int a = 1;

  for(int i = 0; i < N; i++) {
    if (a * 2 < a + K) {
      a *= 2;
    }
    else {
      a += K;
    }
  }

  cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int s_length = s.length();
    int t_length = t.length();
    int dp[s_length+1][t_length+1];
    pair<int, int> traceback[s_length+1][t_length+1];
    pair<int, int> d1 = make_pair(-1, -1);
    pair<int, int> d2 = make_pair(0, -1);
    pair<int, int> d3 = make_pair(-1, 0);
    int score[s_length][t_length];

    for (int i=0; i<=s_length; ++i){
        for (int j=0; j<=t_length; ++j){
            if(j == 0){
                dp[i][j] = 0;
                traceback[i][j] = d2;
            }
            else if(i == 0){
                dp[i][j] = 0;
                traceback[i][j] = d3;
            }
            else {
                int score_a = dp[i-1][j-1];
                score_a += (s[i-1] == t[j-1]) ? 1 : 0;
                int score_b = dp[i-1][j];
                int score_c = dp[i][j-1];
                dp[i][j] = max(max(score_a, score_b), score_c);
                if(score_a >= score_b && score_a >= score_c){
                    traceback[i][j] = d1;
                }
                else if(score_b >= score_a && score_b >= score_c){
                    traceback[i][j] = d2;
                }
                else if(score_c >= score_b && score_c >= score_a){
                    traceback[i][j] = d3;
                }
            }
        }
    }
    vector<char> ans;
    int m = s_length;
    int n = t_length;

    while(m > 0 || n > 0){
        pair<int, int> d = traceback[m][n];
        int i = m-1;
        int j = n-1;
        if((m > 0 && n > 0 && s[i] == t[j]) && d.first == -1 && d.second == -1){
            ans.push_back(s[i]);
        }
        m += d.second;
        n += d.first;
    }
    for (int i=ans.size()-1; i>=0; --i){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 105856
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
int max;

Node root,NIL;

/*Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  while( u != NIL && k != u ->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;

}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  int H;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if( y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}





void inorder( Node u){
  if( u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder( Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
 }


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  max = 0;
  /* for(i = 0; i < n; i++){
    scanf("%s",com);
    if( strcmp(com, "insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(com, "print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    }*/
   for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
   }

  return 0;
}



Measured memory_bytes: 25120
from operator import itemgetter

n = int(input())
data = []
for i in range(n):
    s, p = list(input().split())
    data.append((s, int(p), i + 1))

sorted_data = sorted(data, key=itemgetter(1), reverse=True)
sorted_data = sorted(sorted_data, key=itemgetter(0))

for s, p, i in sorted_data:
    print(i)

Measured memory_bytes: 3064
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	print $ which 0 1 $ n `mod` k == 0

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  ll N;
  cin >> N;
  vector<P> q,x,t,c;
  x.push_back({0,0});
  ll ans = 0;
  FOR(i,0,11){
    for(auto &&b:x){
      ll a = b.first;
      ll used = b.second;  
      t.push_back({a*10+3,used | 1});
      t.push_back({a*10+5,used | 2});
      t.push_back({a*10+7,used | 4});
      q.push_back({a*10+3,used | 1});
      q.push_back({a*10+5,used | 2});
      q.push_back({a*10+7,used | 4});
    }
    x = t;
    t = c;
  } 

  FOR(i,0,q.size()){
    ans += (q[i].first <= N && q[i].second==7);
  }

  cout << ans << endl;

}


Measured memory_bytes: 17596
n,m=map(int,input().split())
j=[0]*n
c=[0]*n
wa=0
ac=0
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s[0]=="A" and j[p]==0:
        j[p]=1
        ac+=1
        wa+=c[p]
    elif s[0]=="W":c[p]+=1
print(ac,wa)

Measured memory_bytes: 4596
#make the building table
table = [[[0]*10 for i in range(0,3)] for k in range(0,4)] 

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    table[b-1][f-1][r-1] += v

x=0

for j in range(4):
    if x!=0:
        print('#'*20)
    x +=1
    
    for k in range(3):
        for m in range(10):
            print(" %d"%(table[j][k][m]), end = "")
        print()



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  
  for(int i=0; i<N; i++){
    cin >> a.at(i); 
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int alice = 0;
  int bob = 0;
  
  for(int i=0; i<N; i++){
    if( i%2 == 0 )
      alice += a.at(i);
    else
      bob += a.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        String answer = "";
        if(a > b){
            answer = createString(a, b);
        } else {
            answer = createString(b, a);
        }
        System.out.println(answer);
    }

    private static String createString(int a, int b) {
        StringBuilder builder = new StringBuilder();
        for(int i = 0; i < a; i++){
            builder.append(b);
        }
        return builder.toString();
    }
}

Measured memory_bytes: 21844
def main():
  import itertools
  s=list(input())
  n=len(s)

  for pm in itertools.product("+-", repeat=3):
    tmp=""
    for i,j in zip(s,pm):
      tmp+=i+j
    else:
      tmp+=s[-1]
    if eval(tmp)==7:
      print(tmp+"=7")
      exit()
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define UB upper_bound
#define LB lower_bound;

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;
typedef long double DB;

int a[100100];

int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	
	int n;
	ll sum(0) , tmp(0) , cnt(0);
	cin >> n;	
	
	for(int i = 0 ; i < n ; i++){
	   cin >> a[i];
	   sum += a[i];
	   tmp += (a[i]%2);
	   if(a[i] == 0){
		   cnt += tmp%2;
		   tmp = 0;
	   }
	}

	cnt += tmp%2;
	cout << (sum-cnt)/2 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M; cin >> N >> M;
  vector<int> v(N, inf);
  rep(i, M) {
    int x; cin >> x; x--;
    v[x] = 0;
  }

  REP(i, 1, N) {
    v[i] = min(v[i], v[i-1] + 1);
  }

  for(int i=N-2; i>=0; i--) {
    v[i] = min(v[i], v[i+1] + 1);
  }

  cout << *max_element(all(v)) << endl;

  return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char s[20];

    scanf("%s", s);

    for(int i = 0; i < 19; i++){
        if(s[i] == ','){
            printf(" ");
        }else{
            printf("%c", s[i]);
        }
    }
    printf("\n");

    return 0;
}

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

int main(void) {
	int n, k, div = 1;
	long int a[100000];

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
	}

	for (k = 1; k < n; k++) {
		if (a[k - 1] < a[k]) {
			while (a[k - 1] <= a[k] && k < n)k++;
			if(k != n)div++;
		}
		else if (a[k - 1] > a[k]) {
			while (a[k - 1] >= a[k] && k < n)k++;
			if (k != n)div++;
		}
	}
	printf("%d\n", div);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

enqueue(P x){
  
  Q[tail]=x;
  if(tail+1==LEN) tail=0;  
  else tail++;
 
}

P dequeue(){
   P x;
  x=Q[head];
  if(head+1==LEN) head=0;
  else head++;
  return x;
}


int main(){
  int elaps=0,count=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 0; i < n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t);
   enqueue(u);}

  while(n>0){
     u=dequeue();
    if(u.t<=q){
      elaps+=u.t;
       printf("%s %d\n",u.name,elaps);
      n--;  }
    else if(u.t>q){
      u.t-=q;
      elaps+=q;
      enqueue(u);}
   }
 
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	ll n;
	cin >> n;
	ll ans = 0;
	repn(i, n) {
		ll cnt = 0;
		repn(j, i) if (i % j == 0) cnt++;
		if (i & 1 == 1 && cnt == 8) ans++;
	}
	co(ans);

	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25
int main() {
    int n, k;
    cin >> n >> k;
    vector<char> d(k);
    rep(i, k) cin >> d[i];
    int i = 0;
    while(1){
        ll p = (ll)n + i;
        string s = to_string(p);
        bool flag = true;
        rep(j, s.length()){
            rep(l, k){
                //cout << s[j] << ", " << d[l] << ", " << p << endl;
                if(s[j] == d[l]) {
                    flag = false;
                    //cout << "!" << endl;
                    break;
                }
            }
            if(!flag) break;
        }
        if(flag){
            cout << p << endl;
            return 0;
        }
        i++;
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1145141919
int DP[100010];
int a[100010];
int main(){
  for(int i = 0;i < 100010;i++)DP[i]=INF;
  int n;
  cin >> n;
  for(int i = 0;i < n;i++)cin >> a[i];
  for(int i = 0;i < n;i++)*lower_bound(DP,DP+n,a[i])=a[i];
  cout << (lower_bound(DP,DP+n,INF) - DP) << endl;
}



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

int main(){
    int N;
    int total = 0;
    cin >> N;

    rep(i, N){
        int r, l;
        cin >> l >> r;
        total = total + (r-l + 1);
    }

    cout << total << endl;

}

Measured memory_bytes: 3564
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.nextInt()
  val b = sc.nextInt()

  var ba = a
  var bb = b

  var sum = 0
  if (ba > bb) {
    sum += ba
    ba--
  } else {
    sum += bb
    bb--
  }
  if (ba > bb) {
    sum += ba
  } else {
    sum += bb
  }

  println(sum)

}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n, -1);
    int s, c;
    for (int i = 0; i < m; i++)
    {
        cin >> s >> c;
        s--;
        if (x[s] != - 1 && x[s] != c)
        {
            cout << - 1 << endl;
            return 0;
        }
        x[s] = c;
    }
    if (n == 1 && (x[0] == -1 || x[0] == 0))
    {
        cout << 0 << endl;
        return 0;
    }
    if (x[0] == 0)
    {
        cout << - 1 << endl;
        return 0;
    }
    if (x[0] == - 1) cout << '1';
    else cout << (char)(x[0] + '0');
    for (int i = 1; i < n; i++)
    {
        if (x[i] == - 1) cout << '0';
        else cout << (char)(x[i] + '0');
    }
    cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int n; cin >> n;
	vector<int>x(n), y(n);
	vector<char> u(n);
	vector<set<int>>stU(200010), stD(200010);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		cin >> u[i];
		if (u[i] == 'U') {
			stU[x[i]].insert(y[i]);
		}
		else if (u[i] == 'D') {
			stD[x[i]].insert(y[i]);
		}
	}
	int ans = 1001001001;
	for (int i = 0; i < 200010; i++) {
		for (auto j : stU[i]) {
			auto it = stD[i].lower_bound(j);
			if (it != stD[i].end()) {
				ans = min(ans, *it - j);
			}
		}
	}
	vector<set<int>>stR(200010), stL(200010);
	for (int i = 0; i < n; i++) {
		if (u[i] == 'R') {
			stR[y[i]].insert(x[i]);
		}
		else if (u[i] == 'L') {
			stL[y[i]].insert(x[i]);
		}
	}
	for (int i = 0; i < 200010; i++) {
		for (auto j : stR[i]) {
			auto it = stL[i].lower_bound(j);
			if (it != stL[i].end()) {
				ans = min(ans, *it - j);
			}
		}
	}
	map<int, vector<pair<int, char>>>mp;
	for (int i = 0; i < n; i++) {
		if (u[i] == 'R') {
			mp[y[i] - x[i]].push_back({ x[i],'R' });
		}
		else if(u[i] == 'D'){
			mp[y[i] - x[i]].push_back({ x[i],'D' });
		}
	}
	for (auto p : mp) {
		sort(p.second.begin(), p.second.end());
		for (int i = 0; i < p.second.size() - 1; i++) {
			if (p.second[i].second == 'R' && p.second[i + 1].second == 'D') {
				ans = min(ans, (p.second[i + 1].first - p.second[i].first) * 2);
			}
		}
	}
	mp.clear();
	for (int i = 0; i < n; i++) {
		if (u[i] == 'U') {
			mp[y[i] - x[i]].push_back({ x[i],'U' });
		}
		else if (u[i] == 'L') {
			mp[y[i] - x[i]].push_back({ x[i],'L' });
		}
	}
	for (auto p : mp) {
		sort(p.second.begin(), p.second.end());
		for (int i = 0; i < p.second.size() - 1; i++) {
			if (p.second[i].second == 'U' && p.second[i + 1].second == 'L') {
				ans = min(ans, (p.second[i + 1].first - p.second[i].first) * 2);
			}
		}
	}
	mp.clear();
	for (int i = 0; i < n; i++) {
		if (u[i] == 'R') {
			mp[y[i] + x[i]].push_back({ x[i],'R' });
		}
		else if (u[i] == 'U') {
			mp[y[i] + x[i]].push_back({ x[i],'U' });
		}
	}
	for (auto p : mp) {
		sort(p.second.begin(), p.second.end());
		for (int i = 0; i < p.second.size() - 1; i++) {
			if (p.second[i].second == 'R' && p.second[i + 1].second == 'U') {
				ans = min(ans, (p.second[i + 1].first - p.second[i].first) * 2);
			}
		}
	}
	mp.clear();
	for (int i = 0; i < n; i++) {
		if (u[i] == 'L') {
			mp[y[i] + x[i]].push_back({ x[i],'L' });
		}
		else if (u[i] == 'D') {
			mp[y[i] + x[i]].push_back({ x[i],'D' });
		}
	}
	for (auto p : mp) {
		sort(p.second.begin(), p.second.end());
		for (int i = 0; i < p.second.size() - 1; i++) {
			if (p.second[i].second == 'D' && p.second[i + 1].second == 'L') {
				ans = min(ans, (p.second[i + 1].first - p.second[i].first) * 2);
			}
		}
	}
	if (ans == 1001001001) {
		cout << "SAFE" << endl;
	}
	else {
		cout << ans * 5 << endl;
	}
	return 0;
}


Measured memory_bytes: 73488
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;
#define N 200010


int mark[N]={0};
    int num[N][2];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int x,y;
    int k=0,j=0;

    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        if(x==1&&y!=1)
            mark[y]=1;
        if(y==1&&x!=1)
            mark[x]=1;
        num[i][0]=x;
        num[i][1]=y;
    }
    for(int i=0;i<m;i++)
    {
        if(num[i][0]==n&&mark[num[i][1]]==1)
        {
            printf("POSSIBLE\n");return 0;
        }
        if(num[i][1]==n&&mark[num[i][0]]==1)
        {
            printf("POSSIBLE\n");return 0;
        }

    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 2560
#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 ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>

int mul(int a, int b) {
	return (long long)a * b % MOD;
}

int power(int a, int b) {
	int ans = 1;
	while (b > 0) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}
//bitset<400000010> b;

// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (!p[i])
			//primes.push_back(i);
			for (ll j = i; j <= n; j += i) {
				if (i != j)
					;
				p[j] = 1;
			}
	}
}


// ll nextPowerOf2(ll n)
// {
//     ll p = 1;
//     if (n && !(n & (n - 1)))
//         return n;

//     while (p < n)
//         p <<= 1;

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

}
ll factorial(ll n)
{
	if (n == 0)
		return 1;
	return n * factorial(n - 1);
}
struct segmenttree {
	vector<int> st;
	int n;
	void init(int _n) {
		n = _n;
		st.clear();
		st.resize(4 * _n, 0);
	}

	void update(int l, int r, int indup, int val, int node) {
		if (l == r) {
			st[node] += val;
			return;
		}
		else {
			int mid = (l + r) / 2;
			if (indup >= l && indup <= mid) {
				update(l, mid, indup, val, node * 2 + 1);
			}
			else {
				update(mid + 1, r, indup, val, node * 2 + 2);
			}
			st[node] = st[2 * node + 1] + st[2 * node + 2];
		}
	}

	int query(int si, int se, int l, int r, int node) {
		if (se < l || si > r || l > r) {
			return 0;
		}
		if (si >= l && se <= r) {
			return st[node];
		}
		int mid = (si + se) / 2;
		int q1 = query(si, mid, l, r, node * 2 + 1);
		int q2 = query(mid + 1, se, l, r, node * 2 + 2);
		return q1 + q2;
	}
	int query(int l, int r) {
		return query(0, n - 1, l, r, 0);
	}
	void update(int index, int val) {
		update(0, n - 1, index, val, 0);
	}
} tree;

bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] > mis)
			sum += a[i] - mis;
		if (sum >= k)
			return true;
	}


	return false;
}
struct cmp {
	bool operator() (const pair<ll, ll> &a, const pair<ll, ll> &b )const
	{
		ll lena = a.S - a.F;
		ll lenb = b.S - b.F;
		if (lena == lenb)
			return a.F < b.F;
		return lena > lenb;
	}
};

int32_t main()
{	fast

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll k;
	string s;
	cin >> k >> s;
	if (s.length() <= k)
		cout << s << endl;
	else {
		cout << s.substr(0, k ) + "...";

	}

}

Measured memory_bytes: 27056
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
v = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    l = int(str(i)[0])
    r = int(str(i)[-1])
    v[l][r] += 1


ans = 0
for i in range(10):
    for j in range(10):
        ans += v[i][j] * v[j][i]

print(ans)


Measured memory_bytes: 43244
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String[] hiki = scan.nextLine().split(" ");
    int n = Integer.parseInt(hiki[0]);
    int w = Integer.parseInt(hiki[1]);
    int[] weight = new int[n];
    int[] value = new int[n];
    for(int i = 0;i < n;i ++){
      hiki = scan.nextLine().split(" ");
      weight[i] = Integer.parseInt(hiki[0]);
      value[i] = Integer.parseInt(hiki[1]);
    }
    long[][] dp = new long[n][w + 1];
    dp[0][weight[0]]=value[0];
    for(int i = 1;i < n;i ++){
      for(int j = 0;j <= w;j ++){
        if(dp[i-1][j] > 0){
          dp[i][j] = Math.max(dp[i-1][j], dp[i][j]);
          if(j+weight[i] <= w)
          	dp[i][j+weight[i]] = Math.max(dp[i-1][j] + value[i], dp[i][j+weight[i]]);
        }
      }
      dp[i][weight[i]] = Math.max(value[i], dp[i][weight[i]]);
    }
    long max = 0;
    for(int i = 0;i <= w;i ++){
      max = Math.max(max, dp[n-1][i]);
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 127444