akhauriyash/Code-Regression huggingface dataset:
while True:
    H, W = [int(i) for i in input().split()]
    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')

Measured memory_bytes: 8996
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (1000 + 2)
ll dp[MAX_N][MAX_N];

void exec(){
  string a[MAX_N];
  int h, w;

  cin >> h >> w;

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

  dp[0][0] = 1;

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (a[i][j] == '#'){
        continue;
      }

      if (i - 1 >= 0){
        dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
      }
      if (j - 1 >= 0){
        dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
      }
    }
  }

  cout << dp[h-1][w-1] << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


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

using namespace std;

typedef long long ll;
ll maxLL = 10000000000LL;

ll mn(ll h, ll w){
  ll mini = maxLL;
  for(int i = 1; i < h; ++i){
    vector<ll> v = {w*i, w/2*(h-i), (w+1)/2*(h-i)};
    ll dif = max(v[0], max(v[1], v[2]))-min(v[0], min(v[1],v[2]));
    mini = min(mini, dif);
  }
  return mini; 
}



int main(){
  int h, w;
  cin >> h >> w;

  ll minh = maxLL, minw = maxLL;
  if(h > 2)
    minh = w*(h % 3 == 0 ? 0 : 1);
  if(w > 2)
    minw = h*(w % 3 == 0 ? 0 : 1); 

  cout << min(mn(h, w), min(mn(w, h), min(minw, minh))) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
	int N;
	cin >> N;
	
	long sum = 0;
	
	for(int i = 1; i <= N; i++){
		if(i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}
 
	cout << sum << endl;
	
	return 0;
}

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

string r, a;

int main () {
	while (cin >> r >> a, r != "0" || a != "0") {
		int hit = 0, blow = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (r[j] == a[i]) {
					if (i == j) hit++;
					else blow++;
					break;
				}
			}
		}
		cout << hit << ' ' << blow << endl;
	}
	return 0;
}

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

using namespace std;
int main()
{
  double n ;
  cin>>n;
  double x = n/3;
  double vol = x*x*x;
  cout << fixed << setprecision(12) <<vol;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner scn = new Scanner(System.in);
    if(scn.nextInt() % 2 == 0 || scn.nextInt() % 2 == 0){
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 20820
s = gets.chomp

total = 0
last_reversed = {nil => 0, 0 => 1}
before = s[0]

s.split("").each_with_index{ |c, i|
	next if i == 0
	temp = {}
	last_reversed.each { |k, v|
		if c == before then
			# 1つ前をひっくり返していて同じ
			if k != i - 1 then
				temp[i] = last_reversed[k] + 1
				last_reversed.delete(k)
			end
		else
			# 1つ前をひっくり返していて違う
			if k == i - 1 then
				temp[i] = last_reversed[k] + 1
				last_reversed.delete(k)
			end
		end
	}
	last_reversed = last_reversed.merge(temp)

	before = c
}

puts last_reversed.values.min

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

int main(){
    int n;
    cin >> n;
    lint d[90];
    d[0] = 2;
    d[1] = 1;
    REP(p, 2, n+1){
        d[p] = d[p-2] + d[p-1];
    }
    cout << d[n]  << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
a = int(input())
mon = list(map(int, input().split(" ")))
att = list(map(int, input().split(" ")))
kil = 0

b = len(mon)

for i in range(b):
#    print(mon[i])
    if i == a :
        if  mon[i] >= att[i-1]:
            kil = kil + att[i-1]
        elif mon[i] < att[i-1] :
            kil = kil + mon[i]
        break
    elif i > 0 and att[i-1] > 0 :
        if mon[i] >= att[i-1]:
            kil = kil + att[i-1]
            mon[i] = mon[i] - att[i-1] 
        elif mon[i] < att[i-1] :
            kil = kil + mon[i]
            continue
    if mon[i] >= att[i]:
        kil = kil + att[i]
        att[i] = 0
    elif mon[i] < att[i] :
        kil = kil + mon[i]
        att[i] = att[i] - mon[i]
#    print('result'+str(i)+':')
#    print('kil:'+str(kil))
#    print('zanAtt:'+att[])
        
print(kil)

Measured memory_bytes: 85468
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

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

  LL N;
  cin >> N;
  LL cnt = 0;
  while(N>1){
    N = (N + 2) / 3;
    cnt++;
  }
  cout << cnt << endl;
}



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

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

    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(i % 2 == 0) ans += a[i];
        else ans -= a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a=0,i;
    cin>>n;
    int ar[n];
    for(i=0;i<n;i++)cin>>ar[i];
    int j;
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++)a=(a+ar[i]*ar[j]);
    }
    cout<<a;
    return 0;
}

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

