akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string s;
  cin >> s;
  for (int i=0; i<7; i++) {
    if (s==a[i]) {
      cout << 7-i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h == 0 && w == 0){
                break;
            }
            
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)){
                        System.out.print('#');
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 36628
n,t = map(int,input().split())

c = []

for i in range(n):
	c.append(list(map(int,input().split())))



a = 100000000
for i in c:
	if i[1] <= t:
		a = min(a,i[0])

if a == 100000000:
	print('TLE')
else:
	print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back

using namespace std;

int main() {

      int n;
       cin>>n;
       int a[n];
       map<int,int> m;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           m[a[i]]++;
       }
      int co=0;
      //hi
       for(int i=0;i<n;i++)
       {
           int f=0;
           for(int j=2;j*j<=(a[i]);j++)
           {
               if(a[i]%j==0)
               {
                   if(m[j]==0&&m[a[i]/j]==0)
                   {
                       
                   }
                   else
                   {
                       f=123;
                       break;
                   }
               }
           }
           if(f==0&&m[a[i]]==1&&m[1]==0)
           {
               co++;
           }
       }
       if(m[1]>1||m[1]==0)
       cout<<co;
       else
       cout<<co+1;
      
}

Measured memory_bytes: 33264
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

LL dp[1000005][10][2] = {0};
string s;
LL n,ans = 0x3f3f3f3f3f3f3f3f;

int main(){
	memset(dp,0x3f,sizeof(dp));
	cin >> s; n = s.length(); s = ' ' + s;
	dp[0][1][1] = 1; dp[0][0][0] = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= 9;j ++){
			for(LL k = 0;k <= 9;k ++){
				if(j < s[i] - '0') dp[i][j][0] = min(dp[i][j][0],dp[i - 1][k][1] + (10 + j - (s[i] - '0')) % 10 + j);
				else dp[i][j][0] = min(dp[i][j][0],dp[i - 1][k][0] + (10 + j - (s[i] - '0')) % 10 + j);
				if(j - 1 < s[i] - '0') dp[i][j][1] = min(dp[i][j][1],dp[i - 1][k][1] + (19 + j - (s[i] - '0')) % 10 + j);
				else dp[i][j][1] = min(dp[i][j][1],dp[i - 1][k][0] + (19 + j - (s[i] - '0')) % 10 + j);
			}
		}
	}
	for(LL j = 0;j <= 9;j ++) ans = min(ans,dp[n][j][0]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 158596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef pair<int,int> pii;
int w[100005];
int no[100005];
int fa[100005];
int num[100005];
pii node[100005];
bool vis[100005];
int find(int x){
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
bool merge(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx==fy) return false;
	fa[fx]=fy;
	return true;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) fa[i]=i;
	for(int i=0;i<n;i++) scanf("%d",&w[i]);
	int treenum=n-m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		merge(u,v);
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(fa[i]==i) no[i]=cnt++;
	}
	for(int i=0;i<n;i++)
	{
		if(fa[i]!=i) no[i]=no[find(i)];
	}
	int tot=0;
	for(int i=0;i<n;i++){
		node[tot++]=pii(w[i],no[i]);
	}
	memset(num,0,sizeof(num));
	memset(vis,0,sizeof(vis));
	long long ans=0;
	sort(node,node+tot);
	int can=0;
	for(int i=0;i<tot;i++){
		if(can==(treenum-1)*2) break;
		if(!num[node[i].second]){
			vis[i]=1;
			can++;
			num[node[i].second]=1;
			ans+=node[i].first;
		}
	}
	for(int i=0;i<tot;i++)
	{
		if(can==(treenum-1)*2) break;
		if(!vis[i]&&num[node[i].second]<treenum-1){
			num[node[i].second]++;
			can++;
			ans+=node[i].first;
		}
	}
	if(can!=(treenum-1)*2) printf("Impossible\n");
	else printf("%lld\n",ans);
}

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

