akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
 
int main(void) {
  
  int N,B[100];
  
  //標準入力
  scanf("%d", &N);
  for(int i = 0; i < N - 1; i++)  {
    scanf("%d", &B[i]);
  }
  
  //Aの要素の総和の最大値sumを求める
  int sum = 0;
  sum += B[0];
  for(int i = 0; i < N - 2; i++) {
    if (B[i] <= B[i+1]) {
      sum += B[i];
    } else {
      sum += B[i+1];
    }
  }
  sum += B[N-2];
  
  //出力
  printf("%d\n", sum);
  
  return 0;
  
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define f first
#define s second
#define y1 asafsaf
#define kz ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
using namespace std;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll linf = 1e18;
const double pi = acos(-1.0);

int n, ans;

int main(){
    cin >> n;
    while(n--){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n, a,b,c,d = map(int, input().split())
s = input()

def check_twice(left, right, l):
    for i in range(left-1, right):
        if l[i] == '#' and l[i+1] == '#':
            return False
    return True

def check_triple(left, right, l):
    f = False
    for i in range(left-1, right-2):
        if l[i] == '.' and l[i+1] == '.' and l[i+2] == '.':
            f = True
            break
        else:
            continue
    return f

if c < d:
    flg = check_twice(a, c, s) & check_twice(b, d, s)
    if flg is True:
        print('Yes')
    else:
        print('No')

else:
    flg = check_twice(a, c, s) & check_triple(b-1, d+1, s)
    if flg is True:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

bool is_integer( double x ){
  return std::floor(x)==x;
}

int main(){
  string s;
  ll k;
  cin >> s >> k;
  rep(i, min((ll)s.size(), k)){
    if(s[i] >= '2'){
      cout << s[i];
      exit(0);
    }
  }
  cout << '1';
}


Measured memory_bytes: 256
X = int(input())
if 400<=X<=599:
    print('8')
elif 600<=X<=799:
    print('7')
elif 800<=X<=999:
    print('6')
elif 1000<=X<=1199:
    print('5')
elif 1200<=X<=1399:
    print('4')
elif 1400<=X<=1599:
    print('3')
elif 1600<=X<=1799:
    print('2')
elif 1800<=X<=1999:
    print('1')

Measured memory_bytes: 61640
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
for i in range(N):
  if A[i] - B[i] < 0:
    count += A[i]
    B[i] -= A[i]
    if A[i+1] - B[i] < 0:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] -= B[i]
  elif A[i] - B[i] == 0:
    count += A[i]
  else:
    count += B[i]
print(count)

Measured memory_bytes: 18624
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


def main():
    N = int(readline())

    n = isqrt(N)
    ans = INF
    for i in range(1, n + 1):
        if N % i == 0 and ans > N // i + i - 2:
            ans = N // i + i - 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
const long long mod = 1e9+7;
int main(){
	int n , m ;
	cin >> n >> m ;
	ll max_l=-1 , min_r=10000000;
	ll L , R;
	rep(i,m){
		cin >> L >> R;
		chmax(max_l,L);
		chmin(min_r,R);
	}
	if(min_r >= max_l){
	cout << min_r - max_l +1 <<endl;
	}
	else cout << 0 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll l,r;
  cin >> l >> r;
  if(r-l>2019) {
    cout << 0 << endl;
    return 0;
  }
  ll ans=inf;
  for(ll i=l;i<=r;i++) {
    for(ll j=i+1;j<=r;j++) {
      ans=min(i*j%2019,ans);
    }
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int nxt = 1, ans = 0;
    for (int i = 0; i < n; ++i){
        if (nxt == a[i]){
            ++nxt;
        }
        else{
            ++ans;
        }
    }
    if (ans == n) ans = -1;
    cout << ans << endl;
    return 0;
}

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

int main() {
	int N, A[50], MAX = 0, MIN = 0;
	cin >> N >> A[0];
	for (int i = 1; i < N; i++) {
		cin >> A[i];
		if (A[MAX] < A[i]) MAX = i;
		if (A[MIN] > A[i]) MIN = i;
	}
	cout << (N - 1) * 2 << endl;
	if (abs(A[MAX]) > abs(A[MIN])) {
		for (int i = 0; i < N; i++) {
			if (i == MAX) continue;
			cout << MAX + 1 << " " << i + 1 << endl;
		}
		for (int i = 1; i < N; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i == MIN) continue;
			cout << MIN + 1 << " " << i + 1 << endl;
		}
		for (int i = N; i > 1; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}
}

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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    set<string> S;
for (int i = 0; i < N; i++){
    string s;
    cin >> s;
    S.insert(s);
}
    cout << S.size() <<endl;
    return 0;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int n,q;
  cin>>n>>q;
  vector<queue<int> > Q(n);
  
  while(q--){
    int cmd;
    cin>>cmd;
    
    if(cmd == 0){
      int t, x;
      cin>>t>>x;
      Q[t].push(x);
    }
    if(cmd == 1){
      int t;
      cin>>t;
      if(!Q[t].empty()) cout<<Q[t].front()<<endl;
    }
    
    if(cmd == 2){
      int t;
      cin>>t;
      if(!Q[t].empty()) Q[t].pop();
    }
  }


  
  return 0;
}



Measured memory_bytes: 5120
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

long long n;


int main() {
	cin >> n;
	long long x = (sqrt(4*n+1)-1)/2-1e-9;
	long long ans = 0;
	for (int i = 1; i <= x; i++)
	{
		if (n%i==0)
		{
			ans += n / i - 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
g1 = set([1, 3, 5, 7, 8, 10, 12])
g2 = set([4, 6, 9, 11])
g3 = set([2])

ans = "No"
for g in [g1, g2, g3]:
    if x in g and y in g:
        ans = "Yes"
print(ans)
        

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

string to_string(string s) { return '\"' + s + '\"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A,B> p)
{ return "(" + to_string(p.F) + ", " + to_string(p.S) + ")"; }
template <typename T> string to_string(T v) {
	int f = 0; string res = "{";
	for (const auto &x: v)
		res += (f++ ? ", " : "") + to_string(x);
	return res + "}";
}
void debug_out() { cerr << "]\n"; }
template <typename T, typename... V>
void debug_out(T a, V... v)
{ cerr << to_string(a); if (sizeof...(v)) cerr << ", "; debug_out(v...); }

#ifdef LOCAL // add -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif // debug(var1, var2, ...);

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

	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	REP(i, l, r)
	{
		if (i % d == 0)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }

  ll ans = 0;
  sort(p.begin(), p.end());
  int cnt = 0;
  rep(i, m){
    if(p[cnt].second){
      ans += p[cnt].first;
      p[cnt].second--;
    }
    else{
      cnt ++;
      ans += p[cnt].first;
      p[cnt].second --;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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; }

int n;

ll calc(vector<ll> a, ll p) {
	ll temp = p;
	rep(i,n) {
		//cout << "i:" << i << " temp:" << temp << " a[i]:" << a[i] << endl;
		if(a[i] < temp && i%2 == 0) return -1;
		else if(a[i] < temp && i%2 == 1) return -2;
		else temp = a[i] - temp;
	}
		//cout << "p:" << p << " temp:" << temp << endl;
	if (p == temp) return 1;
	else if (p < temp) {
		//cout << "p:" << p << " temp:" << temp << endl;
		return -2;
	}
	else if (p > temp) {
		//cout << "p:" << p << " temp:" << temp << endl;
		return -1;
	}
}

ll binary_search(vector<ll> a, ll max) {
	ll left = 0, right = max;
	while(right >= left) {
		int mid = (right + left) / 2;
		//cout << "left:" << left << " right: " << right << " mid:" << mid << endl;
		//cout << "calc: " << calc(a,mid) << endl;
		ll temp = calc(a,mid);
		if(temp == 1) return mid;
		else if (temp == -1) right = mid - 1;
		else if (temp == -2) left = mid + 1;
	}
}
int main() {
	cin >> n;
	vector<ll> a(n);
	ll max = -1e18;
	rep(i,n) {
		cin >> a[i];
		chmax(max, a[i]);
	}
	vector<ll> ans(n);
	
	ans[0] = binary_search(a, max);
	for(int i=1; i<n; i++) {
		ans[i] = a[i-1] - ans[i-1];
	}
	rep(i,n) {
		cout << ans[i]*2;
		if (i != n-1) cout << " ";
		else cout << endl;
	}


  return 0;
}


Measured memory_bytes: 3552
#include <stdio.h>
#define N 100000
int LinerSearch(int A[], int n, int key){
        int i=0;
        A[n]=key;
        while(A[i]!=key) {
                i++;
        }
        return i != n;
}

int main(){
        int i,n,A[N+1],q,key,Sum=0;
        scanf("%d",&n);
        for(i=0; i<n; i++) {
                scanf("%d",&A[i]);
        }
        scanf("%d",&q);
        for(i=0; i<q; i++) {
                scanf("%d",&key);
                if(LinerSearch(A,n,key)) {
                        Sum++;
                }
        }
        printf("%d\n",Sum);
        return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int R;
    cin >> R;
    double PI = 3.141592653589793;
    printf("%.2f",2*PI*R);
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

inline D dot(P x, P y){return real(conj(x)*y);}
inline D cross(P x, P y){return imag(conj(x)*y);}

int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline bool is_cp(L a,L b){
  if(para(a,b))return false;
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

vector<P> p[2];
inline D len(D x, int id){
  L l = L( P(x,-1000), P(x,1000) );
  vector<P> res;
  rep(i,p[id].size()){
    L a = L( p[id][i], p[id][(i+1)%p[id].size()] );
    if(is_cp(a,l)){
      P cp = line_cp(a,l);
      if(!EQ(cp,p[id][i]))res.push_back(cp);
    }else if(para(a,l) && ccw(l.fs,l.sc,a.sc)==0){
      res.push_back(a.sc);
    }
  }

  if(res.size()<2)return 0;
  return abs(res[0]-res[1]);
}

inline D f(D x){
  return len(x,0) * len(x,1);
}

int main(){
  int m,n;
  while(cin >> m >> n, m){
    D minx[2], maxx[2];
    p[0].resize(m); p[1].resize(n);
    minx[0] = minx[1] = 1000;
    maxx[0] = maxx[1] = -1000;

    rep(i,m){
      D x,y;
      cin >> x >> y;
      p[0][i] = P(x,y);
      minx[0]=min(minx[0],x);
      maxx[0]=max(maxx[0],x);
    }

    rep(i,n){
      D x,z;
      cin >> x >> z;
      p[1][i] = P(x,z);
      minx[1]=min(minx[1],x);
      maxx[1]=max(maxx[1],x);
    }

    D ans = 0;
    for(D i=-100;i<100;i+=1){
      if(minx[0]<=i+0.5 && i+0.5<=maxx[0]){
	if(minx[1]<=i+0.5 && i+0.5<=maxx[1]){
	  ans += f(i)+4*f(i+0.5)+f(i+1);
	}
      }
    }
    cout << fixed << setprecision(9) << ans/6 << endl;
  }
}

Measured memory_bytes: 1328
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

struct Edge {
    int u, v, f;
    Edge(int u = 0, int v = 0, int f = 0) : u(u), v(v), f(f) {}
};

const int maxn = 105;

int n, m;
//vector<Edge> edge;
//vector<int> g[maxn];
//
//void add(int u, int v, int f) {
//    edge.push_back(Edge(u, v, f));
//    g[u].push_back(edge.size() - 1);
//}
int g[maxn][maxn];

int maxv;
int ans[maxn];
int picked[maxn];
void dfs(int k) {
    int sum = 0;
    for(int i = 1; i <= k; i++) if(picked[i]) {
        int minv = 1 << 29;
        for(int j = 1; j <= k; j++) if(picked[j] && i != j) {
            minv = min(minv, g[i][j]);
        }
        sum += minv == 1 << 29 ? 0 : minv;
    }
    maxv = max(maxv, sum);

    for(int i = k + 1; i <= n; i++) {
        int flag = 1;
        for(int j = 1; j <= k; j++) if(picked[j]) 
            {
            if(g[i][j] == 0) flag = 0;
        }
        if(flag) {
            picked[i] = 1;
            dfs(i);
            picked[i] = 0;
        }
    }
}
int main() {
    while(scanf("%d%d", &n, &m) != EOF) {
        memset(g, 0, sizeof(g));
        for(int i = 0; i < m; i++) {
            int u, v, f;
            scanf("%d%d%d", &u, &v, &f);
            g[u][v] = g[v][u] = f;
//            add(u, v, f);
//            add(v, u, f);
        }
        maxv = 0;
        memset(picked, 0, sizeof(picked));
        for(int i = 1; i <= n; i++) {
            picked[i] = 1;
            dfs(i);
            picked[i] = 0;
        }
        printf("%d\n", maxv);
    }
    return 0;
}

Measured memory_bytes: 1080
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		scanner.nextInt();
		int k = scanner.nextInt() -1;
		scanner.close();
		String string = br.readLine();

		char characters[] = new char[string.length()];
		for(int i=0; i<string.length(); i++) {
			characters[i] = string.charAt(i);
		}
		characters[k] = Character.toLowerCase(characters[k]);
		System.out.println(String.valueOf(characters));

	}

}


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

long A, B, C, K;

int main(void) {

    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << min(A, K) << endl;
    }
    else if (K <= A + B) {
        cout << A << endl;
    }
    else {
        cout << A - (K - A - B) << endl;
    }

    return 0;

}

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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
    
  int x;cin >> x;
  if(x <= 599)cout << 8 << '\n';
  else{
    cout << 10 - (x/200) << '\n';
  }
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
#define ll long long
#define mod 1000000007
ll int memo[1001][1001];
ll int function(char mat[1001][1001],ll int i,ll int j,ll int h,ll int w,ll int memo[1001][1001])
{
	if(i>h||j>w||mat[i][j]=='#')
	{
		//cout<<"hello";
		return 0;
	}
	if(i==h&&j==w)
	  return 1;
	if(memo[i][j]!=-1)
	{
		return memo[i][j];
	}
	else
	{
		ll int x=function(mat,i+1,j,h,w,memo);
		ll int y=function(mat,i,j+1,h,w,memo);
		ll int answer=(x+y)%mod;
		memo[i][j]=answer;
		return answer;
	}
}
int main()
{
	ll int h,w;
	cin>>h>>w;
	char mat[1001][1001];
	ll int i,j;
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		  cin>>mat[i][j];
    }
	for(i=0;i<=h;i++)
	{
		for(j=0;j<=w;j++)
		{
			memo[i][j]=-1;
		}
	}
	ll int answer=function(mat,1,1,h,w,memo);
	cout<<answer<<endl;
}

Measured memory_bytes: 9216
#include<stdio.h>

int main(){
  int i,n,a[100],j,tmp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %d",&a[i]);
  }
    for(j = 0;j<n;j++){
      printf("%d",a[j]);
      if(j + 1 != n) printf(" ");
      else printf("\n");
    }
  for(i=1;i<n;i++){
    for(j=i ; a[j]<a[j-1] && j!=0;j--) {
      tmp=a[j-1];
      a[j-1] = a[j]; 
      a[j] = tmp;
    }
    for(j = 0;j<n;j++){
      printf("%d",a[j]);
      if(j + 1 != n) printf(" ");
      else printf("\n");
    }
  }
return 0;
}



Measured memory_bytes: 2128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

bool IsValid(VV<long long> &G) {
    int N = G.size();
    repeat(k, N) {
        repeat(i, N) {
            repeat(j, N) {
                if (G[i][j] > G[i][k] + G[k][j]) {
                    return false;
                }
            }
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    auto A = vectors(0LL, N, N);
    repeat(i, N) {
        repeat(j, N) {
            cin >> A[i][j];
        }
    }
    if (!IsValid(A)) {
        cout << -1 << endl;
    } else {
        long long res = 0;
        const int INF = 1e9 + 7;
        repeat(k, N) {
            repeat(i, N) {
                repeat(j, N) {
                    if (i == k || j == k) continue;
                    if (A[i][j] == A[i][k] + A[k][j]) {
                        A[i][j] = INF;
                    }
                }
            }
        }
        repeat(i, N) {
            repeat_from(j, 0, i) {
                if (A[i][j] != INF) {
                    res += A[i][j];
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

vector<int> color;
void dfs(vector<vector<int>> &board, vector<vector<int>> &distance, int v){
    for(int j=0; j<board[v].size(); j++){
        int i=board[v][j];

        if(color[i] != -1){
            continue; //すでに色付けしてあるならスルー
        }
        if(distance[v][j] == 0){//もし距離が偶数なら同じ色
            color[i] = color[v];
            dfs(board, distance, i);
            continue;
        }
        if(distance[v][j] == 1){//もし距離が奇数なら違う色
            color[i] = 1 - color[v];
            dfs(board, distance, i);
            continue;
        }
    }
}

int main(){
    int N; cin >> N;

    vector<vector<int>> board(N+1);//つながっている橋
    vector<vector<int>> distance(N+1);//それぞれの距離

    for(int i=0; i<N-1; i++){
        int A, B, dis;
        cin >> A >> B >> dis;

        dis = dis%2; //偶数の時は０奇数の時は１となる

        board[A].push_back(B);
        board[B].push_back(A);

        distance[A].push_back(dis);
        distance[B].push_back(dis);
    }

    color.assign(N+1, -1);
    color[1] = 0;

    dfs(board, distance, 1);

    for(int i=1; i<=N; i++){
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 16732
#include <bits/stdc++.h>
#define ll long long
using namespace std ;
#define MAX 800
const int N = 1e6 + 5 ;
int arr[ N ] ;
int main()
{
    set < int > st ;
    int n , d ;
    cin >> n ;
    while(n--){
        cin >> d ;
        st.insert(d);
    }
    cout << st.size() << endl ;


}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
#include <random>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> P;
struct edge { ll to, cost; };

#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(i,0,n)
#define RREP(i,n) RFOR(i,n-1,-1)

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

/*
ll fact[100001], fact_inv[100001];
void calc_fact{
	fact[0]=1;
	REP(i,100000){
		fact[i+1]=mmul(fact[i],i+1);
		fact_inv[i+1]=minv(fact[i+1]);
	}
}
ll combi(int a, int b) {
	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
}
*/


int main(void) {
	int n, a, b;
	cin >> n;
	vector<int> deg(n);
	vector<vector<int>> edgs(n);
	map<P, int> res;
	vector<P> edgmemo;
	REP(ed, n-1) {
		cin >> a >> b;
		a--;
		b--;
		edgmemo.push_back(P(a, b));
		edgs[a].push_back(b);
		edgs[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	int k = 0;
	int first = 0;
	REP(i, n) {
		if (deg[i] > k) {
			k = deg[i];
			first = i;
		}
	}
	cout << k << endl;
	queue<int> st;
	vector<int> sk(n);
	st.push(first);
	while (!st.empty()) {
		int t = st.front();
		st.pop();
		int toskip = sk[t];
		int col = 1;
		for (int i : edgs[t]){
			P p = P(min(t, i), max(t, i));
			if (res[p] != 0) continue;
			if (col == toskip) col++;
			res[p] = col;
			sk[i] = col;
			col++;
			st.push(i);
		}
	}
	for (P p : edgmemo) {
		cout << res[p] << endl;
	}
	return 0;
}

Measured memory_bytes: 13812
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  string str;
  vector<string> strList;
  long num,loop,ii,jj,prevPos = 0;
  long sum = 0;
  cin >> str;
  num = str.length();
  loop = pow(2,num-1);

  
  for(ii=0;ii<loop;ii++){
	//cout << "ii" << ii << endl;
	strList.resize(0);
	prevPos = 0;
	for(jj=0;jj<=10;jj++){

	  //cout << str << endl;
	  if(ii & (int)pow(2,jj)){
		strList.push_back(str.substr(prevPos,jj-prevPos+1));
		prevPos = jj+1;
	  }
	}
	strList.push_back(str.substr(prevPos,num-prevPos));
	for(string s : strList){
	  sum += atol(s.c_str());
	  //cout << s << endl;
	}
	
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
def main():
    N = int(input())
    MOD = 10 ** 9 + 7

    if N == 1:
        print(0)
        return
    if N == 2:
        print(2)
        return
    print((pow(10, N, MOD) - (pow(9, N, MOD) * 2) + pow(8, N, MOD)) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  int dp[N];
  for (int i = 0; i < N; i++) {
    dp[i] = 999999999;
  }
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= K; j++) {
      dp[i] = min(dp[i],dp[max(0,i - j)] + abs(h[i] - h[max(i-j,0)]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = []
for _ in range(n) :
    s += [input()]
m = int(input())
t = []
for _ in range(m) :
    t += [input()]
wordlist = list(set(s))
s_countdict = {word : s.count(word) for word in wordlist}
t_countdict = {word : t.count(word) for word in wordlist}
pointlist = [s_countdict[word] - t_countdict[word] for word in wordlist]
print(max(max(pointlist), 0))

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

int main(){
    ll n,k;
    cin>>n>>k;
    ll s[100009]={0};
    rep(i,n){
        ll a=0,b=0;
        cin>>a>>b;
        s[a]+=b;
    }
    rep(i,100009){
        if(s[i]>0) k -= s[i];
        if(k<=0){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	int turn = 0;
	while (a > 0 and c > 0) {
		if (turn == 0) {
			c -= b;
			turn = 1;
		}
		else {
			a -= d;
			turn = 0;
		}
	}
	if (turn == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

int main ()
{
	string s;
    cin >> s;
    int a,b,c,d;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';

	if (a+b+c+d==7){
		cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
	}
	else if (a+b+c-d==7){
		cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
	}
	else if (a+b-c-d==7){
		cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
	}
	else if (a-b-c-d==7){
		cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
	}
	else if (a-b+c-d==7){
		cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
	}
	else if (a+b-c+d==7){
		cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
	}
	else if (a-b+c+d==7){
		cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
	}
	else if (a-b-c+d==7){
		cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<stack>
using namespace std;
int main(){
    int a;
    stack<int>car;
    while(scanf("%d",&a)!=EOF){
    if(a!=0){
        car.push(a);
    }
    else{
        int b=car.top();
        printf("%d\n",b);
        car.pop();
    }
    }
    return 0;
}

Measured memory_bytes: 1036
#include<stdio.h>

int main(void)
{
	int j, q, k, a;
	int h, m, s;
	int x;
	
	
	scanf("%d", &x);
	h = x / 3600;
	x = x % 3600;
	m = x / 60;
	s = x % 60;
	printf("%d:%d:%d\n",h, m, s);
	
	return 0;
}


Measured memory_bytes: 2116
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>

constexpr long long MOD = 1000000007;

int main()
{
  long long a[5];
  long long N;
  std::cin >> N;
  for (auto& val: a)
    std::cin >> val;
  std::sort(std::begin(a), std::end(a));
  if (N % a[0] == 0)
  {
    std::cout << (N / a[0]) + 5 - 1 << std::endl;
  }
  else
  {
    std::cout << ((N / a[0]) + 1) + 5 - 1 << std::endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

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

LLONG times[50][2501];

int main()
{
    int N; cin >> N;    // N <= 1e5
    // 色ごとの最大値（実際には符号反転するので最小値）
    // ai = 0 が最小なので，反転を考慮し初期値は1とする
    // 色ごとの最大値をmultisetで管理し，新しい値を越えるもののうち
    // 最小の値を更新していく:O(NlogN)
    multiset<int> maxValues{ 1 };
    for (int i = 0; i < N; ++i)
    {
        int ai; cin >> ai;
        // upper_boud()を使うため符号反転する
        ai *= -1;
        auto itr = maxValues.upper_bound(ai);   // O(log(Size))
        if (itr == maxValues.end())
        {
            maxValues.insert(ai);   // O(log(Size))
        }
        else
        {
            maxValues.erase(itr);   // O(1)
            maxValues.insert(ai);   // O(log(Size))
        }
    }
    cout << maxValues.size() << endl;
}

Measured memory_bytes: 4992
from sys import stdin
from fractions import gcd
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split())
g = a[0]
for x in a:
    g = gcd(g, x)
m = max(a)
if k > m or (m - k) % g:
    print "IMPOSSIBLE"
else:
    print "POSSIBLE"


Measured memory_bytes: 12644
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define N 300009
#define inf 2e16
#define pi pair<ll,ll>
#define pb push_back
using namespace std;
typedef long long ll;
void slv()
{
    int n;
    cin>>n;
    for(int i=1;i<=9;i++) {
        if(n%i==0)
        {
            int d=n/i;
            if(d>0 && d<10) 
            {
                puts("Yes");
                return ;
            }
        }
    }
    puts("No");
}
int main()
{
    ll tt;
    tt=1;
    while (tt--)
    {
        slv();
    }
    return 0;
}


Measured memory_bytes: 3572
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		System.out.println((""+sc.next().charAt(0))+(""+sc.next().charAt(1))+(""+sc.next().charAt(2)));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 39032
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int n,m,q;
vector<int> vec;
vector<int> a,b,c,d;

int dfs(int digit, int mind){
    int res = 0;
    if(digit == n){
        rep(i,0,q-1){
            if(vec[a[i]] + c[i] == vec[b[i]])res += d[i];
        }
        // vecprint(vec);
        // cout << res << endl;
        return res;
    }else{
        rep(i,mind,m){
            vec[digit] = i;
            res = max(res,dfs(digit+1, i));
        }
    return res;
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,0,q-1){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;b[i]--;
    }
    vec.resize(n);

    int ans = dfs(0,1);

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  char cur = s[0];
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (cur == s[i]) { continue; }
    ++ans;
    cur = (cur == 'W') ? 'B' : 'W';
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
n = int(input())
t, a = map(int, input().split())
data = list(map(int, input().split()))

#temp = []
diff = ''
index = ''
for i in data:
    #temp.append(t - i * 0.006)
    temp = t - i * 0.006
    if diff == '':
        diff = abs(temp - a)
        index = 1
    else:
        if abs(temp - a) < diff:
            diff = abs(temp - a)
            index = data.index(i) + 1
        else:
            continue
print(index)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	int a = 0, b = 0,tmp;
	REP(j, 4) {
		in >> tmp;
		a += tmp;
	}
	REP(i, 4) {
		in >> tmp;
		b += tmp;
	}
	int ans=a;
	if (a < b)ans = b;
	out << ans << endl;
	return 0;

}

Measured memory_bytes: 3064
n = gets.to_i
p = gets.split.map(&:to_i)
q = gets.split.map(&:to_i)

numbers = (1..n).to_a.map(&:to_s)
perms = numbers.permutation.map(&:join)

a = perms.find_index(p.map(&:to_s).join)
b = perms.find_index(q.map(&:to_s).join)

puts (a - b).abs


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, k;
    int64_t r, s, p;
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    int64_t ans = 0;
    for(int rem=0;rem<k;++rem){
        int64_t dp[3] = {0};
        if(t[rem] == 'r') dp[2] = p;
        if(t[rem] == 's') dp[0] = r;
        if(t[rem] == 'p') dp[1] = s;
        for(int i=1;i*k+rem<n;++i){
            const int j = i*k+rem;
            int64_t prev[3] = { dp[0], dp[1], dp[2] };
            dp[0] = max(prev[1], prev[2]);
            dp[1] = max(prev[2], prev[0]);
            dp[2] = max(prev[0], prev[1]);
            if(t[j] == 'r') dp[2] += p;
            if(t[j] == 's') dp[0] += r;
            if(t[j] == 'p') dp[1] += s;
        }
        ans += max({ dp[0], dp[1], dp[2] });
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

#define UQwoS(v) v.erase(unique(ALL(v)), v.end())
#define UQ(v) sort(ALL(v)); UQwoS(v)
#define LB(v, x) distance(v.begin(), lower_bound(ALL(v), x))
#define UB(v, x) distance(v.begin(), upper_bound(ALL(v), x))

#define PQ priority_queue
template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };

#define until(e) while(! (e))

const int M = 200000;
int n, q, d[M];
array<int, 3> a[M];

int main() {
	cin >> n >> q;
	inc(i, n) {
		int s, t, x;
		cin >> s >> t >> x;
		a[i] = { x, s - x, t - x };
	}
	inc(i, q) { cin >> d[i]; }
	sort(a, a + n);
	
	vector<int> v;
	inc(i, n) { v.PB(a[i][1]); }
	inc(i, n) { v.PB(a[i][2]); }
	inc(i, q) { v.PB(d[i]); }
	UQ(v);
	
	vector<vector<pair<bool, int>>> w(SI(v));
	inc(i, n) {
		w[LB(v, a[i][1])].EB(true,  i);
		w[LB(v, a[i][2])].EB(false, i);
	}
	
	set<int> ds;
	inc(i, q) { ds.insert(d[i]); }
	
	RPQ<int> Q;
	vector<bool> ok(n, false);
	inc(i, SI(v)) {
		RF(e, w[i]) {
			if(e.FI) {
				Q.push(e.SE);
				ok[e.SE] = true;
			} else {
				ok[e.SE] = false;
			}
		}
		
		if(ds.count(v[i]) == 1) {
			until(Q.empty() || ok[Q.top()]) { Q.pop(); }
			cout << (Q.empty() ? -1 : a[Q.top()][0]) << "\n";
		}
	}
	
	return 0;
}


Measured memory_bytes: 44780
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n;
  cin >> n;
  vector<ll> memo(n+10, 0);
  REPC(k, 1, n) {
    int i = k;
    while(i <= n) {
      memo[i]++;
      i += k;
    }
  }
  ll ans = 0;
  REPC(k, 1, n) {
    ans += k * memo[k];
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 81340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==1){
        cout<<"0"<<endl;
        return 0;
    }
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i]-i-1;
    }
    sort(b,b+n);
    long long sad1=0,sad2=0;
    for(int i=0;i<n;i++){
        sad1+=abs(a[i]-b[n/2]-i-1);
        sad2+=abs(a[i]-b[n/2+1]-i-1);
    }
    cout<<min(sad1,sad2)<<endl;
    return 0;
}

Measured memory_bytes: 1792
fun main( args : Array<String> ) {
  val N  = readLine()!!.toInt()
  val Ts = readLine()!!.split(" ").map { x -> x.toInt() }
  val M  = readLine()!!.toInt()
  val px = (1..M).map { x ->
    val (m, x) = readLine()!!.split(" ").map { x -> x.toInt() }
    Pair(m, x)
  }.toList().map { xy ->
    val (x, y) = xy
    val ts     = Ts.toMutableList()
    ts[x-1] = y
    println( ts.sum() )
  }

}

Measured memory_bytes: 38056
from collections import deque
H, W = map(int, input().split())
S = [input() for _ in range(H)]
white = sum(s.count(".") for s in S)
visited = [[-1] * W for _ in range(H)]
deq = deque([(0,0)])
visited[0][0] = 1
dia = [1, 0, -1, 0, 1]
while deq:
    i, j = deq.popleft()
    if i == H - 1 and j == W - 1:
        break
    d = visited[i][j]
    for x, y in zip(dia, dia[1:]):
        ii, jj = i + x, j + y
        if 0 <= ii < H and 0 <= jj < W and S[ii][jj] == "." and visited[ii][jj] < 0:
            visited[ii][jj] = d + 1
            deq.append((ii, jj))
print(white - visited[H-1][W-1] if visited[H-1][W-1] > 0 else -1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    ll N; cin >> N;
    map<ll,ll> mp;
    map<ll,ll> mp2;
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        mp[x]++;
    }
    ll M; cin >> M;
    for(int i=0;i<M;i++){
        int x;
        cin >> x;
        mp2[x]++;
    }
    bool ans=true;
    for(auto x:mp2){
        if(x.second>mp[x.first])ans=false;
    }
    if(ans)cout << "YES";
    else cout << "NO";
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    
    


}

/*



 */



Measured memory_bytes: 25216
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	m := make(map[int]int)
	for i, ai := range a {
		m[i] = ai - 1
	}

	count := 0
	for i := 0; i < n; i++ {
		mi := m[i]
		if i > mi {
			continue
		}
		mii := m[mi]
		if mii == i {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    ll N,A,B;
    cin >> N >> A >> B;
    ll X[N],ans = 0;
    REP(i,N) cin >> X[i];

    REP(i,N-1){
        if((X[i+1] - X[i])*A >= B){
            ans += B;
        }
        else ans += (X[i+1] - X[i])*A;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
D = list(map(int,input().split()))
Ta = [0]*13
Ta[0] = 1
for i in range(N):
    Ta[min(D[i],24-D[i])] += 1

if max(Ta)>=3:
    print(0)
elif Ta[0]>=2:
    print(0)
elif Ta[12]>=2:
    print(0)
else:
    L1 = []
    L2 = []
    for i in range(13):
        if Ta[i] ==1:
            if i==0 or i==12:
                L2.append(i)
            else:
                L1.append(i)
        elif Ta[i]==2:
            L2.append(i)
            L2.append(24-i)
    NL1 = len(L1)
    from itertools import product,combinations
    LS = list(product([0,1], repeat=NL1))
    NLS = len(LS)
    out = 0
    for i in range(NLS):
        L = LS[i]
        L3 = L2[:]
        score = 100
        for j in range(NL1):
            if L[j]==1:
                L3.append(L1[j])
            elif L[j]==0:
                L3.append(24-L1[j])
        CS = list(list(combinations(L3,2)))
        NCS = len(CS)
        for k in range(NCS):
            score = min(score,min(abs(CS[k][0]-CS[k][1]),24-abs(CS[k][0]-CS[k][1])))
        out=max(out,score)

    print(out)

Measured memory_bytes: 74056
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=1;i<n;i++){
    if(s[i]=='W') ans += 1;
  }
  //cout << ans << endl;
  int cand = ans;
  for(int i=1;i<n;i++){
    if(s[i-1]=='E') cand ++;
    if(s[i]=='W') cand --;
    ans = max(ans,cand);
  //cout << ans << endl;
  }
  cout << n-ans-1 << endl;
  return 0;
}


Measured memory_bytes: 900