akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll b[n],c[n],ans1=0,ans2=0;
    if (n&1)
    {
        int ctr=n-1;
        for (i=2;i<n-1;i+=2)
        {
            b[i]=a[ctr];
            ctr--;
        }
        b[n-1]=a[ctr];
        ctr--;
        b[0]=a[ctr];
        for (i=1;i<n;i+=2)
            b[i]=a[(i+1)/2-1];
        for (i=0;i<n-1;i++)
            ans1+=abs(b[i+1]-b[i]);
        ctr=n-1;
        for (i=1;i<n;i+=2)
        {
            c[i]=a[ctr];
            ctr--;
        }
        c[0]=a[ctr];
        ctr--;
        c[n-1]=a[ctr];
        for (i=2;i<n;i+=2)
            c[i]=a[i/2-1];
        for (i=0;i<n-1;i++)
            ans2+=abs(c[i+1]-c[i]);
    }
    else
    {
        int ctr=n-1;
        for (i=2;i<n-1;i+=2)
        {
            b[i]=a[ctr];
            ctr--;
        }
        b[0]=a[ctr];
        for (i=1;i<n;i+=2)
            b[i]=a[(i+1)/2-1];
        for (i=0;i<n-1;i++)
            ans1+=abs(b[i+1]-b[i]);
        ctr=n-1;
        for (i=1;i<n;i+=2)
        {
            c[i]=a[ctr];
            ctr--;
        }
        c[0]=a[ctr];
        for (i=2;i<n;i+=2)
            c[i]=a[i/2-1];
        for (i=0;i<n-1;i++)
            ans2+=abs(c[i+1]-c[i]);
    }
    cout<<max(ans1,ans2)<<endl;
}

Measured memory_bytes: 2688
import sys

sys.setrecursionlimit(1000000000)

n = int(input())

ulist = []

for _ in range(n):
    ulist.append([])

vlist = [True] * n

for _ in range(n - 1):
    u, v, w = map(int, input().split())
    ulist[u - 1].append([v - 1, w])
    ulist[v - 1].append([u - 1, w])


def check(checkV, fromV):
    for data in ulist[checkV]:
        if data[0] != fromV:
            vlist[data[0]] = vlist[checkV] if data[1] % 2 == 0 else not vlist[checkV]
            check(data[0], checkV)

check(0, -1)

for i in range(n):
    print(1 if vlist[i] else 0)

Measured memory_bytes: 85208
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}


void solve(std::string S){
    ll len=S.length();
    string ret(len,'x');
    cout << ret << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

struct magic{
    int a;
    int b;
};

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

    int h, n;
    cin >> h >> n;
    vector<magic> magics(n);
    for(int i=0; i<n; i++){
        cin >> magics[i].a >> magics[i].b;
    }

    vector<vector<lint>> dp(h+1, vector<lint>(n+1, 0));
    int mmax = numeric_limits<int>::max();
    for(int i=1; i<h+1; i++){
        dp[i][0] = mmax;
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<n+1; j++){
            dp[i][j] = min(dp[max(0, i-magics[j-1].a)][j] + magics[j-1].b, dp[i][j-1]);
        }
    }

    COUT(dp.back().back());

    return 0;
}

Measured memory_bytes: 78848
use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}
impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

pub fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let q: usize = iter.next().unwrap().parse().unwrap();

    let s: Vec<i64> = (&mut iter).take(a).map(|x| x.parse().unwrap()).collect();
    let t: Vec<i64> = (&mut iter).take(b).map(|x| x.parse().unwrap()).collect();
    
    for _ in 0..q {
        let x: i64 = iter.next().unwrap().parse().unwrap();
        let s_fst_right_idx = s.lower_bound(&x);
        let s_indices = [s_fst_right_idx.checked_sub(2),s_fst_right_idx.checked_sub(1),Some(s_fst_right_idx),s_fst_right_idx.checked_add(1)];

        let t_fst_right_idx = t.lower_bound(&x);
        let t_indices = [t_fst_right_idx.checked_sub(2),t_fst_right_idx.checked_sub(1),Some(t_fst_right_idx),t_fst_right_idx.checked_add(1)];

        let mut ret = std::i64::MAX / 10;
        // s -> t
        for i in 0..4 {
            for j in 0..4 {
                match (s_indices[i],t_indices[j]) {
                    (Some(si), Some(ti)) if si < a && ti < b => {
                        ret = std::cmp::min(ret, (x - s[si]).abs() + (s[si] - t[ti]).abs());
                    },
                    _ => ()
                }
            }
        }
        // t -> s
        for i in 0..4 {
            for j in 0..4 {
                match (s_indices[i],t_indices[j]) {
                    (Some(si), Some(ti)) if si < a && ti < b => {
                        ret = std::cmp::min(ret, (x - t[ti]).abs() + (t[ti] - s[si]).abs());
                    },
                    _ => ()
                }
            }
        }
        println!("{}", ret);
    }

}