int main(){
        long long int n, a, b;
        cin>>n>>a>>b;
        long long int ans;
        if(a>b || (n==1 && (a!=b))) ans=0;
        else{
                ans= (a+b*(n-1)) - (a*(n-1)+b) + 1;
        }
        cout<<ans<<endl;
        return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back
#define cl (c*2)
#define cr (cl+1)
#define mid ((be+en)/2)

using namespace std;

const int N = 5e3+100;

int a[N], n, k;

bitset<N>pre[N], suf[N];

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    for(int i = 0 ; i < n ; i++ ) {
        cin >> a[i];
        a[i] = min(a[i], 5000);
    }
    pre[1][0] = 1;
    pre[0][0] = 1;
    for(int i = 0 ; i < n ; i++ ) {
        pre[i+1] |= pre[i+1] << a[i];
        pre[i+2] = pre[i+1];
    }
    suf[0][0] = 1;
    suf[1][0] = 1;
    for(int i = 0 ; i < n ; i++ ) {
        suf[i+1] |= suf[i+1] << a[n - i - 1];
        suf[i+2] =  suf[i+1];
    }
    int ans = 0;
    for(int i = 0 ; i < n ; i++ ) {
        set<int>s;
        s.clear();
        for(int j = 0 ; j <= 5000 ; j++ ) {
            if(suf[n-i-1][j]) s.insert(j);
        }
        /*cout << '\t' << i << '\n';
        for(int u: s) cout << u << ' ' ;
        cout << '\n';*/
        bool ok = 1;
        for(int j = 0 ; j <= 5000 ; j++ ) {
            if(pre[i][j]) {
                auto it = s.lower_bound(k - j - a[i]);
               // cout << j << ' ' << (it == s.end()) << ' ' << *it<< '\n';
                if(it != s.end()) {
                    if(*it + j < k) {
                        ok = 0;
                    }
                }
            }
        }
        ans+=ok;
    }
    cout << ans;
}


