akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

signed main(void)
{
	int n;
	long long cnt;
	map<long long, long long> mp, sp;

	cin >> n;
	rep(i, n)
	{
		int v;
		cin >> v;
		mp[(i + 1) + v]++;
		sp[(i + 1) - v]++;
	}
	cnt = 0;
	for(auto m : mp)
	{
		auto k = m.first;
		auto v = m.second;
		if (sp[k] > 0)
			cnt += v * sp[k];
	}
	cout << cnt <<  endl;
	return 0;
}


Measured memory_bytes: 37780
#ABC103D
n,m=map(int,input().split())
from collections import deque
branch=[]
for i in range(m):
    s,e=map(int,input().split())
    branch.append((s,e))
branch.sort(key=lambda x:x[1],reverse=True)
ans=0
before=0
while len(branch)>0:
    check=branch.pop()
    if before>=check[0]:continue
    else:
        before=check[1]-1
        ans+=1
print(ans)

Measured memory_bytes: 19652
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ELISDL {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, A, B;
        cin >> N >> A >> B;

        if (A + B - 1 > N) {
            cout << -1 << endl;
            return;
        }
        if (A * B < N) {
            cout << -1 << endl;
            return;
        }

        vector<int> res;
        int remain = N - A;
        int cur = N;
        REP(i, A) {
            int num = min(remain, B - 1);
            REP(j, num + 1) {
                res.push_back(cur - num + j);
            }
            remain -= num;
            cur -= (num + 1);
        }
        reverse(res.begin(), res.end());

        REP(i, N) cout << res[i] << " ";
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ELISDL solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 6128
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll h, w, n;
  cin >> h >> w >> n;

  const array<ll, 9> dy = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
  const array<ll, 9> dx = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  
  unordered_map<ll, ll> table;
  for(int i = 0; i < n; i++)
  {
	ll a, b;
	cin >> a >> b;
	for(int j = 0; j < dy.size(); j++)
	{
	  ll ny = a + dy[j] - 1;
	  ll nx = b + dx[j] - 1;
	  if(0LL <= ny && ny < h &&
		 0LL <= nx && nx < w)
	  {
		ll idx = ny * w + nx;
		if(table.find(idx) == table.end())
		{
		  table[idx] = 1;
		}
		else
		{
		  table[idx]++;
		}
	  }
	}
  }

  array<ll, 10> ans;
  fill(ans.begin(), ans.end(), 0);
  
  for(const auto &v : table)
  {
	const int y = v.first / w;
	const int x = v.first % w;
	if(1 <= x && x < w - 1 &&
	   1 <= y && y < h - 1)
	{
	  // cerr << "(y,x): (" << v.first / w << "," << v.first % w << ") = " << v.second << endl;
	  if(1 <= v.second && v.second <= 9)
	  {
		ans[v.second]++;
	  }
	}
  }
  
  ans[0] = (w - 2) * (h - 2);
  for(int i = 1; i <= 9; i++)
  {
	ans[0] -= ans[i];
  }
  for(auto v : ans)
  {
	cout << v << endl;
  }
}


Measured memory_bytes: 36624
#include<bits/stdc++.h>
using namespace std;int a,b,c,d[10000],e,i,m;int main(){cin>>a>>b>>c;for(;e<b;e++)cin>>d[e];sort(d,d+b);int m=d[b-1]-d[0]+min({abs(d[b-1]-c),abs(c-d[0]),abs(a-(d[b-1]-c)),abs(a-(c-d[0]))});for(;i<b-1;i++){m=min(m,a-(d[i+1]-d[i])+min({abs(d[i]-c),abs(d[i+1]-c),a-(abs(d[i] - c)),a-(abs(d[i + 1] - c))}));}cout << m*100<< endl;}

Measured memory_bytes: 3136
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    for i in range(1, n + 1):
      if n < 2:
        break
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
  except:
    pass
print((r, 0)[n > 1])

Measured memory_bytes: 22636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        r: u32,
    }
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
/*g++ main.cpp -o main.out*/
/*./main.out*/
/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(n,a) memset(n,a,sizeof(n));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

LL jc(LL n)
{
    LL ans=1;
    rer(i,1,n)ans=(ans*i)%Mod;
    return ans;
}

