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

using namespace std;
using ll = long long;

namespace mod {

template <class T, int M>
class MInt;

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template <class T, int M>
class MInt {
  T n_;

 public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt &operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt &operator/=(const MInt &rhs) { return (*this) *= Inv(rhs); }

  T Get() { return n_; }
};

template <class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template <class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template <class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template <class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }

  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }

  return a;
}

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}  // namespace mod

const int md = 1e9 + 7;
using MInt = mod::MInt<long long, md>;

int main(int argc, const char *argv[]) {
  ll n, m;
  cin >> n >> m;

  vector<ll> vx(n), vy(m);
  for (int i = 0; i < n; ++i) {
    cin >> vx[i];
  }

  for (int i = 0; i < m; ++i) {
    cin >> vy[i];
  }

  vector<MInt> vdx(n - 1), vdy(m - 1);
  for (int i = 1; i < n; ++i) {
    vdx[i - 1] = vx[i] - vx[i - 1];
  }

  for (int i = 1; i < m; ++i) {
    vdy[i - 1] = vy[i] - vy[i - 1];
  }

  MInt sx = accumulate(vdx.begin(), vdx.end(), MInt(0)),
       sy = accumulate(vdy.begin(), vdy.end(), MInt(0));

  MInt mn = n, mm = m;

  MInt ans1(0);
  for (int i = 0; i < vdx.size(); ++i) {
    ans1 += MInt(i + 1) * MInt(vdx.size() - i) * vdx[i];
  }

  MInt ans2(0);
  for (int i = 0; i < vdy.size(); ++i) {
    ans2 += MInt(i + 1) * MInt(vdy.size() - i) * vdy[i];
  }

  cout << (ans1 * ans2).Get() << '\n';

  return 0;
}

Measured memory_bytes: 6428
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  for(int i =0; i < n; i++){
    int base = 0;
    int p = 0;
    for(int out = 0; out < 3;){
      string str;
      cin >> str;
      if(str == "HIT"){
	base++;
      }else if(str == "OUT"){
	out++;
      }else{
	p += base + 1;
	base = 0;
      }
    }
    p += max(0,base - 3);
    cout << p << endl;
  }
}

Measured memory_bytes: 1212
sz;
long s,t,u;
char x[18],buf[5<<17];
main()
{
	read(0,buf,5<<17);
	while(buf[sz]!=10)
	{
		t=u=0;
		while(buf[sz]=='<')++t,++sz;
		while(buf[sz]=='>')++u,++sz;
		s+=(t*(t+1)+u*(u+1)>>1)-(t<u?t:u);
	}
	sz=17;
	do{
		x[--sz]=s%10+'0';
		s/=10;
	}while(s);
	write(1,x+sz,17-sz);
}

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

int main(){
	//For AOJ
	while(true){
		int N;
		std::vector<int> taro, hanako;

		std::cin >> N;

		//For AOJ
		if(N == 0){
			break;
		}
		//
		
		for(int i = 0; i < N; ++i){
			int input;
			std::cin >> input;
			taro.push_back(input);
		}

		for(int i = 1; i <= N * 2; ++i){
			if(std::find(taro.begin(), taro.end(), i) == taro.end()){
				hanako.push_back(i);
			}
		}

		bool is_taros_turn = true;
		while(!taro.empty() && !hanako.empty()){
			int card = 0;

			while(true){
				std::sort(taro.begin(), taro.end());
				std::sort(hanako.begin(), hanako.end());
				if(is_taros_turn){
					is_taros_turn = false;
					auto itr = taro.begin();
					bool flag = true;
					for(; itr != taro.end(); ++itr){
						if(*itr > card){
							flag = false;
							break;
						}
					}
					
					if(flag){
						card = 0;
						break;
					}
					
					card = *itr;
					taro.erase(itr);
					if(taro.empty()){
						break;
					}
				}
				else{
					is_taros_turn = true;
					auto itr = hanako.begin();
					bool flag = true;
					for(; itr != hanako.end(); ++itr){
						if(*itr > card){
							flag = false;
							break;
						}
					}
					
					if(flag){
						card = 0;
						break;
					}

					card = *itr;
					hanako.erase(itr);
					if(hanako.empty()){
						break;
					}
				}
			}
		}

		std::cout << hanako.size() << std::endl << taro.size() << std::endl;
	}
	//

	return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
 
using namespace std;
 
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
}
 
const int N = 1e6 + 100;
const ll mod = 998244353; //1e9 + 7