Measured memory_bytes: 13176
import statistics

n = int(input())
ab = [list(map(float, input().split())) for _ in range(n)]
a = []
b = []
for i in ab:
    a.append(i[0])
    b.append(i[1])
# print(a)
# print(b)

min_median = statistics.median(a)
max_median = statistics.median(b)
# print(min_median)
# print(max_median)
c = max_median-min_median
if n%2 ==0:
    ans = int(c*2)
else:
    ans = int(c)
print(ans+1)

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

int main() {
  std::vector<int64_t> l(87);

  l[0] = 2;
  l[1] = 1;

  for (int i = 2; i < 87; i++) {
    l[i] = l[i - 1] + l[i - 2];
  }

  int n;
  std::cin >> n;

  std::cout << l[n] << std::endl;
  return 0;
}


Measured memory_bytes: 256
import sys

k,n=map(int,input().split())
a=list(map(int,input().split()))
a=[[a[i],i] for i in range(n)]

if n==1: print(a[0][0]-1);sys.exit()

pre=-1
ans=0
for _ in range(k):
    a.sort(reverse=True)
    if a[0][1]!=pre:
        a[0][0]-=1
        pre=a[0][1]
    elif a[1][0]>0:
        a[1][0]-=1
        pre=a[1][1]
    else:
        ans=a[0][0]
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>


using namespace std;


using ll = long long;

class node {
    public:
        node();
        ll p, l, r;
};


node::node()
    : p(-1), l(-1), r(-1)
{
}


void preorder(ll now, vector<node> &nodes, vector<ll> &log)
{
    log.push_back(now);
    if (nodes[now].l != -1)
        preorder(nodes[now].l, nodes, log);
    if (nodes[now].r != -1)
        preorder(nodes[now].r, nodes, log);
}


void inorder(ll now, vector<node> &nodes, vector<ll> &log)
{
    if (nodes[now].l != -1)
        inorder(nodes[now].l, nodes, log);
    log.push_back(now);
    if (nodes[now].r != -1)
        inorder(nodes[now].r, nodes, log);
}


void postorder(ll now, vector<node> &nodes, vector<ll> &log)
{
    if (nodes[now].l != -1)
        postorder(nodes[now].l, nodes, log);
    if (nodes[now].r != -1)
        postorder(nodes[now].r, nodes, log);
    log.push_back(now);
}


void print_log(vector<ll> &log)
{
    for (auto e : log) {
        cout << " " << e;
    }
    cout << endl;
}


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

    vector<node> nodes(n);
    for (ll i = 0; i < n; i++) {
        ll id, l, r;
        cin >> id >> l >> r;
        nodes[id].l = l;
        nodes[id].r = r;
        nodes[l].p = id;
        nodes[r].p = id;
    }

    ll r;
    for (ll i = 0; i < n; i++) {
        if (nodes[i].p == -1) {
            r = i;
            break;
        }
    }

    vector<ll> log;
    preorder(r, nodes, log);
    cout << "Preorder" << endl;
    print_log(log);
    log.clear();

    inorder(r, nodes, log);
    cout << "Inorder" << endl;
    print_log(log);
    log.clear();

    postorder(r, nodes, log);
    cout << "Postorder" << endl;
    print_log(log);
}



Measured memory_bytes: 3160
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

pre = [[0]*(3+1) for _ in range(C+1)]
for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
    pre = now

print(max(now[C]))


Measured memory_bytes: 221868
n = int(input())
buffer = []
i = 0
while i<n:
    b,f,r,v = map(int,input().split())
    buffer.append([b,f,r,v])
    i = i + 1

room = []
for h in range(15):
    if h == 3 or h == 7 or h == 11:
        room.append(['**']*10)
    else:
        room.append([0]*10)
            
for y in range(n):
    if buffer[y][0] == 1:
        room[buffer[y][1]-1][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1][buffer[y][2]-1]
    elif buffer[y][0] == 2:
        room[buffer[y][1]-1+4][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+4][buffer[y][2]-1]
    elif buffer[y][0] == 3:
        room[buffer[y][1]-1+8][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+8][buffer[y][2]-1]
    elif buffer[y][0] == 4:
        room[buffer[y][1]-1+12][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+12][buffer[y][2]-1]
        
for x in range(15):
    if x == 3 or x == 7 or x == 11:
        print("####################")
    else:
        for y in range(10):
            print(" "+str(room[x][y]), end = "")   
        print()
 


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

string s;

