akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
f = lambda x: n//k + (x <= (n % k)) if x != 0 else n // k
res = 0
for a in range(k // 2 + 1):
    if (2 * (k - a)) % k == 0:
        res += f(a) * (f(((k - a)) % k) ** 2)
print(res)

Measured memory_bytes: 3060
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N  = Number(arg[0].split(" ")[0]);
    const Q  = arg[0].split(" ")[1];
    const S  = arg[1];
    //const lr = arg.split("\n").slice(2, N + 1);
    let dp = new Array(N).fill(0);
    let cnt = 0;
    
    for(let i in dp) {
        if(S[i] === "A" && S[parseInt(i)+1] === "C") {
            cnt++;
        }
        
        dp[parseInt(i)+1] = cnt;
    }

    for(let i=0; i<Q; i++) {
        let lr = arg[i+2].split(" ");
        let l = lr[0];
        let r = lr[1];
        
        console.log(dp[r-1]-dp[l-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 38696
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  while(n){
    ans++;
    n/=k;
  }
  cout << ans << endl;
return 0;}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min(a,b)
#define rmax(a,b) a = max(a,b)

#define fi first
#define se second

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	ll x, k, d; cin >> x >> k >> d;
	
	x = abs(x);
	ll ans = x;
	
	if(k>LLONG_MAX/d or k*d>x){
		ll qnt = x/d;
		
		x-= qnt*d;
		k-=qnt;
		
		if(k&1) x-=d;
		
		ans = abs(x);
	} else{
		x -= k*d;
		ans = x;
	}
	
	cout << ans << "\n";
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<pair<int, int> > changers(M);
    for (int i = 0; i < M; i++) {
        int B, C; cin >> B >> C;
        changers[i] = {C, B};
    }
    sort(changers.begin(), changers.end(), greater<pair<int, int> >());
    int ind = 0;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        if (ind >= M || A[i] >= changers[ind].first) {
            ans += A[i];
        } else {
            ans += changers[ind].first;
            changers[ind].second--;
        }
        if (ind != M && changers[ind].second == 0) {
            ind++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3

N = int(input())

H = list(map(int, input().split()))

num = 1
if N > 2:
    for i in range(1,N):
        cansee = True
        for j in range(i):
            if H[i] < H[j]:
                cansee = False
                break
        if cansee:
            num += 1

print(num)



Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int book(int r){
    if(r<400)  return 1;
    else if(r<800)  return 2;
    else if(r<1200)  return 3;
    else if(r<1600)  return 4;
    else if(r<2000)  return 5;
    else if(r<2400)  return 6;
    else if(r<2800)  return 7;
    else if(r<3200)  return 8;
    else return 0;
}
int main(){
    int n,t,block[9]={0};
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>t;
        block[book(t)]++;
    }
    int res=0;
    for(int i=1;i<=8;i++){
        if(block[i]!=0){
            res++;
        }
    }
    if(res!=0)
        cout<<res<<" "<<res+block[0];
    else 
        cout<<1<<" "<<block[0];
    return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
if n <= a:
  print(n)
elif n <= a+b:
  print(a)
else:
  t = (n//(a+b))
  m = n - (a+b)*t
  if m <= a:
    print(m + t*a)
  else:
    print((t+1)*a)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define N 100010
int n,m;
int p[N];
long long y[N];
vector<long long> V[N];
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n>>m)
    {
        for(int i=1;i<=n;i++) V[i].clear();
        for(int i=1;i<=m;i++)
        {
            cin>>p[i]>>y[i];
            V[p[i]].push_back(y[i]);
        }
        for(int i=1;i<=n;i++) sort(V[i].begin(),V[i].end());
        string str;
        for(int i=1;i<=m;i++)
        {
            str="";
            for(int j=1;j<=6-to_string(p[i]).length();j++) str+='0';
            str+=to_string(p[i]);
            int pos=upper_bound(V[p[i]].begin(),V[p[i]].end(),y[i])-V[p[i]].begin();
            //二分查找,线性TLE
            for(int j=1;j<=6-to_string(pos).length();j++) str+='0';
            str+=to_string(pos);
            cout<<str<<endl;
        }
    }
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
using namespace std;

int main()
{
	int N;
	cin >> N;
 
	vector<int> A(N + 1);
	vector<int> B(N);
 
	for (int i = 0; i <= N; i++)
	{
		cin >> A[i];
	}
 
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}
 
	long long int ans = 0;
	for (int i = 0; i <= N; i++)
	{
		if (i == 0)
		{
			ans += min(A[i], B[i]);
		}
		else if(i == N)
		{
			int tmp = min(A[i], B[i - 1] - min(A[i - 1], B[i - 1]));
			ans += tmp;
		}
		else
		{
			int tmp = min(A[i], B[i - 1] - min(A[i - 1], B[i - 1]));
			ans += tmp;
			A[i] = A[i] - tmp;
			ans += min(A[i], B[i]);
		}
	}
 
	cout << ans << endl;
 
	return 0;
 
}

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




int N, M;
string A[50];
string B[50];
//-----------------------------------------------------------------
bool chk(int x, int y) {
	rep(i, 0, M) rep(j, 0, M) {
		if (A[i + x][j + y] != B[i][j]) return false;
	}
	return true;
}
//-----------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> A[i];
	rep(j, 0, M) cin >> B[j];

	rep(i, 0, N - M + 1) rep(j, 0, N - M + 1) {
		if (chk(i, j)) {
			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");
}

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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
#define vv(T) vector<vector<T>>
#define vvv(T) vector<vector<vector<T>>>
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}
// Template END


const int mxn = (int)1e7 ;

signed main(){
	int n ; cin >> n ;
	int ans3 = 0, lmt ;
	for( int j = 1 ; j <= n ; j++ ){
		lmt = n / j ;
		ans3 += ( ( lmt * ( lmt + 1 ) ) * j ) / 2 ;
	}
	
	cout << ans3 ;
	return 0 ;
}













Measured memory_bytes: 3652
var n,l,i,tt,min,res:integer;
    a:array[1..100] of integer;
begin
  readln(n,l);
  for i:=1 to n do 
    begin
      a[i]:=l + i - 1;
      tt:=tt + a[i];
    end;
  min:=high(integer);
  for i:=1 to n do 
    begin
      if abs(tt - (tt - a[i])) < min then 
        begin
          min:=abs(tt - (tt - a[i]));
          res:= tt - a[i];
        end;
    end;
  write(res)
end.

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

struct Point {double x,y;};

void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th=M_PI*60.0/180.0;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);

}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;

}