Measured memory_bytes: 10108
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w, n) = (v[0], v[1], v[2]);
    let mut blocks = vec![vec![]; w];
    let mut blocks_set = HashSet::new();
    for i in 0..n {
        let v = read_vec::<usize>();
        let (x, y) = (v[0] - 1, v[1] - 1);
        blocks[y].push(x);
        blocks_set.insert((x, y));
    }
    for y in 0..w {
        blocks[y].sort();
    }
    let mut cur = 0;
    let mut ans = h;
    for y in 0..w {
        let idx = blocks[y].lower_bound(&cur);
        if idx != blocks[y].len() {
            ans = min(blocks[y][idx], ans);
        }
        cur += 1;
        if y == w - 1 {
            break;
        }
        while blocks_set.contains(&(cur, y + 1)) {
            cur += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

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


Measured memory_bytes: 24056
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	var a, b int
	fmt.Scan(&a, &b)
	var u string
	fmt.Scan(&u)
	if u == s {
		a--
	} else {
		b--
	}
	fmt.Printf("%d %d\n", a, b)
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int min(int x, int y){return x < y ? x : y;}

int main(){
	int input[5];
	for(int i = 0; i < 5; i++) cin >> input[i];
	int res = 10000;
	int time = 0;
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 5; j++){
			if(i == j) continue;
			for(int k = 0; k < 5; k++){
				if(i == k || j == k) continue;
				for(int l = 0; l < 5; l++){
					if(i == l || j == l || k == l) continue;
					for(int m = 0; m < 5; m++){
						if(m == i || m == j || m == k || m == l) continue;
						time += input[i];
						time = (time % 10 == 0) ? time : ((time / 10 + 1) * 10);
						time += input[j];
						time = (time % 10 == 0) ? time : ((time / 10 + 1) * 10);
						time += input[k];
						time = (time % 10 == 0) ? time : ((time / 10 + 1) * 10);
						time += input[l];
						time = (time % 10 == 0) ? time : ((time / 10 + 1) * 10);
						time += input[m];
						res = min(res, time);
						time= 0;
					}
				}
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(A):
    min_num = A[0] + A[-1]


def main():
    N = int(input())
    R = []
    for _ in range(N):
        X, L = map(int, input().split())
        R.append((X - L, X + L))
    
    R.sort(key=lambda l: l[1])

    res = 0
    T = None    
    for r in R:
        if T is None or r[0] >= T:
            T = r[1]
            res += 1

    print(res)


if __name__ == "__main__":
    main()


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

int main(int argc, char const *argv[]) {
	int x, y;

	while (true) {
		cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		}
		else if (x > y) {
			swap(x, y);
		}
		cout << x << " " << y << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>

#define MAXLENGTH 10009
#define SLENGTH 109
#define NUM 102

void dictionary_order(int n, char s[NUM][SLENGTH]);

int main(void){
	int n,l,i;
	char s[NUM][SLENGTH]={};
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	dictionary_order(n,s);
	printf("\n");
	return 0;
}

void dictionary_order(int n,char s[NUM][SLENGTH]){
	int i,j,disorder=1;
	while(disorder==1){
		disorder=0;
		for(i=0;i<n-1;i++){
			if(strcmp(s[i], s[i+1])>0){
				char temp[SLENGTH]={};
				for(j=0;s[i][j]!='\0';j++){
					temp[j]=s[i][j];
				}
				for(j=0;s[i][j]!='\0';j++){
					s[i][j]=s[i+1][j];
				}
				for(j=0;temp[j]!='\0';j++){
					s[i+1][j]=temp[j];
				}
			}
		}
		for(i=0;i<n-1;i++){
			if(strcmp(s[i],s[i+1])>0){disorder=1;}
		}
	}
	for(i=0;i<n;i++){printf("%s", s[i]);}
}

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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
	int arr[205], n, l;
	
	cin>> n >> l;
	
	int sum = 0;
	
	for(int i = 1; i <= n; i++)
	{
		arr[i] = l+i-1;
		sum +=arr[i];
	}
	
	int ans,mx, diff = INT_MAX;
	
	for(int i = 1; i <= n;i++)
	{
		ans = abs(sum - (sum-arr[i]));
		if(ans < diff) {diff = ans;mx = sum-arr[i];}
	}
	
	
	cout << mx << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    S = str(input())
    T = str(input())

    count = 0
    if S == T :
        print("0")
    else :
        for i in range(len(S)) :
            if S[i] != T[i] :
                count += 1
            else :
                pass
        print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9560
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n, m, v, p;
llint a[100005];

bool check(llint x)
{
	llint sum = 0, ub = a[x]+m;
	if(ub < a[p]) return false;
	if(v <= p) return true;
	
	for(int i = p; i <= n; i++){
		if(i == x) continue;
		sum += min(m, ub-a[i]);
	}
	return sum/(v-p) >= m;
}

int main(void)
{
	cin >> n >> m >> v >> p;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	
	llint ub = n+1, lb = p, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	while(cin >> s) {
		for(unsigned int i = 0; i < s.size(); ++i) {
			if(s[i] == '@') {
				for(int j = 0; j < s[i+1] - '0'; ++j) {
					cout << s[i+2];
				}
				i += 2;
			}
			else {
				cout << s[i];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;

int main()
{
    fastio;
    int a, b, c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
    
    return 0;
}


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

typedef long long ll;

int main() {
  int n;
  while(cin >> n && n) {
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a,a+n);
    ll ans=0,sum=0;
    for(int i=0; i<n-1; i++) {
      sum+=a[i];
      ans+=sum;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>

int main()
{
    int N, M, K;
    std::cin >> N >> M >> K;
    unsigned long long A[N+1], B[M+1];
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    for(int i=0; i<M; i++){
        std::cin >> B[i];
    }
    A[N] = INT32_MAX;
    B[M] = INT32_MAX;

    for(int i=1; i<N; i++){
        A[i] += A[i-1];
    }
    for(int j=1; j<M; j++){
        B[j] += B[j-1];
    }

    int i=N-1;
    int best = 0;
    while(A[i] > K){
        i--;
        if(i < 0) break;
    }

    int j = -1;
    for(; i>=-1; i--){
        int ans = 0;
        if(i == -1){
            while(B[j+1] <= K){
                j++;
                if(j >= M) break;
            }
        }else{
            while(A[i] + B[j+1] <= K){
                j++;
                if(j >= M) break;
            }
        }
        ans = i+j+2;
        if(ans > best){
            best = ans;
        }
    }

    std::cout << best << std::endl;

    //int end;
    //std::cin >> end;
    return 0;
}

Measured memory_bytes: 6748
// inputに入力データ全体が入る
function Main(input) {
	input = input.split('\n');
  	tmp = input[1].split(' ');
  	for(let i = 0; i < tmp.length; i++){
      tmp[i] = parseInt(tmp[i]);
    }

  	let arr = [];
  	for(let i = 0 ; i < tmp.length; i++){
      if(arr.length===0 || tmp[i]-tmp[i-1] >= 0 ){
        arr.push(0);
      }else{
        arr.push(tmp[i-1]-tmp[i]);
        tmp[i] += tmp[i-1]-tmp[i];
      }
    }
  
	let result = 0;
    for(let i = 0; i < arr.length; i++){
      result += arr[i];
    }
  	console.log(result);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 54892
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

using cat = long long;

vector< vector<cat> > solve(int l, int r, int N, cat M) {
	vector< vector<cat> > ret(N+1, vector<cat>(N+1, 0));
	if(l == N && r == 2*N) {
		for(int i = 0; i <= N; i++) ret[i][0] = 1;
		return ret;
	}
	int Xr = floor(sqrt(4*N*N-r*r));
	Xr = min(2*N-1, Xr);
	if(l == N) {
		auto dp = solve(l, r+1, N, M);
		for(int i = 0; i <= N; i++) {
			int prev = 2*N-1-r;
			ret[i][0] = dp[i][0] * max(0, Xr+1-prev) % M;
		}
		return ret;
	}
	int Xl[] = {floor(sqrt(4*N*N-l*l)), floor(sqrt(N*N-1-l*l))};
	Xl[0] = min(2*N-1, Xl[0]);
	if(Xl[1] < Xr) {
		auto dp = solve(l, r+1, N, M);
		for(int i = 0; i <= N; i++) for(int j = 0; j <= N-i; j++) {
			int prev = 2*N-1-r+j;
			ret[i][j] = dp[i][j] * max(0, Xr+1-prev) % M;
		}
		return ret;
	}
	auto dp = solve(l+1, r, N, M);
	// Xr, ..., Xl[1], ..., Xl[0]
	for(int i = 0; i <= N; i++) for(int j = 0; j <= N-i; j++) {
		// take Xl[0]
		int prev = 2*N-1-l+i;
		ret[i][j] = dp[i][j] * max(0, Xl[0]+1-prev) % M;
	}
	for(int i = 1; i <= N; i++) for(int j = 0; j <= N-i; j++) {
		// take Xl[1]
		int prev = 2*N-r+i-1;
		ret[j][i] = (ret[j][i] + dp[j+1][i-1] * max(0, Xl[1]+1-prev)) % M;
	}
	return ret;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int N;
	cat M;
	cin >> N >> M;
	auto dp = solve(0, N, N, M);
	cat ans = 0;
	for(int i = 0; i <= N; i++) ans += (i&1) ? -dp[0][i] : dp[0][i];
	ans %= M;
	if(ans < 0) ans += M;
	cout << ans << "\n";
}


Measured memory_bytes: 250880
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

ans1 = 0
ans2 = 0

(0..(n-1)).each do |i|
  e = a[i]
  ((i+1)..(n-1)).each do |j|
    f = a[j]
    # p [e,f].join(',')
    if e > f
      ans1 += 1
    end
  end
end

a.each do |e|
  a.each do |f|
    # p [e,f].join(',')
    if e > f
      ans2 += 1
    end
  end
end

# puts [ans1, ans2].join(', ')
# puts ans1 + ans2

mod = 10**9 + 7
ans = ans1 * k + ans2 * k * (k-1) /2
# puts ans
puts ans % mod

Measured memory_bytes: 1916
import heapq

n = int(input())
a = list(map(int, input().split()))

first = a[:n]
second = a[n : 2 * n]
third = a[2 * n:]

s_minus = [-i for i in second]
t_minus = [-i for i in third]

former = [sum(first)]
latter = [sum(t_minus)]

heapq.heapify(first)
for k in range(n):
	heapq.heappush(first, second[k])
	former.append(former[-1] + second[k] - heapq.heappop(first))

heapq.heapify(t_minus)
for k in range(n):
	heapq.heappush(t_minus, s_minus[-(k + 1)])
	latter.append(latter[-1] + s_minus[-(k + 1)] - heapq.heappop(t_minus))

new_latter = [latter[-(i + 1)] for i in range(n + 1)]

ans = -5000000000000000000000000000000
for f, l in zip(former, new_latter):
	if f + l >= ans:
		ans = f + l

print(ans)

Measured memory_bytes: 39260
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>


int main() {
    //std::ifstream in("in01.txt");
    //std::cin.rdbuf(in.rdbuf());

    std::string str;
    int a;
    std::cin >> a;
    std::cin >> str;
    
    if (a >= 3200) {
        std::cout << str << std::endl;
    } else {
        std::cout << "red" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import sys
from string import ascii_uppercase

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    n = len(S)

    if S[0] != 'A':
        print("WA")
        sys.exit()

    for i in range(2, n-1):
        if S[i] == 'C':
            idx = i
            break
    else:
        print("WA")
        sys.exit()

    for i in range(n):
        if i == 0 or i == idx: continue
        if S[i] in ascii_uppercase:
            print("WA")
            sys.exit()
    else:
        print("AC")

if __name__ == '__main__':
    main()

Measured memory_bytes: 39024
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


m = Mod(10**9 + 7)


def slv(N, M, A):
    dp = [0] * (N+3)
    b = [False] * (N+3)
    for a in A:
        b[a] = True

    dp[0] = 1
    for i in range(N):
        if not b[i+1]:
            dp[i+1] = m.add(dp[i+1], dp[i])
        if not b[i+2]:
            dp[i+2] = m.add(dp[i+2], dp[i])
    return dp[N]


def main():
    N, M = read_int_n()
    A = [read_int() for _ in range(M)]
    print(slv(N, M, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11076
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	while (true) {
		auto input = []() {
			vector<pair<char, int>> ans;
			while (true) {
				string s;
				cin >> s;
				if (s == "$") return ans;
				int a;
				cin >> a;
				ans.push_back(mp(s[0], a));
			}
		};
		auto output = [](vector<pair<char, int>> a) {
			for (int i = 0; i < a.size(); ++i) {
				if (a[i].second == 0) {
					a.erase(a.begin() + i);
					i--;
					continue;
				}
				if (i + 1 < a.size() && a[i].first == a[i + 1].first) {
					a[i].second += a[i + 1].second;
					a.erase(a.begin() + i + 1);
					i--;
					continue;
				}
			}
			for (int i = 0; i < a.size(); ++i) {
				if (a[i].second == 0) {
					a.erase(a.begin() + i);
					i--;
					continue;
				}
				if (i + 1 < a.size() && a[i].first == a[i + 1].first) {
					a[i].second += a[i + 1].second;
					a.erase(a.begin() + i + 1);
					i--;
					continue;
				}
			}
			int skipping = 0;
			REP(i, a.size()) {
				if (skipping == 1) cout << " ";
				skipping = 1;
				cout << a[i].first << " " << a[i].second;
			}
			cout << " $" << endl;
		};

		vector<pair<char,int>> A = input(), B = input(), C = input();
		if (B.size() == 1) {
			// exception here.
			for (int i = 0; i < A.size(); ++i) {
				if (A[i].first == B[0].first && A[i].second >= B[0].second) {
					A[i].second -= B[0].second;
					for (int q = C.size() - 1; q >= 0; --q) {
						A.insert(A.begin() + i, C[q]);
					}
					break;
				}
			}
		}
		else {
			for (int i = 0; i < (int)A.size() - (int)B.size() + 1; ++i) {
				if (A[i].first == B[0].first && A[i].second >= B[0].second) {
					int ok = 1;
					for (int q = 1; q < B.size() - 1; ++q) {
						if (A[i + q] != B[q]) {
							ok = 0;
							break;
						}
					}
					if (ok == 0) continue;
					if (A[i + B.size() - 1].first != B.back().first || A[i + B.size() - 1].second < B.back().second) continue;
					A[i].second -= B[0].second;
					REP(q, B.size() - 2) {
						A.erase(A.begin() + i + 1);
					}
					A[i + 1].second -= B.back().second;
					REP(q, C.size()) {
						A.insert(A.begin() + i + 1, C[C.size()-1-q]);
					}
					break;
				}
			}
		}
		output(A);
		return;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3336
// 選択ソート
#include<iostream>
#include<algorithm>
using namespace std;

static const int MAX_N = 100;

void selectionSort(int A[], int n);

int main(void)
{
    int N;
    int ary_sequence[MAX_N];

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> ary_sequence[i];
    }

    selectionSort(&ary_sequence[0], N);

    return 0;
}

// 選択ソートを実施する関数
void selectionSort(int A[], int n)
{

    int count = 0;
    // 最小値の存在する配列の要素No.
    int min_pos;

    for(int i = 0; i < n - 1; i++)
    {
        min_pos = i;

        for(int j = i; j < n; j++)
        {
            if( A[j] < A[min_pos] )
            {
                // 最小値の存在する位置を保存する
                min_pos = j;
            }
        }

        if( i != min_pos )
        {
            // 最小値を移動させる
            swap(A[i], A[min_pos]);

            count++;
        }
    }

    // 結果表示用
   for(int i = 0; i < n; i++)
   {
       if( i )
       {
           cout << ' ';
       }

       cout << A[i];
   }

   cout << endl;
   cout << count << endl;

    return;
}



Measured memory_bytes: 3092
n = int(input())
a = list(map(int,input().split()))
ni = 0
yon = 0
hoka = 0
for i in range(n):
  if a[i] %4 == 0:
    yon += 1
  elif a[i] %2 == 0:
    ni += 1
  else:
    hoka += 1
if ni == 0:
  ha = 0
else:
  ha = 1
if 2+yon-1 >= hoka + ha:
  print("Yes")
elif ni == n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main()
{
	string s="";
	cin>>s;
	rep(i, s.length())cout<<"x";
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

int H, W;
vector<string> s;
map<vector<string>, int> dp; // 1:ok, -1:ng, 0:unknown
int gx, gy;

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

vector<string> play(vector<string> s, int i, int j, int k) {
    for ( ; s[i][j] == 'o' && inside(i + dx[k], j + dy[k]); i += dx[k], j += dy[k]) {
        swap(s[i][j], s[i + dx[k]][j + dy[k]]);
    }
    return s;
}

int dfs(vector<string> s) {
    if (dp[s] != 0) return dp[s];

    if (s[gx][gy] == 'o') {
        return dp[s] = 1;
    }

    int ret = -1;
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == 'o') {
                rep(k, 4) {
                    auto t = play(s, i, j, k);
                    if (dp.count(t) == 0 && dfs(t) == 1) {
                        ret = 1;
                    }
                }
            }
        }
    }
    return dp[s] = ret;

}

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

    cin >> H >> W;
    s.resize(H);
    rep(i, H) cin >> s[i];

    int N = 0;
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == 'o') {
                N++;
            }
            if (s[i][j] == '@') {
                gx = i, gy = j;
                s[i][j] = '.';
            }
        }
    }

    if (H > 1 && W > 1 && N >= 3) {
        cout << "yes" << endl;
        return 0;
    }

    cout << (dfs(s) == 1 ? "yes" : "no") << endl;

}

Measured memory_bytes: 3736
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

struct Edge {
	ll to, cost;
	Edge() = default;
	Edge(ll a, ll b) { to = a, cost = b; }
};

ll N, M, X;
ll H[100000];
ll d[100000];
vector<vector<Edge>> e;
const ll INF810 = 1145141919810893;

void djk() {
	for (int i = 0; i < N; i++)d[i] = INF810;

	priority_queue<P, vector<P>, greater<P>> pq;
	d[0] = 0;
	pq.push(P(0, 0));

	while (pq.size()) {
		auto tmp = pq.top(); pq.pop();
		if (tmp.first > d[tmp.second])continue;
		
		ll high = d[tmp.second] > X ? 0 : X - d[tmp.second];

		for (int i = 0; i < e[tmp.second].size(); i++) {
			Edge& next = e[tmp.second][i];

			//?????????????£????????????´???
			if (H[tmp.second] < next.cost)continue;

			//???????¨?????????£????£???¶??´???
			if (H[next.to] + next.cost < high) {
				if (d[next.to] > d[tmp.second] + next.cost + (high - (H[next.to] + next.cost))) {
					d[next.to] = d[tmp.second] + next.cost + (high - (H[next.to] + next.cost));
					pq.push(P(d[next.to], next.to));
				}
				continue;
			}

			//????????????????????§?£?????????´???
			if (high > next.cost) {
				if (d[next.to] > d[tmp.second] + next.cost) {
					d[next.to] = d[tmp.second] + next.cost;
					pq.push(P(d[next.to], next.to));
				}
				continue;
			}

			//???????¨?????????£????£???¶??´???
			if (d[next.to] > d[tmp.second] + next.cost + (next.cost - high)) {
				d[next.to] = d[tmp.second] + next.cost + (next.cost - high);
				pq.push(P(d[next.to], next.to));
			}
		}

	}

}

int main() {
	cin >> N >> M >> X;
	for (int i = 0; i < N; i++)cin >> H[i];
	e.resize(N);
	for (int i = 0; i < M; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		e[a].push_back(Edge(b, c));
		e[b].push_back(Edge(a, c));
	}

	djk();

	if (d[N - 1] == INF810) {
		cout << -1 << endl;
		return 0;
	}
	if (d[N - 1] < X) {
		cout << d[N - 1] + (H[N - 1] - (X - d[N - 1])) << endl;
	}
	else {
		cout << d[N - 1] + H[N - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 23216
X = int(input())
answer = 0
for b in range(1,X + 1):
    if b == 1 and answer == 0:
        answer = 1
        continue
    for p in range(2,X + 1):
        fact = b ** p
        if fact <= X:
            if fact > answer:
                answer = fact
        else:
            break
print(answer)

Measured memory_bytes: 3060
#include <iostream>

long long int A, B, C, K;

int main() {
  std::cin >> A >> B >> C >> K;
  int max = 0;
  
  if (K <= A) {
    max = K;
  }
  else if (A <= K && K <= A + B) {
    max = A;
  }
  else {
    max = A - (K - (A + B));
  }

  std::cout << max << std::endl;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


const int MOD = 1000000007;

mii PFs;
mii mxPFs;
void getPFs(ll x) {
	for (ll i = 2; i * i <= x; ++i)
		while (x % i == 0)
			PFs[i]++, x /= i;
	if (x > 1)
		PFs[x]++;
}

ll inv(ll a, ll b) {
	return 1 < a ? b - inv(b % a, a) * b / a : 1;
}



int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N;

	cin >> N;

	vi A(N);

	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		PFs.clear();
		getPFs(A[i]);
		for (auto& pr : PFs) {
			mxPFs[pr.fs] = max(mxPFs[pr.fs], pr.sc);
		}
	}

	int L = 1;

	for (auto& pr : mxPFs) {
		for (int i = 1; i <= pr.sc; ++i) {
			L = (L * 1LL * pr.fs) % MOD;
		}
	}

	int ans = 0;

	for (int i = 0; i < N; ++i) {
		ans = (ans + ((L * inv(A[i], MOD)) % MOD)) % MOD;
	}

	cout << ans << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 768
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val x, y = sc.nextInt()
  (0 to x).find( i =>
    2 * i + 4 * (x-i) == y
  ) match {
    case Some(_) => println("Yes")
    case None => println("No")
  }
}


Measured memory_bytes: 55304
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

	if (N == 1){
		cout << a[0] << endl;
		return 0;
	}
	for (int i = a.size() - 1; i >= 0; i -= 2){
		cout << a[i]<<" ";
	}
	for (int i = (N % 2); i < a.size(); i += 2){
		cout << a[i];
		if (i + 2 >= a.size()){
			break;
		}
		cout << " ";
	}
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.next.toInt
    val bottons = List.fill(n)(sc.nextInt)
    val indexBottonMap = bottons.zipWithIndex.map(item => (item._2, item._1)).toMap

    def go(n: Int, k: Int, acc: Int): Int = {
      if (n == -1) -1
      else if (k == 2) acc
      else {
        go(n - 1, indexBottonMap(k - 1), acc + 1)
      }
    }

    println(go(n, 1, 0))
  }
}


Measured memory_bytes: 89964
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,ans=0,t[55]={},f=0;
  string s[55]={},x;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> x;
  for(int i=0; i<n; i++) {
    if(f) {
      ans+=t[i];
    }
    if(s[i]==x) {
      f=1;
    }
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
        } else {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a + b);
        }

    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,D;
int main(){
  cin>>N>>D;
  int x=2*D+1;
  if(N%x==0) prin(N/x);
  else prin(N/x+1);
  return 0;
}


Measured memory_bytes: 256
class Graph
  include Comparable
  attr_reader :id, :depth
  @@nodes = Array.new
  def initialize(id, left = nil, right = nil)
    @id = id
    @left = left == -1? nil: left
    @right = right == -1? nil: right
    @degree = 0
    @degree += 1 if @left
    @degree += 1 if @right
    @depth = -1
    @parent = -1
    @sibling = -1
    @@nodes[id] = self
  end
  
  def set_parent(other)
    @parent = other
  end
  
  def set_child
    @@nodes[@left].set_parent(self) if @left
    @@nodes[@right].set_parent(self) if @right
    if @left and @right
      @@nodes[@left].set_sib(@@nodes[@right])
      @@nodes[@right].set_sib(@@nodes[@left])
    end
  end
  
  def set_children
    set_child
    @@nodes[@left].set_children if @left
    @@nodes[@right].set_children if @right
  end
  
  def set_sib(other)
    @sibling = other
  end
  
  def depth
    if @parent != -1
      @parent.depth + 1
    else
      0
    end
  end
  
  def height
    left = @left? @@nodes[@left].height: -1
    right = @right? @@nodes[@right].height: -1
    if left < right
      right + 1
    else
      left + 1
    end
  end
  
  def <=>(other)
    if Graph === other
      @id <=> other.id
    else
      @id <=> other
    end
  end
  
  def type
    if @parent == -1
      return "root"
    elsif @degree == 0
      return "leaf"
    else
      return "internal node"
    end
  end
  
  def order(n)
    arr = []
    if n == 0
      preorder(arr)
      return ["Preorder", " " + arr.join(" ")]
    elsif n == 1
      inorder(arr)
      return ["Inorder", " " + arr.join(" ")]
    else
      postorder(arr)
      return ["Postorder", " " + arr.join(" ")]
    end
  end
  
  def preorder(arr)
    arr << @id
    @@nodes[@left].preorder(arr) if @left
    @@nodes[@right].preorder(arr) if @right
  end
  
  def inorder(arr)
    @@nodes[@left].inorder(arr) if @left
    arr << @id
    @@nodes[@right].inorder(arr) if @right
  end
  
  def postorder(arr)
    @@nodes[@left].postorder(arr) if @left
    @@nodes[@right].postorder(arr) if @right
    arr << @id
  end
  
  def inspect
  end
  
  def to_s
    "node #{@id}: parent = #{@parent.id}, sibling = #{@sibling.id}, degree = #{@degree}, depth = #{depth}, height = #{height}, #{type}"
  end
end
def main
  arr = []
  gets.to_i.times do
    arr << Graph.new(*gets.split(" ").map(&:to_i))
  end
  root = 0
  arr.each{|item|
    if item.type == "root"
      item.set_children
      root = item
    end
  }
  arr.sort!
  3.times do |n|
    puts root.order(n)
  end
end
main

Measured memory_bytes: 6092
s = input()
for i in range(len(s)):
  if (i+1)/2 != int((i+1)/2):
    if (s[i] == 'R') or (s[i] =='U') or (s[i] =='D'):
      pass
    else:
      print('No')
      exit()
  else:
    if (s[i] == 'L') or (s[i] =='U') or (s[i] =='D'):
      pass
    else:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 3064
def main():
  import sys
  n = int(input())
  a = tuple(map(int,sys.stdin.readline().split()))
  b = tuple(map(int,sys.stdin.readline().split()))
  
  count=0
  cNow=a[0]
  cNext=a[1]
  
  for i in range(n):
    cNext=a[i+1]
    h = b[i]
    count+=min(cNow,h)  
    if h>cNow:
        count+=min(h-cNow,cNext)
        cNow=max(0,cNext-(h-cNow))
        continue
    cNow=cNext
  print(count)
  
if __name__=="__main__":
  main()

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

signed main() {
	int n, i;
	int l[200];
	
	cin >> n;
	for (i = 0; i < 2 * n; i++) cin >> l[i];
	sort(l, l + 2 * n);
	
	int ans = 0;
	for (i = 0; i < 2 * n; i += 2) {
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
    double x[n];
    string y[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    double ans = 0;
    for (int i = 0; i < n; i++) {
      if (y[i] == "JPY") {
        ans += x[i];
      }
      else {
        ans += x[i]*380000.0;
      }
    }
    cout << ans << endl;
}
	

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

int main(void)
{
    int time;
    int h, m, s;

    cin >> time;

    h = time / 3600;
    m = (time - h * 3600) / 60;
    s = time - (m * 60 + h * 3600);

    cout << h << ":" << m << ":" << s << "\n";

    return (0);
}




Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
using namespace std;
int T, N, K, X[100000+10], A[100000+10];
int main()
{
  int temp=0;
  cin >> T;
  for(int t=0; t<T; ++t)
    {
      cin>>N>>K;
      for (int i=0; i<N; ++i)
	cin >> X[i];
      for (int i=0; i+1<N; ++i)
	A[i] = X[i+1]-X[i];
      sort(A,A+N-1);
      temp=0;
      for(int i=0;i<max(0,N-K);i++)
	{
	  temp+=A[i];
	}
      cout<<temp<<endl;
    }
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

int main(){
  int N;
  cin>>N;
  //Graph
  vector<vector<int>> G(N);
  //edge
  vector<pair<int,int>> vp;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }
 
  int K=0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0);
 
  vector<int> used(N,0);//color
  queue<int> que;
  used[0]=1;//init color
  que.emplace(0);//初期位置
  //bfs
  while(!que.empty()){
    int v=que.front();que.pop();
    if(K<(int)G[v].size()) K=G[v].size();//色の最大数がエッジ分なかったら増やす
    int cur=1;
    //グラフの走査
    for(int u:G[v]){
      if(used[u]) continue;//探索済みならスルー
      if(cur==cs[v]) cur++;//取り出したノードがいまあるの色数を使用済み
      //使った色の記録
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }
 
  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;
  return 0;
}

Measured memory_bytes: 20084
TH = 10**9 + 7
_ = gets.to_i
a = gets.chomp.split.map(&:to_i)
h = Hash.new(0)
is_include_zero = false
a.each do |_a|
  h[_a] += 1
  is_include_zero = true if _a.zero?
end
contradiction = false
if is_include_zero
  if h[0] == 1
    x = h.select { |k, v| k != 0 && v != 2 }
    contradiction = true unless x.empty?
  else
    contradiction = true
  end
else
  x = h.select { |_, v| v != 2 }
  contradiction = true unless x.empty?
end

if contradiction
  puts '0'
else
  ans = 1
  h.each do |_k, v|
    ans = (ans * v) % TH
  end
  puts ans
end


Measured memory_bytes: 25796