int main(void){
	cin >> s;
	vector<int> c(26);
	rep(i, s.size()) c[s[i]-'a']++;
	rep(i, 26){
		if(c[i]%2 == 1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    double areamax = W*H/2;
    int judge = 0;
    if (x == W/2 && y == H/2){
    judge = 1;
    }
    else{
    judge = 0;
    }
    cout << areamax << endl;
    cout << judge <<endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
for i in range(n):
  if 2*a[i]<a[i+1]:flag=0
  else:flag=1
  a[i+1]+=a[i]
  a[i]*=flag
ans=0
for i in a[::-1]:
  if i:ans+=1
  else:break
print(ans)

Measured memory_bytes: 87684
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String c[]=new String[3];
    for (int i=0;i<3;i++) {
      c[i]=sc.next();

    }

    for (int i=0;i<3;i++) {
        // System.out.println(c[i]);
        char a=c[i].charAt(i);
        System.out.print(a);
    }

    System.out.println();
  }
}


Measured memory_bytes: 21716
N,K=input().split()
MOD = 1000000007
mmax = 0
mmin = 0
result = 0
for i in range(int(N)+1):
    mmin = mmin + i
    mmax = mmax + int(N) - i
    if i >= int(K) - 1:
        result = result + mmax - mmin + 1
print(result%MOD)

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
    std::cin >> N;

    if (N % 2 == 1)
    {
        std::cout << "No" << std::endl;
        return;
    }

    std::string S;
    std::cin >> S;

    bool ok = true;
    for (int64_t i = 0; i < N / 2; i++)
    {
        if (S[i] != S[i + N / 2]) ok = false;
    }

    std::string ans = ok ? "Yes" : "No";
    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3660
a = input()
answer = 0

a = a.replace("B", "-")
a = a.replace("D", "-")
a = a.replace("E", "-")
a = a.replace("F", "-")
a = a.replace("H", "-")
a = a.replace("I", "-")
a = a.replace("J", "-")
a = a.replace("K", "-")
a = a.replace("L", "-")
a = a.replace("M", "-")
a = a.replace("N", "-")
a = a.replace("O", "-")
a = a.replace("P", "-")
a = a.replace("Q", "-")
a = a.replace("R", "-")
a = a.replace("S", "-")
a = a.replace("U", "-")
a = a.replace("V", "-")
a = a.replace("W", "-")
a = a.replace("X", "-")
a = a.replace("Y", "-")
a = a.replace("Z", "-")

strs = int(a.count("-")) + 1
a = a.split("-")

for i in range(strs):
    if len(a[i]) > answer:
        answer = len(a[i])

print(answer)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  char s[20],t[20];
  scanf("%s",s);
  scanf("%s",t);
  
  for(int i=0;i<=15;i++){
    if(90>s[i]){s[i]='A';}
  }
  for(int i=0;i<=20;i++){
    if(s[i]=='A'){break;}
    if(s[i]!=t[i]){printf("No");return 0;}
  }
  printf("Yes");
  return 0;
}




Measured memory_bytes: 1712
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7


int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> L(N);
  rep(i, N) {
    cin >> L[i];
  }
  sort(all(L)); // Now, L is sorted

  // a < b < c.
  // We fix b and c, then search a.
  // c < a + b <=> c-b < a

  ll ans = 0;
  for (int i = 1; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int b = L[i];
      int c = L[j];
      auto it = upper_bound(all(L), c - b);
      int iter = it - L.begin();
      if (iter < i) { // a exists.
        ans += i - iter;
      }
    }
  }

  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<queue<int>> A(n);
    int a;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-1; ++j) {
            cin >> a;
            A[i].push(a-1);
        }
    }

    int res = 0;
    while (1) {
        bool fin = true;
        bool loop = true;
        vector<bool> checked(n, false);
        for (int i = 0; i < n; ++i) {
            if (checked[i]) continue;

            if (A[i].empty()) {
                continue;
            } else {
                fin = false;
            }

            if (A[A[i].front()].front() == i && !checked[A[i].front()]) {
                checked[i] = true;
                checked[A[i].front()] = true;

                A[A[i].front()].pop();
                A[i].pop();
                loop = false;
            }
        }
        if (fin) break;
        if (loop) {
            cout << -1 << endl;
            return 0;
        }
        res++;
    }
    cout << res << endl;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

struct Eratosthenes {
  vector< bool > prime;
  Eratosthenes(int _size) {
    init(_size);
  }

  void init(int n) {
    prime.resize(n + 1);
    REP(i, prime.size()) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i = 2; i < sqrt(n); i++) {
      if (prime[i]) {
        for (int j = 0; i * (j + 2) < n; j++) {
	  prime[i * (j + 2)] = false;
	}
      }
    }
  }
};