Measured memory_bytes: 2568
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;
using i64 = int64_t;
const i64 mod = 1e9 + 7;
i64 n;
vector<i64> a, ss, zs;
int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ss.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        ss[i] = ss[i - 1] ^ a[i - 1];
    }
    zs.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        zs[i] = zs[i - 1] + (ss[i] == 0);
    }
    cerr << "all xor " << ss[n] << endl;
    map<i64, vector<int>> mp;
    for (int i = 1; i <= n; ++i) {
        mp[ss[i]].push_back(i);
    }
    i64 ans = 0;
    for (auto p : mp) {
        i64 x = p.first;
        if (x == 0) continue;
        auto& v = p.second;
        i64 c0 = 1, cx = 0;
        for (int i = 0; i < v.size(); ++i) {
            i64 d = i < v.size() - 1 ? zs[v[i + 1]] - zs[v[i]] : zs[n] - zs[v[i]];
            (cx += c0) %= mod;
            (c0 += d * cx) %= mod;
        }
        (ans += cx) %= mod;
        if (x == ss[n]) {
            cout << c0 << endl;
            return 0;
        }
    }
    i64 x = 1;
    for (int i = 0; i < zs[n - 1]; ++i) {
        (x *= 2) %= mod;
    }
    (ans += x) %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 44660
/*
 * Atcoder Beginner Contest 154 C - Distinct or Not
 * 
 * Time: 322ms
 * Memory: 9600KB
 * 
 * Author: DragonLee
 */

#include <iostream>
#include <set>
using namespace std;

int main() {
    int n, num;
    set<int> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> num;
        s.insert(num);
    }
    if (n == s.size()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){
	long long N;
	cin >> N;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	vector<long long> B(N);
	for(int i=0;i<N;i++){
		B[i] = A[i] - i;
	}
	sort(B.begin(), B.end());
	long long center1, center2;
	if(N % 2) {
		center1 = B[N / 2];
		center2 = B[N / 2];
	}
	else{
		center1 = B[N / 2];
		center2 = B[N / 2 - 1];
	}
	long long ans1, ans2;
	for(int i=0;i<N;i++){
		ans1 += abs(B[i] - center1);
		ans2 += abs(B[i] - center2);
	}
	cout << min(ans1, ans2) << endl;
}

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

int main(){
    string s;
    cin>>s;
    int a = 0;
    for (int i = 0; i < 3;i++){
        if(s.at(i)=='o'){
            a++;
        }
    }
    cout << 700 + a * 100 << endl; }

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

