akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int n, k;
            while((n = scn.nextInt()) > 0 | (k = scn.nextInt()) > 0) {
                int[] s = new int[k];
                for(int i = 0; i < k; i++) {
                    s[i] = scn.nextInt();
                }
                for(int i = 0; i < n; i++) {
                    for(int j = 0; j < k; j++) {
                        s[j] -= scn.nextInt();
                    }
                }
                Arrays.sort(s);
                System.out.println(s[0] < 0 ? "No" : "Yes");
            }
        }
    }
}

Measured memory_bytes: 101724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  string s;
  cin >> s;
  rep(i, 3) cout << s[i];
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define maxn 200000+5
#define inf 0x3f3f3f3f
using namespace std;

string a[maxn];
string s;
map<string,int> st;

int main(){
	int n;
	cin>>n;
	int maxx = -inf;
	for(int i=0;i<n;i++){
		cin>>a[i];
		st[a[i]]++;
		maxx = max(st[a[i]],maxx);
	}
	int len = st.size();
	for(auto i=st.begin();i!=st.end();i++){
		//cout<<i->first<<" "<<i->second<<endl;
		if(i->second == maxx){
			cout<<i->first<<endl;
		}
	}
	return 0;
} 


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

int main()
{
    int a,b;

    cin >> a >> b;

    if(a>b){
        cout << "a > b" << endl;
    }
    else if(a<b){
        cout << "a < b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }

    return 0;
}


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

int main()
{
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(ll i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    cout<<endl;
    return 0;

}

Measured memory_bytes: 8236
#include<iostream>
using namespace std;
int n,m,pd[100001],x1[100001],y1[100001],ans;
int main() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		int x,y;
		char c;
		cin>>x>>y>>c;
		x%=2*m,y%=2*m;
		if(c=='W')pd[i]=1;
		else pd[i]=0;
		x1[i]=x;
		y1[i]=y;
	}
	for(int i=0; i<=m; i++) {
		int big=0,hh[10001]={0};
		for(int j=1; j<=n; j++) {
			int p=(i<=x1[j]&&x1[j]<i+m);
			int q=(0<=y1[j]&&y1[j]<m);
			if(p^q==pd[j]) {
				big++;
				hh[y1[j]]++;
			}
			else{
				hh[y1[j]]--;
			}
		}
		for(int j=0; j<=m; j++) {
			ans=max(big,max(ans,n-big));
			if(j!=m)big=big-hh[j]-hh[j+m];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    t = min(A[i], B[i])
    ans += t
    A[i] -= t
    B[i] -= t
    s = min(A[i+1], B[i])
    ans += s
    A[i+1] -= s
print(ans)

Measured memory_bytes: 19156
first = input()
first = first.split()

K = int(first[0])
N = int(first[1])

second = input()
second = second.split()

distance = []
diff = 0

for i in range(0, N):
    if i == N-1:
        diff0 = 0
        diff1 = 0
        diff0 = int(second[0])
        diff1 = K - int(second[i])
        diff = diff0 + diff1
        distance.append(diff)
    else:
        diff = int(second[i+1]) - int(second[i])
        distance.append(diff)
        
MaxIndex = distance.index(max(distance))
distance.pop(MaxIndex)
Max = sum(distance)
print(Max)

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

using namespace std;

int main() {
  int A, B, C, K;
  int ans=0;
  cin >> A >> B >> C >> K;
  // A >= K なら K
  // A+B >= K なら A
  // A+B+C >= K なら A - (K-(A+B))
  if(A>=K) ans = K;
  else
  if(A+B>=K) ans = A;
  else
  if(A+B+C>=K) ans = A - (K-(A+B));
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int A, B, C, X, Y;

    scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);

    if(2 * C > (A + B)){
        printf("%d\n", A * X + B * Y);
    }else{
        if(X < Y){
            if(C * 2 * X + B * (Y - X) < C * 2 * Y){
                printf("%d\n", C * 2 * X + B * (Y - X));
            }else{
                printf("%d\n", C * 2 * Y);
            }
        }else{
            if(C * 2 * Y + A * (X - Y) < C * 2 * X){
                printf("%d\n", C * 2 * Y + A * (X - Y));
            }else{
                printf("%d\n", C * 2 * X);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1724
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

int main(){
	int N,K;
	cin>>N>>K;
	vector<rn> dp(K,0.0L);
	for(int i = K - 1;i >= 1;i--){
		if(i*2>=K){
			dp[i] += 0.5L;
		}else{
			dp[i] += 0.5L*dp[i*2];
		}
	}
	rn ans = 0.0L;
	for(int i = 1;i <= N;i++){
		if(i<=K-1){
			ans += 1.0L/(rn)N*dp[i];
		}else{
			ans += 1.0L/(rn)N;
		}
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, factorial, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N, K = 0, 0


def set_inputs():
    global N, K
    N, K = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    sum_abc = itertools.dropwhile(
        lambda x: x < 3,
        itertools.takewhile(
            lambda x: x <= 3 * N,
            itertools.count(2 * K, K)
        )
    )
    ans = 0
    if K % 2 == 0:
        # a + b + c = (l + m + n) * (K // 2)
        # a, b, c >= 1
        x = N // K
        y = N // (K // 2) - x
        ans = x ** 3 + y ** 3
    else:
        # 2 * (a + b + c) = (l + m + n) * K
        x = N // K
        ans = x ** 3
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3696
#include<stdio.h>
#include<string.h>
int main()
{
  int a=0,i,j,ans=0;
  char x[1000];
  while(1){
    scanf("%s",x);
    if(x[0]=='0')break;
    int len=strlen(x);
    for(i=0;i<len;i++){
      x[i]-='0';
      ans+=x[i];
    }
    printf("%d\n",ans);
    a++;
    ans=0;
  }
  return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define ll long long 
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b) 
#define forn(n) for(ll i=0;i<n;i++) 
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
const int MOD = 1e9 + 7;
const int v1=1e5+5;
#define pi 3.141592653589793238
const int N=2e5+5;
 
 
//cout<<"Case #"<<p<<": "<<;
//f ile input  freopen("input.txt","r",stdin); 
//file output freopen("output.txt","w",stdout);
 
using namespace std;

int32_t main()
{
  IOS;
  ll n=0;
    cin>>n;
  ll a[n][3]={};
  forn(n)
  cin>>a[i][0]>>a[i][1]>>a[i][2];
  vector <ll> dp(n);
  for(ll i=1;i<n;i++)
  {
    a[i][0]+=max(a[i-1][1],a[i-1][2]);
    a[i][1]+=max(a[i-1][0],a[i-1][2]);
    a[i][2]+=max(a[i-1][0],a[i-1][1]);
  }
  cout<<max3(a[n-1][0],a[n-1][1],a[n-1][2]);
}

Measured memory_bytes: 3328
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
const int max_n = 400005;

ll n, m, a[max_n], bit[max_n];
vl v;
ll update(ll pos,ll val){
    while(pos<n+5){
        bit[pos]+=val;
        pos+=pos&(-pos);
    }
}
ll query(ll pos){
    ll sum=0;
    while(pos>0){
        sum+=bit[pos];
        pos-=pos&(-pos);
    }
    return sum;
}
ll solve(ll mid){
    ll arr[max_n],i,c,ans=0,minn=inf,val;
    rep(i,n+5){
        bit[i]=0;
    }
    rep(i,n){
        if(a[i]<=mid){
            arr[i]=1;
        }
        else{
            arr[i]=-1;
        }
        arr[i]=i>0?arr[i-1]+arr[i]:arr[i];
        minn=min(minn,arr[i]);
    }
    if(minn<=0){
        rep(i,n){
            arr[i]-=minn;
            arr[i]++;
        }
        //cout<<"hi"<<endl;
    }
    else{
        minn=1;
    }
    c=0;
    ll maxx=-1;
    fd(i,n-1,0){
        maxx=max(maxx,arr[i]);
        update(arr[i],1);
        if(i==0){
            val=-1*minn+1;
        }
        else{
            val=arr[i-1];
        }
        ans+=query(maxx)-query(val);
        //cout<<(maxx)<<" "<<i<<" "<<ans<<endl;
    }
    return ans;
}
int main(){
    std::ios::sync_with_stdio(false); 
    ll val,lo,hi,ans,i;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        v.pb(a[i]);
    }
    sort(all(v));
    v.resize(unique(v.begin(),v.end())-v.begin());
    lo=0;
    hi=(int)v.size()-1;
    val=n*(n+1);
    val/=2LL;
    val=(val/2)+1;
    while(lo<=hi){
        int mid=(lo+hi)/2;
        if(solve(v[mid])>=val){
            ans=v[mid];
            hi=mid-1;
        }
        else{
            lo=mid+1;
        }
    }
    //cout<<solve(20)<<endl;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,k,a[1010],sum =0;
    cin>>n>>k;
    for(int i =0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int j=0;j<k;j++){
        sum +=a[j];
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 3584
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();

    let mut dp = vec![0; 100001];
    for m in 1..100001 {
        dp[m] = 1000000;
        let mut p = 1;
        while p <= m {
            dp[m] = std::cmp::min(dp[m], 1 + dp[m - p]);
            p *= 6;
        }
        p = 1;
        while p <= m {
            dp[m] = std::cmp::min(dp[m], 1 + dp[m - p]);
            p *= 9;
        }
    }
    println!("{}", dp[n]);
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void solve() {
	int n, y; scanf("%d%d", &n, &y);
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n-i; ++j) {
			int x = i*10000+j*5000+(n-i-j)*1000;
			if (x == y) {
				printf("%d %d %d", i, j, n-i-j);
				return;
			}
		}
	}
	printf("-1 -1 -1");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp1[5000][5000];
int dp2[5000][5000];
long long b[5000];
long long c[5000];
int main(){
	int a;
	scanf("%d",&a);
	//while(~scanf("%d",&a)){
		for(int i=0;i<a;i++){
			scanf("%lld",b+i);
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=a;j++){
				dp1[i][j]=999999999999999LL;
				dp2[i][j]=0;
			}
			dp1[i][i]=0LL;
			dp2[i][i]=i;
		}
		for(int i=0;i<=a;i++)c[i]=0LL;
		for(int i=0;i<a;i++)c[i+1]=c[i]+b[i];
		for(int w=1;w<=a;w++){
			for(int i=0;i+w<a;i++){
				int j=i+w;
				for(int k=dp2[i][j-1];k<=dp2[i+1][j];k++){
					long long val=dp1[i][k]+dp1[k+1][j]+(c[j+1]-c[i]);
					if(val<dp1[i][j]){
						dp1[i][j]=val;
						dp2[i][j]=k;
					}
				}
			}
		}
	//	for(int i=0;i<=a;i++){
	//		for(int j=0;j<=a;j++)
	//			printf("%15lld ",dp1[i][j]);
	//		printf("\n");
	//	}
		printf("%lld\n",dp1[0][a-1]);
	
}

Measured memory_bytes: 240624
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  if(n<a) cout<<0;
  else cout<<10;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, k;

int main() { 

  cin >> n >> k;

  int ans = 1;
  ans += (n - k + k - 2) / (k - 1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

N, Q = map(int, input().split())
l, q = [], []
u = set()

for _ in range(N):
    S, T, X = map(int, input().split())
    l.append((S-X, 1, X))
    l.append((T-X, 0, X))

for i in range(Q):
    l.append((int(input()), 2, i))

l.sort()

for _, m, x in l:
    if m==0:
        u.remove(x)
    elif m==1:
        heappush(q, x)
        u.add(x)
    else:
        while q:
            if q[0] not in u:
                heappop(q)
            else:
                break
        print(q[0] if q else -1)


Measured memory_bytes: 96932
#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <complex>
#include <limits>
#include <random>

#define int64 long long int

const int M = 1e9 + 7;

void MultL(int64 &a, int64 b) {
    a = (a * b) % M;
}
void AddL(int64 &a, int64 b) {
    a = (a + (b + M)) % M;
}

int64 Mult(int64 a, int64 b) {
    return (a * b) % M;
}
int64 Add(int64 a, int64 b) {
    return (a + (b + M)) % M;
}

using namespace std;



int main() {
    std::ios::sync_with_stdio(false);

    string str;
    cin >> str;
    int r = 0;
    for (int i =0 ; i < str.size(); ++i) {
        if (str[i] == '+') ++r;
        else --r;
    }
    cout << r << endl;

    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL a,b,c,d,e,n,m,l,r,x,y,z,ans=0,ans2=0;
string s,S,t;
int main() {
ios_base::sync_with_stdio(false);
  cin >> n;
vLL(A,n);
REP(i,n){
    if((i+1)%2!=0&&A[i]%2!=0)ans++;
}
cout <<ans;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<vector>
std::vector <int> ve[100050];
int m,n,ans[100050],pre[100050],suf[100050],dp[100050];
void dfs(int u,int fa){
	int lim=ve[u].size(),y;
	dp[u]=1;
	for (int i=0;i<lim;i++)if ((y=ve[u][i])!=fa){
		dfs(y,u);
		pre[y]=dp[u];
		dp[u]=(dp[y]+1)*1ll*dp[u]%m;
	}
	int k=1;
	for (int i=lim-1;i>=0;i--)if ((y=ve[u][i])!=fa){
		suf[y]=k;
		k=(dp[y]+1)*1ll*k%m;
	}
}
void get_ans(int u,int fa,int t){
	ans[u]=(t+1)*1ll*dp[u]%m;
	int lim=ve[u].size(),y;
	for (int i=0;i<lim;i++)if ((y=ve[u][i])!=fa)get_ans(y,u,(t+1)*1ll*pre[y]%m*suf[y]%m);
}
int main(){
	int u,v;
	scanf("%d%d",&n,&m);
	for (int i=1;i<n;i++)scanf("%d%d",&u,&v),ve[u].push_back(v),ve[v].push_back(u);
	dfs(1,0);
	get_ans(1,0,0);
	for (int i=1;i<=n;i++)printf("%d\n",ans[i]);
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

set<int> S[32];

int32_t main()
{
    IOS
    int n,q;
    string s;
    cin>>n>>s>>q;
    for (int i=0;i<n;i++)
        S[s[i]-'a'].insert(i+1);
    for (int i=1;i<=q;i++)
    {
        int type;
        cin>>type;
        if (type==1)
        {
            int id;
            char c;
            cin>>id>>c;
            S[s[id-1]-'a'].erase(id);
            S[c-'a'].insert(id);
            s[id-1]=c;
        }
        else
        {
            int l,r;
            cin>>l>>r;
            int ans=0;
            for (int j=0;j<26;j++)
                if (S[j].lower_bound(l)!=S[j].end()&&(*S[j].lower_bound(l))<=r) ans++;
            cout<<ans<<endl;
        }
    }
}



Measured memory_bytes: 24220
#include<iostream>
#include<string>
int main(){
    std::string num;
    int flg=1;
    std::cin>>num;
    for(int i=1;i<num.size();i++){
        if(num[i]==num[i-1])flg++;
        else if(!(flg>=3))flg=1;
    }
    if(flg>=3)printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
a = []
b = list(map(int, input().split()))

for i in range(n):
    a.append(list(map(int, input().split())))

count = 0
for i in range(n):
    x = 0
    for j in range(m):
        x += a[i][j] * b[j]
    x += c

    if x > 0:
        count += 1
            
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MAX (ll)(4e3 + 4)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18 + 3)
#define PI (double)(3.14159265)

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	int x;
	cin >> x;
	int re = x % 100;
	int di = x / 100;
	int cc = 5, co = 0;
	while (cc) {
		co += re / cc;
		re = re % cc;
		cc--;
	}
	cout << (di >= co) << "\n";
}
		
		
		



Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;



int main()
{
	int a;
	cin >> a;
	ll ans = a + a * a + a * a * a;
	cout << ans;

}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		 String strLine = br.readLine();
		 
		 String[] lineArray = strLine.split(" ");
		 int height	= Integer.parseInt(lineArray[0]);
		 int width	= Integer.parseInt(lineArray[1]);
		 
		 System.out.printf("%d %d\n", height * width, 2 * (height + width)); 	  
	}
}


Measured memory_bytes: 24652
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int i=0;i<=N-1;i++){
            a[i] = sc.nextInt();
        }
        int count = 0;
        for(int i=0;i<N-1;i++){
            for(int j=N-1;j>i;j--){
                if (a[j-1] > a[j]){
                    int tmp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = tmp;
                    count++;
                }
            }
        }
        for(int i=0;i<N-1;i++){
            System.out.printf("%d ",a[i]);
        }
        System.out.printf("%d",a[N-1]);
        System.out.printf("\n%d\n",count);
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
   int d,g;
   cin>>d>>g;
   int p[d],c[d];
   rep(i,d){
       cin>>p[i]>>c[i];
   }
   int ans=INF;
    for(int bit = 0; bit < (1<<d); ++bit){
        int count=0,mx=-1,cnt=0;
        for(int i = 0; i < d; ++i){
            if(bit & (1<<i)){
                count+=100*(i+1)*p[i]+c[i];
                cnt+=p[i];
            }else
            {
                mx = i;
            }
        }
        //cout<<count<<endl;
        if(count < g && mx != -1){
            rep(i,p[mx]){
                count+=100*(mx+1);
                cnt++;
                if(count >= g) break;
            }
        }
        
        if(count >= g)
        ans=min(ans,cnt);
        
    }
    cout<<ans<<endl;
    return 0;
}


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

#define int long long
#define double long double
#define pb push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
#define Ptest(x) return cout << x << endl, 0;

typedef vector <int> vi;
typedef pair <int, int> ii;
typedef vector <vi > vvi;
typedef vector <ii > vii;

const int N = 1e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7;

int n, m, sum, p, d, k;
int a[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    m = (n * (n + 1)) / 2;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    if (sum % m){
        Ptest("NO");
    }
    k = sum / m;
    for (int i = 0; i < n; i++){
        d = a[(i + 1) % n] - a[i];
        if (k < d || (k - d) % n){
            Ptest("NO");
        }
        p += (k - d) / n;
    }
    if (k != p){
        Ptest("NO");
    }
    cout << "YES";
}

/*
----------------------------------+
INPUT:                            |
==============================    |
5
4 5 1 2 3
==============================    |
5
6 9 12 10 8
==============================    |
4
1 2 3 1
==============================    |
----------------------------------+
OUTPUT:                           |
==============================    |
YES
==============================    |
YES
==============================    |
NO
==============================    |
----------------------------------+
*/

Measured memory_bytes: 1024
N,M=map(int,input().split())
INF=10**18
dp=[INF]*(1<<N)
dp[0]=0
cost=[None]*M
target=[0]*M

for i in range(M):
    cost[i],b=map(int,input().split())
    
    c=[int(x) for x in input().split()]
    for j in c:
        target[i]=target[i]|(1<<(j-1))
    
for s in range(1<<N):
    for i in range(M):
        ns=s|target[i]
        dp[ns]=min(dp[ns],dp[s]+cost[i])
if dp[-1]==INF:
    print(-1)
else :
    print(dp[-1])


Measured memory_bytes: 9232
from collections import deque
n = int(input())
e = [[] for _ in range(n)]
AB = [list(map(int, input().split())) for _ in range(n - 1)]
AB = [(a -1, b - 1) for a, b in AB]

for itr, (a, b) in enumerate(AB):
  e[a].append(b)
  e[b].append(a)
  
colors = [-1] * n

# ２色で塗分けする。
q = deque()
# 現在見ている頂点、親の色
q.append((0, 0))
while q:
  v, pcol = q.popleft()
  # 親と異なる色で塗る。
  if colors[v] == -1:
    col = not pcol
    colors[v] = col
    for i in e[v]:
      if colors[i] == -1:
        q.append((i, col))

# print(e)
# print(colors)
        
m = [deque([i for i in range(1, n + 1) if i % 3 == j]) for j in range(3)]

# print(m)

def opop(n, ne):
  if m[n]:
    p = m[n].pop()
  else:
    if n == 1 or n == 2:
      if m[ne]:
        p = m[ne].pop()
      else:
        p = m[0].pop()
    else:
      if m[1]:
        p = m[1].pop()
      else:
        p = m[2].pop()
  return p

ans = [0] * n

if sum(colors) <= len(m[0]):
  for itr, i in enumerate(colors):
    if i:
      ans[itr] = opop(0, 0)
    else:
      ans[itr] = opop(1, 2)
elif sum(colors) >= len(m[1]) + len(m[2]):
  for itr, i in enumerate(colors):
    if not i:
      ans[itr] = opop(0, 0)
    else:
      ans[itr] = opop(1, 2)
else:
  for itr, i in enumerate(colors):
    if i:
      ans[itr] = opop(1, 0)
    else:
      ans[itr] = opop(2, 0)
print(*ans)


Measured memory_bytes: 93392
#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = a; i <= b; i++)
	{
		if (c % i == 0)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int main(void){
	int a;
	scanf("%d", &a);
	a = a % 10;

	if(a == 3){
		printf("bon");
		return 0;
	}
	else if(a == 0 || a == 1 || a == 6 || a == 8){
		printf("pon");
		return 0;
	}
	else{
		printf("hon");
	}
	return 0;
}



Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, int, int> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int fuc(int num){
  if(num%2==0){
    return num/2;
  }
  else return 3*num+1;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int s;cin>>s;
  map<int,int> mp;
  mp[s]++;
  vector<int> a(10000000,0);
  a[1]=s;
  for(int i=2;i<=1000000;i++){
    a[i] = fuc(a[i-1]);
    //cout << i << ":" << a[i] << endl;
    if(mp[a[i]]>0){
      cout << i << endl;
      return 0;
    }
    else mp[a[i]]++;
  }
}

Measured memory_bytes: 39296
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


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

  int n;
  cin >> n;
  double ret = (double)2.0 * 3.141592653 * n;
  cout << ret << endl;

  return 0;
}



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

using namespace std;

int main()
{
    int n,i,count=0;
    cin >> n;
    int arr[n];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    for(i=0; i<n; i++)
    {
        if(arr[i]%2!=0)
        {
           count++;
        }
    }
   if(count%2==0)
    cout << "YES";
   else
   cout << "NO";
    return 0;

}


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;

int main(){
	string s;
	cin >> s;
	if( s[0] == s[s.size()-1] ) cout << s[0] << endl;
	else cout << "o" << endl;
}

Measured memory_bytes: 0
#include<stdio.h>

int main() {
    int n,m,t[100],p[100],x[100],j,k,sum=0;
    scanf("%d",&n);
    for (int i = 0;i<n;i++){
        scanf("%d",&t[i]);
    }
    scanf("%d",&m);
    for (int i = 0;i<m;i++){
        scanf("%d%d",&j,&k);
        sum+=k;
        for(int x= 0;x<n;x++){
            if(x==j-1) continue;
            sum+=t[x];
        }
        printf("%d\n",sum);
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 1712
A, B = map(int, input().split())
AA = A
BB = B
lcm = 1
cont = 1

while cont == 1:
  if A % B == 0 or B % A == 0:
    lcm = min(A, B)
    break
  
  if A < B:
    B = B % A
  elif A > B:
    A = A % B

ans = int(AA * BB / lcm)
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){ 
  int N, K, i;
  scanf("%d %d", &N, &K);
  
  int h[N];
  
  for(i = 0; i < N; i++){
    scanf("%d", &h[i]);
  }
  
  qsort(h, N, sizeof(int), compare_int);
  
  int min = 1000000000;
  
  for(i = 0; i < N-K+1; i++){
    if(h[i + K - 1] - h[i] < min){
      min = h[i + K - 1] - h[i];
    }
  }
                                                                                                  
  printf("%d\n", min);

  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

bool is_prime(int N){
    
    if (N == 1) return false;
    
    int sqn = sqrt(N);
    
    for(auto i = 2; i<=sqn; i++){
        if (N % i == 0) return false;
    }
    return true;
}


int main() {
    int n,h;cin>>n>>h;
    vector<pii> k(n);
    rep(i,n){
        cin>>k[i].first>>k[i].second;
    }
    
    sort(all(k),[](pii a, pii b){return a.second > b.second;});
    auto mx = *max_element(all(k),[](pii a, pii b){return a.first < b.first;});
    int p = 0;
    while(k[p].second>mx.first){
        p++;
    }
    
    k.erase(next(k.begin(),p),k.end());
    
    ll attacksum = 0;
    for(auto el:k){
        attacksum += el.second;
    }
    
    int count = 0;
    
    if (h > attacksum){
        count = (h-attacksum)/mx.first;
        h -= count*mx.first;
        
        if(h>attacksum){count++; h -= mx.first;}
        
    }

        
    int q = 0;
    while(h>0){
        h -=k[q].second;
        count++;
        q++;
    }
    
    cout<<count<<endl;
    
    
    return 0;
}










Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N, i, a[101], sum1, sum2, mid1, mid2;
int main()
{
    cin >> N;
    for(i=0;i<N;i++)
        cin >> a[i], sum1+=a[i];
    mid1 = ceil((float)sum1/N);
    mid2 = sum1/N;
    //cout << mid << endl;
    sum1 = 0;
    for(i=0;i<N;i++)\
    {
        sum1 += abs(a[i]-mid1)*abs(a[i]-mid1);
        sum2 += abs(a[i]-mid2)*abs(a[i]-mid2);
    }
    cout << min(sum1, sum2) << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
long n,i,j,s,a[11][11];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)
for(j=0;j<n;j++)cin>>a[i][j];
for(i=0;i<n;i++){
for(s=0,j=0;j<n;j++)s+=a[i][j];
a[i][j]=s;
}
for(j=0;j<=n;j++){
for(s=0,i=0;i<n;i++)s+=a[i][j];
a[i][j]=s;
}
for(i=0;i<=n;i++){
for(j=0;j<=n;j++)printf("%5d",a[i][j]);
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 1164
tmp = input().split()
A = int(tmp[0])
B = int(tmp[1])
C = int(tmp[2])
K = int(tmp[3])

remainCard = K

if K <= A:
    print(K)
else:
    remainCard = remainCard-A
    if remainCard <= B:
        print(A)
    else:
        remainCard = remainCard-B
        print(A-remainCard)



Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
const Int MAX = 505;
const Int INF = 1e18;
Int A[MAX][MAX];
Int dp[MAX][MAX];

Int X[MAX][MAX];
Int Y[MAX][MAX];

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

  Int n;
  cin>>n;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      if(i!=j) cin>>A[i][j];

  memset(X,0,sizeof(X));
  for(Int k=1;k<n;k++){
    for(Int i=0;i<k;i++){
      if(i) X[k][i]=X[k][i-1];
      Int a=i;
      for(Int b=k+1;b<n;b++)
        X[k][i]+=A[b][a];
    }
  }

  memset(Y,0,sizeof(Y));
  for(Int k=1;k<n;k++){
    for(Int i=k-1;i>=0;i--){
      Y[k][i]=Y[k][i+1];
      Int a=i;
      for(Int b=a+1;b<=k;b++)
        Y[k][i]+=A[a][b];
    }
  }

  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=INF;

  for(Int k=1;k<n;k++)
    for(Int i=0;i<k;i++)
      dp[k][i]=X[k][i]+Y[k][i+1]+Y[i][0];

  for(Int i=0;i+1<n;i++)
    for(Int j=0;j<i;j++)
      for(Int k=i+1;k+1<n;k++)
        chmin(dp[k][i],dp[i][j]+(X[k][i]-X[k][j])+Y[k][i+1]);

  Int ans=INF;
  for(Int k=0;k+1<n;k++){
    Int tmp=0;
    for(Int a=0;a<n;a++)
      for(Int b=a+1;b<n;b++)
        if(a<=k and k<b) continue;
        else tmp+=A[a][b];
    chmin(ans,tmp);
  }

  for(Int i=0;i+1<n;i++)
    for(Int j=0;j<i;j++)
      chmin(ans,dp[i][j]+Y[n-1][i+1]);

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


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

namespace AtCoder
{
    class Abc165B
    {
        public static void Main()
        {
            var x = long.Parse(Console.ReadLine());

            int i = 0;
            long n = 100;
            while (n < x)
            {
                n = (long)(n * 1.01);
                i++;
            }
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 27536
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a[1000], b[1000], n, i, I, x, y = 0, z;
	scanf("%d", &n);
	while(scanf("%d", &x))
	{
		a[y] = x;
		char c = getchar();
		if(c == '\n')
		{
			break;
		}
		y++;
	}
	for(i = 0, I = n-1 ; i < n ; i++, I--)
	{
		b[I] = a[i];
	}
	for(i = 0 ; i < n ; i++)
	{
		printf("%d", b[i]);
		if(i < n-1)
		{
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  ll ans = 0;
  REP(i, N) {
    ans += (i + 1);
  }
  cout << ans - N << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	string b="CF";
	int s=0;
	cin>>a;
	for(int i=0;i<a.size();i++){
		if(b[s]==a[i])s++;
		if(s==2)break;
	}
	if(s==2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int a[maxn];
int b[maxn];
int aa[maxn];
int bb[maxn];
int n;
int get_pos(int a[],int x){
    int l = -1, r = n;
    while (r - l > 1){
        int mid = (l + r) >> 1;
        if (a[mid] >=x) r = mid;
        else l = mid;
    }
    return r;
}

int get_pos2(int a[],int x){
    int l = -1, r = n;
    while (r - l > 1){
        int mid = (l + r) >> 1;
        if (a[mid] >= x) r = mid;
        else l = mid;
    }
    return r - 1;
}
int Get(int x){
    for (int i = 0; i < n; i++){
        aa[i] = a[i] % (1 << (x + 1));
        bb[i] = b[i] % (1 << (x + 1));
    }
    sort(bb,bb + n);
    /*for (int i = 0; i < n; i++){
        cout << aa[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++){
        cout << bb[i] << " ";
    }*/
    //cout << endl;
    /// 2^k <= ai + bj < 2^(k + 1)
    int tot = 0;
    for (int i = 0; i < n; i++){
        int lower = get_pos(bb,(1 << x)  - aa[i]);
        int upper = get_pos2(bb,(1 << (x + 1)) - aa[i]);
        //cout << "lower = " << lower << " upper = " << upper << endl;
        if (upper - lower + 1 >= 0){
            tot += upper - lower + 1;
        }
        int pos = get_pos(bb,(1 << x) + (1 <<  (x + 1)) - aa[i]);
        tot += n - pos;
    }
    // << endl;
    return tot;
}

int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }

    for (int i = 0; i < n; i++){
        scanf("%d",&b[i]);
    }

    int ans = 0;
    for (int i = 0; i <= 28; i++){
        int dig = Get(i);
        //cout <<"dig  = " <<  dig << endl;
        ans |= (1 << i) * (dig & 1);
    }

    printf("%d\n",ans);
}


Measured memory_bytes: 3328
N, M = map(int, input().split())

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

d = {0: 1}

A_sum = 0

for i in range(0,N):
    A_sum += A[i]
    d[A_sum%M] = d.get(A_sum%M, 0) + 1

ans = 0

for val in d.values():
    ans += val*(val-1)/2

print(int(ans))
    

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

const int mx=100010;
const ll mod=1e9+7;

int main(){
  ll a,b,k;
  cin >> k >> a >> b;
  if(a+2>=b || k<a+1){
    cout << k+1 << endl; return 0;
  }
  ll ans = a+((k-a+1)/2*(b-a)) + (k-a+1)%2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// abc163_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((ll)1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<P> A(N);
    REP(i, N) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(ALL(A), greater<P>());

    // dp[l][r]: 大きい方からl+r個見て、l個は左、r個右
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0));

    REP(i, N) {
        ll p = A[i].first;
        int idx = (int)A[i].second;
        REP(l, i+1){
            int r = i - l;
            dp[l+1][r] = max(dp[l+1][r], dp[l][r] + p * abs(idx - l));
            dp[l][r+1] = max(dp[l][r+1], dp[l][r] + p * abs(N-1-r - idx));
        }
    }
//    print(dp);

    ll ans = 0;
    REP(i, N){
        ans = max(ans, dp[i][N-i]);
    }

    print(ans);

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S = to_string(N);
  int Nketa = S.length();
  ll ans = 0;
  for (int a = 1; a <= N; a++) {
    if(a%10==0) continue;
    string s = to_string(a);
    if(s[0] == s[s.length()-1]) ans++;
    if(S.length() > 1) {
      for (int keta = 2; keta < Nketa; keta++){
        ans += (int)pow(10, keta-2);
      }
      if((S[0] - '0') > (s[s.length()-1] - '0')) {
        ans += (int)pow(10, Nketa-2);
      } else if ((S[0] - '0') == (s[s.length()-1] - '0')) {
        if((S[S.length()-1] - '0') >= (s[0] - '0')) ans += (N - ((S[0] - '0') * (int)pow(10, Nketa-1))) / 10 + 1;
        else ans += (N - ((S[0] - '0') * (int)pow(10, Nketa-1))) / 10;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    a = input()
    # スペース区切りの整数の入力
    last = ''
    maxl = 0
    cons =0
    for s in a:
        if s=='R':
            cons = cons +1
            if maxl<cons:
                maxl = cons
        else:
            cons = 0

    # 出力
    print("{}".format(maxl))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """RRS"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """SSS"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """RSR"""
        output = """1"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 16364
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	m = []
	for _ in range(h):
		s = input()
		m.append(s)
	ret = [['#']*w for _ in range(h)]
	
	for hi in range(h):
		for wi in range(w):
			p=0
			if m[hi][wi]=='#':
				continue
			for dh in [1, 0, -1]:
				if hi+dh < 0 or hi+dh >= h:
					continue
				for dw in [1, 0, -1]:
					if wi+dw < 0 or wi+dw >= w:
						continue
					if dh == 0 and dw == 0:
						continue
					if m[hi+dh][wi+dw]=='#':
						p+=1
			ret[hi][wi]=p
	for v in ret:
		print(''.join([str(i) for i in v]))
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 42096
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned long long ans = 1;
  bool f = false;
  for (int i = 0; i < n; ++i) {
    unsigned long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ans != 0 && a <= 1000000000000000000ll / ans) {
      ans *= a;
    } else {
      f = true;
    }
  }
  if (f) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3636