int Q;
int cnt[MAX_N];

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

  Eratosthenes e(MAX_N);
  REP(i, MAX_N) {
    cnt[i + 1] += cnt[i] + (e.prime[i + 1] && e.prime[(i + 2) / 2] ? 1 : 0);
  }

  cin >> Q;
  while(Q--) {
    CIN(l, r);
    int ans = cnt[r] - cnt[l - 1];
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
 int a[100005][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
         for(int j=0;j<3;j++)
             cin>>a[i][j];
         if(i!=1)
         {
           for(int j=0;j<3;j++)
           a[i][j]+=max(a[i-1][(j+1)%3],a[i-1][(j+2)%3]);
         }
    }
    
    cout<<max(a[n][1],max(a[n][0],a[n][2]))<<"\n";
}

Measured memory_bytes: 1408
N = int(input())
S = input()
X = [0]*3
for s in S:
  if s == "R":
    X[0] += 1
  elif s == "B":
    X[1] += 1
  else:
    X[2] += 1
total = X[0]*X[1]*X[2]
flag = [False] * 3
for i in range(N-2):
  for j in range(i+1, N-1):
    if S[i] == "R":
      flag[0] = True
    elif S[i] == "B":
      flag[1] = True
    else:
      flag[2] = True
    if S[j] == "R":
      flag[0] = True
    elif S[j] == "B":
      flag[1] = True
    else:
      flag[2] = True
    k = j + j - i
    if k <= N-1:
      if S[k] == "R":
        flag[0] = True
      elif S[k] == "B":
        flag[1] = True
      else:
        flag[2] = True
    if all(flag):
      total -= 1
    flag = [False]*3
print(total)

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