int main() {
  std::string A, B, C;
  std::cin >> A >> B >> C;
  if (A.back() != B.front()) {
    std::cout << "NO" << std::endl;
  } else if (B.back() != C.front()) {
    std::cout << "NO" << std::endl;
  } else {
    std::cout << "YES" << std::endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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 P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long
int dp[55][55][3010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = INF;
	for (int i = -100; i <= 100; i++) {
		int now = 0;
		rep(j, n) {
			now += (a[j] - i)*(a[j] - i);
		}
		chmin(ans, now);
	}
	cout << ans << endl;
	return 0;
}


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

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

  int ans=0;
  for(int i=1; i<s.size(); i++){
    if(s[i]==s[i-1]){
      if(s[i-1]=='0')s[i]='1';
      if(s[i-1]=='1')s[i]='0';
      ans++;
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
vector<int>v;
int m[11];
string s[20011];
int main(){
	m[1]=2;
	m[2]=5;
	m[3]=5;
	m[4]=4;
	m[5]=5;
	m[6]=6;
	m[7]=3;
	m[8]=7;
	m[9]=6;
	cin>>N>>M;
	REP(i,M){
		int a;
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	string x="";
	REP(i,20011){
		x.push_back('9');
	}
	REP(i,N+1){
		s[i]="";
	}
	s[N]=x;
	REP(k,M){
		int a=v[k];
		int b=m[v[k]];
		for(int i=N;i>=0;i--){
			if(i-b>=0){
				string ss=s[i]+to_string(a);
				//cout<<ss<<endl;
				if(s[i-b].size()<ss.size()){
					s[i-b]=ss;
				}else if(s[i-b].size()>ss.size()){
				
				}else{
					s[i-b]=max(s[i-b],ss);
				}
			}
		}
		/*REP(i,21){
			cout<<0;
			REP(j,s[i].size()){
				if(j<20011)continue;	
				cout<<s[i][j];
			}
			cout<<endl;
		}
		cout<<endl;*/
	}
	REP(i,s[0].size()){
		if(i<20011)continue;
		cout<<s[0][i];
	}
	cout<<endl;
}

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

int n;
vector<int> a(200005);

int main() {
  cin >> n;
  rep(i,n)
  cin >> a[i];
  int cnt=0,l=0;
  rep(i,n){
  if(find(a.begin()+l,a.end(),i+1)==a.end())
  break;
  else {
  l=find(a.begin()+l,a.end(),i+1)-a.begin();
  cnt++;
  }
  }
  if(cnt==0)
  cout << -1 << endl;
  else 
  cout << n-cnt << endl;
}

Measured memory_bytes: 1024
while True:
    n,a,b,c,x = map(int,input().split())
    if n==0: break
    l = list(map(int,input().split()))
    for i in range(0,10001):
        if l[0]==x:
            del l[0]
            if not(l):
                print(i)
                break
        x = (a*x+b)%c
    else: print(-1)

Measured memory_bytes: 7612
n=int(input())
a=[int(_) for _ in input().split()]

s = 0
x = [0]*n
y = 0
for i in range(n):
  s += a[i]

for i in range(n)[1::2]:
  y+=2*a[i]

x[0]=s-y

for i in range(n-1):
  if i+1 == n:
    x[i+1]==2*a[i+1] - x[0]
    break
  else:
    x[i+1]=2*a[i]-x[i]

print(' '.join(map(str, x)))

Measured memory_bytes: 19140
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;
int D[100008];
int main() {
	long long int N;
	cin >> N;
	long long int d;
	for (int i = 0; i < N; i++) {
		cin >> d;
		D[d]++;
	}
	long long int Z = 0;
	for (int i = 0; i < 100007; i++) {
		if (D[i] > 0)Z++;
	}
	if ((N-Z) % 2 == 1) {
		cout << Z-1 << endl;
	}
	else {
		cout << Z << endl;
	}

	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,a,b;
	cin>>n>>a>>b;
	if(abs(b - a)%2 == 0)
		cout<<"Alice\n";
	else
		cout<<"Borys\n";
	return 0;
}

Measured memory_bytes: 256
/*
Selection Sort
ALDS1_2_B
選択ソート
*/

package main

import (
	"fmt"
	"strconv"
)

func array_data(data []int) string {
	s := ""
	for i := 0; i < len(data); i++ {
		s += strconv.Itoa(data[i])
		if i != len(data)-1 {
			s += " "
		}
	}

	return s
}

func selection_sort(data []int, n int) ([]int, int) {
	changed := 0

	for i := 0; i < n; i++ {
		minj := i
		for j := i; j < n; j++ {
			if data[j] < data[minj] {
				minj = j
			}
		}

		if i != minj {
			data[i], data[minj] = data[minj], data[i]
			changed++
		}
	}

	return data, changed
}

func main() {
	var n int
	var data [100]int

	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i])
	}

	sorted, changed := selection_sort(data[:n], n)

	fmt.Println(array_data(sorted))
	fmt.Println(changed)
}


Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
typedef pair<P, int>PP;
const long long inf = 1ll << 61;
vector<int>V;

void dfs(int now) {
	V.push_back(now);
	if (now > 3234566667)return;
	int x = now % 10;
	dfs(now * 10 + x);
	if (x)dfs(now * 10 + x - 1);
	if (x != 9)dfs(now * 10 + x + 1);
}

signed main() {
	int k; cin >> k;
	rep(i, 9)dfs(i + 1);
	sort(V.begin(), V.end());
	cout << V[k - 1] << endl;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
const int N=21; 
int n,v[N],c[N],A;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=n;i++)
		A+=max(0,v[i]-c[i]);
	cout<<A;
	return 0;
}

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

int main () {
	
	int N, M;
	std::cin >> N >> M;
	
	const int count = 1000000;
	const double p = std::pow(0.5, M);
	const double q = 1 - p;
	
	double ans = 0;
	for (int i = 1; i < count; ++i) {
		double time = (1900*M + 100*(N-M)) * i;
		ans += time * std::pow(q, i-1) * p;
	}
	std::cout << std::round(ans) << std::endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int i;
	int j;
		for (i = 1; i <= 9; i++) {
   for (j = 1; j <= 9; j++) {
     printf("%dx%d=%d\n", i, j, i*j);
   }
 }


		
	return 0;
}

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

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int x, k, d;
    cin>>x>>k>>d;

    x = abs(x);

    int rem = x%d;
    int mul = x/d;

    if (mul>=k){
        cout<<x-k*d<<endl;
    }
    else{
        int rem = mul-k;
        int a = x%d;
        int b = d-x%d;
        if (rem%2){
            cout<<b<<endl;
        }
        else{
            cout<<a<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3668
N = gets.to_i
s = (1..N).map{gets.to_i}.sort

class Array
	def summ
		ret=0
		self.each{|e|ret += e}
		ret
  end
end

S = s.summ
if S%10 != 0
	p S
	exit
end

ans = 0
for i in 1..N
	for j in 0..N-i
		ns = S - s[j,i].summ
		ans = [ans, ns].max if ns%10 != 0
	end
end
p ans
# p n=100;Array.new(n){rand(100)}.each{|e|p e}

Measured memory_bytes: 1788
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
unordered_map<int,int> mp;
int n,m;


int main(){
	n=D(),m=D();
	if(n>m)
		printf("%d\n",n-m);
	else
		puts("0");

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;


//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}


int32_t main() {
    start;


    string str, sub;
    cin >> str >> sub;
    int n = str.size();
    int m = sub.size();
    int ans = INT64_MAX;
    for (int i = 0; i < n - m + 1; ++i) {
        int cur_ans = 0;

        for (int j = 0; j < m; ++j) {
            if (str[i + j] != sub[j]) {
                cur_ans += 1;
            }
        }

        ans = min(ans, cur_ans);
    }

    cout << ans << '\n';

    finish;
}

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

signed main(){
  int N;
  cin >> N;
  int A = 0, B = 0;
  vector<int> num(N);
  for(int i = 0; i < N; i++){
    cin >> num.at(i);
  }
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());
  
  for(int i = 0; i< N; i++){
    if(i % 2 == 0){
      A += num.at(i);
    }
    if(i % 2 == 1){
      B += num.at(i);
    }
  }
  cout << A - B << endl;
}
      

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

bool check(ll score, ll K, vector<ll> &A, vector<ll> &F) {
    ll N = A.size();
    rep(i, N) {
        K -= max(0LL, A[i] - score / F[i]);
        if(K < 0)
            return false;
    }
    return true;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<ll> F(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    rep(i, N) cin >> F[i];

    if(sum <= K) {
        cout << 0 << endl;
        return 0;
    }
    sort(All(A));
    sort(F.rbegin(), F.rend());
    ll lb = 0, ub = LINF;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if(check(mid, K, A, F)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    cout << ub << endl;
    return 0;
}

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

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 10010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
#define LOOP 10000000


int main() {

  int N, M;
  cin >> N >> M;
  vector<pair<int, string>> q(M);
  int tmp;
  string tmpstr;
  int tmpwanum = 0, wasum = 0, acnum = 0;
  vector<int> acflag(N, 0);
  vector<int> wanum(N, 0);
  int j = 0;

  REP(i, M){
    cin >> tmp >> tmpstr;
    q[i] = make_pair(tmp, tmpstr);
  }

  REP(i, M){
    j = q[i].first;
    if( q[i].second == "WA" ){
      if( acflag[j] == 0 ){
        wanum[j]++;
      }
    } else {
      if( acflag[j] == 0 ){
        acnum++;
        acflag[j] = 1;
        wasum += wanum[j];
      }
    }
  }

  cout << acnum << " " << wasum << endl;;

  return 0;



 
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 7296
#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct Struct{
        string name;
        int time;
};
int main(){
        int N,q;
        cin >> N >> q;
        Struct process[100000];
        queue<Struct> circle;
        for(int i=0 ; i<N ; i++ ){
                cin >> process[i].name >> process[i].time;
                circle.push(process[i]);
        }
        int counter=0;
        while(circle.size()!=0){
                Struct now=circle.front();circle.pop();
                now.time-=q;
                if(now.time<=0){
                        cout << now.name<<" "<<counter+(q+now.time)<<endl;
                        counter+=now.time;
                }
                else
                        circle.push(now);
                counter+=q;
        }
        return 0;
}


Measured memory_bytes: 7796
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
int main()
{
    lli d[100005], p[100005];
    lli N;
    cin >> N;
    lli t[100005], a[100005];
    rep(i, N)
    {
        cin >> t[i];
    }
    rep(i, N) cin >> a[i];

    lli tmp = 0;
    rep(i, N)
    {
        if (tmp == t[i]) {
            d[i] = t[i];
        } else {
            d[i] = 1;
        }
        tmp = max(t[i], tmp);
    }
    int index;
    rep(i, N)
    {
        if (tmp == t[i]) {
            index = i;
            break;
        }
    }
    int l = tmp;
    tmp = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (tmp == a[i]) {
            p[i] = a[i];
        } else {
            p[i] = 1;
        }
        tmp = max(a[i], tmp);
    }
    int index2;
    for (int i = N - 1; i >= 0; i--) {
        if (tmp == a[i]) {
            index2 = i;
            break;
        }
    }
    if (tmp != l || index > index2) {
        cout << 0 << endl;
        return 0;
    }
    lli ans = 1;

    rep(i, N)
    {
        ans = (ans * min(d[i], p[i]) + MOD) % MOD;
    }
    // rep(i, N) cout << d[i] << ' ';
    // cout << endl;
    // rep(i, N) cout << p[i] << ' ';
    cout << (ans + MOD) % MOD << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main() {
    // insert code here...
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int x;
    scanf("%d", &x);
    printf("%d\n", a[x-1]);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
march = ["M", "A", "R", "C", "H"]
num = [0] * 5
for i in range(n):
    s = input()
    if s[0] in march:
        num[march.index(s[0])] += 1
ans = 0
for i in range(0,3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += num[i] * num[j] * num[k]
print(ans)




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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		char a = s.charAt(0);
		int b = s.length()-2;
		char c = s.charAt(s.length()-1);
		System.out.print(a);
		System.out.print(b);
		System.out.print(c);

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int n,x; cin >> n >> x;
	int l[n]; REP (i,n) cin >> l[i];
	int ans = 1; int tmp = 0;
	REP (i,n) {
		tmp += l[i];
		if (tmp <= x) ans++;
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
ans = []
maxa = max(A)
mina = min(A)
if abs(mina) > abs(maxa):
    for i in range(n)[:0:-1]:
        if A[i-1] > A[i]:
            while A[i-1] > A[i]:
                ma = min(A)
                argmina = A.index(ma)
                A[i-1] += ma
                ans.append((argmina+1, i-1+1))
else:
    for i in range(n-1):
        pa = A[i]
        aa = A[i+1]
        if pa > aa:
            while pa > A[i+1]:
                ma = max(A)
                argmaxa = A.index(ma)
                A[i+1] += ma
                ans.append((argmaxa+1, i+1+1))

print(len(ans))
for a in ans:
    print(*a)


Measured memory_bytes: 63940
mod = 10 ** 9 + 7
s = input()
n = len(s)
dp = [[0 for _ in range(13)] for _ in range(n + 1)]
dp[0][0]=1
for i in range(n):
    if s[i] == '?': 
        for j in range(10):
            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13]+=dp[i][k] % mod
    else:
        for k in range(13): 
            dp[i + 1][(k * 10+ int(s[i])) % 13]+=dp[i][k] % mod
print(dp[-1][5] % mod)

Measured memory_bytes: 66268
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999

int a, b, c, d;

int main() {
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/


P dat[1000000];
int size_ = 1;
void init(int x) {
	while (size_ < x)size_ *= 2;
}
void eval(int k, int l, int r) {
	if (dat[k].second) {
		dat[k].first += dat[k].second;
		if (r - l > 1) {
			dat[k * 2 + 1].second += dat[k].second / 2;
			dat[k * 2 + 2].second += dat[k].second / 2;
		}
		dat[k].second = 0;
	}
}
void update(int a, int b, int k, int x, int l, int r) {
	eval(k, l, r);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		dat[k].second += (r - l) * x;
		eval(k, l, r);
	}
	else {
		update(a, b, k * 2 + 1, x, l, (l + r) / 2);
		update(a, b, k * 2 + 2, x, (l + r) / 2, r);
	}
}
int query(int a, int k, int l, int r) {
	eval(k, l, r);
	if (r - l == 1)return dat[k].first;
	if (a < (l + r) / 2)return query(a, k * 2 + 1, l, (l + r) / 2);
	return query(a, k * 2 + 2, (l + r) / 2, r);
}
signed main() {
	int n, q;
	cin >> n >> q;
	init(n);
	rep(i, q) {
		int a; cin >> a;
		if (!a) {
			int s, t, x; cin >> s >> t >> x;
			s--;
			update(s, t, 0, x, 0, size_);
		}
		else {
			int x; cin >> x;
			x--;
			cout << query(x, 0, 0, size_) << endl;
		}
	}
}


Measured memory_bytes: 6248
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n; char s[N];

int main() {
	scanf("%s",s+1); n=strlen(s+1);
	int ans=0;
	for (int i=1;i<n;++i) ans+=s[i]!=s[i+1];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3932
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}
 
const int N=3005;
int mod,phi;
namespace{
	int fac[N],rev[N],s[N][N];
	int power(int x,int p,int mo){
		int res=1;
		for(;p;p>>=1,x=(ll)x*x%mo)
			if(p&1)res=(ll)res*x%mo;
		return res;
	}
	int mul(int x,int y){
		return static_cast<ll>(x)*y%mod;
	}
	void add(int &x,int y){
		x=(x+y>=mod?x+y-mod:x+y);
	}
	int fix(int x){
		return x>=mod?x-mod:x;
	}
	int C(int n,int m){
		return m<0||m>n?0:mul(fac[n],mul(rev[m],rev[n-m]));
	}
	void init(){
		const int lim=3000;
		fac[0]=1;
		rep(i,1,lim)fac[i]=(ll)fac[i-1]*i%mod;
		rev[lim]=power(fac[lim],mod-2,mod);
		per(i,lim,1)rev[i-1]=(ll)rev[i]*i%mod;
		rep(i,0,lim)s[i][0]=1;
		rep(i,1,lim)rep(j,1,i)
			s[i][j]=fix(s[i-1][j-1]+mul(s[i-1][j],j+1));
	}
}
int n,ans;

int main(){
	read(n),read(mod),init();
	rep(i,0,n){
		int tot=power(2,power(2,n-i,mod-1),mod);
		int t=power(2,n-i,mod),coef=mul((i&1?mod-1:1),C(n,i));
		rep(j,0,i){
			add(ans,mul(coef,mul(tot,s[i][j])));
			tot=mul(tot,t);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 34176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll n;
  string s;
  cin>>n>>s;
  ll t=s.size();
  loop(i,t){
    if(s[i]+n<='Z'){
    s[i]=(char)(s[i]+n);
    }
    else{
      s[i]=(char)((s[i]+n)-'Z'+64);
    }
  }
  putout(s);
}

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

int main() {
    string odd, even, res;
    cin >> odd >> even;
    int cure = 0, curo = 0;
    for (int i = 0; i < odd.length() + even.length(); i++) {
        if (i % 2 == 0) res += odd[curo++];
        else res += even[cure++];
    }
    cout << res << endl;
}

Measured memory_bytes: 256
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())

Measured memory_bytes: 2568
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

long long int mod(long long int x, long long int m){
  if(x>0){
    return x%m;
  }
  else if(x==0){
    return 0;
  }
  return 0;
}

int main(){
  long long int L, R;
  scanf("%lld%lld", &L, &R);
  
  std::vector<long long int> mod_count1(2019);
  mod_count1[0] = R/2019 - (L-1)/2019;
  for(long long int i = 1; i < 2019; i++){
    mod_count1[i] = (R+(2019-i))/2019 - (L-1+(2019-i))/2019;
  }
  
  std::vector<long long int> mod_ij(2019);
  for(long long int i = 0; i < 2019; i++){
    if(mod_count1[i] > 0){
      if(mod_count1[i] > 1){
        mod_ij[mod(i*i, 2019)] = 1;
      }
      for(long long int j = i+1; j < 2019; j++){
        if(mod_count1[j] > 0){
          mod_ij[mod(i*j, 2019)] = 1;
        }
      }
    }
  }
  
  long long int ans = 0;
  for(long long int i = 0; i < 2019; i++){
    if(mod_ij[i] != 0){
      ans = i;
      break;
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() 
{
	int n; cin >> n;
	if (n % 1000 == 0) cout << 0;
	else {
		int tmp = n;
		int cnt = 1;
		while (tmp > 1000){
			cnt++;
			tmp -= 1000;
		} 
		cout << cnt * 1000 - n;
	}
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5],k;
    for(int i=0;i<5;i++) cin>>a[i];
    cin>>k;
    sort(a,a+5);
    if(abs(a[4]-a[0])>k) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


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

int main(){
        int n,q,i,b,c,tmp;
        long long sum,t;
        cin >> n;
        vector<int> a(n);
        vector<int> cnt(1000000);
        vector<long long> ans;
        for(i=0;i<n;++i){
                cin >> tmp;
                ++cnt.at(tmp);
                sum += tmp;
        }
        cin >> q;
        for(i=0;i<q;++i){
                cin >> b >> c;
                sum  += (c-b)*cnt.at(b);
                cnt.at(c) += cnt.at(b);
                cnt.at(b) = 0;
                cout << sum << endl;
        }
        return 0;
}

Measured memory_bytes: 7484
import Data.Functor
import Data.List

main :: IO ()
main = do
  { [ss] <- getInts
  ; let (mm,s) = divMod ss 60
  ; let (h,m) = divMod mm 60
  ; putStrLn (intercalate ":" (map show [h, m, s]))
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

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

int main(){
    
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    
    sort(a.begin(), a.end());
    int total = 0;
    for(int i = 0; i < k; i++){
        total += a[i];
    }
    
    cout << total << endl;
    
} 


Measured memory_bytes: 3548
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    r,g,b = LI()
    ans = ["YES","NO"]
    print(ans[((((((g<<1)&b)<<1)+((g<<1)^b))&3)>>int(math.log(max(1,(((((g<<1)&b)<<1)+((g<<1)^b))&3)&(-(((((g<<1)&b)<<1)+((g<<1)^b))&3))),2)))&1])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38512
def main():
    N, K = map(int, input().split())
    A = [0 for a in range(N)]

    for i in range(K):
        d = int(input())
        O = [int(a) for a in input().split()]

        for j in range(d):
            A[O[j]-1] += 1
    cnt = 0
    for i in range(N):
        if A[i] == 0:
            cnt += 1

    print(cnt)
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    int x,n; cin >> x >> n;
    if(n==0) cout << x << endl;
    else {
        vector<int> A(102,0);
        rep(i,n) {
        int p; cin >> p;
        A[p]++;
        }
        int r=101,ans=0;
        for(int i=101; i>=0; i--) {
            if(A[i]==0) {
                int R=abs(x-i);
                if(R<=r){
                    r=R; ans=i;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
n = gets.chomp.to_i
hash = {}

def hoge(n)
  result = 0
  n.times do |i|
    result += i
  end
  result
end

n.times do
  s = gets.chomp.split('').sort.join
  hash[s] ? hash[s] += 1 : hash[s] = 1
end
result = 0

hash.each do |k,v|
  if (v > 1)
    result += hoge(v)
  end
end
puts result

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int N,M;
  cin>>N>>M;
  map<int,int> m;
  m[1]=2;
  m[2]=5;
  m[3]=5;
  m[4]=4;
  m[5]=5;
  m[6]=6;
  m[7]=3;
  m[8]=7;
  m[9]=6;
  map<int,int> d;
  for(int i = 0; i < M; i++){
    int x;
    cin>>x;
    chmax(d[m[x]],x);
  }
  vector<int> dp(N+1,-1);
  dp[0]=0;
  for(int i = 0;i<N+1;i++){
    for(auto x:d){
      if(i<x.first) continue;
      if(dp[i-x.first]==-1) continue;
      chmax(dp[i],dp[i-x.first]+1);
    }
  }
  vector<int> s;
  for(auto x:d) s.push_back(x.second);
  sort(s.begin(),s.end());
  reverse(s.begin(),s.end());
  int cnt = 0;
  for(int i = 0; i < dp[N]-1; i++){
    for(int j = 0; j < (int)s.size();j++){
      if(N-cnt-m[s[j]]>=0&&dp[N-cnt]==dp[N-cnt-m[s[j]]]+1&&dp[N-cnt-m[s[j]]]!=-1) {
        cout<<s[j];
        cnt+=m[s[j]];
        break;
      }
    }
  }
  cout<<d[N-cnt]<<endl;
}

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

int main(){
    string Sd, T, subs, ans="UNRESTORABLE";
    int i, j;
    bool fit;

    cin >> Sd >> T;

    for (i=(Sd.size() - T.size()); i>=0; i--) {
        fit = true;
        subs = Sd.substr(i, T.size());
        for (j=0; j<T.size(); j++) {
            if ((subs[j] != '?') && (subs[j] != T[j])) {
                fit = false;
                break;
            } 
        }
        if (fit == true) {
            ans = Sd;
            ans = ans.replace(i, T.size(), T);
            for (j=0; j<ans.size(); j++) {
                if (ans[j] == '?') ans[j] = 'a';
            }
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

void add_mod(ll& val, ll add_val) {
	val = (val + add_val) % 100000007;
}

struct Student {
	int order;
	int idx;
};

int main (int argc, char* argv[]) {
	vector<Student> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int order;
		cin >> order;
		s.push_back({ order, i });
	}
	sort(s.begin(), s.end(), [](const auto& l, const auto& r) {
			return l.order < r.order;
			});

	for (const auto& st : s) {
		cout << st.idx + 1 << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 1780
#include<iostream>
using namespace std;
int main(){
string s,t;
  int ans=0;
  cin >> s >> t;
  if(s.at(0)==t.at(0)){
  ans++;
  }
  if(s.at(1)==t.at(1)){
  ans++;
  }
  if(s.at(2)==t.at(2)){
  ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int H = in.nextInt();
            int W = in.nextInt();
            int[][] c = new int[10][10];
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    c[i][j] = in.nextInt();
                }
            }

            int[][] A = new int[H][W];
            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    A[h][w] = in.nextInt();
                }
            }

            for (int k = 0; k < 10; k++) {
                for (int from = 0; from < 10; from++) {
                    for (int to = 0; to < 10; to++) {
                        c[from][to] = Math.min(c[from][to], c[from][k] + c[k][to]);
                    }
                }
            }

            long sum = 0;
            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    if (A[h][w] != -1) {
                        sum += c[A[h][w]][1];
                    }
                }
            }

            System.out.println(sum);
        }
    }
}


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

#define ll long long

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a ,b;
    cin >> n >> a >> b;

    ll ans = 0;
    for (int i = 1; i <= n; i++){
        int N = i;
        int sum = 0;
        while(N){
            sum += N%10;
            N /= 10;
        }

        if (sum >= a && sum <=b) ans += i;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

double calc(int x1,int y1,int x2,int y2){
    return((double)sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    double ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=calc(x[i],y[i],x[j],y[j])*2;
        }
    }
    cout<<setprecision(10)<<ans/n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int X;
	cin >> X;
	int ans = 0;
	rep(N, 1100) {
		int Xtmp = X - N * 100;
		if (Xtmp >= 0 && Xtmp <= N * 5)
			ans = 1;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n), b(n);
        int mi = 1e9 + 5;
        long long s = 0;
        rep(i, n) {
                scanf("%d%d", &a[i], &b[i]);
                if (a[i] > b[i]) {
                        mi = min(mi, b[i]);
                }
                s += a[i];
        }
        if (mi == 1e9 + 5) {
                printf("0\n");
        } else {
                printf("%lld\n", s - mi);
        }
        return 0;
}


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

using namespace std;

const int MAXN = 2005;
const int MAXK = 10005;

int n, k, br;
string s[MAXN], curr;
int z[MAXK*2];
bool dp[MAXN][MAXK], ok[MAXK];

void precompute () {
    dp[n][0] = 1;
    for (int i = n-1; i >= 0; i--) {
        int len = s[i].size();
        for (int j = 0; j <= k; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j - len >= 0) dp[i][j] |= dp[i + 1][j - len];
        }
    }
}

void z_algo (int ind) {
    string t = s[ind] + '.' + curr;
    int l = 0, r = 0, len = t.size();
    for (int i = 1; i < len; i++) {
        if (r < i) {
            l = r = i;
            while (r < len && t[r - l] == t[r]) r++;
            z[i] = r - l; r--;
        } else {
            int k = i - l;
            if (z[k] < r - i + 1) {
                z[i] = z[k];
            } else {
                l = i;
                while (r < len && t[r - l] == t[r]) r++;
                z[i] = r - l; r--;
            }
        }
    }
    int org = s[ind].size();
    for (int i=0; i<k; i++) {
        z[i] = z[i + org + 1];
    }
}

void calc () {
    for (int i=0; i<k; i++) curr += '{';
    ok[0] = 1;
    for (int i=0; i<n; i++) {
        int len = s[i].size(), ind = -1, d = -1;
        z_algo(i);
        for (int j = 0; j + len <= k; j++) {
            if (!ok[j] || !dp[i+1][k - (j+len)]) continue;
            if (j + z[j] < k && z[j] < len && s[i][z[j]] < curr[j + z[j]]) {
                ind = j;
                break;
            }
        }
        if (ind == -1) continue;
        br = ind + len;
        for (int j=0; j<len; j++) {
            if (d == -1 && curr[ind + j] != s[i][j]) d = ind + j;
            curr[ind + j] = s[i][j];
        }
        for (int j=br; j<k; j++) {
            curr[j] = '{';
        }
        for (int j = d + 1; j <= k; j++) {
            ok[j] = 0;
        }
        ok[br] = 1;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> s[i];
    }
    precompute();
    calc();
    cout << curr;
    return 0;
}


Measured memory_bytes: 21120