int main()
{
    NO_TLE
    int n,m;
    LL ans;
    cin>>n>>m;
    if(n-m>1||m-n>1)cout<<'0'<<endl;
    else if(n==m)
    {
        ans=(((jc(n)*jc(n))%Mod)*2)%Mod;
        cout<<ans<<endl;
    }
    else
    {
        ans=(jc(n)*jc(m))%Mod;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a=0,i=0;
    char s[17]="CODEFESTIVAL2016";
    char c[17]="\0";
    // 整数の入力
    scanf("%17s", c);

    for(i=0;i<16;i++){

        if(s[i]!=c[i]) a++;


    }





    // 出力
    printf("%d\n",a);
    return 0;
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
    if ( l >= r) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m + 1, r);
    post.push_back(root);
}

void solve() {
    pos = 0;
    rec(0, pre.size());
    for ( int i = 0; i < n; i++) {
        if ( i ) cout << " ";
        cout << post[i];
    }
    cout << endl;
}

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

    for ( int i = 0; i < n; i++ ) {
        cin >> k;
        pre.push_back(k);
    }

    for ( int i = 0; i < n; i++ ) {
        cin >> k;
        in.push_back(k);
    }

    solve();

    return 0;
}


Measured memory_bytes: 3168
def main():
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    B = [[a, d[a]] for a in d]
    count = 0
    if len(B) > K:
        B = sorted(B, key = lambda x: x[1])
        for i in range(len(B)-K):
            count += B[i][1]
    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 47772
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }.groupBy { it }
    val q = readLine()!!.toInt()

    val aMap = mutableMapOf<Int, Long>()
    var sum = 0L
    aa.forEach { a ->
        aMap[a.key] = a.value.size.toLong()
        sum += a.key * a.value.size
    }

    repeat(q) {
        val (b, c) = readLine()!!.split(" ").map { it.toInt() }
        if ((aMap[b] ?: 0L) > 0L) {
            sum -= b * aMap[b]!!
            sum += c * aMap[b]!!

            aMap[c] = (aMap[c] ?: 0L) + aMap[b]!!
            aMap[b] = 0L
        }
        println(sum)
    }
}

Measured memory_bytes: 80884
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a == 2 || b == 2) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


main(){
  ll n,ans=0,ans2=0;
  cin>>n;
  ll z=n/2;
  while(z>0){
    ans+=z/5;
    z/=5;
  }
  if(n%2==1)cout<<0;
  else cout<<ans;
}

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

int main(void){
    ll n; cin >> n; n--;
    ll ans = (1+n) * (n/2);
    if(n%2!=0) ans += (n/2) + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int a, b, c; cin >> a >> b >> c;
    set<int> num;
    num.insert(a);
    num.insert(b);
    num.insert(c);
    if(num.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct bian
{
	int nxt,to;
}bi[200020];
int n,head[100010],num,d[100010],rt,ans=0,m,sum,f[100010],g[100010],s[100010];
char c[100010];
inline void add(int from,int to){bi[++num]=bian{head[from],to},head[from]=num;}
bool cut[100010];
void dfs(int v,int fa)
{
	f[v]=2*s[v];
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa||cut[u])continue;
		dfs(u,v);
		ans=max(ans,f[v]+g[u]);
		ans=max(ans,f[u]+g[v]);
		f[v]=max(f[v],f[u]+2*s[v]);
		g[v]=max(g[v],g[u]+2*s[v]);
		g[v]=max(g[v],f[u]+2*s[v]);
	}
}
int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x),++d[x],++d[y];
	}
	scanf("%s",c+1);
	queue<int>q;
	m=n;
	for(int i=1;i<=n;++i)if(d[i]<=1&&c[i]=='B')q.push(i),cut[i]=1,--m;
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(int i=head[x];i;i=bi[i].nxt)
		{
			y=bi[i].to;
			--d[y];
			if(d[y]==1&&c[y]=='B')q.push(y),cut[y]=1,--m;
		}
	}
	for(int i=1;i<=n;++i)if(!cut[i]){rt=i;break;}
	if(!rt)return printf("0"),0;
	sum=(m-1)*2;
	for(int i=1;i<=n;++i)if(!cut[i])sum+=s[i]=(d[i]+(c[i]=='W'))&1;
	dfs(rt,0);
	printf("%d",sum-ans);
	return 0;
}