int main()
{
  string s;
  cin >> s;
  vector<int> v(26, 0);

  for (int i = 0; i < s.size(); i++)
  {
    int a = s[i] - 97;
    v.at(a)++;
  }

  char ans = 'a';

  for (int i = 0; i < 26; i++)
  {
    if (v.at(i) == 0)
    {
      ans += i;
      break;
    }
    if (i == 25)
    {
      cout << "None" << endl;
      return 0;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long ll;
#define max(x,y) ((x<y)?y:x)
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,m,k,l;
    cin>>n>>m>>k;
    ll a[200005]={0},b[200005]={0};
    a[0]=0,b[0]=0;
    for(int i=1;i<=n;i++)
    {
        
        cin>>l;
        a[i]=a[i-1]+l;
    }
    for(int i=1;i<=m;i++)
    {
        
        cin>>l;
        b[i]=b[i-1]+l;
    }
    ll j=0,x=m,mx=0;
    for( j=0;j<=n;j++)
    {
        
        while(b[x]+a[j]>k) x--;
        mx=max(mx,j+x);
       // cout<<mx<<endl;
    }
    cout<<mx<<endl;
    return 0;
} 

Measured memory_bytes: 6740
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0
for i in range(n) :
    s = input()
    if s == 'AC' :
        ac += 1
    elif s == 'WA' :
        wa += 1
    elif s == 'TLE' :
        tle += 1
    else :
        re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9212
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cassert>

using namespace std;

const int MAXN = 200000 + 10;

int N;
char S[MAXN];
vector <int> V[26];
int Next[MAXN][26];
int first[MAXN], last[MAXN], nd;
int dp[MAXN][26], pre[MAXN][26];

void Work()
{
	scanf("%s", S);
	N = strlen(S);

	for (int i = 0; i < N; i ++)
		V[S[i] - 'a'].push_back(i);
	
	for (int i = 0; i < N; i ++)
		for (int c = 0; c < 26; c ++)
		{
			auto it = lower_bound(V[c].begin(), V[c].end(), i);
			Next[i][c] = (it == V[c].end()) ? -1 : (*it);
		}

	nd = 0;
	int here = 0;
	while (1)
	{
		if (here >= N)
		{
			for (int c = 0; c < 26; c ++)
				dp[nd][c] = 1;
			nd ++;
			break;
		}

		int fn = 0;
		for (int c = 0; c < 26; c ++)
			if (Next[here][c] == -1)
				fn = 1;
		if (fn)
		{
			for (int c = 0; c < 26; c ++)
				if (Next[here][c] == -1)
					dp[nd][c] = 1;
			nd ++;
			break;
		}

		int nxt = 0;
		for (int c = 0; c < 26; c ++)
			nxt = max(nxt, Next[here][c]);
		first[nd] = here;
		last[nd] = nxt;
		nd ++;
		
		here = nxt + 1;
	}

	for (int i = nd - 2; i >= 0; i --)
	{
		for (int c = 0; c < 26; c ++)
		{
			for (int cc = 0; cc < 26; cc ++)
				if (dp[i + 1][cc] && (Next[Next[first[i]][c] + 1][cc] == -1 || Next[Next[first[i]][c] + 1][cc] > last[i]))
				{
					dp[i][c] = 1;
					pre[i][c] = cc;
					break;
				}
		}
	}

	int ptr;
	for (int c = 0; c < 26; c ++)
		if (dp[0][c])
		{
			ptr = c;
			break;
		}

	for (int i = 0; i < nd; i ++)
	{
		printf("%c", 'a' + ptr);
		ptr = pre[i][ptr];
	}
	printf("\n");
}

int main()
{
	Work();
	return 0;
}


Measured memory_bytes: 29824
#pragma region Imports
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#pragma endregion
#pragma region Macros
#pragma GCC optimize (2)
#define uns unsigned
#define out cout
#define in cin
#define au auto
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define elif else if
#define sz(x) x.size()
#define fl(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define fli(i, a, b, c) for(int (i)=a;(i)<(b);(i)+=(c))
#define fr(i, x) for(int (i)=(x)-1;(i)>=0;(i)--)
#define fb(i, x) for(int (i)=0;(i)<(x);(i)++)
#define fa(i, x) for(auto& (i):(x))
#define ia(a, n) for(int qw=0;qw<(n);qw++)cin>>(a)[qw];
#define oa(a, n) for(int qw=0;qw<(n);qw++)cout<<(a)[qw]<<" ";
#define im(a, n, m) fb(i,(n))fb(j,(m))cin>>(a)[i][j];
#define om(a, n, m) fb(i,(n))fb(j,(m))cout<<(a)[i][j]<<" \n"[j==(m)-1];
#define eb(v, x) (v).emplace_back(x);
#define seb(s, x) (s).emplace(x);
#define pr(x, y) pair<x,y>
#define vr(x) vector<x>
#define mp(x, y) make_pair(x,y)
#define hm(x, y) map<x,y>
#define um(x, y) unordered_map<x,y>
#define stk(x) stack<x>
#define qu(x) queue<x>
#define dq(x) deque<x>
#define pq(x) priority_queue<x>
#define pqm(x) priority_queue<x,vector<x>,greater<(x)>>
#define mem(a, x) memset(a,(x),sizeof(a));
#define fi(x) (x).first
#define se(x) (x).second
#define ql(x) int tc;tc=(x);if(tc==-1)cin>>tc;while(tc--)
#define srt(x) sort((x).begin(),(x).end());
#define pops(y, x) auto (y)=(x).front();(x).pop();
#define ppc(x) __builtin_popcount((x))
#define all(x) (x).begin(),(x).end()
#define sieve(b, n) bool (b)[(n)];mem((b),true);int sq=int(sqrt(n))+1;(b)[0]=(b)[1]=false;fl(i,2,sq)if((b)[i])fli(j,i*i,n,i)(b)[j]=false;
#define dbg(x) cout<<#x<<" "<<(x)<<"\n";
#pragma endregion
#pragma region Typedefs and Consts
typedef long long int ll;
typedef unsigned long long int ull;
typedef string stg;
typedef float flo;
typedef char chr;
typedef vector<int> vi;
const ull mod = 1000000007;
const int imx = INT_MAX;
const int imn = INT_MIN;
const ll lmx = LLONG_MAX;
const ll lmn = LLONG_MIN;
#pragma endregion
#pragma region Functions
inline ull powm(ull x,ull y,bool b=false,ull m=mod){ if(b){ ull t=1;x%=m;while(y>0){ if(y%2)t=(t*x)%m;y=y>>1;x=(x*x)%m; }return t; }else
    { ull t=1;while(y>0){ if(y&2)t*=x;y=y>>1;x*=x; }return t;}}
inline ll gcd(ll a,ll b){a=abs(a);b=abs(b); while(b!=0){ ll c=a%b;a=b;b=c;}return a;}
#pragma endregion

//cout<<"Case #"+to_string(tc+1)+": "+to_string(z)<<endl;
double d[3000][6000];
double f(double a[],int n,int i,int s){
  if(i==n)
    return s>0?1.0:0.0;
  if(s+(n-i)<=0)
    return 0.0;
  if(d[i][s+n]==-1.0)
    d[i][s+n]=a[i]*f(a,n,i+1,s+1)+(1.0-a[i])*f(a,n,i+1,s-1);
  return d[i][s+n];
}
int main() {
  fio
  int n;
  in>>n;
  double a[n];
  ia(a,n)
  fb(i,3000)
    fb(j,6000)
    d[i][j]=-1.0;
  out<<setprecision (10)<<f(a,n,0,0);
  return 0;
}


Measured memory_bytes: 141184
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max({ a,b,c }) - min({ a,b,c }) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1e5+5;
int main()
{
	int n;
	int max=0;
	int min=0;
	int node[maxn];
	cin>>n;
	node[0] = 0;
	node[n+1] = 0;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		node[i] = t;
	}
	int sum1 = 0;
	for(int i=0;i<n+1;i++)
	{
		sum1 += fabs(node[i+1]-node[i]);
	}
	for(int i=1;i<=n;i++)
	{
		int sum = sum1;
		sum  = sum1 - fabs(node[i]-node[i-1]) - fabs(node[i+1]-node[i]);
		sum  = sum + fabs(node[i+1]-node[i-1]);
		cout<<sum<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout <<  ((a + b + c >= 22) ? "bust" : "win") << endl;
}

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

#define inf 1e9+1
vector<long long >v;
vector<long long>w;
vector<vector<long long >>dp;

long long minwt(long long n,long long val){

        if(dp[n][val]!=-1){
            return dp[n][val];
        }
        long long mn = minwt(n-1,val);
        if(val>=v[n]){
            long long b = minwt(n-1,val-v[n])+w[n];
            mn = min(mn,b);
        }
        return mn;
}
void solve(){
    int n,wt;cin>>n>>wt;
    v.resize(n);
    w.resize(n);
    int mxval = n*1000;
    dp.resize(n,vector<long long>(mxval+1,inf));

    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }

    dp[0][0]=0;
    dp[0][v[0]]=w[0];
    //cout<<v[0]<<" "<<w[0]<<"\n";
    for(int i=1;i<n;i++){
        for(int j=0;j<=mxval;j++){

            dp[i][j]= dp[(i-1)][j];
            if(j>=v[i]){

                dp[i][j]= min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
            }

        }
        //cout<<i<<"\n";
    }

    long long ans = 0;
    for(int i=mxval;i>=0;i--){
        if(dp[n-1][i]<=wt){
            ans = i;
            break;
        }
    }
    cout<<ans<<"\n";
}

int main(){

    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0){
            res.push_back(i);
            if (n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<int> sum(n+1, 0);
    vector<int> num(n+1, -1);
    vector<int> res;
    for (int i = n-1; i >= 0; --i) {
        int tmp;
        if (sum[i+1] % 2 != a[i]) {
            tmp = 1;
        } else {
            tmp = 0;
        }

        if (num[i+1] != -1 && num[i+1] != tmp) {
            cout << -1 << endl;
            return 0;
        }
        num[i+1] = tmp;
        if (tmp == 1) {
            res.push_back(i+1);
            auto V = enum_divisors(i+1);
            for (auto v : V) {
                sum[v]++;
            }
        }
    }
    cout << res.size() << endl;
    for (auto v : res) {
        cout << v << endl;
    }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int size=1000;
  vector<bool> hurui(size*size+1,true);
  hurui[0]=hurui[1]=false;
  for(int i=2;i<=size*size;i++){
    if(hurui[i]){
      for(int j=2*i;j<=size*size;j+=i) hurui[j]=false;
    }
  }
  vector<vector<int>> doukutu(size,vector<int>(size));
  int now=1;
  for(int i=0;i<size/2;i++){
    for(int j=size/2-i;j<=size/2+i;j++){
      doukutu[j][size/2-1-i]=now;
      now++;
    }
    for(int j=size/2-i;j<=size/2+i;j++){
      doukutu[size/2+i][j]=now;
      now++;
    }
    for(int j=size/2-1+i;j>=size/2-1-i;j--){
      doukutu[j][size/2+i]=now;
      now++;
    }
    for(int j=size/2-1+i;j>=size/2-1-i;j--){
      doukutu[size/2-1-i][j]=now;
      now++;
    }
  }
  // for(int i=0;i<size;i++){
  //   for(int j=0;j<size;j++) cout << doukutu[i][j] << " ";
  //   cout << endl;
  // }
  while(1){
    int m,n;
    cin >> m >> n;
    if(n==0) return 0;
    pair<int,int> ma;
    vector<vector<pair<int,int>>> dp(size,vector<pair<int,int>>(size,{0,0}));
    vector<vector<bool>> ok(size,vector<bool>(size,false));
    for(int i=0;i<size;i++){
      for(int j=0;j<size;j++){
        if(doukutu[i][j]==n) ok[i][j]=true;
        if(hurui[doukutu[i][j]]) dp[i][j].first++,dp[i][j].second=doukutu[i][j];
        if(ok[i][j]){
          if(i<999){
            for(int k=-1;k<=1;k++){
              if(0<=j+k&&j+k<size){
                if(doukutu[i+1][j+k]<=m){
                  ok[i+1][j+k]=true;
                  dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]);
                }
              }
            }
          }
          ma=max(ma,dp[i][j]);
        }
      }
    }
    cout << ma.first SP ma.second << endl;
  }
  return 0;
}