int main () 
{
    data();                                 
    string s;
    cin >> s;
    ll sum = 0;
    for (int i = 0; i < s.size(); i++)
    {
    	sum += s[i] - '0';
    }
    if (sum % 9 == 0)
    {
    	cout << "Yes";
    }
    else {
    	cout << "No";
    }
}


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

int main()
{
    string s;
    cin >> s;
    int sum = 0;
    int bit;
    for (bit = 0; bit < (1 << 3); bit++)
    {
        sum = s[0] - '0';
        for (int i = 0; i < 3; i++)
        {
            if (bit & (1 << i))
            {
                sum -= (s[i + 1] - '0');
            }else
            {
                sum += (s[i + 1] - '0');
            }
        }
        if (sum == 7)
            break;
    }

    cout << s[0];
    for (int i = 0; i < 3; i++)
    {
        if (bit & (1 << i))
        {
            cout << '-' << s[i+1];
        }else
        {
            cout << '+' << s[i+1];
        }
        
    }

    cout << "=7" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String ns = in.nextLine();
		//Scanner ins = new Scanner(System.in);
		String string = in.nextLine();
		int n = Integer.parseInt(ns);
		String s = string.split("\\s+")[0];
		String t = string.split("\\s+")[1];
		StringBuilder sb = new StringBuilder("");
		for(int i=0; i<n; i++) {
			sb.append(s.charAt(i));
			sb.append(t.charAt(i));
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 21588
#54
import sys
N = int(input())
word = [] 

w = input()
word.append(w)

for i in range(N-1):
    w = input()
    if word[-1][-1] != w[0]:
        print("No")
        sys.exit()
    for j in word:
        if j == w:
            print("No")
            sys.exit()
    word.append(w)
    
print("Yes")

Measured memory_bytes: 9132
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
ll N,X;
vector<pair<ll,ll> > shops;
ll paty[55],bans[55],layer[55];

ll dfs(ll dim,ll eat)
{
  if(eat>=(layer[dim]-1))
    {
      return paty[dim];
    }
  else if(eat<=1)
    {
      return 0;
    }
  else if(eat<=layer[dim-1]+1)
    {
      return dfs(dim-1,eat-1);
    }
  else if(eat==2+layer[dim-1])
    {
      return paty[dim-1]+1;
    }
  else if(eat>layer[dim-1]+2 && eat<=2+2*layer[dim-1])
    {
      return paty[dim-1]+1+dfs(dim-1,eat-2-layer[dim-1]);
    }
}

int main(void)
{
  paty[0]=1,bans[0]=0;
  layer[0]=1;
  cin >> N >> X;
 ll dim=N;
 ll eat=X;
 for (int i=1; i <= N; ++i)
   {
     paty[i]=2*paty[i-1]+1;
     bans[i]=2*bans[i-1]+2;
     layer[i]=paty[i]+bans[i];
   }
 if(N==1)
   {
     if(X<=4) cout << X-1 << endl;
     else cout << 3 << endl;
     return 0;
   }
 cout << dfs(dim,eat) << endl;;
 return 0;
}
     


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

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


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

int main()
{
    string s;
    cin >> s;
    bool ans = true;
    for (int i=0; i<s.size(); i++)
    {
        if (i%2 == 1)
        {
            if (s[i] == 'R') 
            {
                ans = false;
                break;
            }
        }
        else
        {
            if (s[i] == 'L')
            {
                ans = false;
                break;
            }
        }
    }
    if(ans) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

input = sys.stdin.readline

n,k = map(int,input().split())
l = [int(input()) for _ in range(n)]

#print(l)

l = sorted(l)

#print(l)

ansmin = float("inf")
for i in range(n-k+1):
	if ansmin > l[i+k-1]-l[i]:
		ansmin = l[i+k-1]-l[i]

print(ansmin)





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

int main()
{       
        
        int H, W, r, c;
        cin >> H >> W;
        while((H!=0) || (W!=0)){
                for(r = 0; r < H; r++) {
                        for(c = 0; c<W; c++) {
                                cout<<"#";
                        }
                        cout<<endl;
                }
                cout<<"\n";
                cin >> H >> W;
        }
}



Measured memory_bytes: 3092
#include<cstdio>

char s[1000006];
int dp[1000006][2];

int min(int x, int y) {
  return x < y ? x : y;
}

int main() {
  scanf("%s", s + 1);
  dp[0][0] = 0;
  dp[0][1] = 1;
  int len = 1;
  for (int i = 1; s[i]; len = i++) {
    dp[i][0] = min(dp[i - 1][0] + min(s[i] - '0', 11 - (s[i] - '0')), dp[i - 1][1] + 10 - (s[i] - '0'));
    dp[i][1] = min(dp[i - 1][0] + min(s[i] - '0' + 1, 10 - (s[i] - '0')), dp[i - 1][1] + 9 - (s[i] - '0'));
  }
  printf("%d\n", dp[len][0]);
}


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  
  int cnt = 0;
  for(int i = 0; i < s.size(); i++) cnt++;
  
  if(cnt <= k) {
    cout << s << endl;
    return 0;
  }
  for(int j = 0; j < k; j++) cout << s.at(j);
  cout << "..." << endl;
}

Measured memory_bytes: 3608
N = int(input())
H = list(map(int, input().split()))

cnt = 0
buf = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        if cnt > buf:
            buf = cnt
        cnt = 0
if cnt > buf:
    buf = cnt

print(buf)

Measured memory_bytes: 14252
#include<cstdio>
#include<vector>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


void calc(vll&d, vvpii&v, int k, ll s)
{
	if(d[k]<=s) return;
	d[k]=s;
	for(auto ve:v[k])
	{
		calc(d, v, ve.first, ve.second+s);
	}
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vvpii v(n+1);
		vll d(n+1, 1000000000LL*100000);

		for(int i=0;i<n-1;i++)
		{
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			v[a].push_back(make_pair(b, c));
			v[b].push_back(make_pair(a, c));
		}

		int q, k;
		scanf("%d%d", &q, &k);
		calc(d, v, k, 0);
		for(int i=0;i<q;i++)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			printf("%lld\n", d[x]+d[y]);
		}
	}

	return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=100+10,maxn=60000+10,inf=0x3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll onefour,onetwo,one,two,n,s[5];
    cin>>onefour>>onetwo>>one>>two>>n;
    s[1]=onefour*8,s[2]=onetwo*4,s[3]=one*2,s[4]=two;
    ll t=min(s[1],min(s[2],min(s[3],s[4])));
    int id;
    for(int i=1;i<=4;i++)
    {
        if(t==s[i])
        {
            s[i]=1e18;
            id=i;
            break;
        }
    }
    if(id==1)cout<<n*4*onefour<<endl;
    else if(id==2)cout<<n*2*onetwo<<endl;
    else if(id==3)cout<<n*one<<endl;
    else
    {
        if(n%2==0)
        {
            cout<<n/2*two<<endl;
            return 0;
        }
        ll sum=n/2*two;
        t=min(s[1],min(s[2],min(s[3],s[4])));
        for(int i=1;i<=4;i++)
        {
            if(t==s[i])
            {
                id=i;
                break;
            }
        }
        if(id==1)cout<<4*onefour+sum<<endl;
        else if(id==2)cout<<sum+2*onetwo<<endl;
        else if(id==3)cout<<sum+one<<endl;
    }
    return 0;
}
/********************
20 30 70 90
3
160 120 140 90
0.25 0.5  1  2
********************/


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