Measured memory_bytes: 8064
import sys
input = sys.stdin.readline
import math
def make_divisors(t):
    divisors = []
    for i in range(1, int(t**0.5)+1):
        if t % i == 0:
            divisors.append(i)
            if i != t // i:
                divisors.append(t//i)
    divisors.sort()
    return divisors

def solve():
  n = int(input())
  
  d  = make_divisors(n)
  ans = 0
  for i in d:
    if i-1 <= 1: continue
    else:
      if math.floor(n/(i-1)) == n%(i-1):
        ans += i-1
  print(ans)
solve()

Measured memory_bytes: 3288
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int A, P;
    cin >> A >> P;

    cout << (A * 3 + P) / 2 << endl;

    return 0;
}


Measured memory_bytes: 3192
let () =
  let a, b, c = Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c) in
  let ans = ref 0 in
  for d = a to b do
    if c mod d = 0 then ans := !ans + 1 else ()
  done;
  Printf.printf "%d\n" !ans

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

int main()
{
	long int a,b,i,k;

	while(cin>>a>>b){
		long int x=1, y=0;	//x最大公約数 y最小公倍数
		long int large ,small;

		//最小公倍数を求める処理
		if(a<b){small=a; large=b;}
		else{small=b; large=a;}
		for(i=large ;y==0 ;i+=large){
			if(i%small==0) y=i;
		}
		
		//最大公約数を求める処理
		long int ans[1000];
		i=2; k=0;
		while(a>=i && b>=i){
			if(a%i==0 && b%i==0){
				ans[k]=i;
				a/=i; b/=i;
				k++;
			}else{
				i++;
			}
		}
		for(i=0 ;i<k ;i++) x*=ans[i];

		cout<<x<<" "<<y<<endl;
	}
}

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

int main(){
  while(true){
  int n,m,value;
  value = 0;
  cin >> n >> m;
  if(n==0&&m==0) break;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i] > m){
      i--;
      n--;
    }
  }

  for(int i=0; i<n-1; i++){
    for(int j=1; j<n-i; j++){
      if(value<a[i]+a[i+j]&&a[i]+a[i+j]<=m){
        value = a[i]+a[i+j];
      }
    }
  }

  if(value==0){
    cout << "NONE" <<endl;
  }else{
    cout << value << endl;
  }
}
return 0;
}



Measured memory_bytes: 3004
#include <iostream>

using namespace std;

typedef long long ll;

int main(){


    ll x, y, i;
    cin >> x >> y;

    ll temp = x, cnt = 1;

    for (;;){
        if (temp * 2 <= y){
            temp = temp * 2;
            cnt++;
        } else {            
            break;
        }
    }


    cout << cnt << endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
    int n;
    string str;
    set<string> strlist;
    cin>>n;
    for(int l=0;l<n;l++){
        strlist.clear();
        cin>>str;
        int len=str.length();
        
        for(int i=0;i<len;i++){
            string str1=str.substr(0,i);
            string str2=str.substr(i,len-i);
            
            string revstr1=str1;
            reverse(revstr1.begin(),revstr1.end());
            
            string revstr2=str2;
            reverse(revstr2.begin(),revstr2.end());
            
            strlist.insert(str1+str2);
            strlist.insert(str1+revstr2);
            strlist.insert(revstr1+str2);
            strlist.insert(str2+str1);
            strlist.insert(str2+revstr1);
            strlist.insert(revstr2+str1);
            strlist.insert(revstr1+revstr2);
            strlist.insert(revstr2+revstr1);
        }
        cout<<strlist.size()<<endl;
    }
    return 0;
}

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