Measured memory_bytes: 15112
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	long long int n,m,sum;
	std::cin >> n;

	std::vector<long long int> v(5);
	for (long long int& x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());

	if (n%v[0] == 0) {
		m = n / v[0];
	}
	else {
		m = n / v[0] + 1;
	}

	sum = 4 + m;
 

	std::cout << sum << std::endl;
	return 0;
}

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

int main() {

  int s;

  cin >> s;

  int a1 = s/100;
  int t1 = s%100;
  int a2 = t1/10;
  int a3 = t1%10;

  cout << a1+a2+a3 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll cd=c*d/GCD(c,d);

    ll ax=(a-1)/c;
    ll ay=(a-1)/d;
    ll az=(a-1)/cd;
    ll bx=b/c;
    ll by=b/d;
    ll bz=b/cd;
    ll abx=bx-ax;
    ll aby=by-ay;
    ll abz=bz-az;
    cout<<(b-a+1) - abx - aby + abz<<endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashMap<String, Integer> M = new HashMap<>();

		int q = sc.nextInt();

		for (int i = 0; i < q; i++) {
			int p = sc.nextInt();
			if (p == 0) {
				String key = sc.next();
				int x = sc.nextInt();
				M.put(key, x);
			}else if(p==1) {
				String key=sc.next();
				System.out.println(M.get(key));
			}
		}

		sc.close();

	}

}



