akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
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; }
static const lint MOD = (lint)1e9+7;

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

    string T;
    cin >> T;

    int cnt = 0;
    for (int i = 0; i < 3; ++i)
    {
        if (S[i] == T[i])
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using ll = long long;

constexpr int INF = (1 << 30) - 1;
constexpr int MOD = 1000000000 + 7;

int n, m;
vector<int> c;
int dp[50001];

int main(){
  cin >> n >> m;
  c.resize(m);
  for(int i=0; i<m; i++) cin >> c[i];
  
  for(int i=0; i<=n; i++) dp[i]=INF;

  dp[0]=0;
  for(int i=1; i<=n; i++){
    for(int j=0; j<m; j++){
      if(c[j]>i) continue;
      else{
        dp[i]=min(dp[i-1]+1, min(dp[i], dp[i-c[j]]+1));
      }
    }
  }

  cout << dp[n] << endl;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n+2);
    a[0] = a[n+1] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> pre(n+2), suf(n+2);
    pre[0] = 0;
    for (int i = 1; i <= n+1; i++) {
        pre[i] = pre[i-1] + abs(a[i]-a[i-1]);
    }
    suf[n+1] = 0;
    for (int i = n; i >= 0; i--) {
        suf[i] = suf[i+1] + abs(a[i]-a[i+1]);
    }
    for (int i = 1; i <= n; i++) {
        int res = pre[i-1] + suf[i+1] + abs(a[i-1]-a[i+1]);
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	unsigned long long int H;
	unsigned long long int N=1;
	cin >> H;
	int ctr=0;
	while(H>0){
		ctr++;
		H/=2;
	}
	for (int i = 0; i < ctr; ++i) {
		N*=2;
	}
	cout << N-1 << endl;
	return 0;
}

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

const int MOD=1000000007;

LL beki(LL a,LL b)
{
	if(b==0)return 1;
	LL x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

LL inv(LL a)
{
	return beki(a,MOD-2);
}



LL combi(LL a,LL b)
{
	LL ret=1;
	for(LL i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}

int main()
{
	LL n;
	LL a,b;
	LL ans=0;
	cin>>n>>a>>b;
	
	ans=(beki(2,n)-1-combi(n,a)-combi(n,b)+MOD*2)%MOD;
	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
x=1
if m%n==0:
    print(m//n)
else:
    for i in range(1,m//n+1):
        if m%i==0 and i*n<=m:
            x=max(x,i)
        if m%i==0 and (m//i)*n<=m:
            x=max(x,m//i)
    print(x)

Measured memory_bytes: 41728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

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

    /*素因数分解*/
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= n; ++a)
    {
        long long ex = 0; // 指数
        while (n % a == 0)
        {
            ++ex;
            n /= a;
        }
        res.push_back({a, ex});
    }
    if (n != 1)
        res.push_back({n, 1});

    int ret = 0;
    for (auto a : res)
    {
        ll cnt = 0;
        ll sum = 0;
        for (int i = 1; sum + i <= a.second; i++)
        {
            sum += i;
            cnt++;
        }
        ret += cnt;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 19652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

string s[100];
int h,w;

int main()
{
	int a,b;
	h=100;
	w=100;
	//a..."."
	//b..."#"
	cin>>a>>b;

	//50*100のエリアにそれぞれ塗る
	//上が".",下が"#"
	for(int i=0;i<50;i++)
	{
		for(int j=0;j<100;j++)
		{
			s[i]+='.';
			s[i+50]+='#';
		}
	}
	a--;
	b--;

	//それぞれのエリアに必要な数だけ挿入する
	//上側
	int index=0;
	while(b>50)
	{
		for(int j=0;j<100;j+=2)
		{
			s[index][j]='#';
			b--;
		}
		index+=2;
	}
	for(int i=0;i<b;i++)
	{
		s[index][i*2]='#';
	}
	//下側
	index=51;
	while(a>50)
	{
		for(int j=0;j<100;j+=2)
		{
			s[index][j]='.';
			a--;
		}
		index+=2;
	}
	for(int i=0;i<a;i++)
	{
		s[index][i*2]='.';
	}
	cout<<h<<" "<<w<<endl;
	for(int i=0;i<h;i++)
	{
		cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char ch[100100];
int h[100100];
int main(){	
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	int nowl,nowr;
	for(int i=1;i<=n;i++){
		if(ch[i]=='L'){
			nowl=i;break;
		}
	}
	for(int i=1;i<=n;i++){
		if(ch[i]=='R'){
			nowr=i;break;
		}
	}
	for(int i=1;i<=n;i++){
		if(ch[i]=='R'){
			if(nowl<i){
				for(int j=i;j<=n;j++){
					if(ch[j]=='L'){
						nowl=j;break;
					}
				}
			}
			if((nowl-i)%2==0){
				h[nowl]++;
			}
			else h[nowl-1]++;
			nowr=i;
		}
		else{
			if(abs(nowr-i)%2==0){
				h[nowr]++;
			}
			else{
				h[nowr+1]++;
			}
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",h[i]);
	return 0;
}

Measured memory_bytes: 896
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))

using vec = vector<int>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

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

    int n, m;
    cin >> n;
    vector<string> s(n);
    init(s);
    cin >> m;
    vector<string> t(m);
    init(t);

    map<string, int> mp;
    for (auto& e : s) mp[e]++;

    for (auto& e : t) mp[e]--;

    int maval = 0;
    for (auto& e : mp) chmax(maval, e.second);

    print(maval);

    return 0;
}


Measured memory_bytes: 256
using System;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (N % 2 > 0)
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine(S.Substring(0, N / 2) == S.Substring(N / 2, N / 2) ? "Yes" : "No");
        }
    }
}

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

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

	for (int i = 0, index = 0; i < s.length(); i++) {
		if (i == index) {
			cout << s[i];
			index += w;
		}
	}
	cout << "\n";
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();

//        int[] p = new int[n];
//        int h = 0, sum = 0;
//        for (int i = 0; i < n; i++){
//            p[i] = input.nextInt();
//            if (p[i] > h){
//                sum += h;
//                h = p[i];
//
//            } else {
//                sum += p[i];
//            }
//        }
//        System.out.println(Arrays.toString(p));
//        System.out.print(sum + h/2);

        int k = input.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++){
            h[i] = input.nextInt();
        }
        Arrays.sort(h);
//        System.out.println(Arrays.toString(h));

        int max = h[k-1] - h[0];
        for (int i = 1; i <= n - k; i++) {
            max = Math.min(h[i+k-1]-h[i], max);
        }
        System.out.print(max);
    }
}


Measured memory_bytes: 52284
#include<stdio.h>
int main()
{
int t,max,a,b,c,m,n,i;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d %d %d",&a,&b,&c);
max=a;
n=b*b+c*c;
if(b>max)
{max=b;
n=a*a+c*c;
}
if(c>max)
{max=c;
n=a*a+b*b;
}
m=max*max;
if(m==n)
printf("YES\n");
else
printf("NO\n");
}

return 0;
}

Measured memory_bytes: 580
N, C = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
P = 10**9+7
Y = [[pow(i, j, P) for j in range(401)] for i in range(401)]
for i in range(1, 401):
    for j in range(401):
        Y[i][j] = (Y[i][j] + Y[i-1][j]) % P
X = [[0] * (C+1) for _ in range(N+1)]
X[0][0] = 1
for i in range(1, N+1):
    for j in range(C+1):
        X[i][j] = sum([X[i-1][k] * (Y[B[i-1]][j-k] - Y[A[i-1]-1][j-k]) % P for k in range(j+1)]) % P
print(X[N][C])

Measured memory_bytes: 47708
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	V<int> a(4),b={1,4,7,9};
	fo(i,4)
	cin>>a[i];
	Sort(a);
	if(a==b)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

typedef pair<int,int> pii;

int n,f[2001][2001],X,Y;
queue<pii> q;
vector<int> a[2001];

void nhap()
{
    scanf("%d %d %d",&n,&X,&Y);
    for (int i=1;i<n;++i)
    {
        f[i][i+1]=f[i+1][i]=1;
        q.push({i,i+1});
        a[i].push_back(i+1);
        a[i+1].push_back(i);
    }
    f[X][Y]=1;
    f[Y][X]=1;
    q.push({X,Y});
    a[X].push_back(Y);
    a[Y].push_back(X);
}

void process()
{
    for (int i=1;i<n;++i)
    {
        cout<<q.size()<<"\n";
        while (f[q.front().first][q.front().second]==i)
        {
            int u=q.front().first,v=q.front().second;
            q.pop();
            for (auto x:a[u])
            {
                if (x!=v && !f[x][v])
                {
                    f[x][v]=f[v][x]=f[u][v]+1;
                    q.push({x,v});
                }
            }
            for (auto x:a[v])
            {
                if (x!=u && !f[x][u])
                {
                    f[x][u]=f[u][x]=f[u][v]+1;
                    q.push({x,u});
                }
            }
        }
    }
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>

using namespace std;

int main(){

  int r,g,b,number;

  while(cin >> r >> g >> b){

    number=(r*100)+(g*10)+b;

    if((number%4)==0) cout << "YES" << endl;

    else cout << "NO" << endl;

  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] w = new String[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.next();
        }

        // 主処理
        List<String> list = new ArrayList<>();
        list.add(w[0]);
        String next = String.valueOf(w[0].charAt(w[0].length() - 1));
        boolean judge = true;
        for (int i = 1; i < w.length; i++) {
            String head = String.valueOf(w[i].charAt(0));
            if (!next.equals(head) || list.contains(w[i])) {
                judge = false;
                break;
            }
            list.add(w[i]);
            next = String.valueOf(w[i].charAt(w[i].length() - 1));
        }
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
#define MAX 30
#define NIL -1

struct Node{int p,l,r;};
Node T[MAX];

void preParse(int u){
	if(u==NIL)return;
	cout << " " << u;
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u){
	if(u==NIL)return;
	inParse(T[u].l);
	cout << " " << u;
	inParse(T[u].r);
}
void postParse(int u){
	if(u==NIL)return;
	postParse(T[u].l);
	postParse(T[u].r);
	cout << " " << u;
}


int main(){
	int r,l,a,n;
	cin >> n;
	for(int j=0;j<n;j++)T[j].p=NIL;
	for(int s=0;s<n;s++){
		cin >> a >> l >> r;
		T[a].l = l;T[a].r = r;
		if(l!=NIL)T[l].p = a;
		if(r!=NIL)T[r].p = a;
	}
	for(int j=0;j<n;j++){
		if(T[j].p == NIL) r=j;
	}

	cout << "Preorder" << endl;
	preParse(r);
	cout << endl << "Inorder" << endl;
	inParse(r);
	cout << endl << "Postorder" << endl;
	postParse(r);
	cout << endl;

	return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;
const int maxn=3e5+5;
int cnt0[maxn],cnt1[maxn];
char s[maxn];
int n;
int main(){
	cin>>n;
	scanf("%s",s+1);
	for (int i=1;i<=n;i++){
		if (s[i]=='W') cnt0[i]++;
		cnt0[i]+=cnt0[i-1];
	}
	for (int i=n;i>=1;i--){
		if (s[i]=='E') cnt1[i]++;
		cnt1[i]+=cnt1[i+1];
	}
	int ans=n;
	for (int i=1;i<=n;i++){
		ans=min(ans,cnt0[i-1]+cnt1[i+1]);
	}
	cout<<ans<<endl;
}

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

int main() {
  int n,k;
  string s;
  char tmp;
  cin>>n>>s>>k;

  tmp=s[k-1];

  for(int i=0;i<n;i++){
    if(s[i]!=s[k-1]) s[i]='*';
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


P calc(vector<P> A, int target){
  int N = A.size();
  vector<vector<int> > dp(N+1, vector<int>(target+1));
  dp[0][0] = 1;
  for(int i=0;i<N;i++){
    int a, b;
    tie(a, b) = A[i];
    for(int j=0;j<=target;j++){
      if(j + a <= target) Max(dp[i+1][j+a], dp[i][j]);
      if(j + b <= target) Max(dp[i+1][j+b], dp[i][j]);
    }
  }
  int sum = 0;
  for(auto p:A) sum += p.first + p.second;
  int x = target;
  while(x >= 0 && dp[N][x] == 0) x--;
  int y = sum - x;
  if(x < 0) return P(-1, -1);
  return P(target, y);
}

vector<int> X;
vector<vector<int> > G;
P dfs(int pos, int pre){
  vector<P> A; 
  for(int to:G[pos]){
    if(to == pre) continue;
    auto p = dfs(to, pos);
    if(p == P(-1, -1)) return P(-1, -1);
    A.push_back(p);
  }
  return calc(A, X[pos]);
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin>>N;

  G.resize(N);
  for(int i=1;i<N;i++){
    int p;
    cin>>p; p--;
    G[p].push_back(i);
    G[i].push_back(p);
  }

  X.resize(N);
  cin>>X;

  auto p = dfs(0, -1);

  if(p != P(-1, -1)) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  
  return 0;
}


Measured memory_bytes: 1348
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	cout << abs(a - b) << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main()
{
  int n;
  cin>>n;
  double sum = 0.0;
  REP(i,n) {
    double a;
    cin>>a;
    sum += 1.0 / a;
  }
  cout<<fixed<<setprecision(10)<<(1.0/sum)<<endl;
  return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
S = gets.chomp
ANS = []

N.times.inject(N) do |pos,c|
  break if pos == 0
  k_ = M.downto(1).find do |k|
    pos - k >= 0 && S[pos - k] == '0'
  end
  if k_.nil?
    puts -1
    exit
  end
  ANS << k_
  pos - k_
end
puts ANS.reverse * ' '



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

using namespace std; 

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

		int diff = 0;
		for (int i=0; i < S.size(); i++) {
			if (S[i] != T[i]) {
				diff += 1;
			}
		}
		cout << diff;
}

Measured memory_bytes: 3908
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
 
n = ini()
ans = True
prevt = 0
prevx = 0
prevy = 0
for _ in range(n):
    t, x, y = inm()
    if (abs(x - prevx) + abs(y - prevy)) > (t - prevt) or (t - prevt) % 2 != (abs(x - prevx) + abs(y - prevy)) % 2:
        ans = False
        break
    prevt = t
    prevx = x
    prevy = y
print("Yes" if ans else "No")

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

int main() {
  int H, N;
  cin >> H >> N;
  
  vector<int> attack(N);
  int total = 0;
  
  for (int i = 0; i < N; i++)  cin >> attack.at(i);
  
  for (int i = 0; i < N; i++)  total += attack.at(i);
   
  
  if (total >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;
    
    vec<map<int, int>> X(n);

    for (int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        for (int j = 0; j < a; ++j)
        {
            int x, y;
            cin >> x >> y;
            --x;
            X[i][x] = y;
        }
    }

    int ans{};
    for (int b = 0; b < (1 << n); ++b)
    {
        bitset<15> bits(b);
        bool ok{ true };

        for (int i = 0; i < n; ++i)
        {
            if (!bits.test(i))
                continue;

            for (auto p : X[i])
            {
                auto x = p.first;
                auto y = p.second;

                ok &= ((bits.test(x) ? 1 : 0) == y);
            }
        }
        if (ok)
            ans = max(ans + 0_sz, bits.count());
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
x=int(input())

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(x)==True:
        break
    else:
        x+=1
print(x)

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

ll a, b, v, w, t;

int main() {
	ll a;
	string b;
	cin >> a >> b;

	string c;
	rep(i,b.size()) {
		if (b[i] == '.') continue;
		c.push_back(b[i]);
	}
	ll ans = a*stoi(c)/100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3580
numstr = gets.chomp

num_len = numstr.length

like_num = nil
min_diff = nil

(num_len-2).times do |i|
  num = numstr[i..(i+2)].to_i
  diff = (num - 753).abs
  if like_num.nil? || diff < min_diff
    like_num = num
    min_diff = diff
  end
end

p min_diff

Measured memory_bytes: 1788
#include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <set>
    #include <utility>
    using namespace std;
    typedef long long ll;
     
    struct Event{
    int day;
    int index;
    };
     
    bool operator<(const Event& l, const Event& r){
    if (l.day != r.day) return l.day < r.day;
    return l.index < r.index;
    }
     
    const int MAX_DAY = 3652425;
     
    int N,Q;
    ll w[100000];
    int t[100000];
    int x[100000];
    int y[100000];
    ll v[MAX_DAY+2];
    int ans[100000];
     
    void solve(){
    for (int i = 0; i < N; ++i) {
    ans[i] = 1 << 30;
    }
    int device = 0;
    ll val = 0;
    ll x1 = 1;
    ll x2 = 0;
    ll x2c = 0;
    ll x3 = 0;
    ll x3d = 0;
    ll x3c = 0;
    set<Event> es;
    for (int i = 0; i <= MAX_DAY; ++i) {
    while(device < N && w[device] <= val) {
    ans[device] = i;
    es.insert({i + x[device] - 1, device});
    if (t[device] == 0) {
    ++x1;
    } else if (t[device] == 1) {
    ++x2c;
    } else {
    ++x3d;
    ++x3c;
    }
    ++device;
    }
    val += x1;
    x2 += x2c;
    val += x2;
    x3 += x3d;
    val += x3;
    x3d += x3c * 2;
    v[i+1] = val;
    while(!es.empty() && (*es.begin()).day == i) {
    const Event& rme = *(es.begin());
    if (t[rme.index] == 0) {
    --x1;
    } else if (t[rme.index] == 1) {
    x2 -= x[rme.index];
    --x2c;
    } else {
    x3 -= x[rme.index] * x[rme.index];
    x3d -= 2 * x[rme.index] + 1;
    --x3c;
    }
    es.erase(es.begin());
    }
    }
     
    for (int i = 0; i < N; ++i) {
    if (ans[i] > MAX_DAY) {
    printf("Many years later\n");
    } else {
    printf("%d\n", ans[i]);
    }
    }
    for (int i = 0; i < Q; ++i) {
    printf("%lld\n", v[y[i]]);
    }
    }
     
    int main() {
    cin >> N >> Q;
    for(int i = 0; i < N; ++i) {
    scanf("%lld %d %d", w + i, t + i, x + i);
    }
    for(int i = 0; i < Q; ++i) {
    scanf("%d", y + i);
    }
    solve();
    return 0;
    }

Measured memory_bytes: 36792
S = input()
K = int(input())
a = 0
if S[0] != '1':
  print(S[0])
else:
  for i in S:
    if i == '1':
      a += 1
    else:
      temp = i
      break
  if a >= K:
      print('1')
  else:
      print(temp)
      

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << "\t";
  return os;
}

int main() {
  LL N, C; cin >> N >> C;
  vector<LL> X(N), V(N);
  for (int i = 0; i < N; ++i) cin >> X[i] >> V[i];

  vector<LL> L(N + 1), L2(N + 1);
  L[0] = 0, L2[0] = 0;
  LL vsum = 0;
  for (int i = 0; i < N; ++i) {
    vsum += V[i];
    L[i + 1] = max(vsum - X[i], L[i]);
    L2[i + 1] = max(vsum - 2 * X[i], L2[i]);
  }

  vector<LL> R(N + 1), R2(N + 1);
  R[N] = 0, R2[N] = 0;
  vsum = 0;
  for (int i = N-1; i >= 0; --i) {
    vsum += V[i];
    R[i] = max(vsum - (C - X[i]), R[i + 1]);
    R2[i] = max(vsum - 2 * (C - X[i]), R2[i + 1]);
  }

  LL vmax = 0;
  for (int i = 0; i <= N; ++i) {
    vmax = max(vmax, L2[i] + R[i]);
  }
  for (int i = 0; i <= N; ++i) {
    vmax = max(vmax, R2[i] + L[i]);
  }
  cout << vmax << endl;
}


Measured memory_bytes: 8020
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    println!("{}", (n * n - n + m * m - m) / 2);
}


Measured memory_bytes: 4352
//Many Requirements

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int n,m,q;
set<vector<int>>t;

void dfs(vector<int>s){
    if(s.size()==n+1){
        t.insert(s);
    }else{
        vector<int>t;
        rep(i,s[s.size()-1],m+1){
            t=s;
            t.pb(i);
            dfs(t);
        }
    }
}

signed main (){
    cin>>n>>m>>q;
    vector<int>s;
    s.pb(1);
    dfs(s);
    vector<vector<int>>r(q,vector<int>(4));
    int ans = 0;
    rep(i,0,q){
        cin>>r[i][0]>>r[i][1]>>r[i][2]>>r[i][3];
    }
    for(auto i:t){
        int c = 0;
        rep(j,0,q){
            if(i[r[j][1]]-i[r[j][0]]==r[j][2])c+=r[j][3];
        }
        ans=max(ans,c);
    }
    cout<<ans<<nnn;
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
	int a, b, c = 0;
	cin >> a >> b >> c;

	for (int i = 0; i <= 100000; i += a)
	{
		if (i % b == c)
		{
			COUT("YES");
			return 0;
		}
	}
	COUT("NO");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
#define M 1000001
#define L 14
 
char Hash[M][L]; 
 
int getChar(char);
long long getKey(char[]);
int key(int);
int key(int);
int insert(char[]);
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

 
int hash1(int key){ 
  return key%M; 
}


int hash2(int key){ 
  return 1+key%(M-1); 
}

 
int find(char str[]){
 long long key;
 int i,x,y,sum;
 
 key = getKey(str);
 x = hash1(key);
 y = hash2(key);
 
 for( i = 0 ; i < M ; i++ ){
     sum = (x+i*y)%M;
     if( strcmp(Hash[sum],str) == 0 )
       return 1;
     else if( Hash[sum][0] == '\0' )
         return 0;
   }
 return 0;
}
 
int insert(char str[]){
 long long key;
 int i,x,y,sum;
 
 key = getKey(str);
 x = hash1(key);
 y = hash2(key);
 
 for( i = 0 ; i < M ; i++ )
   {
     sum = (x+i*y)%M;
     if( strcmp(Hash[sum],str) == 0 )
       return 1;
     else if( Hash[sum][0] == '\0' )
       {
	 strcpy(Hash[sum],str);
	 return 0;
       }
   }
 return 0;
}
 
int main(){
  int i, n, h;
  char str[L], com[9];
  
  for ( i = 0; i < M; i++ ) 
    Hash[i][0] = '\0';
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
    
    if ( com[0] == 'i' ){
      insert(str);
    } 
    else {
      if (find(str))
        printf("yes\n");
      else 
        printf("no\n");        
    }
  }
  return 0;
}

Measured memory_bytes: 14280
#include<iostream>
#define MOD 1000000007
using namespace std;
int n,i,Dp[200005],Sum[200005],prv,x;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n;
    Dp[0]=1;
    prv=0;
	for(i=1; i<=n; i++)
	{
        cin>>x;
        if(prv!=x)
            Sum[x]=(Sum[x]+Dp[i-1])%MOD;
        Dp[i]=Sum[x];
        prv=x;
	}
	cout<<Dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int ans=1;
    for(int i=n-1;i>=1;i--){
        int cnt=0;
        for(int j=i-1;j>=0;j--){
            if(v[i]>=v[j]){
                cnt++;
            }
        }
        if(cnt==i){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int h, w;
    scanf("%d %d", &h, &w);

    char s[h][w];
    for (int i = 0; i < h; i++) {
        scanf("%s", s[i]);
    }

    int offset[4][2] = {
        {0, -1},
        {-1, 0},
        {1, 0},
        {0, 1},
    };

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                int flag = 0;
                for (int k = 0; k < 4; k++){
                    int x = i + offset[k][0];
                    int y = j + offset[k][1];

                    if (x < 0 || x >= h) {
                        continue;
                    }
                    if (y < 0 || y >= w) {
                        continue;
                    }

                    if (s[x][y] == '#') {
                        flag = 1;
                    }
                }
                if (flag < 1) {
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

const string YES = "YES";
const string NO = "NO";

template<typename T>
class CumulativeSum {
    const int n;
    std::vector<T> sum_data;
public:
    CumulativeSum(vector<T> data) : n(data.size()) {
        sum_data.resize(n + 1);
        for (int i = 0; i < n; i++) {
            sum_data[i + 1] = sum_data[i] + data[i];
        }
    }

    // 区間 [l, r) 番目の範囲の和を求める．(l = r のときは 0 を返す．)
    T sum(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        return sum_data[r] - sum_data[l];
    }
};

typedef CumulativeSum<ll> CumSum;


void solve(std::string S, std::string T, long long q, std::vector<long long> a,
           std::vector<long long> b, std::vector<long long> c,
           std::vector<long long> d) {
    vector<ll> A(S.size());
    vector<ll> B(T.size());

    for (int i = 0; i < S.size(); i++) {
        A[i] = S[i] == 'A';
    }
    for (int i = 0; i < T.size(); i++) {
        B[i] = T[i] == 'A';
    }

    CumSum X(A);
    CumSum Y(B);
    for (int i = 0; i < q; i++) {
        --a[i];
        --c[i];
        int aCnt = X.sum(a[i], b[i]) + 2 * (b[i] - a[i] - X.sum(a[i], b[i]));
        int bCnt = Y.sum(c[i], d[i]) + 2 * (d[i] - c[i] - Y.sum(c[i], d[i]));
        if (aCnt % 3 == bCnt % 3) {
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }


}

int main() {
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    long long q;
    scanf("%lld", &q);
    std::vector<long long> a(q);
    std::vector<long long> b(q);
    std::vector<long long> c(q);
    std::vector<long long> d(q);
    for (int i = 0; i < q; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        scanf("%lld", &c[i]);
        scanf("%lld", &d[i]);
    }
    solve(S, T, q, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 8048
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static class City implements Comparable<City> {

		public int getP() {
			return P;
		}

		public void setP(int p) {
			P = p;
		}

		public int getY() {
			return Y;
		}

		public void setY(int y) {
			Y = y;
		}

		public int getSORT() {
			return SORT;
		}

		public void setSORT(int sORT) {
			SORT = sORT;
		}

		public String getCityNumber() {
			return cityNumber;
		}

		public void setCityNumber(String cityNumber) {
			this.cityNumber = cityNumber;
		}

		int P;
		int Y;
		int SORT;
		String cityNumber;

		public City() {
		}

		@Override
		public int compareTo(City o) {
			// TODO Auto-generated method stub
			int i = this.P - o.P;
			if (i == 0) {
				return this.Y - o.Y;
			}
			return i;
		}
	}

	public static void main(String args[]) throws Exception {

		int N;
		int M;
		int P;
		int Y;

		ArrayList<City> citys = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		if (N >= 1 && N <= (int)Math.pow(10,5)) {
			M = sc.nextInt();
			sc.nextLine();
			if (M >= 1 && M <= (int)Math.pow(10,5)) {
				for (int i = 1; i <= M; i++) {
					P = sc.nextInt();
					if (P >= 1 && P <= N) {
						Y = sc.nextInt();
						if (Y >= 1 && Y <= (int)Math.pow(10,9)) {
							City city = new City();
							city.setCityNumber("");
							city.setP(P);
							city.setSORT(i);
							city.setY(Y);
							sc.nextLine();
							citys.add(city);
						}

					}

				}

			}
		}
		Collections.sort(citys);
		int i = 0;
		int currentP = 1;
		for (City city : citys) {
			String cityName = "";
			int tempP1 = city.P;
			if (tempP1 == currentP) {
				i++;
			} else {
				i = 1;
				currentP = tempP1;
			}
			currentP = tempP1;
			String city1 = addZeroForNum(String.valueOf(city.P), 6);
			String city2 = addZeroForNum(String.valueOf(i), 6);
			String cityTemp = city1 + city2;
			city.setCityNumber(cityTemp);
		}
		Collections.sort(citys, new Comparator<City>() {

			@Override
			public int compare(City o1, City o2) {
				return o1.SORT - o2.SORT;
			}
		});
		for (City city : citys) {
			System.out.println(city.getCityNumber());
		}

	}

	public static String addZeroForNum(String str, int strLength) {
		int strLen = str.length();
		StringBuffer sb = null;
		while (strLen < strLength) {
			sb = new StringBuffer();
			sb.append("0").append(str);
			str = sb.toString();
			strLen = str.length();
		}
		return str;
	}

}


Measured memory_bytes: 164184
# -*- coding: utf-8 -*-
n = str(input())

if int(n) < 10:
    print(n)
    exit()

m = [0 for _ in range(len(n))]
for i in range(len(n)):
    m[i] = int(n[i])

ans = 0
for i in range(len(n)):
    ans += int(n[i])
ans2 = 0
m[-1] = 9
if n[len(n) - 2] != '0':
    m[len(n) - 2] -= 1
else:
    m[len(n) - 3] -= 1
    m[len(n) - 2] = 9
for i in range(len(n)):
    ans2 += m[i]
ans3 = 9 * (len(n) - 1) + (m[0] - 1)
print(max(ans, ans2, ans3))


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

int main()
{
    int r,c,arr[101][101] = {};
    cin >> r >> c;
    
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            cin >> arr[i][j];
            arr[r][j] += arr[i][j];
            arr[i][c] += arr[i][j];
            arr[r][c] += arr[i][j];
        }
    }
    
    for (int m=0; m <= r; m++){
        for (int k=0; k <= c; k++){
            cout << arr[m][k];
            
            if(k == c){
                cout << endl;
            }else{
                cout << ' ';
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 1208
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

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

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int R;
    cin >> R;
    cout << 2 * R * PI << endl;
}

Measured memory_bytes: 3784
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc162/tasks/abc162_f

//参考：
//https://at274.hatenablog.com/entry/2020/04/14/002124

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = -INF;

void solve(){
	//dp[i][j][k]
	//i個目まで見て
	//j=1ならi個目をとったことを表し、j=0ならとっていないことを表す
	//i個の中からk個選ぶ
	vector<vector<map<LL,LL>>> dp(N+1,vector<map<LL,LL>>(2));
	dp[0][0][0] = 0;
	auto chmax = [&](int i,int j,int k,LL new_value){
		if(dp[i][j].count(k)==1) dp[i][j][k] = max(dp[i][j][k],new_value);
		else dp[i][j][k] = new_value;
	};
	auto show_dp = [&](){
		for(int i=0;i<=N;i++){
			for(int j=0;j<=1;j++){
				for(auto iter=dp[i][j].begin();iter!=dp[i][j].end();iter++){
					printf("dp[%d][%d][%lld]=%lld,",i,j,iter->first,iter->second);
				}
				cout << endl;
			}
			cout << endl;
		}
	};
	//ばらまく
	for(int i=0;i<N;i++){
		for(int k=i/2-1;k<=i/2+1;k++){
			if(k<0 || k>N/2) continue;
			if(dp[i][0].count(k)==1){
				chmax(i+1,1,k+1,dp[i][0][k]+A[i]);
				chmax(i+1,0,k,dp[i][0][k]);
			}
			if(dp[i][1].count(k)==1) chmax(i+1,0,k,dp[i][1][k]);
		}
	}

	for(int j=0;j<=1;j++){
		for(auto iter=dp[N][j].begin();iter!=dp[N][j].end();iter++){
			if((iter->first)==N/2) ans = max(ans,iter->second);
		}
	}
	//show_dp();
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];

    solve();

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

Measured memory_bytes: 77804
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0
for _ in [0] * n:
    x1, y1, x2, y2 = (map(int, readline().split()))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))
        h_num += 1
class BinaryIndexedTree:
    __slots__ = ('data', 'num')
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n
    def switch(self, i, d):
        while i <= self.num:
            self.data[i] += d
            i += i & -i
    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s
    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)
EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0
for p in EP:
    e = p[1]
    if e == l:
        BIT.switch(d_vs_x[p[2]], 1)
    elif e == u:
        BIT.switch(d_vs_x[p[2]], -1)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += BIT.seg_sum(l_x, r_x)
        h_num -= 1
    if h_num == 0: break
print(cnt)

Measured memory_bytes: 35480