int main() {
	long long n, a, b, ans = 0; cin >> n >> a >> b;
	ans = n / (a + b) * a;
	long long tmp = n % (a + b);
	if (tmp) {
		ans += (tmp >= a ? a : tmp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
   ll n;
   cin>>n;
   ll i,j;
   ll a[n];
   for(i=0;i<n;i++)cin>>a[i];
   ll maxi = a[0];
   ll res=0;
   for(i=1;i<n;i++)
   {
       ll no = max(0ll,maxi-a[i]);
       res+=no;
       maxi=max(maxi,a[i]);
   }
   cout<<res<<"\n";
}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

using namespace std;

int n,m;

bool check(vector<string> &a){
	set<string> s;
	
	for(int i=0;i<m;i++){
		string cur,rev;
		for(int j=0;j<n;j++){
			rev+=a[j][i];
		}
		cur=rev;
		reverse(rev.begin(),rev.end());
		
		if(s.find(rev) == s.end()){
			s.insert(cur);
		}
		else{
			s.erase(rev);
		}
	}
	
	if(s.empty())
		return 1;
	else if(s.size()>1)
		return 0;
	else{
		auto cur = *s.begin();
		for(int j=0;j<n;j++){
			if(cur[j]!=cur[n-j-1])
				return 0;
		}
		return 1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	cin >> n >> m;
	vector<string> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	int runs = 100000;
	while(runs--){
		shuffle(a.begin(),a.end(),rng);
		if(check(a)){
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

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

using namespace std;

int main(){
    ll N,tmp;
    cin >> N;
    string  res = "No";

    ll han = N/2;//+1せんでいい
    ll cnt2 = 0; 
    ll cnt4 = 0; 

    REP(i,N)
    {
        cin >> tmp;
        if(tmp % 4 == 0)cnt4++;
        else if(tmp % 2 == 0)cnt2++;
    }

    if(cnt4 + cnt2/2 >= han)res = "Yes";

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,minn=10000;
  cin>>N;
  int arr[N],sum[N+1];
  sum[0]=0;
  for(int i=0;i<N;i++) {cin>>arr[i];sum[i+1]=sum[i]+arr[i];}
  for(int i=1;i<=N;i++) minn=min(minn,abs(sum[N]-2*sum[i]));
  cout<<minn;}

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

class Mondai
{
    static void Main()
    {
        var nk = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var K = nk[1];
        var N = nk[0];
        var S = Console.ReadLine();
        var newStr = string.Empty;
        for (int i=0;i<N;++i)
        {
            if (i == K - 1) newStr += Char.ToLower(S[i]);
            else newStr += S[i];
        }
        Console.WriteLine(newStr);
    }
}


Measured memory_bytes: 11220
using System;
 class Program{
    static void Main(){
    string[] str = Console.ReadLine().Split(' ');
    Array.Sort(str);
    int a=int.Parse(str[0]);
    int b=int.Parse(str[1]);
    int c=int.Parse(str[2]);
    Console.WriteLine("{0} {1} {2}",a,b,c);
    }
}


Measured memory_bytes: 18740
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

struct LowestCommonAncestor {
    size_t n;
    size_t size() const { return n; }
    vector<int> color, parent, depth, topDepth, goUp, visited;
    vector<vector<int>> g;
    LowestCommonAncestor(size_t n_) : n(n_), g(n) {}
    void addEdge(int u, int v){
        g[u].push_back(v); g[v].push_back(u);
    }
    void decomp(int root = 0, int B = 700){
        parent.assign(n, -1); depth.assign(n, 0);
        topDepth.assign(n, 0); goUp.assign(n, -1); visited.assign(n, false);
        vector<int> tord;
        vector<int> q(n+1); int l = 0, r = 0;
        q[r++] = root;
        while(l != r){
            int v = q[l++]; visited[v] = true;
            tord.push_back(v);
            for(int c : g[v]){
                if(!visited[c]){ parent[c] = v; depth[c] = depth[v] + 1; q[r++] = c; }
            }
        }
        swap(color, visited); // ?????¢????????±??????
        color.assign(n, 0);
        int c = 0;
        for(int u : tord){
            if(color[u]) continue;
            c++;
            l = 0, r = 0;
            q[r++] = u;
            for(int i = 0; i < B && l != r; i++){
                int v = q[l++];
                color[v] = c; goUp[v] = parent[u]; topDepth[v] = depth[u];
                for(int c : g[v]) if(!color[c]) q[r++] = c;
            }
        }
    }
    int solve(int u, int v){
        while(color[u] != color[v]){
            if(topDepth[u] > topDepth[v]) u = goUp[u];
            else v = goUp[v];
        }
        while(u != v){
            if(depth[u] > depth[v]) u = parent[u];
            else v = parent[v];
        }
        return u;
    }
};

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor g(n);
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g.addEdge(i,c);
        }
    }
    g.decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << g.solve(u,v) << endl;
    }
}

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


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, W, A, B;
  cin >> N >> W >> A >> B;
  for (int i = 0; i < N; ++i, cout << '\n') for (int j = 0; j < W; ++j) {
    cout << ((i < B) xor (j < A));
  }
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> dp(n, 1e9 + 10);
  for (int i = 0; i < n; ++i) {
    *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }
  cout << lower_bound(dp.begin(), dp.end(), 1e9 + 10) - dp.begin() << endl;
  return 0;
}


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i<3; i++) {
    for (int j = 0; j<3; j++) cin >> A.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i<N; i++) cin >> B.at(i);
  for (int i = 0; i<3; i++) {
    for (int j = 0; j<3; j++) {
      for (int k = 0; k<N; k++) {
        if (A.at(i).at(j) == B.at(k)) A.at(i).at(j) = 0;
      }
    }
  }
  bool ans = false;
  for (int i = 0; i<3; i++) {
    if (A.at(i).at(0)==0 && A.at(i).at(1)==0 && A.at(i).at(2)==0) ans = true;
  }
  for (int i = 0; i<3; i++) {
    if (A.at(0).at(i)==0 && A.at(1).at(i)==0 && A.at(2).at(i)==0) ans = true;
  }
  if (A.at(0).at(0)==0 && A.at(1).at(1)==0 && A.at(2).at(2)==0) ans = true;
  if (A.at(0).at(2)==0 && A.at(1).at(1)==0 && A.at(2).at(0)==0) ans = true;
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let nr=[n]
  let owari=false,i=1
  while(!owari){
    nr.push(nr[i-1]%2==0?nr[i-1]/2:3*nr[i-1]+1)
    i++
    for(let j=0;j<nr.length-1;j++){
      if(nr[j]==nr[nr.length-1]){
        t.o(i)
        return;
      }
    }
  }
}
main()