Measured memory_bytes: 195080
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int s=0;
    int t=n;
    while(true){
        s+=t%10;
        t/=10;
        if(t==0) break;
    }
    if(n%s==0){
        cout <<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

const int N = 100 + 5;

int main ()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

using ll = long long;

using namespace std;

int main() {
	ll A, B, V, W, T;

	cin >> A >> V >> B >> W >> T;

	if (V <= W) {
		cout << "NO" << endl;
	}
	else if (abs(A - B) <= (V - W)*T) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 3128
let for_range s e step f =
  let rec loop i =
    if i > e then ()
    else
      begin f i;loop (i + step) end
  in loop s;;
let () =
  let num = 104730 in
  let p = Array.init (num+1) (fun x -> x) and
      q = Array.init (num+1) (fun x -> 0) and
      j = ref 1
  in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) > 0 then
          begin
            p.(i*2) <- 0;
            for_range (i*3) num (i*2) (fun x -> p.(x) <- 0);
          end;
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);
  for_range 4 num 2 (fun x -> p.(x) <- 0);
  loop 3;
  for i = 1 to num-1 do
    if p.(i) > 0 then
      begin
        q.(!j) <- p.(i) + q.(!j-1);
        j:=!j+1;
      end;
  done;
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        Printf.printf "%d\n" q.(n);
        read ();
      end;
  in read ();;

Measured memory_bytes: 3924
#include <iostream>
#include <unordered_map>
#include <vector>
#define ll long  long int
#define mod 998244353
using namespace std;
int main() {
    ll n,k;
    cin>>n>>k;
    ll sum[n+2]={0};
    sum[n]=1;
    sum[n+1]=0;
    vector<ll> l(k);
    vector<ll> r(k);
    for(ll i=0;i<k;i++)
    {
        cin>>l[i]>>r[i];
    }
    for(ll i=n-1;i>0;i--)
    {
        ll curr=0;
        for(ll j=0;j<k;j++)
        {
            ll le=i+l[j];
            ll ri=i+r[j]+1;
            if(le>n)
            {
                le=n+1;
            }
            if(ri>n)
            {
                ri=n+1;
            }
            //cout<<sum[le]<<" "<<sum[ri]<<endl;;
            ll cu=sum[le]-sum[ri];
            curr=curr+cu;
            curr=(curr+mod)%mod;
        }
        sum[i]=(sum[i+1]+curr)%mod;
        //cout<<i<<": "<<curr<<"  "<<sum[i]<<endl;
    }
    ll ans=sum[1]-sum[2];
    ans=(ans+mod)%mod;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define ld long double
const int N=1e5+10;
const int mod=1e9+7;
ll dp1[N],dp2[N];
void dfs(int v,int par,vector<int>adj[])
{
    ll sum1=1;
    ll sum2=1;
    int ch=0;
    for(auto node:adj[v])
    {
        if(node==par) continue;
        ch=1;
        dfs(node,v,adj);
        sum2=(sum2*dp1[node])%mod;
        sum1=(sum1*(dp1[node]+dp2[node]))%mod;
    }
   if(ch==0)
   {
       dp1[v]=dp2[v]=1;
   }else{
       dp1[v]=sum1;
       dp2[v]=sum2;
   }
 
}
int main()
{
    int n;
    cin>>n;
    vector<int>adj[n+1];
    forl(i,0,n-1)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1,-1,adj);
    cout<<(dp1[1]+dp2[1])%mod<<endl;


}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
constexpr int MOD = 1000000007;
using P = pair<int,int>;
//////////////////////////////////////////