#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
#define min(a, b, c) min(a, min(b, c))
#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>str;
	for(int i=0;i<str.length();i++)
	{
	    if(str[i]=='+')
	    a++;
	    else
	    a--;
	}
	cout<<a;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i;
  char s[6];
  for(i=0; i<6; i++){
    scanf("%c", &s[i]);
  }
  if(s[2]==s[3] && s[4]==s[5]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
	if int(s) > N:
		return 0
	ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
	for c in '753':
		ret += dfs(s + c)
	return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

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

double time500[7] = { 35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0 };
double time1000[7] = { 71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0 };
string acd[7] = { "AAA", "AA", "A", "B", "C", "D", "E" };
int main() {
      int a,b;
      double time5,time1;
      while(cin>>time5>>time1) {
        for(int i=0; i<7; ++i) {
          if(time5 < time500[i] && time1 < time1000[i]) {
            cout<<acd[i]<<endl;
            goto NEXT;
          }
        }
        cout<<"NA"<<endl;
      NEXT:
        ;
      }
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 3 -10");
            WillReturn.Add("1 2 3");
            WillReturn.Add("3 2 1");
            WillReturn.Add("1 2 2");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 2 -4");
            WillReturn.Add("-2 5");
            WillReturn.Add("100 41");
            WillReturn.Add("100 40");
            WillReturn.Add("-3 0");
            WillReturn.Add("-6 -2");
            WillReturn.Add("18 -13");
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3 3 0");
            WillReturn.Add("100 -100 0");
            WillReturn.Add("0 100 100");
            WillReturn.Add("100 100 100");
            WillReturn.Add("-100 100 100");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int C = wkArr[2];

        SplitAct(InputList[1]);
        int[] BArr = wkArr;

        var AArrList = new List<int[]>();
        foreach (string EachStr in InputList.Skip(2)) {
            SplitAct(EachStr);
            AArrList.Add(wkArr);
        }

        int AnswerCnt = 0;
        foreach (int[] EachAArr in AArrList) {
            int ProdSum = 0;
            for (int I = 0; I <= BArr.GetUpperBound(0); I++) {
                ProdSum += BArr[I] * EachAArr[I];
            }
            if (ProdSum + C > 0) AnswerCnt++;
        }
        Console.WriteLine(AnswerCnt);
    }
}


Measured memory_bytes: 13524
#include<stdio.h>
#include<string.h>

char x[2000];
char y[2000];

int LCS(int,int);

int main(){
  int i,j,k,sumstring;
  scanf("%d",&sumstring);

  for(i = 0; i < sumstring; i++){
    scanf("%s",x);
    scanf("%s",y);
    printf("%d\n",LCS(strlen(x),strlen(y)));
  }

  return 0;
}

int LCS(int length1, int length2){

  int i,j,a,answer[1001][1001];

  a = 0;

  for(i = 0; i < length1; i++){
    answer[i][0] = 0;
  }

  for(i = 0; i < length2; i++){
    answer[0][i] = 0;
  }
  for(i = 0; i < length1; i++){
    for(j = 0; j < length2; j++){
      if(x[i]==y[j] && x[i]!=' ' && y[i] != ' '){
        if(i == 0 || j == 0){
          answer[i][j] = 1;
        }
        else{
          answer[i][j] = answer[i-1][j-1]+1  ;
        }
      }

      else{
        if(i == 0 && j != 0){
          answer[i][j] = answer[0][j-1];
        }
        else if(i !=0 && j == 0){
          answer[i][j] = answer[i-1][0];
        }
        else if(i == 0 && j == 0){
          answer[0][0] = 0;
        }
        else if(i != 0 && answer[i-1][j] > answer[i][j-1]){
          answer[i][j] = answer[i-1][j];
        }
        else if(answer[i-1][j] <= answer[i][j-1]){
          answer[i][j] = answer[i][j-1];
        }
      }
    }
  }
  return answer[length1-1][length2-1];
}



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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();
    int ans = 1005;
    for (int i = 0; i <= n - m; i++) {
        int change = 0;
        for (int j = 0; j < m; j++) {
            change += s[i + j] != t[j];
        }
        ans = min(ans, change);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3612
import { readFileSync } from "fs";

const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const cnt = (() => {
    const css: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );

    const initialBlackCnt = css
      .map((cs) => cs.reduce((acc, c) => (c === "Black" ? acc + 1 : acc), 0))
      .reduce((acc, x) => acc + x, 0);

    const hPickFn = (n: number, hPicks: [number, boolean][]): number => {
      const wPickFn = (hPicks: [number, boolean][]): number => {
        const wPickFn = (n: number, wPicks: [number, boolean][]): number =>
          n >= W
            ? initialBlackCnt -
                (() => {
                  const hCnt = hPicks
                    .filter(([, b]) => b)
                    .map(([i]) =>
                      range(W)
                        .map((j) => (css[i][j] === "Black" ? 1 : 0))
                        .reduce((acc: number, x) => acc + x, 0)
                    )
                    .reduce((acc: number, x) => acc + x, 0);

                  const wCnt = range(H)
                    .map((i) =>
                      wPicks
                        .filter(([, b]) => b)
                        .map(([j]) => (css[i][j] === "Black" ? 1 : 0))
                        .reduce((acc: number, x) => acc + x, 0)
                    )
                    .reduce((acc: number, x) => acc + x, 0);

                  const hwCnt = hPicks
                    .filter(([, b]) => b)
                    .map(([i]) =>
                      wPicks
                        .filter(([, b]) => b)
                        .map(([j]) => (css[i][j] === "Black" ? 1 : 0))
                        .reduce((acc: number, x) => acc + x, 0)
                    )
                    .reduce((acc: number, x) => acc + x, 0);

                  return hCnt + wCnt - hwCnt;
                })() ===
              K
              ? 1
              : 0
            : wPickFn(n + 1, wPicks) +
              wPickFn(
                n + 1,
                wPicks.map(([j, b]) => (j === n ? [j, true] : [j, b]))
              );

        return wPickFn(
          0,
          range(W).map((j) => [j, false] as [number, boolean])
        );
      };

      return n >= H
        ? wPickFn(hPicks)
        : hPickFn(n + 1, hPicks) +
            hPickFn(
              n + 1,
              hPicks.map(([i, b]) => (i === n ? [i, true] : [i, b]))
            );
    };

    return hPickFn(
      0,
      range(H).map((i) => [i, false] as [number, boolean])
    );
  })();

  console.log(cnt);
}