Measured memory_bytes: 7372
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val aList = LongArray(n) { readLong() }.sorted()

    val ans = if (n % 2 == 1) {
        val plus2Count = (n - 2 + 1) / 2
        val minus2Count = n - 2 - plus2Count
        val ans1 = - 2 * aList.take(minus2Count).fold(0L, Long::plus) -
                aList.drop(minus2Count).take(2).fold(0L, Long::plus) +
                2 * aList.takeLast(plus2Count).fold(0L, Long::plus)
        val ans2 = - 2 * aList.take(plus2Count).fold(0L, Long::plus) +
                aList.drop(plus2Count).take(2).fold(0L, Long::plus) +
                2 * aList.takeLast(minus2Count).fold(0L, Long::plus)
        max(ans1, ans2)
    } else {
        val plus2Count = (n - 2) / 2
        val minus2Count = plus2Count
        val ans1 = - 2 * aList.take(minus2Count).fold(0L, Long::plus) -
                aList.drop(minus2Count).first() +
                aList.drop(minus2Count).drop(1).first() +
                2 * aList.takeLast(plus2Count).fold(0L, Long::plus)
        ans1
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 52964
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int dp[110][100100];

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> w(N);
  vector<int> v(N);
  rep(i,N){
    cin >> w[i] >> v[i];
  }
  rep(i,N+1){
    rep(j,100100){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  rep(i,N){
    rep(j,100100){
      chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
      chmin(dp[i+1][j],dp[i][j]);
    }
  }
  int ans=0;
  rep(j,100100){
    if(dp[N][j]<=W) ans=j;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 41216
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    IOS;
    string s;
    cin>>s;
    bool f=true;
    for(int i=1;i<4;i++)
    {
        if(s[i]==s[i-1]) 
        {
            f=false;
            break;
        }
    }
    if(f) cout<<"Good\n";
    else cout<<"Bad\n";
}
 

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in);
  val n = sc.nextInt();
  val xys = Array.fill(n)((sc.nextInt, sc.nextInt));
  val xys2 = xys.map { case (x, y) => (x + y, x - y) }
  val x_min = xys2.map(_._1).min;
  val x_max = xys2.map(_._1).max;
  val y_min = xys2.map(_._2).min;
  val y_max = xys2.map(_._2).max;
  val answer = (x_max - x_min) max (y_max - y_min);
  println(answer);
}

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

int main()
{
    int i, j, k;
    int n, t, m;
    int h , w;
    double l;
    cin >> l;
    printf("%.7f\n", (l/3)*(l/3)*(l/3));
    return 0;
    cin >> n >> m;
    int ans = 0;
    if(n >= 2) {
        ans += n*(n-1)/2;
    }
    if(m >= 2) {
        ans += m*(m-1)/2;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
    LL n,m;
    cin>>n>>m;
    if(n%m == 0)
        cout<<"-1"<<endl;
    else
    {
         cout<<n*(m-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
r_list = [set() for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    r_list[A-1].add(B)
    r_list[B-1].add(A)
# print(r_list)
count = 0
for i in range(N):
    flag = True
    for j in range(len(r_list[i])):
        next_index = r_list[i].pop()
        # print('now {} next {}'.format(i+1, next_index))
        if H[i] <= H[next_index-1]:
            flag = False
    if flag:
        count += 1
print(count)

Measured memory_bytes: 45340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll;
 
int main() {
  int n , l ;
  cin >> n >> l ;
  int ans = 0 ;
  for( int i = n+l-1 ; i > l - 1 ; i-- ) ans += i ;
  
  if( l >= 0 ) cout << ans - l << endl ;
  else if( l < 0 && l + n - 1 < 0 )cout << ans- ( n+l-1 ) << endl ;
  else if( l < 0 && l + n - 1 >= 0 )cout << ans << endl ;
}

Measured memory_bytes: 256
primes = [2]

def is_prime(num):
    root = num ** 0.5
    for prime in primes:
        if root < prime:
            break
        if num % prime == 0:
            return False
    return True

def create_primes(primes, max):
    for i in range(primes[-1] + 1,max):
        if is_prime(i):
            primes += [i]

create_primes(primes, 10000)
count = 0
n = int(input())   
for _ in range(n):
    if is_prime(int(input())):
        count += 1
print(count)

Measured memory_bytes: 6848
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int x1=gi();
        int y1=gi();
        int x2=gi();
        int y2=gi();
        
        int dx=x2-x1;
        int dy=y2-y1;
        
        int x3=x2-dy;
        int y3=y2+dx;
        int x4=x3-dx;
        int y4=y3-dy;

        
        System.out.println(x3+" "+y3+" "+x4+" "+y4);
//        if (a>0) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 39940
a,b,h,m = gets.chomp.split(" ").map(&:to_i)

s = (h * 60 + m) * 360 / (12 * 60).to_f
t = m * 360 / 60.to_f

if s == t
  puts (b - a).abs
elsif s > t
  puts Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos((s - t) * Math::PI / 180.to_f))
else
  puts Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos((t - s) * Math::PI / 180.to_f))
end




Measured memory_bytes: 14724
#include <iostream>
using namespace std;
int main(void){
   
    int A, B, C;
    cin >> A >> B >> C;
    
    if(A == 5 && B == 5 && C == 7) cout << "YES" <<endl;
    else if(A == 5 && B == 7 && C == 5) cout << "YES" <<endl;
    else if(A == 7 && B == 5 && C == 5) cout << "YES" <<endl;
    else cout << "NO" <<endl;
 
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct
{
	int n, e, w, s, t, b;
} dice;

void dice_scan(dice *x)
{
	scanf("%d %d %d %d %d %d", &x->t, &x->s, &x->e, &x->w, &x->n, &x->b);
}

void dice_rorate_n(dice *x)
{
	int temp;
	temp = x->n;
	x->n = x->t;
	x->t = x->s;
	x->s = x->b;
	x->b = temp;
}

void dice_rorate_e(dice *x)
{
	int temp;
	temp = x->e;
	x->e = x->t;
	x->t = x->w;
	x->w = x->b;
	x->b = temp;
}

int main()
{
	dice d;
	char op[128];

	dice_scan(&d);
	scanf("%s", op);

	for(int i = 0; op[i]; ++i)
	{
		switch(op[i])
		{
			case 'S':
				dice_rorate_n(&d);
				dice_rorate_n(&d);
			case 'N':
				dice_rorate_n(&d);
				break;

			case 'W':
				dice_rorate_e(&d);
				dice_rorate_e(&d);
			case 'E':
				dice_rorate_e(&d);
				break;
		}
	}
	printf("%d\n", d.t);

	return 0;
}


Measured memory_bytes: 2112
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    int mi = INF, ma = -INF;
    int a;
    rep(i, N) {
        cin >> a;
        mi = min(mi, a);
        ma = max(ma, a);
    }
    cout << ma - mi << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,q;
  int a;
  int c=0;
  vector<int> s;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    s.push_back(a);
  }
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> a;
    int l=0,r=s.size(),m;
    while(l<r){
      m=(l+r)/2;
      if(s[m]==a){
	c++;
	break;
      }
      if(a<s[m])r=m;
      else l=m+1;
    }
  }
  cout << c << endl;
  return 0;
}

  

Measured memory_bytes: 3352
d, g = map(int,input().split())
p=[0]*d
c=[0]*d
for i in range(d):
    p[i], c[i] = map(int,input().split())
import numpy as np
import math
b = 2**d
pnum = np.array(p)
cnum = np.array(c)
ans = 10**30
score_comp = np.zeros(d)
for di in range(d):
    score_comp[di] = pnum[di]*(100*(di+1))+cnum[di]

for i in range(b):
    comp_str = bin(i)[2:].zfill(len(bin(b-1))-2)
    comp_num = np.array([float(j) for j in list(comp_str)])
    comp_cnt = int((comp_num*pnum).sum())
    total_comp_score = (comp_num*score_comp).sum()
    if total_comp_score >= g:
        if ans > comp_cnt:
            ans = comp_cnt
    else:
        rest = g-total_comp_score
        rest_id = comp_str.rfind('0')
        if rest_id>=0:
            rest_cnt = math.ceil(rest/(rest_id+1)/100)
            if pnum[rest_id] > rest_cnt:
                if (ans > comp_cnt + rest_cnt):
                    ans = comp_cnt + rest_cnt
print(ans)

Measured memory_bytes: 12508
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
    bool flagp=false,flagm=false,flag=false;
    int N,A[110000],temp=100000;
    ll tempm,tempp;
    ll ans=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0) flagm=true;
        else if(A[i]==0) flagp=true;
        else flagp=true;
        
        ans+=abs(A[i]);
        temp=min(temp,abs(A[i]));
    }
    if(!flagp) sort(A,A+N,greater<int>());
    else sort(A,A+N);
    if(flagm && flagp){
        cout<<ans<<endl;
        tempm=A[N-1]; tempp=A[0];
        for(int i=1;i<N-1;i++){
            if(A[i]<=0){
                cout<<tempm<<" "<<A[i]<<endl;
                tempm-=A[i];
            }else{
                cout<<tempp<<" "<<A[i]<<endl;
                tempp-=A[i];
            }
        }
        cout<<tempm<<" "<<tempp<<endl;
    }else{
        ans-=temp*2;
        cout<<ans<<endl;
        temp=A[0];
        for(int i=1;i<N-1;i++){
            cout<<temp<<" "<<A[i]<<endl;
            temp-=A[i];
        }
        if(flagp) cout<<A[N-1]<<" "<<temp<<endl;
        else cout<<temp<<" "<<A[N-1]<<endl;
    }
}


Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLine();
            var canPaper = false;
            var point = 0;
            foreach (var c in s)
            {
                switch (c)
                {
                    case 'g':
                        if (canPaper) ++point;
                        canPaper = !canPaper;
                        break;
                    case 'p':
                        if (!canPaper) --point;
                        canPaper = !canPaper;
                        break;
                }
            }
            WriteLine(point);
        }
    }

    public static class Utils
    {
        #region Extensions for IO

        public static long ReadLong()
            => ReadLine().ToLong();
        public static int ReadInt()
            => ReadLine().ToInt();

        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static IEnumerable<string> ReadStrings()
            => ReadLine().Split(' ');

        public static IEnumerable<string> ReadLines(int n)
        {
            foreach (var i in Enumerable.Range(0, n))
            {
                yield return ReadLine();
            }
        }

        #endregion

        #region Extensions of int

        public static bool IsOdd(this int n)
            => !n.IsEven();

        public static bool IsEven(this int n)
            => n % 2 == 0;

        public static bool CanDivideWith(this int n, int divisor)
            => n % divisor == 0;

        #endregion

        #region Extensions of string

        public static int ToInt(this string str)
            => int.Parse(str);

        public static long ToLong(this string str)
            => long.Parse(str);

        public static double ToDouble(this string str)
            => double.Parse(str);

        public static bool IsNullOrEmpty(this string str)
            => string.IsNullOrEmpty(str);

        #endregion

        public static TSource Min<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
            where TKey : IComparable
            => source.OrderBy(keySelector).First();

        public static TSource Max<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
            where TKey : IComparable
            => source.OrderByDescending(keySelector).First();

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }

        public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
            return source;
        }
    }
}