int main(){
  ini(N);
  vi a(N); in(a);

  int s = 0; rep(i,N) s += a[i];

  int idx = -1 , m = inf;
  rep(i,N){
    if(amin(m , abs(a[i] * N - s))) idx = i;
  }
  out(idx);
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> v(m);
    vector<int> p(m);
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k){
            int s;
            cin >> s;
            s--;
            v.at(i).push_back(s);
        }
    }
    rep(i,m) cin >> p.at(i);
    int ans = 0;
    for(int bit = 0; bit < (1 << n);bit++){
        int i = 0;
        vector<int> onoff(n,0);
        bool flg = true;
        while(i < n){
            if(bit & (1 << i)) onoff.at(i) = 1;
            i++;
        }
        rep(j,m){
            int size = v.at(j).size();
            int cnt = 0;
            rep(k,size) cnt += onoff.at(v.at(j).at(k));
            if((cnt%2)!=p.at(j)){
                flg = false;
                break;
            }
        }
        if(flg) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
using namespace std;
int main (){
    int N;
    cin >> N;
    // cout << N;
    vector <int> factor(N+1);
    int n = N;
    for (int j=N;j>1;j--){
        n=j;
    for (int i=2; i<=N;i++){
        while(n%i==0){
            factor.at(i)++;
            n /=i;
        }
    }
    }

    long long ans=1;

    for (int i = 2; i <= N; i++)
	{	
        // cout << i << " "<<factor.at(i)<< endl;
		ans *= factor.at(i) + 1; //それぞれを+1して掛けていく
        ans%= 1000000007;
    }
    cout << ans ;
    return 0;

}

Measured memory_bytes: 256
N = int(input())
cnt = 0

L = input().split()
L = [int(s) for s in L]

L.sort(reverse=True)

for i in range(len(L)-2):
    for j in range(i, len(L)-1):
        for k in range(j, len(L)):
            if L[i] < L[j] + L[k] and (L[i] != L[j] and L[i] != L[k] and L[j] != L[k]):
                # print(L[i] , L[j] , L[k])
                cnt += 1

print(cnt)

Measured memory_bytes: 9096
N = int(input())
X = [0] * N
for i in range(N):
    a = int(input()) - 1
    X[a] = i

ma = 1
s = 0
for i in range(1, N):
    if X[i] < X[i-1]: s = i
    ma = max(ma, i - s + 1)

print(N - ma)

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

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007LL;

int main(void) {
    int N, K;
    string S;
    cin >> N >> K >> S;
    S[K-1] += 32;
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 764
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	v, _ := strconv.Atoi(read())
	return v
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	M := nextInt()
	C := nextInt()

	B := make([]int, M)
	// var B [20]int
	for i := 0; i < M; i++ {
		B[i] = nextInt()
	}
	// fmt.Println(B)

	A := make([][]int, N)
	// var A [20][20]int
	for i := 0; i < N; i++ {
		A[i] = make([]int, M)
		for j := 0; j < M; j++ {
			A[i][j] = nextInt()
		}
	}

	// fmt.Println(A)
	var sum, count int

	for i := 0; i < N; i++ {
		sum = 0
		for j := 0; j < M; j++ {
			sum += A[i][j] * B[j]
		}
		if sum+C > 0 {
			count++
		}
	}
	fmt.Println(count)

}


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

int z;
int n;
int x[100005];
int now ;
int counter = 1;
int a;

int main()
{
	cin >> n;
	for(int i = 0 ; i <= n - 1 ; i ++)
	{
		cin >> x[i];
	}
	now = x[0] ;
	counter = 1;
	if(now != 2)
	{
	
	while(1)
	{
		if(x[now - 1] == 0)
		{
			counter = -1;
			break;
		}
		a = x[now - 1] ;
		x[now - 1] = 0;
		counter ++;
		
		now = a;
		if(now == 2)
		{
			break;	
		}
	}
}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
C = input()

W_total = C.count("W")
R_total = N - W_total
w_cur = 0
r_cur = R_total
ans = R_total
cur = 0

for i in range(N):
    if C[i] == "W":
        w_cur += 1
    else:
        r_cur -= 1

    ans = min(ans, min(w_cur, r_cur) + abs(w_cur - r_cur))

print(ans)

Measured memory_bytes: 69272