akhauriyash/Code-Regression huggingface dataset:
N,K = map(int, input().split())

grid = [[0 for _ in range(2*K)] for _ in range(2*K)]

for _ in range(N):
    x, y, c = input().split()
    i, j = int(x), int(y)
    if c == "B":
        j += K
    i %= (2*K)
    j %= (2*K)
    grid[i][j] += 1

for i in range(2*K):
    for j in range(2*K):
        if i == 0:
            if j != 0:
                grid[i][j] += grid[i][j-1]
        else:
            if j == 0:
                grid[i][j] += grid[i-1][j]
            else:
                grid[i][j] += (grid[i-1][j] + grid[i][j-1] - grid[i-1][j-1])
        

ans = 0
M = grid[2*K-1][2*K-1]
for i in range(K):
    for j in range(K):
        temp = 0
        c = 0
        temp += (M-grid[i+K-1][-1]-grid[-1][j+K-1]+grid[i+K-1][j+K-1])
        temp += grid[i+K-1][j+K-1]
        if i > 0 and j == 0:
            temp += (grid[i-1][-1]-2*grid[i-1][j+K-1])
        if i == 0 and j > 0:
            temp += (grid[-1][j-1]-2*grid[i+K-1][j-1])
        if i > 0 and j > 0:
            temp += (grid[i-1][-1]-2*grid[i-1][j+K-1])
            temp += (grid[-1][j-1]-2*grid[i+K-1][j-1])
            temp += 2*grid[i-1][j-1]
        ans = max(ans, temp, M-temp)
        
print(ans)

Measured memory_bytes: 81116
#include<iostream>
#include<string>
using namespace std;
 
int main()
  {
  string s;
  cin>>s;
  int len,c=0;
  len=s.length();
  for(int i=0;i<len/2;i++)
    {
    if(s[i]!=s[len-1-i])
      c++;
    }
  cout<<c;
  return 0;
  }

Measured memory_bytes: 256
x, k , d = map(int , input().split())
r = abs(x)//d

if x > 0:
  if k - r > 0:
    print(abs(x-r*d-(k-r)%2*d))
  else :
    print(abs(x-k*d))
else :
  if k - r > 0:
    print(abs(x+r*d+(k-r)%2*d))
  else :
    print(abs(x+k*d))

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

int main() {
long	double n,x,p;
	cin>>n;
	x=ceil(n/1.08);
p=	floor(x*1.08);
	if(p==n)
	cout<<x;
	else
	cout<<":(";
	//cout<<p;
	//cout<<x;
}

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