Measured memory_bytes: 3032
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
tr = set()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]: continue
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b+c and b < c+a and c < a+b:
                ans +=1
            # if l[i] < l[j]+l[k]: ans += 1
print(ans)


# tr = set()
# for i in range(n-2):
#     for j in range(i+1,n-1):
#         for k in range(j+1,n):
#             if l[i] == l[j] or l[j] == l[k]: continue
#             a = l[i]
#             b = l[j]
#             c = l[k]
#             t = [a,b,c]
#             t.sort()
#             t = tuple(t)
#             if a < b+c:
#                 if t in tr:continue
#                 ans +=1
#                 tr.add(t)
#             # if l[i] < l[j]+l[k]: ans += 1
# print(ans)





# for a in l:
#     for b in l:
#         for c in l:
#             if a == b or b == c: continue
#             if a<b+c or b < c+a or c < a+b:
#                 ans += 1
# print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
typedef long long ll;
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	bool a, b, c;
	a = b = c = false;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'a')
			a = true;
		if(s[i] == 'b')
			b = true;
		if(s[i] == 'c')
			c = true;
	}
	if(a && b && c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    ll x;
    cin>>x;
    ll a=100;
    int ans=0;
    while(a<x){
        ans++;;
        a=(long double)a*(long double)1.01;
    }
    OUT(ans);
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int>suki(m+1, 0);
  for(int i=0; i<n; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int a;
      cin >> a;
      suki[a]++;
    }
  }
  int cnt=0;
  for(int i=0; i<m+1; i++){
    if(suki[i]==n)cnt++;
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N, K;

int main() {
  cin >> N >> K;
  int n = 1;
  for (int i = 0; i < N; i++)
    n = min(2 * n, n + K);

  cout << n << endl;

  return 0;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int n;
    cin >> n;

    ll mon[n+1],ar[n+1];
    for (int i=0;i<n+1;i++) cin >> mon[i];
    for (int i=0;i<n;i++) cin >> ar[i];
    ar[n]=0;

    ll tot=0,bef=0;
    for (int i=0;i<n+1;i++){
        tot+=min(mon[i],bef);
        mon[i]=max(mon[i]-bef,(ll)0);

        tot+=min(mon[i],ar[i]);
        ar[i]=max(ar[i]-mon[i],(ll)0);
        bef=ar[i];
    }

    cout << tot << el;

    return 0;
}

Measured memory_bytes: 1792
N,K = list(map(int,input().split()))
a = list(map(int,input().split()))

S = [0]
s = 0
for i in range(N):
    s+=a[i]
    S.append(s)

S1 = [0]
s = 0

for i in range(N):
    s+=max(0,a[i])
    S1.append(s)
max_score=0
for i in range(N-K+1):
    max_score=max(S1[i]+max(S[i+K]-S[i],0) + S1[N]-S1[i+K],max_score)

print(max_score)

Measured memory_bytes: 71584
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000LL
#define MX2     1000000LL
#define Inf     1000000000000000LL
#define mod		1000000007LL
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/

    lli N,i,K;
    cin>>N>>K;

    lli Value=1;

    while(N--)
    {
        if(Value<=K)
        {
            Value+=Value;
        }
        else
        {
            Value+=K;
        }
    }

    cout<<Value;





 return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d
m = int(input())
D = 0
S = 0
for _ in range(m):
    d, c = list(map(int, input().split()))
    D += c
    S += c * d
result1 = D - 1
result2 = (S-1)//9
# print(D)
# print(S)
print(result1+result2)


Measured memory_bytes: 74552
#include <atcoder/fenwicktree>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);

    fenwick_tree<long long> fw(n);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        fw.add(i, a);
    }

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 0) {
            int p, x;
            scanf("%d %d", &p, &x);
            fw.add(p, x);
        } else {
            int l, r;
            scanf("%d %d", &l, &r);
            printf("%lld\n", fw.sum(l, r));
        }
    }
}

Measured memory_bytes: 8228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    rep(i,N)cin >> A[i];
    rep(i,N)cin >> B[i];
    rep(i,N-1)cin >> C[i];
    int ans=0;
    rep(i,N){
        ans+=B[i];
        if(i!=0 && A[i]==A[i-1]+1)ans+=C[A[i-1]-1];
    }
    cout << ans;
    


}

/*



 */



Measured memory_bytes: 256