Measured memory_bytes: 40340
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i, n) cin >> b[i];
    rep(i, n - 1) cin >> c[i];
    
    int ans = 0;
    rep(i, n) {
        ans += b[a[i]];
        if(i == n - 1) continue;
        if(a[i + 1] == a[i] + 1) ans += c[a[i]];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
	int n;
	long long int x=1;
	cin>>n;
	for(int i=1; i<=n; i++){
		x*=i;
		x%=1000000007;
	}
 
	cout<<x;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int l=0,r=n-1;
	for(int i=n-1;i>=0;i--)if((n-1-i)&1)b[r--]=a[i];else b[l++]=a[i];
	for(int i=0;i<n;i++)printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>

using namespace std;

int n, k;
int cnt;

int main()
{
    scanf("%d%d", &n, &k);
    if(k > (n - 1) * (n - 2) / 2)
    {
        printf("-1");
        return 0;
    }
    printf("%d\n", n - 1 + (n - 2) * (n - 1) / 2 - k);
    cnt = (n - 2) * (n - 1) / 2 - k;
    for(int i = 2; i <= n; i++)
    {
        printf("1 %d\n", i);
    }
    for(int i = 2; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(cnt <= 0) return 0;
            printf("%d %d\n", i, j);
            cnt--;
        }
    }
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n+1);
		for (int x = 1; x <= 100 ; x++) {
			for (int y = 1; y <= 100 ; y++) {
				for (int z = 1; z <= 100 ; z++) {
					ll i = x*x+y*y+z*z;
					i += x*y+y*z+z*x;
					if(i > n) continue;
					a[i]++;
					}
				}
			}
	rep(i,n) cout << a[i+1] << endl;
}


Measured memory_bytes: 3608
data = [{} for i in range(6)]
n = int(raw_input())
for i in range(n):
    ipt = raw_input().split()
    if data[len(ipt[0])].get(ipt[0])==None: data[len(ipt[0])][ipt[0]] = 0
    data[len(ipt[0])][ipt[0]] += int(ipt[1])
for i in range(1,6):
    for k in sorted(data[i].keys()):
        print k+' '+str(data[i][k])

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

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int x=0; x<=K; x++){
        int mn = max(0, S-x-K), mx = min(K, S-x);
        ans += max(0, mx-mn+1);
    }
    cout << ans << endl;
    return 0;
}


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

LL M[60][60];

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL h, w;
    cin >> h >> w;

    for(LL i = 1; i <= h; i++){
        for(LL j = 1; j <= w; j++){
            char ch;
            cin >> ch;

            if(ch == '#')
                M[i][j] = 999;
        }
    }

    for(LL i = 1; i <= h; i++){
        for(LL j = 1; j <= w; j++){
            if(!M[i][j]){

                LL cnt = 0;
                for(LL x = -1; x < 2; x++){
                    for(LL y = -1; y < 2; y++){
                        if(M[i + x][j + y] == 999)
                            cnt++;
                    }
                }
                M[i][j] = cnt;
            }
        }
    }

    for(LL i = 1; i <= h; i++){
        for(LL j = 1; j <= w; j++){
            if(M[i][j] == 999)
                cout << '#';
            else
                cout << M[i][j];
        }
        cout << '\n';
    }
    return 0;
}



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