int main(){
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000

int main(){
    ll n;
    cin >> n;
    set<string> s;
    string str;
    rep(i,n){
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
}
/*
    vector<string> s(n);
    rep(i,n){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    rep(i,n){
        if(s[i]==s[i+1]){
                s.erase(s.begin()+i);
                i--;
            }
        }
    cout << s.size() << endl;
    }
*/


Measured memory_bytes: 19180
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    int h, n;
    cin >> h >> n;

    for (int i = 0; i < n; ++i) {
        int t; cin >> t; h -= t;
    }
    if (h <= 0) { cout << "Yes"; } else { cout << "No"; }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, H;
int a[100100];
int b[100100];

vector<int> v;

signed main()
{
	cin >> N >> H;
	int max = 0;
	REP(i, N)
	{
		cin >> a[i] >> b[i];
		max = MAX(max, a[i]);
	}

	REP(i, N)
	{
		if (max < b[i])
		{
			v.push_back(b[i]);
		}
	}
	RSORT(v);

	int ans = 0;
	for (int n : v)
	{
		H -= n;
		ans++;
		if (H <= 0)
		{
			cout << ans << endl;
			return 0;
		}
	}

	double d = H / (double)max;
	ans += ceil(d);
	cout << ans << endl;
}



Measured memory_bytes: 2936
n=int(input())
pprr = list(map(int,input().split()))
prr=[0]*n
for ix,p in enumerate(pprr):
    prr[p-1]=ix+1

arr=[]
brr=[]
cumsum=0
for p in prr:
    cumsum+=p
    arr.append(cumsum)
cumsum=0
print(" ".join(map(str,arr)))
for p in reversed(prr):
    cumsum+=p
    brr.append(cumsum)
print(" ".join(map(str,reversed(brr))))


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

int main() {
  int n;
  cin >>n;
  if(n==1){
    cout << "Hello" << " " <<"World";
  }
  else{
    int a,b;
  cin >> a >> b;
 
  cout << a+b << endl;
  }
}

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

int main() {
  ll n, nt = 1, na = 1, t, a, p;
  cin >> n;

  rep(i, n) {
    cin >> t >> a;
    p = max(ceil(nt / (long double)t), ceil(na / (long double)a));
    nt = p * t;
    na = p * a;
  }

  cout << nt + na << endl;
  return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

int check(int x,int y,int z,int w){
	if(x==1&&y==2&&z==3){
		return 0;
	}else if(x==1&&y==2&&w==3){
		return 0;
	}else if(x==1&&z==2&&w==3){
		return 0;
	}else if(y==1&&z==2&&w==3){
		return 0;
	}else if(x==2&&y==1&&z==3){
		return 0;
	}else if(y==2&&z==1&&w==3){
		return 0;
	}else if(x==1&&y==3&&z==2){
		return 0;
	}else if(y==1&&z==3&&w==2){
		return 0;
	}

	return 1;
}


int main(void)
{
	//変数の宣言
	int n;
	static ll int dp[110][4][4][4][4];

	//よく使う変数
	int i,j,k,l,p,q,r,s;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

/*	for(i=0;i<n;i++){
//		scanf("%d",&p[i]);
		scanf_s("%d",&p[i]);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<110;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<4;l++){
					for(p=0;p<4;p++){
						dp[i][j][k][l][p]=0;
					}
				}
			}
		}
	}

	if(n==3){
		printf("61");
		return 0;
	}else{
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				for(k=0;k<4;k++){
					for(l=0;l<4;l++){
						dp[3][i][j][k][l]=check(i,j,k,l);
					}
				}
			}
		}
	}

	for(i=4;i<n;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<4;l++){
					for(p=0;p<4;p++){
						for(q=0;q<4;q++){
							dp[i][j][k][l][p]=dp[i][j][k][l][p]+dp[i-1][q][j][k][l]*dp[3][j][k][l][p];
							dp[i][j][k][l][p]=dp[i][j][k][l][p]%MOD;
						}
					}
				}
			}
		}
	}

	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<4;l++){
					ans=ans+dp[n-1][i][j][k][l];
					ans=ans%MOD;
				}
			}
		}
	}


	//	printf("計算部分終了\n");

	//出力

	printf("%lld",ans);

/*	printf("\n");
	for(i=1;i<=n;i++){
		for(j=i;j<=n;j++){
			printf("hanten[%d][%d]={%d,%d}\n",i,j,hanten[i][j][0],hanten[i][j][1]);
		}
	}*/
	
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007;
const ll INF=1e18;

int K,A,B;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>K>>A>>B;
    int syote=A;
    K-=A-1;
    if(A+2<B){
        syote+=(K/2)*(B-A);
        if(K%2)syote+=1;
    }else{
        syote+=K;
    }
    cout<<syote<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

string eki = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main()
{
	int N;
	while(cin >> N && N)
	{
		vector<int> keys(N);
		rep(nth,N){
			cin >> keys[nth];
		}
		string S;
		cin >> S;
		
		string ans;
		int pos=0;
		rep( i, S.size() )
		{
			int num;
			if('a'<= S[i] && S[i] <= 'z'){
				num = S[i] - 'a';
			}
			else if('A' <= S[i] && S[i] <= 'Z'){
				num = S[i] - 39;
			}
			char res = eki[ ( num - keys[pos] + 52 ) % 52 ];
			pos = (pos+1)%N;
			ans += res;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
ld dp[3001][3001];
ld p[3001];

int main(){
	int n; 
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	dp[0][0] = 1ll - p[0];
	dp[0][1] = p[0];
	
	for(int i = 1; i < n; i++){
		for(int j = 0; j <= i + 1; j++){
			dp[i][j] = dp[i - 1][j] * (1ll - p[i]);
			if(j != 0)
				dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
	ld ans = 0;
	for(int i = n / 2 + 1; i <= n; i++){
		ans += dp[n - 1][i];
	}
	printf("%.9Lf", ans);
}





Measured memory_bytes: 139136
n = int(input())
a = list(map(int, input().split()))

max = a[0]
min = a[0]
sum_a = 0

for i in a:
    sum_a += i
    if max < i:
        max = i
    if min > i:
        min = i
        
print('{} {} {}'.format(min, max, sum_a))


Measured memory_bytes: 6596
#![allow(unused)]

use proconio::{input, fastout};
use proconio::marker::{Chars, Usize1};

#[fastout]
fn main() {
    input! {
        x: i64,
        y: i64
    }

    if y % 2 == 0 {
        let c = 2 * x - y / 2;
        let t = -x + y / 2;
        println!("{}", if c >= 0 && t >= 0 { "Yes" } else { "No" });
    } else {
        println!("No");
    }
}


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

int main() {
 list<UL> L;
 UL N; scanf("%u",&N);
 char command_buf[100] = {};
 rep(n,N){
  scanf("%s",command_buf);
  string S(command_buf);
  if(S=="insert"){
   UL v; scanf("%u",&v);
   L.push_front(v);
  }
  else if(S=="delete"){
   UL v; scanf("%u",&v);
   auto i=L.begin();
   while(i!=L.end()){
    if(*i==v) { i=L.erase(i); break; }
    i++;
   }
  }
  else if(S=="deleteFirst"){
   L.erase(L.begin());
  }
  else if(S=="deleteLast"){
   L.erase(--L.end());
  }
 }
 for(auto i=L.begin(); i!=L.end(); i++){
  if(i!=L.begin()) printf(" ");
  printf("%u",*i);
 } printf("\n");
 return 0;
}



Measured memory_bytes: 34560
import Control.Applicative
import Control.Monad
main = do
  [h, w] <- map (read :: String -> Int) . words <$> getLine
  if h == 0 && w == 0
    then return [()]
    else do
      replicateM h . putStrLn $ replicate w '#'
      putStrLn ""
      main

Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    int X, Y; cin >> X >> Y;
    if(2*X <= Y && Y <= 4*X && Y % 2 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3592
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll K, X; cin >> K >> X;
    FOR(i, X-K+1, X+K) cout << i << " ";
    cout << endstr;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  ll n=s.size()+1;
  vector<ll> d;
  char now=s[0];
  ll cnt=0;
  rep(i,n){
    if(now==s[i]){
      if(now=='<') cnt++;
      else cnt--;
      if(i==n-1){
        d.push_back(cnt);
      }
    }else{
      d.push_back(cnt);
      if(s[i]=='<') cnt=1;
      else cnt=-1;
      now=s[i];
    }
  }
  //cout_vec(d);
  vector<ll> a(d.size()+1);
  ll ans=0;
  rep(i,d.size()){
    if(d[i]>0){
      a[i]=0;
    }else{
      if(i==0){
        a[i]=-d[i];
        ans+=(-d[i])*(-d[i]+1)/2;
      }else{
        a[i]=max(d[i-1],-d[i]);
        if(d[i-1]<-d[i]){
          ans+=-d[i]*(-d[i]+1)/2;
          ans+=(d[i-1]-1)*d[i-1]/2;
        }else{
          ans+=d[i-1]*(d[i-1]+1)/2;
          ans+=(-d[i]-1)*(-d[i])/2;
        }
      }
    }
  }
  if(d.back()>0){
    ans+=d.back()*(d.back()+1)/2;
  }
  //cout_vec(a);
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    string s;
    bool ok=true;
    int cnt=0;
    cin>>s;
    while (cnt!=s.size())
    {
        if (s.substr(cnt, 5)=="dream")
        {
            if (s.substr(cnt+5, 2)=="er")
            {
                if (s.substr(cnt+7, 3)=="ase") cnt+=5;
                else cnt+=7;
            }
            else cnt+=5;
        }
        else if (s.substr(cnt, 5)=="erase")
        {
            if (s.substr(cnt+5, 1)=="r") cnt+=6;
            else cnt+=5;
        }
        else { ok=false; break; }
    }
    if (ok) cout<<"YES\n";
    else cout<<"NO\n";
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()


class UF{
private:
    vector<int> par,rank;
    int _size;
    int groups;
public:
    
    UF(int __size):_size(__size) , par(__size) , rank(__size,0) ,groups(1){
        for(int i=0;i<__size;i++)par[i]=i;
    }
    
    int size(){
        return _size;
    }
    
    int find(int x){
        if(par[x]==x) {
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        
        if(rank[x]<rank[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    UF uf(n);
    rep(i,q){
        int a,b,c;
        cin>>a>>b>>c;
        if(a==0)uf.unite(b,c);
        else    cout<<(uf.find(b)==uf.find(c))<<endl;
    }
}

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

int main()
{
    string S;
    cin >> S;
    S += '0';
    reverse(S.begin(), S.end());
    vector<int> digit(S.size(), 0);
    for (size_t i = 0; i < S.size(); i++)
    {
        digit[i] = S[i] - '0';
    }

    int power = 1;
    vector<int> accum(S.size(), 0);
    vector<int> ans(2019, 0);
    ans[0]++;
    for (size_t i = 1; i < S.size(); i++, power *= 10, power %= 2019)
    {
        accum[i] = power * digit[i] + accum[i - 1];
        accum[i] %= 2019;
        ans[accum[i]]++;
    }

    int ret = 0;
    for (int a : ans)
    {
        ret += a * (a - 1) / 2;
    }
    cout << ret << endl;
}


Measured memory_bytes: 5160
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
	int n,t=0;
	cin>>n;
	bool flag=true;
	vector<string> w(n);
for(int i=0;i<n;i++){
	cin>>w[i];
if(w[i]=="A")t++;
else{
	t--;
	if(t<0){
		flag=false;
		break;
	}
}
}
if(t==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3152
N = gets.to_i
a1 = gets.split.map(&:to_i)
a2 = gets.split.map(&:to_i)
(N-1).times do |i|
    a1[i+1] += a1[i]
    a2[i+1] += a2[i]
end

ans = 0
N.times do |i|
    result = a1[i] + a2[N-1]
    result -= a2[i-1] if i > 0
    ans = result if ans < result
end

puts ans

Measured memory_bytes: 3836
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 4500000;
char reader[sz];
char *pos = reader;
int nn;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    int now = nn;
    int ans = now;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7752
#include <iostream>
#include <algorithm>
#include <bitset>

#define num_cards_total_max 100000

int main (void)
{
	// variables for main process
	int num_cards_total;
	int num_cards_passable;
	int num_gates;
	int index_card_l_max;
	int index_card_r_min;

	// STEP.01
	// read out ...
	// 1. the number of the ID cards
	// 2. the number of the gates
	std::cin >> num_cards_total;
	std::cin >> num_gates;

	// STEP.02
	// construct a status list of the cards whether they can pass through all gates alone
	std::bitset<num_cards_total_max> list;

	// STEP.03
	// initialize the card status as all cards can pass through all gates independently
	for (size_t itr = 0; itr < num_cards_total; itr++) { list.set(itr); }

	// STEP.04
	// judge whether the cards can pass through all gates alone
	index_card_l_max = 0;
	index_card_r_min = num_cards_total;

	for (size_t itr = 0; itr < num_cards_total; itr++)
	{
		// STEP.04.01
		// read out the data whether the cards can pass through the gate
		int index_card_l_buf; std::cin >> index_card_l_buf;
		int index_card_r_buf; std::cin >> index_card_r_buf;

		// STEP.04.02
		// update the index of cards which can pass through all gates alone
		index_card_l_max = std::max(index_card_l_buf, index_card_l_max);
		index_card_r_min = std::min(index_card_r_buf, index_card_r_min);
	}

	// STEP.05
	// update the list of the cards whether they can pass through all gates alone
	for (size_t itr = 0;                   itr <  index_card_l_max - 1; itr++) { list.reset(itr); }
	for (size_t itr = num_cards_total - 1; itr >= index_card_r_min;     itr--) { list.reset(itr); }

	// STEP.05
	// output the number of cards which can pass through all gates alone
	std::cout << list.count() << std::endl;

	// STEP.END
	return 0;
}

Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

#pragma endregion 

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

	int n, x;
	cin >> n >> x;
	vi a(n);
	f_vI(a, n);
	LL ans = 0;
    if (a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}
	f(i, 0, n - 1) {
		if (a[i] + a[i + 1] > x) {
			ans += a[i + 1] - (x - a[i]);
			a[i + 1] = x - a[i];
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        Rep(j,0,i){
            if(a[j]>a[i])ans++;
        }
    }
    ans=ans*k%mod;
    int s=0;
    rep(i,n){
        rep(j,n){
            if(a[i]<a[j])s++;
        }
    }
    ans=(ans+s*((k*(k-1)/2)%mod)%mod)%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

void main(string[] args)
{
    long h, a;
    readf("%d %d", &h, &a);
    if (h % a == 0)
    {
        writeln(h / a);
    }
    else
    {
        writeln(h / a + 1);
    }
}


Measured memory_bytes: 256
n=int(input())
xu=[]
for i in range(n):
    xu.append(list(map(str,input().split())))
yen=0
for i in range(n):
    if xu[i][1]=='JPY':
        yen+=int(xu[i][0])
    else:
        yen+=float(xu[i][0])*380000
print(yen)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        long tmp = N/K;
        long ans = tmp*tmp*tmp;
        if (K%2==0) {
            long tmp_2 = (N+K/2)/K;
            ans += tmp_2*tmp_2*tmp_2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25172
#include <iostream>

using namespace std;

#define MAX_N 1000
#define MAX_M 1000

int N, M, trap[MAX_N + 1], dice[MAX_M + 1];

int main()
{
	while (true)
	{
		cin >> N >> M;

		if (N == 0 && M == 0) { break; }

		for (int i = 1; i <= N; i++)
			cin >> trap[i];

		for (int i = 1; i <= M; i++)
			cin >> dice[i];

		int masu = 1;

		int turn = 0;

		for (turn = 1; turn <= M; turn++)
		{
			masu += dice[turn]; if (masu >= N) { break; }
			masu += trap[masu]; if (masu >= N) { break; }
		}

		cout << turn << endl;
	}

	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
int arr[MAXX];
int countdigit(int num)
{
    int c=0;
    while(num)
    {
        c++;
        num/=10;
    }
    return c%2;
}
void trozen()
{
   int n;
   cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=countdigit(i);
    cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    cout << (a % b != 0) << endl;

}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    cout << n*n*n << '\n';
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
a=[int(i) for i in input().split()]
b=[max([a[i],0]) for i in range(N)]
S=[0 for i in range(N+1)]
T=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+a[i]
    T[i+1]=T[i]+b[i]
ans=0
for i in range(N-K+1):
    tmp=T[N]+S[i+K]-T[i+K]+T[i]-S[i]
    if ans<tmp:
        ans=tmp
for i in range(N-K+1):
    tmp=T[N]
    M=T[i+K]-T[i]
    tmp-=M
    if ans<tmp:
        ans=tmp
print(ans)



Measured memory_bytes: 17804
s_ = input()

s = [c for c in s_]

even=[]
odd=[]
for i in range(len(s)):
  if i%2==0:
    odd.append(s[i])
  else:
    even.append(s[i])
    
even_=[i for i in even if i!="L" and i!="U" and i!="D"]
odd_=[i for i in odd if i!="R" and i!="U" and i!="D"]

if even_==[] and odd_==[]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray(), t = scanner.next().toCharArray();
			System.out.println(IntStream.range(0, s.length).filter(i -> s[i] != t[i]).count());
		}
	}
}


Measured memory_bytes: 42088
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main(){
	int m,n;
	deque<int>deq;
 	while(1){
	    cin>>n;
	    if(cin.eof()) break;
	    if(n!=0) deq.push_back(n);
	    else {  
                     if(deq.empty()) { continue;}
                     else {     cout<<deq[(int)deq.size()-1]<<endl;
				deq.pop_back();}
            }
	}
        return 0;
}

Measured memory_bytes: 1200
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		m[readString()]++
	}

	fmt.Println(len(m))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 18308
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;
struct PrimalDual{
	struct edge{
		int to,cap,cost,rev;
	};
	vector<vector<edge>>graph;
	void add_edge(int from,int to,int cap,int cost){
		graph[from].push_back({to,cap,cost,len(graph[to])});
		graph[to].push_back({from,0ll,-cost,len(graph[from])-1});
	}
	int minCostFlow(int s,int t,int f){
		int V=len(graph);
		vector<int>potential(V),minCost,prevv(V,-1),preve(V,-1);
		vector<bool>used(V);
		int res=0;
		while(f>0){
			minCost.assign(V,inf);
			used.assign(V,0);
			minCost[s]=0;
			rep(_,V-1){
				int mn=inf,idx;
				rep(i,V)if(!used[i]&&chmin(mn,minCost[i]))idx=i;
				used[idx]=true;
				rep(i,len(graph[idx])){
					edge &e=graph[idx][i];
					int nextcost=mn+e.cost+potential[idx]-potential[e.to];
					if(e.cap>0&&minCost[e.to]>nextcost){
						minCost[e.to]=nextcost;
						prevv[e.to]=idx;preve[e.to]=i;
					}
				}
			}
			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			int addflow=f;
			for(int i=t;i!=s;i=prevv[i])chmin(addflow,graph[prevv[i]][preve[i]].cap);
			f-=addflow;
			res+=addflow*potential[t];
			for(int i=t;i!=s;i=prevv[i]){
				edge &e=graph[prevv[i]][preve[i]];
				e.cap-=addflow;
				graph[i][e.rev].cap+=addflow;
			}
		}
		return res;
	}
	PrimalDual(int V):graph(V){};
};

int N,M;
char c[55][55];
bool used[55][55];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>M;
	rep(i,N)rep(j,M)cin>>c[i][j];
	PrimalDual F(N*M+2);
	int cnt=0;
	rep(i,N)rep(j,M){
		if(c[i][j]=='o'){
			cnt++;
			memset(used,0,sizeof(used));
			F.add_edge(N*M,i*M+j,1,0);
			F.add_edge(i*M+j,N*M+1,1,mod);
			used[i][j]=true;
			rep(k,N)rep(l,M){
				if((k!=i||l!=j)&&used[k][l]){
					F.add_edge(i*M+j,k*M+l,1,mod-(k-i+l-j));
				}
				if(c[k+1][l]!='#')used[k+1][l]|=used[k][l];
				if(c[k][l+1]!='#')used[k][l+1]|=used[k][l];
			}
		}else F.add_edge(i*M+j,N*M+1,1,0);
	}
	cout<<cnt*mod-F.minCostFlow(N*M,N*M+1,cnt)<<"\n";
}

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff         first
  #define  ss         second
  #define  pb         push_back
  #define  all(x)     (x).begin(), (x).end()
  #define  rep(i,a,b) for(ll i=a ; i<b ; ++i)
  #define  D(x)       cout << #x << " - " << x << endl;
  #define  IOS        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D2(x)      cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  D2p(x)      cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)    fixed<<setprecision(y)<<x

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll MAX_N = 1e6+4;
  void solve(){
     int n;
     cin >> n;

     vector<int> v(10000);
     for(int i=1;i<=100;i++){
       for(int j=1;j<=100;j++){
         for(int k=1;k<=100;k++){
           if(i*i + j*j + k*k + i*j + j*k + i*k<=n)
          v[i*i + j*j + k*k + i*j + j*k + i*k]++;
         }
       }
     }
     for(int i=1;i<=n;i++){
       cout << v[i] << '\n';
     }
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//AtCoder以外ではコメントアウトを忘れずに！
#include <atcoder/all>
using namespace atcoder;
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; vs S;
int op(int a, int b) {
	return max(a, b);
}
int e() { return -1; }
int target;
bool f(int v) { return v < target; }
int main() {
	cin >> N >> Q;
	segtree<int, op, e> T(N);
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		T.set(i, a);
	}
	for (i = 0; i < Q; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		if (a == 1) {
			b--;
			T.set(b, c);
		}
		else if (a == 2) {
			b--;
			co(T.prod(b, c));
		}
		else {
			b--;
			target = c;
			co(T.max_right<f>(b)+1);
			//一見min_leftの方が素直に思えるが、N+1出力に対応するために敢えてmax_rightを使っている
		}
	}
}

Measured memory_bytes: 6196
import sys


def insert_sort(A, n, g):
    global cnt

    # 指定値のgからリストの大きさまで繰り返す
    for i in range(g, n, 1):
        # print(f"bef{A=}")
        # 最初にヒットした数値
        v = A[i]
        j = i - g
        # print(f"{j=}")
        while 0 <= j and v < A[j]:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
        # print(f"aft{A=}")


n = int(input())
A = [x for x in map(int, sys.stdin)]

cnt = 0
G = [1]
while n >= 3*G[-1] + 1:
    G.append(3*G[-1] + 1)


for g in G[::-1]:
    insert_sort(A, n, g)
print(len(G))
G.reverse()
print(*G)
print(cnt)
for a in A:
    print(a)




Measured memory_bytes: 45524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    rep(i, 5) {
        int x; cin >> x;
        if (x==0) {
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3588
import sys
from heapq import heappop, heappush


def main():
    input = sys.stdin.readline
    INF = 10**9 + 1
    Q = int(input())
    left = []
    right = []
    min_val = 0
    for _ in range(Q):
        q = list(map(int, input().split()))
        if q[0] == 1:
            a, b = q[1], q[2]

            # Update median
            heappush(left, -a)
            heappush(right, a)

            left_max = -heappop(left)
            right_min = heappop(right)

            heappush(left, -min(left_max, right_min))
            heappush(right, max(left_max, right_min))

            # Update minimum value of f(x)
            min_val += abs(right_min - left_max)
            min_val += b

        else:
            median = -heappop(left)
            print('{} {}'.format(median, min_val))

            heappush(left, -median)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19064
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int N = scanner.nextInt();
		int X = scanner.nextInt();
		int T = scanner.nextInt();
		
		scanner.close();
		
		int result = N / X;
		int amari = N % X;
		
		if (amari == 0) {
			System.out.println(result * T);
		} else {
			System.out.println(result * T + T);
		}
	}

}


Measured memory_bytes: 26928
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<char> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n) {
    vector<bool> aa(26,false), bb(26,false);
    rep(j,i) aa[a[j]-'a']=true;
    for(int k = n-1; k >= i; k--) bb[a[k]-'a']=true;
    int cnt = 0;
    rep(m,26) {
      if(aa[m]&&bb[m]) cnt++;
    }
    ans = max(ans,cnt);
  }  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	int n;
	cin>>n;
	vector<ll>a(n);
	//全てのりんごが偶数個の場合と、1つでも奇数個の場合を考えるとすべて０は前者に分類される.
	//自分の番で後者だった場合、奇数のりんごを全て食べれば良いので相手の負けが決定する。
	rep(i,n){
		cin>>a[i];
		if(a[i]%2){
			cout<<"first\n";
			return ;
		}
	}
	cout<<"second\n";
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    string S;
    cin >> S;
    
    for (int i = 0; i < S.size(); i++)
        if(S[i] =='?') S[i] = 'D';
    
    cout << S << endl;
    return 0;
}

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

int main(){
  long long n,m,i,j,cur,ans=0;
  cin >> n >> m;
  vector<long long> a(n),b(n);
  for(i=0; i<n; i++){
    cin >> a[i] >> b[i];
    a[i]=a[i]*100001+b[i];
  }
  sort(a.begin(), a.end());
  
  i=0;
  while(m>0){
    cur=a[i]%100001;
    if(m>cur){
      m-=cur;
      ans+=cur*(a[i]/100001);
    }else{
      cur=m;
      ans+=cur*(a[i]/100001);
      break;
    }
    i++;
  }
  
  cout << ans;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
vector<ll> vec;
int n;
double fans[1000]={0};
double func(ll a){
  if(a<1) return 0;
  if(a==1) return (double)(vec[0]+vec[1])/2;
  if(fans[a]>0) return fans[a];
  else return fans[a]=max((double)(func(a-1)+vec[a]),(double)func(a-2)+(double)(vec[a-1]+vec[a])/2)/2;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    vec.push_back(a);
  }
  sort(vec.begin(),vec.end());
  cout<<func(n-1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	string s; cin >> s;
	if(n % 2 != 0) {
		cout << "No" << endl;
	} else {
		for(int i = 0; i < n / 2; ++i) {
			if(s[i] != s[i + n / 2]) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',]
ex = [0]*26
for i in range(len(S)) :
    index = alpha.index(S[i])
    ex[index] += 1
    if ex[index] != 1 :
        print('no')
        exit()

print('yes')

Measured memory_bytes: 9132