typedef int64_t ll;

int main(){
    ll A,B;
    cin >> A >> B;
    bool ok = false;
    int i;
    for(i=0; i < 10001; i++){
        if((ll)(i*0.08)==A && (ll)(i*0.1)==B){
            ok = true;
            break;
        }
    }
    if(ok) cout << i << endl;
    else cout << -1 << endl;
}

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



int dp[100001];


 vector<int> adj[100001];

int solve(int src)
{
    if(dp[src]!=-1) return dp[src];
      
     bool leaf=1;
     int bestchild=0;
     for(auto child:adj[src])
     {
         leaf=0;
         bestchild=max(bestchild,solve(child));
     }
     return dp[src] = leaf?0:1+bestchild;
}
int main()
{
   
        int n,m;
        cin>>n>>m;
        memset(dp,-1,sizeof(dp));
        
        int ans=0;
       
        for(int i=0;i<m;i++)
        {
            int u,v;
            cin>>u>>v;
            adj[u].push_back(v);
        }
        for(int i=1;i<=n;i++)
        {
            ans=max(ans,solve(i));
        }

        cout<<ans<<endl;

        return 0;


  
}



Measured memory_bytes: 8192
// Problem : D - Banned K
// Contest : AtCoder - AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    map<ll,ll> cnt;
    rep(i,0,n)
    {
    	cin>>a[i];
    	cnt[a[i]]++;
    }
    ll ans=0;
    for(auto i:cnt)
    {
    	ans=ans+(i.sec*(i.sec-1))/2;
    }
    ll glo=ans;
    for(ll i=0;i<n;i++)
    {
    	ans=glo;
    	ll x=cnt[a[i]];
    	ans=ans-((x*(x-1))/2);
    	x=x-1;
    	ans=ans+((x*(x-1))/2);
    	cout<<ans<<"\n";
    	
    }
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 11136
#include <stdio.h>