int main() {
  int n; cin >> n;
  vector<int> t(n+1), x(n+1), y(n+1);
  t[0] = x[0] = y[0] = 0;
  for (int i = 1; i < n+1; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  for (int i = 0; i < n; i++) {
    int dt = t[i+1] - t[i];
    int dis = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    if (dt < dis || dt%2!=dis%2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S=sc.next();
        int n=0;
        for(int i=0;i<6;i++){
            if(S.charAt(i)=='1'){
                n++;
            }
        }
        System.out.println(n);
    }
}


Measured memory_bytes: 22996
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    int a, b;
    cin >> a >> b;
    bool ans = (a % 3 == 0) || (b % 3 == 0) || ((a + b) % 3 == 0);
    cout << (ans ? "Possible" : "Impossible") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int,int> P;

int main(){
    const int INF = 1e9 + 7;
    while(true){
        int N,M;
        cin>>N>>M;
        if(N==0 && M==0) break;
        vector<P> v[151];//v[i]??????i??????????????±?????°?????£????????????v[i][0],v[i][1],...
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            for(int j=0;j<a;j++){
                int b,c;
                cin>>b>>c;
                v[i].push_back(P(b,c));
            }
        }
        int dp[3][80][151][11];//dp[a][Jump][k][l]??§Jump???????????£???????????¨??????k?????????v[k][l]?????§??\?????¨??????????????????????°????
        for(int a=0;a<3;a++){
            for(int b=0;b<80;b++){
                for(int c=0;c<151;c++){
                    for(int d=0;d<11;d++){
                        if( (c==0||c==1) && b==0 ){
                            dp[a][b][c][d]=0;
                        }else if(c==2 && b==1){
                            dp[a][b][c][d]=0;
                        }else{
                            dp[a][b][c][d]=INF;
                        }
                    }
                }
            }
        }
        int ans=INF;
        for(int i=2;i<=N;i++){//i????????????????????´??°????????????
            for(int j=0;j<=M;j++){//j????????£??????????????????????????§?????????
                //?????£???????????????ver.
                int a=(i+2)%3;
                for(int l=0;l<v[i].size();l++){
                    int tmp=INF;
                    for(int s=0;s<v[i-1].size();s++){
                        int risk = (v[i][l].second + v[i-1][s].second)*abs(v[i][l].first - v[i-1][s].first);
                        tmp = min(tmp, dp[a][j][i-1][s]+risk);
                    }
                    dp[i%3][j][i][l]=min(dp[i%3][j][i][l],tmp);
                    if(j<M && i==N-1){
                        ans=min(ans,tmp);
                    }
                    if(j<=M && i==N){
                        ans=min(ans,tmp);
                    }
                }
                //?????£????????????ver.
                if(i>2 && j<M){
                    a=(i+1)%3;
                    for(int l=0;l<v[i].size();l++){
                        int tmp=INF;
                        for(int s=0;s<v[i-2].size();s++){
                            int risk = (v[i][l].second + v[i-2][s].second)*abs(v[i][l].first - v[i-2][s].first);
                            tmp = min(tmp, dp[a][j][i-2][s]+risk);
                        }
                        dp[i%3][j+1][i][l] = min(tmp,dp[i%3][j][i][l]);
                        if(j+1<M && i==N-1){
                            ans=min(ans,tmp);
                        }
                        if(j+1<=M && i==N){
                            ans=min(ans,tmp);
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 4592
function main(arg) {
	arg = arg.split("\n").map(Number)
	var data = [
		arg[1], arg[2], arg[3], arg[4], arg[5]
	]
	var sum = new Array(data.length).fill(0)
	var N = arg[0]

	var min = Math.min(...data)
	if (N <= min) {
		console.log(5)
		return
	} else {
		var ans = Math.ceil(N /min) + 4
		console.log(ans)
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

struct edge{ int to,cost; };
vector< edge > G[2000];
const int INF = 1LL<<60;

signed main(){

  int n,m; cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a,b,c; cin >> a >> b >> c;
    a--,b--;
    G[a].push_back({b,c});
  }

  int dp[2000];
  fill(dp,dp + 2000,-INF);
  dp[0] = 0;
  for(int i = 0; i < m; i++){
    for(int u = 0; u < n; u++){
      for(auto e : G[u]){
        dp[e.to] = max(dp[e.to],dp[u] + e.cost);
      }
    }
  }
  int ans1 = dp[n-1];
  for(int i = 0; i < m; i++){
    for(int u = 0; u < n; u++){
      for(auto e : G[u]){
        dp[e.to] = max(dp[e.to],dp[u] + e.cost);
      }
    }
  }
  int ans2 = dp[n-1];
  if(ans1 != ans2) cout << "inf" << endl;
  else cout << ans1 << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <chrono>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	unsigned long long int N;
	unsigned long long int T;
	cin >> N >> T;
	vector<unsigned long long int> t(N - 1, 0);
	unsigned long long int a, b;
	cin >> a;
	for (int i = 0; i < N - 1; i++) {
		cin >> b;
		t[i] = b - a;
		a = b;
	}
	unsigned long long int sum = 0;
	for (int i = 0; i < N - 1; i++) {
		if (t[i] < T) {
			sum += t[i];
		}
		else {
			sum += T;
		}
	}
	sum += T;
	cout << sum << endl;
}


Measured memory_bytes: 1792
N = input()
s = input()

#累積和 前処理 Eの数を集計
count = s.count('E')

ans = count
#左端1番目からリーダーをずらしながらチェック。
for ch in s:
    if ch == 'E':
        count -= 1
        ans = min(count,ans)
    else:
        count += 1
    
print(ans)


Measured memory_bytes: 9516
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdint>
using namespace std;

const uint64_t kP = 1000000007;

int main()
{
  uint64_t n, K;

  cin >> n >> K;

  uint64_t v[52][52][3000];
  for (uint64_t i = 0; i <= n; ++i) {
    for (uint64_t j = 0; j <= n + 1; ++j) {
      for (uint64_t k = 0; k <= n * n; ++k) {
        v[i][j][k] = 0;
      }
    }
  }
  v[1][0][0] = 1;
  v[1][1][2] = 1;

  for (uint64_t i = 2; i <= n; ++i) {
    for (uint64_t j = 0; j <= i; ++j) {
      for (uint64_t k = 2 * j; k <= n * n; ++k) {
        v[i][j][k] = ((2 * j + 1) * v[i-1][j][k - 2 * j]) % kP;
        v[i][j][k] += (j + 1) * (j + 1) * (v[i-1][j+1][k - 2 * j]);
        v[i][j][k] %= kP;
        if (j) {
          v[i][j][k] += v[i-1][j-1][k - 2 * j];
          v[i][j][k] %= kP;
        }
      }
    }
  }

  cout << v[n][0][K] << endl;

  return 0;
}




Measured memory_bytes: 62976
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

# Σ_{i=0}^{N−1} floor((A×i+B)/M)
def floor_sum(n, m, a, b):
    res = 0
    while True:
        if a >= m:
            res += (n - 1) * n * (a // m) // 2
            a %= m
        if b >= m:
            res += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        if y_max == 0: break
        x_max = b - y_max * m
        res += (n + x_max // a) * y_max
        n, m, a, b = y_max, a, m, x_max % a
    return res

def main():
    T = I()

    for _ in range(T):
        print(floor_sum(*LI()))

if __name__ == '__main__':
    main()

Measured memory_bytes: 75480
from collections import defaultdict
n=int(input())
d=defaultdict(int)
for i in range(n):
    s=input()
    d[s]+=1

print("AC x "+str(d["AC"]))

print("WA x "+str(d["WA"]))

print("TLE x "+str(d["TLE"]))

print("RE x "+str(d["RE"]))

Measured memory_bytes: 9472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    int sum = 0;
    int lmax = 0;
    for(int i=0;i<n;i++){
        cin>>l[i];
        sum += l[i];
        lmax = max(lmax,l[i]);
    }
    if(sum - lmax > lmax) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
using namespace std;


int main(){
	int N, H;
	cin >> N >> H;
	int a[N], b[N];
	int i;
	rep(i,N)
		cin >> a[i] >> b[i];
	sort(a, a+N);
	sort(b, b+N);
	int amax = a[N-1];
	int maxIndex = 0;
	for(int i=N-2; i >= 0; i--){
		if(b[i] < amax){
			maxIndex = i+1;
			break;
		}
	}
	int temp = H;
	int count = 0;

	for(int i = N-1; i >= maxIndex; i--){
		temp -= b[i];
		count++;
		if(temp<=0)
			break;
	}
	while(temp > 0){
		temp -= amax;
		count++;
	}

/*
	if(temp > 0){
		count += temp/amax;
	}
*/

	cout << count <<endl;
	return 0;

}


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

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7, SZ = 3e5 + 100;

ll n;
vector<pair<ll, ll>> dif;

ll dp[SZ][3][3];

void trs0(int i) {
	for (int j = 0; j < 3; j++) {
		dp[i][j][1] += dp[i - 1][j][0];
		dp[i][j][2] += dp[i - 1][j][1];
		dp[i][j][1] += dp[i - 1][j][2];

		dp[i][j][1] %= MOD;
		dp[i][j][2] %= MOD;
	}
}

void trs1(int i) {
	dp[i][2][0] += dp[i - 1][2][0];
	dp[i][2][1] += dp[i - 1][2][1];
	dp[i][2][2] += dp[i - 1][2][2];

	dp[i][2][0] %= MOD;
	dp[i][2][1] %= MOD;
	dp[i][2][2] %= MOD;

	for (int ns = 0; ns <= 1; ns++) {
		for (int zr = 0; zr <= 2; zr++) {
			ll vl = dp[i - 1][ns][zr];
			ll ns2 = ns, zr2 = zr;
			if (zr > 0) {
				zr2--;
			}
			else {
				ns2++;
			}
			dp[i][ns2][zr2] += vl;
			dp[i][ns2][zr2] %= MOD;
		}
	}
}

int main() {
	fastInp;

	string s;
	cin >> s;

	n = s.size();
	dp[0][0][0] = 1;

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

	ll ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (i > j || i == 2) ans += dp[n][i][j];
		}
	}

	cout << ans % MOD;
	return 0;
}

Measured memory_bytes: 24868
#!/usr/bin/env python3

def solve(N, A):
    from collections import defaultdict
    B = defaultdict(int)
    ans = 0
    for i, a in enumerate(A, 1):
        ans += B[a-i]
        B[-a-i] += 1
    return ans

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 61688
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(i*500+j*100+k*50==x){
                    ans++;
                }
            }
        }
    }
    cout << ans;

    return 0;
}

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

struct Node
{
    int ele;
    struct Node *prev, *next;
};

typedef struct Node * DLL;

DLL search(int);
void insert(int);
void deleteNode(DLL);
void delete(int);
void deleteFirst();
void deleteLast();
void initailize();
void priDLL();

DLL head;

int main(void)
{
    int n, x;
    char cmd[12];

    initailize();
    scanf("%d", &n);
    
    while (n--) {
        scanf("%s", cmd);
        if (strcmp(cmd, "insert") == 0) {
            scanf("%d", &x);
            insert(x);
        } else if (strcmp(cmd, "delete") == 0) {
            scanf("%d", &x);
            delete(x);
        } else if (strcmp(cmd, "deleteFirst") == 0) {
            deleteFirst();
        } else if (strcmp(cmd, "deleteLast") == 0) {
            deleteLast();
        }
    }
    priDLL();

    return 0;
}

void initailize()
{
    head = (DLL) malloc(sizeof(struct Node));
    head->prev = head->next = head;
}

void insert(int x)
{
    DLL l = (DLL) malloc(sizeof(struct Node));
    l->ele = x;
    l->next = head->next;
    head->next->prev = l;
    head->next = l;
    l->prev = head;
}

DLL search(int x)
{
    DLL tmp = head->next;
    while (tmp != head && tmp->ele != x)
        tmp = tmp->next;
    return tmp;
}

void deleteNode(DLL l)
{
    if (l == head) return;
    l->prev->next = l->next;
    l->next->prev = l->prev;
    free(l);
}

void delete(int x)
{
    deleteNode(search(x));
}

void deleteFirst()
{
    deleteNode(head->next);
}

void deleteLast()
{
    deleteNode(head->prev);
}

void priDLL()
{
    DLL tmp = head->next;
    if (tmp == head)
        return;
    printf("%d", tmp->ele);
    tmp = tmp->next;
    while (tmp != head) {
        printf(" %d", tmp->ele);
        tmp = tmp->next;
    }
    putchar('\n');
}


Measured memory_bytes: 32952
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
lr=[list(map(int,input().split())) for i in range(n)]
lr.sort()
# print(lr)

alst=[(lr[0][0],lr[0][1])]
blst=[(lr[-1][0],lr[-1][1])]
for i in range(n-1):
    alst.append((lr[i+1][0], min(alst[i][1],lr[i+1][1])))
    blst.append((max(blst[i][0],lr[-i-2][0]), min(blst[i][1],lr[-i-2][1])))
# print(alst)
# print(blst)
ans=0
def sa(lst):
    return max(0,lst[1]-lst[0]+1)

for i in range(n-1):
    ans=max(ans,sa(alst[i])+sa(blst[-i-2]))

lr2=sorted(lr,key=lambda x: x[1])
# print(lr2)
for i in range(n):
    tmp=sa(lr[i])
    l,r=0,0
    if lr[i][0]==lr[-1][0]:
        l=lr[-2][0]
    else:
        l=lr[-1][0]
    if lr[i][1]==lr2[0][1]:
        r=lr2[1][1]
    else:
        r=lr2[0][1]
    # print(tmp,l,r)
    ans=max(ans,tmp+max(0,r-l+1))
print(ans)

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        ans += (s[i] == t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * ALDS1_5_C.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cmath>

double SQRT3 = sqrt(3);

struct Point {
	double x;
	double y;
};

void kochCurve(Point p1, Point p2, int n) {
	if(n == 0) {
		printf("%f %f\n", p1.x, p1.y);
		return;
	}
	double dx = p2.x - p1.x;
	double dy = p2.y - p1.y;
	Point s = {p1.x + dx/3, p1.y + dy/3};
	Point t = {p2.x - dx/3, p2.y - dy/3};
	Point st = {t.x - s.x, t.y - s.y};
	Point u = {s.x + (st.x - SQRT3*st.y)/2, s.y + (SQRT3*st.x + st.y)/2};
	kochCurve(p1, s, n-1);
	kochCurve(s, u, n-1);
	kochCurve(u, t, n-1);
	kochCurve(t, p2, n-1);
}

int main() {
	int n;
	scanf("%d", &n);
	Point l = {0, 0};
	Point r = {100, 0};
	kochCurve(l, r, n);
	printf("100.0 0.0\n");
}



Measured memory_bytes: 2672
#include <iostream>
#include <bits/stdc++.h>
#define scan(n)      scanf("%I64d",&n);
#define scan2(a,b)   scanf("%I64d%I64d",&a,&b);
#define scan3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c);
#define sc(n)        scanf("%c",&n);
#define sf(n)        scanf("%lf",&n);
#define ss(n)        scanf("%s",n);
#define forall(i,a,b)for(long long int i=a;i<b;i++)
#define all(a)       a.begin(), a.end()
#define pb           push_back
#define mp           make_pair
#define FAST_IO      ios_base::sync_with_stdio(false); cin.tie(NULL);
#define minimum(a)   *min_element(a.begin(),a.end())
#define maximum(a)   *max_element(a.begin(), a.end())
#define display(a)   for(auto i : a) cout<<i<<" ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<ll> scanVector(ll n, vector<ll> &v)
{
  ll temp;
  for(ll i = 0; i < n ; i++)
  {
     cin>>temp;
     v.pb(temp);
  }
  return v;
}
bool isPalindrome(string s)
{
    string t = s;
    reverse(all(t));
    if(t == s) return true;
    return false;
}
int main() {
    FAST_IO
    ll t;
    //cin>>t;
    t = 1;
    while(t--)
    {
        string s;
        cin>>s;
        ll n = s.length();
        if(s.length()%2!=0 && isPalindrome(s) && isPalindrome(s.substr(0,(n-1)/2)) && isPalindrome(s.substr(((n+3)/2)-1)))
        {
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[4001], invf[4001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int a, b; cin>>a>>b;
    fac(a+b);
    ll cnt[2010][2010];
    fill(cnt[0], cnt[0]+a+1, 1);
    for(int i=1; i<=b; i++){
        cnt[i][0]=1;
        for(int j=1; j<=a; j++) cnt[i][j]=(cnt[i][j-1]+comb(i-1, j))%MOD;
        for(int j=1; j<=a; j++) (cnt[i][j]+=cnt[i][j-1])%=MOD;
    }
    ll ans=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=min(b-1, i); j++){
            (ans+=comb(b-1, j)*cnt[j][i-j])%=MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  string str;
  cin >> str;
  int n = str.length();
  bool found = false;
  rep(i, n){
    for(int j=i; j<n; j++){
      string tmp = "";
      for(int k=0; k<i; k++){
        tmp += str[k];
      }
      for(int k=j; k<n; k++){
        tmp += str[k];
      }
      if(tmp == "keyence"){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
   cout << "NO" << endl;   
  return 0;
}


Measured memory_bytes: 256
h,m;P(s){printf("%02d:%02d:%02d\n",s/3600,s/60%60,s%60);}main(s){for(;scanf("%d%d%d",&h,&m,&s),h+1;P(s*3))P(s=7200-h*3600-m*60-s);exit(0);}

Measured memory_bytes: 0