int getBlock(int rating)
{
    if (rating < 400) return 1;
    else if (rating < 800) return 2;
    else if (rating < 1200) return 3;
    else if (rating < 1600) return 4;
    else if (rating < 2000) return 5;
    else if (rating < 2400) return 6;
    else if (rating < 2800) return 7;
    else if (rating < 3200) return 8;
    else return 0;
}

int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}

int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}

int main()
{
    int n, t, block[9] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        block[getBlock(t)]++;
    }
    int res = 0;
    for (int i = 1; i <= 8; i++) {
        if (block[i] != 0) res++;
    }
    printf("%d %d", max(res, (bool)block[0]), res + block[0]);
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	N = 0;
	bool flag[11] = {};
	for (int i = 10; i >= 1; i--) {
		string a, b;
		cout << "? 1";
		for (int j = 1; j < i; j++)cout << '0';
		cout << endl;
		cin >> a;
		cout << "? 9";
		for (int j = 1; j < i; j++)cout << '9';
		cout << endl;
		cin >> b;
		if (a == b&&a == "Y") {
			flag[i] = true;
		}
	}
	for (int i = 0; i < 10; i++) {
		if (flag[i] && !flag[i + 1])N = i;
		if (!flag[i] && flag[i + 1])N = i + 1;
	}
	if (!N) {
		cout << "! 1000000000" << endl;
		return 0;
	}
	L = 1;
	R = 10;
	for (int i = 1; i < N; i++) {
		L *= 10;
		R *= 10;
	}
	while (R - L > 1) {
		string a;
		long long int mid = (R + L) / 2;
		cout << "? " << mid << "0" << endl;
		cin >> a;
		if (a == "Y") {
			R = mid;
		}
		else {
			L = mid;
		}
	}
	string a;
	cout << "? " << R << "0" << endl;
	cin >> a;
	if (a == "Y") {
		cout << "? " << L << "0" << endl;
		cin >> a;
		if (a == "Y") {
			cout << "! " << L << endl;
			return 0;
		}
		cout << "! " << R << endl;
		return 0;
	}
	cout << "! " << L << endl;
	return 0;
}


Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	rep(i, 3) {
		if (S[i] == '1') {
			cout << '9';
		}
		else if (S[i] == '9') {
			cout << '1';
		}
		else {
			cout << S[i];
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n, k, ans = 1;
	cin >> n >> k;
	rep(i, n) {
		if (i == 0) ans *= k;
		else ans *= (k - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;

int main()
{
	fastio;
	LL n, k;
	cin>>n>>k;

	LL ans = n%k;
	cout<<min(ans, k-ans)<<endl;

	return 0;
}


Measured memory_bytes: 256
# Acceptance of input

import sys

file_input = sys.stdin

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

adj_mat = [[0] * V for i in range(V)]

for line in file_input:
    u, v, c = map(int, line.split())
    adj_mat[u][v] = c

# Ford???Fulkerson algorithm

import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    flow = [0] * V
    queue = collections.deque()
    queue.append(start)
    flow[start] = 10000
    while queue:
        u = queue.popleft()
        for v, r_capacity in enumerate(adj_mat[u]):
            if not flow[v] and (r_capacity > 0):
                queue.append(v)
                flow[v] = min(flow[u], r_capacity)
                parent[v] = u
                if v == goal:
                    return flow[goal]

def ford_fulkerson(source, sink):
    max_flow = 0
    while True:
        parent = [None] * V
        aug_path_flow = bfs(source, sink, parent)
        if aug_path_flow:
            max_flow += aug_path_flow
            v = sink
            while (v != source):
                u = parent[v]
                adj_mat[u][v] -= aug_path_flow
                adj_mat[v][u] += aug_path_flow
                v = u
        else:
            break
    return max_flow

# output
print(ford_fulkerson(0, V - 1))

Measured memory_bytes: 8164
#include<iostream>
#include<set>
#include<cstdlib>
using namespace std;

int main(){
    int n;
    string s;
    bool cnt[10];
    bool cnt2[10];
    for(int i=0;i<10;i++){
        cnt[i] = false;
        cnt2[i] = false;
    }
    cin >> n >> s;
    set<int> set;
    for(int i=0;i<n-2;i++){
        for(int i=0;i<10;i++){
        cnt2[i] = false;
        }

        if(cnt[s[i]-'0']){
            continue;
        }else{
            cnt[s[i]-'0'] = true;
        }
        for(int j=i+1;j<n-1;j++){
            if(cnt2[s[j]-'0']){
                continue;
            }else{
                cnt2[s[j]-'0'] = true;
            }
            for(int k=j+1;k<n;k++){
                int key = (s[i]-'0')*100 + (s[j]-'0')*10+s[k]-'0';
                //cout << key << endl;
                set.insert(key);
            }
        }
    }
    cout << set.size() << endl;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

x,y,z,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ans1=[]
ans2=[]

for i in range(x):
    for j in range(y):
        ans1.append(a[i]+b[j])
ans1.sort()
ans1.reverse()

if len(ans1)>=k:
    del ans1[k:]
    
for i in range(len(ans1)):
    for j in range(z):
        ans2.append(ans1[i]+c[j])
ans2.sort()
ans2.reverse()

for i in range(k):
    print(ans2[i])


            
            
    

        

    
    


        
    


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

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  long long ans{1};
  long long round{K};
  if ((B - A) > 2 && K >= A + 1) {
    round -= (A + 1);
    ans = B;
    ans += (B - A) * (round / 2);
    ans += round % 2;
  } else {
    ans += K;
  }

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


Measured memory_bytes: 256
program  ec12;
var 
	ans:int64;
	n,m,i:longint;
begin 	
	readln(n,m);
	if abs(n-m)>1 then 
	begin 
		writeln(0);
		halt;
	end;
	ans:=1;
	for i:=2 to n do 
	ans:=(ans*i) mod 1000000007;
	for i:=2 to m do 
	ans:=(ans*i) mod 1000000007;
	if n=m then 
	writeln((ans*2) mod 1000000007)
	else
	writeln(ans);
end. 

Measured memory_bytes: 128
D, G = map(int, input().split())
p = [0] * (D)
c = [0] * (D)
for i in range(D):
    p[i], c[i] = map(int, input().split())

ans = 10000
# bit探索
for i in range(1 << D):
    bonus_sum = 0
    cnt = 0
    for j in range(D):
        if (i >> j) & 1 == 1:
            bonus_sum += c[j] + (j + 1) * 100 * p[j]
            cnt += p[j]
    # ボーナスでGを超えたら最小問題数を出す
    if bonus_sum >= G:
        ans = min(ans, cnt)
    # 超えなかったら点数の大きいものを使う
    # 一番大きいものを全部使って、その次の問題を数問使うパターンはない->break処理
    # 全部使う時点でボーナスが発生するのでそれはiの探索にまかせる
    else:
        # bitの0を探索する
        for j in range(D)[::-1]:
            if (i >> j) & 1 == 0:
                # 最大のものを何問使うか
                for k in range(p[j]):
                    ten = (j + 1) * 100 * k
                    if ten + bonus_sum < G:
                        continue
                    else:
                        cnt += k
                        ans = min(ans, cnt)
                        break
                # 一回探索したから終わり
                break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略
ll n, m, q;
ll a[55], b[55], c[55], d[55];
ll ans=0;
void saiki(ll now, ll num, ll v[]){
  if(now == n){
    ll sum = 0;
    for(int i = 0; i < q; i++){
      if(v[b[i]] - v[a[i]] == c[i]){
      	sum += d[i]; 
      }
    }
    ans = max(ans, sum);
  }else{
  	for(int j = num; j <= m; j++){
    	v[now] = j;
    	saiki(now+1, j, v);
  	}
  }
}
int main(){
  cin >> n >> m >> q;
  for(int i = 0; i < q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  
  ll A[15];
  A[0] = 1;
  saiki(1, 1, A);
  cout << ans;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
using namespace std;
int main()
{
	ll int n,i,s=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		if( (i%3!=0)&&(i%5!=0))
		{
			s+=i;
		}
		
	}
	cout<<s<<endl;
	
	
}
	



Measured memory_bytes: 3596
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h,w=parseMap(split(readline()))
    mi,ma=min(h,w),max(h,w)
    ans=min(parseInt(ceil(ma/3))*mi-div(ma,3)*mi,parseInt(ceil(mi/3))*ma-div(mi,3)*ma)
    for i in 1:ma-1
        arr=[mi*i,div(mi,2)*(ma-i),parseInt(ceil(mi/2))*(ma-i)]
        ans=min(ans,maximum(arr)-minimum(arr))
    end
    for i in 1:mi-1
        arr=[ma*i,div(ma,2)*(mi-i),parseInt(ceil(ma/2))*(mi-i)]
        ans=min(ans,maximum(arr)-minimum(arr))
    end
    println(ans)
end
main()

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

int X, Y; 

int main(){
    int X, Y; 
    cin >> X >> Y;

    if (Y%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    else if (X*2 <= Y && X*4 >= Y){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3636
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    d=parseMap(split(readline()))
    dif=Vector{Int}([0 for i in 1:10^5])
    ans=0
    for i in d
        dif[i]+=1
    end
    for i in 1:10^5
        if i>1
            dif[i]+=dif[i-1]
        end
        if dif[i]==n-dif[i]
            ans+=1
        end
    end
    println(ans)
end
main()

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

int main(){
    long long int X,cash=100;
    cin >> X;

    for(int i=1;i<100000000;i++){
        cash = cash * 1.01;
        if(cash >= X ){
            cout << i;
            break;
        }
    }

}

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

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

	ll k, a, b;
	cin >> k >> a >> b;

	ll ans = 1;

	{
		const ll x = min(k, a - 1);
		k -= x;
		ans += x;
	}

	ans += k / 2 * max(-a + b, 2LL) + k % 2;
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template <class T>
inline void out(T a) { cout << a << endl; }
inline void out(double a) { printf("%.10f\n", a); }
#define all(x) (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes out("Yes");
#define no out("No");

int main()
{
    ins(s);

    if(s.size()<26){
        unordered_map<char,bool> dic;
        
        rep(i,s.size()){
            dic.emplace(s[i],true);
        }

        rep(i,26){
            if(dic.count('a'+i)==0){
                s = s + string{(char)('a'+i)};
                out(s);
                return 0;
            }
        }
    }else{
        if(s=="zyxwvutsrqponmlkjihgfedcba"){
            out(-1);
            return 0;
        }

        auto t = s;
        next_permutation(all(s));

        rep(i,s.size()){
            cout << s[i];
            if(s[i]!=t[i]){
                break;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

string a, b, c;

int main(){
  cin >> a;
  cin >> b;
  for (int i = 0;; i++) {
    if(!(a[i] == '\0')){
      c += a[i];
    }
    if(!(b[i] == '\0')){
      c += b[i];
    }
    if (a[i] == '\0' || (b[i] == '\0' && a[i + 1] == '\0')) {
      break;
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var g = A.GroupBy(a => a);
        var count = g.Count();
        var ok = false;
        if (count == 1)
        {
            ok = A.All(x => x == 0);
        }
        else if (count == 2 && N % 3 == 0)
        {
            ok = A.Count(x => x == 0) == N / 3;
        }
        else if (count == 3 && N % 3 == 0)
        {
            var xs = g.Select(x => x.Key).ToArray();
            ok = (xs[0] ^ xs[1] ^ xs[2]) == 0 && g.All(x => x.Count() == N / 3);
        }
        Console.WriteLine(ok ? "Yes" : "No");
    }
    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 29152
import itertools,math
N=int(input())
N_fac=math.factorial(N)
X={}
Y={}
distance_dic={}
cnt=0
distance=0
for n in range(N):
    x,y=map(int,input().split())
    X[n]=x
    Y[n]=y
lst=list(itertools.permutations(X.keys(),N))
len_lst=len(lst)
for l in lst:
    l_2=list(l)
    for i in range(N-1):
        key1=l[i]
        key2=l[i+1]
        distance=distance+((X[key1]-X[key2])**2+(Y[key1]-Y[key2])**2)**0.5
print(distance/N_fac)

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

long long int f(long long int x){
    
    if (x <= 0)
        return 0;

    long long int dig[40] = {0};
    for (int i = 1; i < 40; i++){
        long long int mod = 1LL << (i + 1);
        
        if (x % mod - (mod / 2) + 1 > 0)
            dig[i] += (x % mod - (mod / 2) + 1) % 2;
    }

    long long int ans = 0;
    for (int i = 1; i < 40; i++)
        ans |= (dig[i] << i);
    
    if (((x + 1)/ 2) % 2 == 1)
        ans |= 1;

    return ans;
}

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

    long long int a, b;
    cin >> a >> b;
    
    cout << (f(b) ^ f(a - 1)) << '\n';

    return 0;
}


Measured memory_bytes: 256
#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[i];
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    for (int i = 0; i < n; i++){
        int ok = - 1;
        int ng = n;
        while (abs(ok - ng) > 1){
            int mid = (ok + ng) / 2;
            if (a[mid] < b[i]) ok = mid;
            else ng = mid;
        }
        long long up = ok + 1;
        ok = n;
        ng = - 1;
        while (abs(ok - ng) > 1){
            int mid = (ok + ng) / 2;
            if (c[mid] > b[i]) ok = mid;
            else ng = mid;
        }
        long long buttom = n - ok;
        ans += up * buttom;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class Program_TTA // ←Class名変更！！
{
    public static void Main()
    {
        var s = ReadLine();
        var ca = s.ToCharArray();
        Array.Reverse(ca);
        var r = s.Length == 2 ? s : string.Join("", ca);

        WriteLine(r);
        return;

    } // Main

}     // Class


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

int main(){
	int ary[3];
	for(int i=0;i<3;i++){
		cin>>ary[i];
	}

	int max;
	for(int i=0;i<3;i++){
		for(int j=i;j<3;j++){
			if(ary[i]>ary[j]){
				int w = ary[i];
				ary[i]=ary[j];
				ary[j]=w;
			}
		}
	}
	cout<<ary[0]<<" "<<ary[1]<<" "<<ary[2]<<endl;
}



Measured memory_bytes: 3112
m = gets.split
r = [1, 2, 6, 5]
c = [1, 3, 6, 4]

for i in gets.split("")
    case i
    when "E"
        c.unshift(c.pop)
        r[0] = c[0]
        r[2] = c[2]
    when "N"
        r.push(r.shift)
        c[0] = r[0]
        c[2] = r[2]
    when "S"
        r.unshift(r.pop)
        c[0] = r[0]
        c[2] = r[2]
    when "W"
        c.push(c.shift)
        r[0] = c[0]
        r[2] = c[2]
    end
end

puts m[r[0] -1]


Measured memory_bytes: 6872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
	int n;cin>>n;
	std::vector<ll> pre(n+1);
	for(int i=1;i<=n;i++) cin>>pre[i];
	ll ans=0,sum=0;
	const int mod=1e9+7;
	for(int i=1;i<=n;i++) {
		ans=(ans+pre[i]*sum%mod)%mod;
		sum=(sum+pre[i])%mod;
	}    
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDSk

using namespace std;


string s;
int main(){
       

       bool y = true;
       cin>>s;
        LL sz = s.size() ; 
       for( LL i = 0 ; i<sz/2 ; i++ ){
           if( s[i] != s[ sz-1-i ] ) y = false;
           if( i<(sz/2)/2 ){
               if( s[i]!=s[ (sz/2) - 1 - i ] ) y = false;
           }
       } 
       if(y) printf("Yes\n");
       else printf("No\n");

return 0;}


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

int main() {
  int N;
  int a=0;
  cin >> N;
  for (int i=0; i<N; i++){
    int l, r;
    cin >> l >> r;
    a+= r-l+1;
    }
  cout << a << endl;
}
   

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

int count(int x){
    if (x<10) return 1;
    return count(x/10)+1;
}

int main() {
	int N;
	cin >> N;
	int ans=0;
	for (int i=1; i<=N; i++){
	    if (count(i)%2==1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<unordered_map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=5e5+20;

int n,L,x[maxn],y[maxn];
ll sx[maxn],sy[maxn];

inline ll X(int l,int r){ return sx[r]-sx[l-1];}
inline ll Y(int l,int r){ return sy[r]-sy[l-1];}

inline void init()
{
	L=read();
	n=read();
	REP(i,1,n)sx[i]=x[i]=read(),sy[i]=y[i]=L-x[i];
	REP(i,1,n)sx[i]+=sx[i-1],sy[i]+=sy[i-1];
}

ll ans;

inline void doing()
{
	ll res;
	chkmax(ans,(ll)x[n]);
	REP(i,1,n>>1)
	{
		int A=i,B=i,now=n-A-B;
		//Right
		res=0;
		res+=X(now+1,now+B)*2;
		res+=Y(now+B+2,n)*2;
		res+=y[now+B+1];
		chkmax(ans,res);

		res=x[now];
		res+=X(now+1,now+B-1)*2+x[now+B];
		res+=Y(now+B+1,n)*2;
		chkmax(ans,res);

		if(i*2+1<=n)
		{
		res=0;
		A=i+1;B=i;now=n-A-B;
		res+=x[now];
		res+=X(now+1,now+B)*2;
		res+=Y(now+B+2,n)*2; res+=y[now+B+1];
		chkmax(ans,res);

		res=0;
		A=i;B=i+1;now=n-A-B;
		res+=X(now+1,now+B-1)*2; res+=x[now+B];
		res+=Y(now+B+1,n)*2;
		chkmax(ans,res);
		}
	}
}

int main()
{
	init();
	doing();
	swap(x,y);
	reverse(x+1,x+n+1); reverse(y+1,y+n+1);
	REP(i,1,n)sx[i]=sx[i-1]+x[i],sy[i]=sy[i-1]+y[i];
	doing();
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 11520
while True:
    H, W=input().split()
    H=int(H)
    W=int(W)
    if H==0:
        break
    a=''
    b='#'
    for m in range(W-2):
        b+='.'
    b+='#'
    for w in range(W):
        a+='#'
    print(a)
    for i in range(H-2):
        print(b)
    print(a)
    if H==0:
        break
    print("")


Measured memory_bytes: 5612
#!/usr/bin python3
# -*- coding: utf-8 -*-

H, W, K = map(int,input().split())
sth, stw, glh, glw = map(int,input().split())
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1

INF = -1
Gmap = [list(input()) for _ in range(H)]
Seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}

from collections import deque

def bfs(sth, stw, glh, glw):
    next_q = deque([])
    next_q.append((sth,stw,0))
    Seen[sth][stw] = 0

    while len(next_q)!=0:
        #キュー取り出し(先頭)
        h, w, c = next_q.popleft()
        for dh, dw in direc:
            for sk in range(1,K+1):
                hs, ws = h + dh*sk, w + dw*sk
                if not (0<=hs<H and 0<=ws<W):
                    break
                if Gmap[hs][ws]=='@':
                    break
                if Seen[hs][ws]==INF:
                    next_q.append((hs,ws,c+1))
                    Seen[hs][ws] = c + 1
                elif Seen[hs][ws]<=c:
                    break
                if hs==glh and ws==glw:
                    return c + 1
    return -1

def main():
    ret = bfs(sth, stw, glh, glw)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43196
import sys
sys.setrecursionlimit(10**6)

n,m = map(int,input().split())
edge=[[] for _ in range(n)]
for _ in range(m):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)


d = [0] * n

def dfs(v,edge):
    depth = 0
    for next_v in edge[v]:
        if d[next_v] == 0:
            depth = max(depth,dfs(next_v,edge))
        depth = max(depth,d[next_v])
    depth += 1 
    d[v] = depth
    return depth

for i in range(n):
    dfs(i,edge)
print(max(d)-1)

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

int main() {
	int H;
	cin >> H;
	int A;
	cin >> A;
	int X=0;
	while(H>0) {
		X++;
		H=H-A;
		
	} 
	 	cout <<   X <<  endl;
	
	// your code goes here
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    double L;
    cin >> L;
    double ans = pow(L/3, 3);
    printf("%f\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	ll n;
	cin>>n;

	ll ans = 0;
	ans = n * (n - 1) / 2; 
	cout << ans;
	return 0;
}


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

int main() {
  long n,c=10000000,d=-10000000,sum=0;
  cin>>n;
  rep(i,n){
    long a;
    cin>>a;
    c=min(a,c);
    d=max(a,d);
    sum+=a;
  }
  cout<<c<<" "<<d<<" "<<sum<<endl;
}


Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main()
{
   long a,b,s,c,i;
   while(cin >> a >> b)
     {
        c=0;
        s = a+b;
        while(s != 0)
         {
             s = s /10;
             c++;
         }
         cout << c << endl;
     }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

void cout_vec(vector<double> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

void cout_mat(vector<vector<double>> &mat){
    for(int i=0; i<mat.size(); i++){
        vector<double> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> a(3,0);
    for(int i=0; i<N; i++){
        int b;
        cin >> b;
        a[b-1]++;
    }
    int sushi = a[0]+a[1]+a[2];
    vector<vector<vector<double> > > dp(N+2,vector<vector<double> >(N+2,vector<double>(N+2,0.0)));

    dp[0][0][0]=0;
    double ans=0;
    for(int k=0; k<N+1; k++){
        for(int j=0; j<N+1; j++){
            for(int i=0; i<N+1; i++){
                if(i+j+k>N || i+j+k==0)continue;
                dp[i][j][k]+=1;
                if(i)dp[i][j][k]+=dp[i-1][j][k]*i/N;
                if(j)dp[i][j][k]+=dp[i+1][j-1][k]*j/N;
                if(k)dp[i][j][k]+=dp[i][j+1][k-1]*k/N;
                dp[i][j][k]*=(double) N/(i+j+k);
            }
        }
    }

    //cout_mat(dp[0]);

    cout << setprecision(10) << dp[a[0]][a[1]][a[2]] << endl;
}

Measured memory_bytes: 219776