akhauriyash/Code-Regression huggingface dataset:
//解き方を説明したver.
//youtube解説とかeditorialの意味がわからなかったので自己流です。
//サンプルケースは4のみ通りません。
#include<stdio.h>
typedef long long int ll;

//aCbを求める
ll conbi(ll a, ll b){
    if(a == b){return 1;}
    ll p1 = 1;
    for(int i = 0; i < b; i++){
        p1 *= a;
        a--;
    }
    if(b == 3){b = 6;}
    return p1/b;
}

int main(void){
    ll N, K;
    scanf("%lld%lld", &N, &K);

    //N以下で、かつKの倍数の数字の個数をmultiofkに入れる
    ll multiOfk = 0;
    for(ll i = 1; i <= N; i++){
        if(i%K == 0){multiOfk++;}
    }
    
    //multiOfkのうちの一つが例えば3であったら、(a, b, c) = (3, 3, 3)
    //のように3つとも同じ数字の組がmultiOfk個できる
    ll ans = multiOfk;//printf("1種類ans:%d\n", ans);
    //とってきた2種類をa, bとすると
    //aが2個bが1個のときの並べ方とaが1個1bが2個のときの並べ方の総数
    if(multiOfk >= 2){ans += conbi(multiOfk,2)*3*2;}//printf("1,2種類ans:%d\n", ans);
    //とってきた2種類をa, b, cとすると、3つの並べ方は3!通り
    if(multiOfk >= 3){ans += conbi(multiOfk,3)*3*2;}//printf("1,2,3種類ans:%d\n", ans);
    //printf("偶奇共通 総ans:%lld\n", ans);
    //Kが偶数の場合は、N以下の数nをKで割った時の余りがK/2の数が
    //存在していて、それらの数を足してもKの倍数になる
    //nをKで割った余りがK/2なので、n≡KK(mod K)より
    //n = K*cnt + KKとなる
    ll cnt = 0;
    if(K%2 == 0){
        ll KK = K/2;
        while(N >= (cnt*K + KK)){cnt++;}
    }
    //printf("偶数特別でK/2の個数 cnt:%d\n", cnt);
    ans += cnt;
    if(cnt >= 2){ans += conbi(cnt,2)*3*2;}
    if(cnt >= 3){ans += conbi(cnt,3)*3*2;}

    printf("%lld\n", ans);
    return 0;

}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    s += 'R';

    int pos = 0;
    bool fr = true;
    vector<int> cnt(n, 0);
    for (int i = 0; i < n; i++) {
        if (s[i] != s[i + 1]) {
            if (fr) {
                for (int j = pos; j <= i; j++) {
                    if ((i - j) % 2 == 0) cnt[i]++;
                    else cnt[i + 1]++;
                }
            } else {
                for (int j = pos; j <= i; j++) {
                    if ((j - pos) % 2 == 0) cnt[pos]++;
                    else cnt[pos - 1]++;
                }
            }
            fr = !fr;
            pos = i + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << cnt[i] << " \n"[i + 1 == n];
    }
    return 0;
}

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

int main() {
	int x;
	cin >> x;
	set<int>s;
	s.insert(1);
	for (int i = 2;(int)pow(i, 2) <= 1000;i++) {
		for (int j = 2;(int)pow(i, j) <= 1000;j++) {
			s.insert(pow(i, j));
		}
	}
	int ans;
	for (auto it = s.begin();it != s.end();it++) {
		if (*it <= x) {
			ans = *it;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        n: u32,
        v: [i32; n],
        c: [i32; n],
    }

    let mut ans = 0;
    for i in 0..1 << v.len() {
        let mut value = 0;
        let mut cost = 0;
        for j in 0..v.len() {
            if (1 << j) & i != 0 {
                value += v.get(j).unwrap().clone();
                cost += c.get(j).unwrap().clone();
            }
        }
        ans = max(ans, value - cost);
        if ans < value - cost {
            ans = value - cost;
        }
        // println!("value: {}, cost: {}", value, cost);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    char s;
    cin>>s;
    cout<<(char)(s + 1)<<endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int ans = 0;
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 != 0) {
        exist_odd = true;
      }
    }
    if (exist_odd == true) {
      break;
    }
    for (int i = 0; i < N; i++) {
      A.at(i) /= 2;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int s = sc.nextInt();
    
    int count = 0;
    for(int x = 0;x<=k;x++){
      for(int y=0;y<=k;y++){
        int z = s-x-y;
        if((z<=k)&&(z>=0)){
          count ++;
        }
      }
    }
    System.out.println(count);
  }
}
           


Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <cstring>
//#include <fstream>

using namespace std;

char M[1001][1001];
const int INF = 10e8;

typedef pair<int, int> P;

int bfs (P & sp, int n, int size, int len )
{
	// up, right, down, left order
	const int dir[][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

	int res = 0;
	vector <vector <int> > path (size, vector <int> (len, INF ) );
	queue <P> Q;
	P curr = sp;
	Q.push (curr);

	path[curr.first][curr.second] = 0;	

	while (!Q.empty() ){
		curr = Q.front(); Q.pop();
		if (M[curr.first][curr.second] == n + '0' ){
			break;
		} // end if
		for (int k = 0; k < 4; ++k){
			int nrow = curr.first  + dir[k][0];
			int ncol = curr.second + dir[k][1];
			if (nrow < 0 || nrow >= size || ncol < 0 || ncol >= len ){
				continue;
			} // end if
			if (M[nrow][ncol] != 'X' && path[nrow][ncol] == INF ){
				Q.push (P(nrow, ncol) );
				path[nrow][ncol] = path[curr.first][curr.second] + 1;
			} // end if
		} // end for
	} // end while
	
	res = path[curr.first][curr.second];

	sp.first = curr.first;
	sp.second = curr.second;

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.cheese3", "r", stdin );
	string str = "";
	int h, w, n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> h >> w >> n;
		memset (M, 0, sizeof (M ) );
		P sp;
		for (int i = 0; i < h; ++i){
			getline (cin, str );
			for (int j = 0; j < w; ++j){
				M[i][j] = str[j];
				if (M[i][j] == 'S' ){
					sp.first = i; sp.second = j;
				} // end if
			} // end for
		} // end for

		int res = 0;
		P cp = sp;
		for (int i = 1; i <= n; ++i){
			res += bfs ( cp, i, h, w );
		} // end for
		cout << res << endl;

	} // end loop
		
	return 0;
}

Measured memory_bytes: 5808
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
	ll a,b;
	int k,i;
	cin>>a>>b>>k;
	for(i=0;i<k;i++){
		if(i%2==0){
			if(a%2!=0)a--;
				b+=a/2;
				a/=2;
		}
		else{
			if(b%2!=0)b--;
			a+=b/2;
			b/=2;
		}
	}
	cout<<a<<" "<<b<<endl;
}
/*reveres begin end
cout<<"\n";
  m.insert(std::make_pair('c', 30));
  .erase(v.begin() + 2)
*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (int i = 0; i < 5; i++) {
			if (0 == sc.nextInt()) {
				System.out.println(i + 1);
			}
		}
	}
}

Measured memory_bytes: 35680
import static java.lang.System.out;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
       int b = sc.nextInt();
      
        out.println(""+a*b+" "+2*(a+b)+"");
    }
}


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

//nC2
ll choose2(ll n)
{
    return n *(n-1)/2;
}

int main(void) 
{
    int n;
    cin >> n;
    vector<int> vec(n);
    vector<int> data(n);
    rep(i,n) cin >> vec[i];
    rep(i,n) vec[i]--;

    rep(i,n) data[vec[i]]++;

    ll total =0;
    rep(i,n) total += choose2(data[i]);

    rep(i,n)
    {
        ll ans = total;
        ans -= choose2(data[vec[i]]);
        ans += choose2(data[vec[i]] - 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
a, b, c, d = map(int, input().split())
 
def gcd(x, y):
    if x < y:
        x, y = y, x
    while True:
        if x % y == 0:
            return y
        x, y = y, x%y
 
x = b - a + 1
cx = b // c - (a-1) // c
dx = b // d - (a-1) // d
cdx = b // (c*d // gcd(c, d)) - (a-1) // (c*d // gcd(c, d))
print(x - cx - dx + cdx)

Measured memory_bytes: 9200
using System;

class Program
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());

    string[] strAry = Console.ReadLine().Split();
    int[] ary = new int[n];
    for (int i = 0; i < n; i++) ary[i] = int.Parse(strAry[i]);


    int min = 0;
    int max = 0;
    long sum = ary[0];

    for (int i = 1; i < n; i++)
    {
      sum += ary[i];
      if (ary[i] < ary[min]) min = i;
      else if (ary[max] < ary[i]) max = i;
    }

    Console.WriteLine("{0} {1} {2}", ary[min], ary[max], sum);
  }
}

Measured memory_bytes: 9860
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll n,m;
ll gcd(ll x,ll y){return !y?x:gcd(y,x%y);}
int main(){
	scanf("%lld%lld",&n,&m);printf("%lld\n",3ll*(n-gcd(n,m)));
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>t;
      if(n>2*t)cout<<n-2*t;
      else cout<<0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <cmath> 
#include <algorithm>
using namespace std; 
const int Mod = 1e9 + 7; 
const int MAX_N = 305; 
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; } 
bool vis[MAX_N << 1], used[MAX_N << 1]; 
int N, M, ans, a[MAX_N << 1];
int c1, c2, num[MAX_N << 1];
int f[MAX_N << 1][MAX_N][MAX_N];
//第i个数，剩j对未匹配的(-1,-1)，剩k对(-1,x)
int main () { 
	scanf("%d", &N);
	for (int i = 1; i <= N << 1; i++) scanf("%d", a + i); 
	for (int i = 1; i <= N << 1; i += 2) { 
		if (a[i] == -1 && a[i + 1] == -1) ++c1; 
		else if (~a[i] && ~a[i + 1]) vis[a[i]] = vis[a[i + 1]] = 1; 
		else ++c2, used[~a[i] ? a[i] : a[i + 1]] = 1; 
	} 
	for (int i = N << 1; i; i--) if (!vis[i]) num[++M] = i; 
	f[0][0][0] = 1; 
	for (int i = 1; i <= M; i++) 
		for (int j = 0; j <= c1 + c2; j++) 
			for (int k = 0; k <= c2; k++) { 
				if (!f[i - 1][j][k]) continue; 
				if (!used[num[i]]) { 
					pls(f[i][j + 1][k], f[i - 1][j][k]); 
					if (j) pls(f[i][j - 1][k], f[i - 1][j][k]); 
					if (k) pls(f[i][j][k - 1], 1ll * f[i - 1][j][k] * k % Mod); 
				} else { 
					pls(f[i][j][k + 1], f[i - 1][j][k]); 
					if (j) pls(f[i][j - 1][k], f[i - 1][j][k]); 
				} 
			} 
	ans = f[M][0][0]; 
	for (int i = 1; i <= c1; i++) ans = 1ll * ans * i % Mod; 
	printf("%d\n", ans); 
    return 0; 
} 

Measured memory_bytes: 217472
#include<stdio.h>
#include<string>
#include<map>
using namespace std;
map<string,int>a;
int xx,yy;
string s[8]= {"hui","zong","lv","qing","lan","huang","cheng","hong"};
int main() {
	int n;
	scanf("%d",&n);
	bool ok=0;
	for(int i=1,x; i<=n; i++) {
		scanf("%d",&x);
		if(x<400) {
			a["hui"]++;
			continue;
		}
		if(x<800) {
			a["zong"]++;
			continue;
		}
		if(x<1200) {
			a["lv"]++;
			continue;
		}
		if(x<1600) {
			a["qing"]++;
			continue;
		}
		if(x<2000) {
			a["lan"]++;
			continue;
		}
		if(x<2400) {
			a["huang"]++;
			continue;
		}
		if(x<2800) {
			a["cheng"]++;
			continue;
		}
		if(x<3200) {
			a["hong"]++;
			continue;
		}
		if(x>=3200) {
			a["orz"]++;
			ok=1;
			continue;
		}
	}
	for(int i=0; i<=7; ++i)
		if(a[s[i]])
			++xx,++yy;
	if(ok&&xx)
		yy+=a["orz"];
	if(ok&&xx==0)
		xx=1,yy=a["orz"];
	printf("%d %d\n",xx,yy);
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
//	"sort"
//	"math"
//	"regexp"
)

var N string
func main(){
	fmt.Scan(&N)

	
	if string(N[0]) == "9"{
		fmt.Println("Yes")
	}else if string(N[1]) == "9"{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

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

typedef vector<vector<int>> MAP;
int H;

int erase(MAP &field) {
  int point = 0;
  for (int y = 0; y < H; ++y) {
    // erase [l, r]
    int l = 2, r = 2;
    int color = field[y][2];
    while (l > 0 and field[y][l-1] == color) l--;
    while (r < 4 and field[y][r+1] == color) r++;
//    cout << "y="<<y<<": (" << l <<", "<<r<<")"<<endl;
    if (r - l >= 2)
      for (int x = l; x <= r; ++x)
        point += field[y][x], field[y][x] = 0;
  }
  return point;
}

void drop(MAP &field) {
  for (int x = 0; x < 5; ++x) {
    vector<int> v;
    for (int y = H - 1; y >= 0; --y) {
      if (field[y][x] != 0) {
        v.push_back(field[y][x]);
        field[y][x] = 0;
      }
    }
    int y = H - 1;
    for (int color : v) {
      field[y][x] = color;
      --y;
    }
  }
}

int main() {
  while (cin >> H and H) {
    MAP field(H, vector<int>(5));
    for (int y = 0; y < H; ++y)
      for (int x = 0; x < 5; ++x)
        cin >> field[y][x];

    int sum = 0, point = 1;
    while (point > 0) {
      point = erase(field);
/*      for (int y=0;y<H;++y) {
        for (int x=0;x<5;++x)cout<<field[y][x];
        cout<<endl;
      }
      cout<<endl;*/
      sum += point;
      drop(field);
/*      for (int y=0;y<H;++y) {
        for (int x=0;x<5;++x)cout<<field[y][x];
        cout<<endl;
      }
      cout<<endl;*/
    }
    cout << sum << endl;
  }
}

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


int main(void) {
    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int x_max = 0;
    rep(i, n){
        if(s[i] == 'I')x ++;
        else x --;
        x_max = max(x, x_max);
    }
    cout << x_max << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
       System.out.print("");  int a = stdIn.nextInt();
       System.out.print("");  int b = stdIn.nextInt();
       System.out.print("");  int c = stdIn.nextInt();
       
       if (a <= c && b >= c)
           System.out.println("Yes");
       else
           System.out.println("No");
    }   
}

Measured memory_bytes: 21844
#include <stdio.h>
#define MOD 1000000007

int main(void)
{
    int N;
    scanf("%d", &N);

    long A[N];
    long long S[N + 1];
    long long ans = 0;
    for(int i = 0; i < N; i++) { scanf("%ld", &A[i]); }

    S[0] = 0;
    for(int i = 0; i < N; i++) { S[i + 1] = S[i] + A[i]; }

    for(int i = 0; i < N - 1; i++) {
        ans += (A[i] * ((S[N] - S[i + 1]) % MOD));
        ans %= MOD;
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// ALDS1_7_C.cpp
// Tree - Tree Walk

#include <iostream>
#include <vector>
using namespace std;

struct Node
{
    int id;
    int lchild;
    int rchild;
    int parent = -1;
};

void Preorder(vector<Node> &nodes, int id)
{
    cout << " " << nodes[id].id;
    if (nodes[id].lchild != -1)
        Preorder(nodes, nodes[id].lchild);
    if (nodes[id].rchild != -1)
        Preorder(nodes, nodes[id].rchild);
}

void Inorder(vector<Node> &nodes, int id)
{
    if (nodes[id].lchild != -1)
        Inorder(nodes, nodes[id].lchild);
    cout << " " << nodes[id].id;
    if (nodes[id].rchild != -1)
        Inorder(nodes, nodes[id].rchild);
}

void Postorder(vector<Node> &nodes, int id)
{
    if (nodes[id].lchild != -1)
        Postorder(nodes, nodes[id].lchild);
    if (nodes[id].rchild != -1)
        Postorder(nodes, nodes[id].rchild);
    cout << " " << nodes[id].id;
}

int main()
{
    int n;
    cin >> n;
    vector<Node> nodes(n);
    for (int i = 0; i < n; i++) {
        int id, lc, rc;
        cin >> id >> lc >> rc;
        nodes[id].id = id;
        nodes[id].lchild = lc;
        nodes[id].rchild = rc;
        if (lc != -1) {
            nodes[lc].parent = id;
        }
        if (rc != -1) {
            nodes[rc].parent = id;
        }
    }

    int root_id;
    for (int i = 0; i < n; i++) {
        if (nodes[i].parent == -1) {
            root_id = i;
            break;
        }
    }

    cout << "Preorder" << endl;
    Preorder(nodes, root_id);
    cout << endl << "Inorder" << endl;
    Inorder(nodes, root_id);
    cout << endl << "Postorder" << endl;
    Postorder(nodes, root_id);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, W;
        cin >> N >> W;
        int max_v = 1000 * 100 + 1;

        vector<vector<ll> > dp(N + 1, vector<ll>(max_v, INFl));
        dp[0][0] = 0;

        vector<ll> w(N), v(N);

        rep(i, 0, N) {
            cin >> w[i] >> v[i];
        }

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < max_v; ++j) {
                int ni = i + 1;
                ll nj = j + v[i];

                chmin(dp[ni][j], dp[i][j]);
                chmin(dp[ni][nj], dp[i][j] + w[i]);
            }
        }

        ll ans = 0ll;
        for (int i = 0; i <= N; ++i) {
            for (int j = 0; j < max_v; ++j) {
                if (dp[i][j] <= W) {
                    chmax(ans, j);
                }
            }
        }

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


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

struct Edge{
	  int tgt_;
	  Edge(int t){
			tgt_ = t;
	  }
};

typedef vector<vector<Edge> > Adj_list;

vector<int> topological_sort(Adj_list& G){

	  const int V = G.size();

	  vector<int> S; // ??\?????????????????????
	  vector<int> inorder(V,0); // ??\?????????????????????
	  
	  for(int i=0; i<V; i++) for(Edge& e : G[i]) inorder[e.tgt_]++;
	  for(int i=0; i<V; i++) if(inorder[i] == 0) S.push_back(i);

	  assert(S.size() > 0);

	  vector<int> topological_order;
	  while(S.size()){
			int v = S[S.size()-1]; S.pop_back();
			topological_order.push_back(v);

			for(int i=G[v].size()-1; i>=0; i--){
				  Edge e = G[v][i];	// G[v].pop_back();
				  inorder[ e.tgt_ ]--; 

				  if( inorder[e.tgt_] == 0) 	S.push_back( e.tgt_ );
			}
	  }
	  for(int i=0; i<V; i++) assert(inorder[i]==0);
	  return topological_order;
}


int main(){

	  int V,E; cin >> V >> E;
	  Adj_list G(V);
	  for(int i=0; i<E; i++){
			int s,t; cin >> s >> t;
			G[s].push_back( Edge(t) );
	  }
	  
	  vector<int> ans = topological_sort(G);
	  for(int i=0; i<V; i++)
			cout << ans[i] << endl;

}

Measured memory_bytes: 3752
import java.util.*;
import java.lang.*;

class Mod{
    static final long MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long adds(long... ar){
        long ans=0;
        for(long x:ar) ans = Mod.add(ans, x);
        return ans;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long mults(long... ar){
        long ans=1;
        for(long x:ar) ans = Mod.mult(ans, x);
        return ans;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }
    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String L = sc.next();
        long equal = 1, less = 0;
        for(int d=0; d<L.length(); d++){
            if(L.charAt(d)=='1'){
                long nextEqual = Mod.mult(equal, 2);
                long nextLess = Mod.add(equal, Mod.mult(less, 3));
                equal = nextEqual;
                less = nextLess;
            }else{
                less = Mod.mult(less, 3);
            }
        }
        System.out.println(Mod.add(equal,less));
    }
}

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

pair<int, bool> bingo_card[3][3]; 
int numOfBalls, cell_value;   

bool check_win_condition() {
    bool we_won = false;

    for (int i = 0; i < 3; i++) {
        if (bingo_card[i][0].second && bingo_card[i][1].second 
            && bingo_card[i][2].second)
            we_won = true; 
    }

    for (int i = 0; i < 3; i++) {
        if (bingo_card[0][i].second && bingo_card[1][i].second
        && bingo_card[2][i].second)
            we_won = true; 
    }

    if (bingo_card[0][0].second && bingo_card[1][1].second && bingo_card[2][2].second)
        we_won = true; 
    
    if (bingo_card[0][2].second && bingo_card[1][1].second && bingo_card[2][0].second)
        we_won = true; 
    
    return we_won; 
}

int main() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            scanf("%d", &cell_value); 
            bingo_card[i][j] = {cell_value, false}; 
        } 
    }

    scanf("%d", &numOfBalls); 

    while (numOfBalls--) {
        scanf("%d", &cell_value); 

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (bingo_card[i][j].first == cell_value)
                    bingo_card[i][j].second = true; 
            }
        }
    }

    if (check_win_condition()) {
        printf("Yes\n"); 
    } else {
        printf("No\n"); 
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
   // FILE
   // SPEED
   int n;
   cin>>n;
   double arr[n];
   fain(arr);
   double dp[n+1][n+1];

   dp[1][0]=1-arr[0];
   dp[1][1]=arr[0];

   for(int i=2;i<=n;i++){
      for(int j=0;j<=i;j++){
         dp[i][j]=dp[i-1][j]*(1-arr[i-1]);
         if(j!=0){
            dp[i][j]+=dp[i-1][j-1]*arr[i-1];
         }
      }
   }

   double ans=0;

   for(int kk=n/2+1;kk<=n;kk++){
      ans+=dp[n][kk];
   }

   printf("%.10lf\n",ans);

}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	vector<int> A(3);
	rep(i, 0, 3)
	{
		cin >> A[i];
	}
	sort(all(A));

	if (A[0] == 5 && A[1] == 5 && A[2] == 7)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    ll a[n];
    ll freq[n+1]={};
    for(ll i=1;i<n;i++){
        cin>>a[i];
        ++freq[a[i]];
    }
    for(ll i=1;i<=n;i++){
        cout<<freq[i]<<"\n";
    }
}

int main(int argc, char const *argv[]){
    ThunderClap;
    cout<<fixed<<setprecision(10);
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 6736
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) throws IOException {
	new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();

		Arrays.sort(x);

		System.out.println( x[2] * 10 + x[1]+ x[0]);
	}
}


Measured memory_bytes: 22100
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  double ans = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += 1.0/a;
  }
  ans = 1.0/ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    
    
    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for i in range(h):
        s.append("##" + input()[:-1] + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))
    
    
    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[ch][cw] = 0
    
    move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), \
             (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), \
             (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), \
             (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), \
             (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
        
    not_yet = deque([(ch, cw)])
    one_time = deque([])
    
    while len(not_yet) > 0:
        x, y = not_yet.popleft()
        one_time.append((x, y))
        for (p, q) in move:
            v1, v2 = x+p, y+q
            if ans[v1][v2] == -1:
                not_yet.append((v1, v2))
                ans[v1][v2] = ans[x][y]
                
        if len(not_yet) == 0:
            while len(one_time) > 0:
                x2, y2 = one_time.popleft()
                for (v1, v2) in move2:
                    i, j = x2+v1, y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        not_yet.append((i, j))
          
    print(ans[dh][dw])
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 23520
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   char c;
   cin >> c;
   if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') {
       cout << "vowel" << endl;
   } else {
       cout << "consonant" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
N = str(input())
if N[0] == N[1] and N[0] == N[2]:
    print(N)
else:
    if N[0] > N[1]:
        print(N[0]*3)
    if N[0] == N[1]:
        if N[0] > N[2]:
             print(N[0]*3)
        else:
            print(str((int(N[0])+1))*3)
    elif N[0] < N[1]:
        print(str((int(N[0])+1))*3)

Measured memory_bytes: 3064
#define $ for(i=0;i<n;i++)for(j=0;j<n;j++)
#define _(a,b)$ for(b=l=0;l<n;)b=(b+a[i][l]*p[l++][j])%m;$ a[i][j]=b;
long m=1e9+7,p[50][50],a[50][50],b[50][50],k,s;i,j,l;main(n){scanf("%d%ld",&n,&k);$ a[i][i]=1;$ scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a,b[i][j])}_(p,b[i][j])}$ s+=a[i][j];printf("%d",s%m);}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd              double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define vdd             vector<double>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long,long long>>
#define vvi             vector<vector<int>>
#define vvll            vector<vector<long long>>
#define mii             map<int,int>
#define mll             map<long long,long long>
#define umii            unordered_map<int,int>
#define umll            unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep2(i,a,b)     for(int i=a;i<b;i++)
#define rev(i,n)        for(int i=n;i>=0;i--)
#define rev2(i,a,b)     for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fio             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl            '\n'
#define all(x)          x.begin(),x.end()
#define d0(x)           cout <<x<<" "
#define d1(x)           cout <<x<<endl
#define d2(x,y)         cout <<x<<" "<<y<<endl
#define d3(x,y,z)       cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)     cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define read2(x,y)      cin>>x>>y
#define read3(x,y,z)    cin>>x>>y>>z
#define read4(x,y,z,w)  cin>>x>>y>>z>>w
#define read5(x,y,z,w,a)cin>>x>>y>>z>>w>>a
#define sz(a)           (int)a.size()
const ll mod=1e9+7;
const double PI = 3.14159265359;
const ll MOD=998244353;
void i_o()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
}

int main() {
   fio
   //i_o();
   int n;
   cin>>n;
   vdd p(n);
   rep(i,n) cin>>p[i];
   dd dp[n][n+1];
   memset(dp,0,sizeof(dp));
   dd ans=0;
   for(int i=0;i<n;i++){
      for(int j=0;j<=i+1;j++){
         if(i==0&&j==0) dp[i][j]=1-p[i];
         else if(i==0&&j==1) dp[i][j]=p[i];
         else if(j==0) dp[i][j]=dp[i-1][j]*(1-p[i]);
         else dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
         if(i==n-1&&j>n/2) ans+=dp[i][j];
      }
   }
   ps(ans,11);
}



Measured memory_bytes: 70528
program main
 implicit none
 integer N
 integer,allocatable :: X(:)
 integer i,j
 integer :: sumr=0, minr=-1
 
 read *,N
 allocate(X(N))
 read *,X
 
 do i=1,100
  sumr=0
  do j=1,N
  sumr=sumr+(i-X(j))*(i-X(j))
  end do
  if ( sumr < minr .or. minr == -1) minr=sumr
 end do
 
 print '(i0)', minr
 
 endprogram main

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int K; cin>>K;
  cout<<50<<endl;
  int X=K/50*51+49-K;
  rep(i,0,K%50) cout<<X+51<<" ";
  rep(i,0,50-K%50) cout<<X<<" ";
  cout<<endl;
  }




Measured memory_bytes: 256
N = int(input())
results = [0,0,0,0]
for i in range(N):
    result = input()
    if result[0]=="A":
        results[0]+=1
    elif result[0]=="W":
        results[1]+=1
    elif result[0]=="T":
        results[2]+=1
    elif result[0]=="R":
        results[3]+=1
print("AC x ",results[0],"\n","WA x ",results[1],"\n","TLE x ",results[2],"\n","RE x ",results[3])

Measured memory_bytes: 9212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <stack>
#include <queue>
#include <numeric>
#include <cstring>

using namespace std;

#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

vector<bool> isprime(123456*2+1, true);

void sieve(int n){
  int i, j;

  isprime[0] = isprime[1] = false;
  
  rep(i, n) if(isprime[i]){
    for(j = 2*i; j <= n; j += i) isprime[j] = false;
  }
  
  return;
}

int main(){
  int i, j;
  int n;
  int ret = 0;

  while(true){
    ret = 0;
    cin >> n;
    if(n == 0) break;
    
    sieve(2*n+1);
    
    REP(i, n+1, 2*n+1) if(isprime[i]) ret++;
    
    cout << ret << endl;
  }
  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/03  Problem: ABC 120 B / Link: http://abc120.contest.atcoder.jp/tasks/abc120_b  ----- */
long long  gcd(long long  a, long long  b) { return b ? gcd(b, a%b) : a; }
long long  lcm(long long  a, long long  b) { return a / gcd(a, b) * b; }


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

	LL A, B, K; cin >> A >> B >> K;
	
	VL ans; {
		FOR(i, 1, 100000) {
			if (A%i == 0 && B%i == 0) {
					ans.push_back(i);
			}
		}
	}
	RSORT(ans);
	DD(de(ans));
	cout << (ans[K-1]) << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int n, m;
    int[] xs, ys;
    int MOD = 1000000007;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        xs = new int[n];
        ys = new int[m];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            ys[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        //Arrays.sort(xs);
        long xSum = 0;
        for (int i = 0; i < n; i++) {
            xSum += (long)(2 * i - n + 1) * xs[i];
            xSum %= MOD;
        }
        //Arrays.sort(ys);
        long ySum = 0;
        for (int i = 0; i < m; i++) {
            ySum += (long)(2 * i - m + 1) * ys[i];
            ySum %= MOD;
        }

        System.out.println(xSum * ySum % MOD);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 43304
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = 0
i = 0
while i < N:
    if A[i] <= B[i]:
        cnt += A[i]
        if A[i+1] >= (B[i] - A[i]):
            cnt += (B[i] - A[i])
            A[i+1] = A[i+1] - (B[i] - A[i])
        else:
            cnt += A[i+1]
            A[i+1] = 0
        i += 1

    else:
        cnt += B[i]
        i += 1

print(cnt)

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

bool contains(string str, string pre){
    int s = str.length(), p = pre.length();
    if(s < p)   return false;

    for(int i = 0; i <= s - p; i++){
        int j;
        for(j = 0; j < p; j++){ 
            if(str[i+j] != pre[j])  break;
        }
        if(j == p)  return true;
    }

    return false;
}

int main(){
    string s, t;
    cin >> s >> t;
    t += t;
    if(contains(t, s))  cout << "Yes" << endl;
    else                cout << "No" << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    for (int i=0;i<s.size();++i) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                cout << "No";
                return 0;
            }
        }
        else {
            if (s[i] == 'R') {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main()
{
  int n, sum, sum1;
  cin >> n;
  sum=0;
  int w[n];
  for(int i=0; i<n; i++)cin >> w[i];
  int a[n];
  for(int i=0; i<n; i++)sum=sum+w[i];
  for(int i=0; i<n; i++){
    sum1=0;
    for(int j=0; j<i+1; j++) sum1=sum1+w[j];
    a[i]=abs((sum1-(sum-sum1)));
  }
  sort(a,a+n);
  cout << a[0];
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final String UPPER_CASE = "[A-Z]";

    private static final String LOWER_CASE = "[a-z]";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println(str.matches(UPPER_CASE) ? "A" : "a");
    }
}

Measured memory_bytes: 35772
from fractions import gcd

# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = gcd(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = gcd(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p,q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = gcd(res, seg[p])
        if q & 1 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    
    return res


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

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)

Measured memory_bytes: 90104
#include<stdio.h>
#include<stdlib.h>
 
#define NIL NULL
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};



typedef struct node * Node;
  
Node root;
 
void treeD(Node);
void treeInsert(int);
void inorder(Node);
void preorder(Node);
Node treeMin(Node);
Node treeS(Node,int);
Node treeSuc(Node);



int main(){
 
  int res, i, alt;
 
  char com[20];
   
  scanf("%d", &res);
  
  for (i = 0;i < res;i ++ )
    {
    scanf("%s", com);
 
    if (com[0] == 'f' )
      {
    scanf("%d", &alt);
    Node t = treeS(root, alt);
    if ( t != NIL ) printf("yes\n");
    else printf("no\n");
      }
    else if ( com[0] == 'i' )
      {
    scanf("%d", &alt);
    treeInsert(alt);
      }
    else if ( com[0] == 'p' )
      {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
      }
    else if ( com[0] == 'd' )
      {
    scanf("%d", &alt);
    treeD(treeS(root, alt));
      }
    }
  return 0;
}



 
Node treeMin(Node x){
 
  while(x->left != NIL)
    {
      x = x->left;
    }
  return x;
}


  
Node treeS(Node u, int k){
 
  if(u == NIL || k == u->key)
    {
      return u;
    }
   
  if(k < u->key)
    {
      return treeS(u->left, k);
    }
  else{
    return treeS(u->right,k);
  }
}


 
Node treeSuc(Node x){
 
  Node y;
   
  if(x->right != NIL)
    {
      return treeMin(x->right);
    }
   
  y = x->parent;
 
  while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
  return y;
}


 
void treeD(Node z){
  Node y; 
  Node x; 
}


  
void treeInsert(int r){
 
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
 
  z->key = r;
  z->left = NIL;
  z->right = NIL;
  
  while (x!=NIL)
    {
      y = x;
      if (z->key < x->key)
    {
      x = x->left;
    }
      else {
    x = x->right;
      }
    }
   
  z->parent = y;
   
  if(y == NIL)
    {
      root = z;
    }
  else if(z->key < y->key)
    {
      y->left = z;
    }
  else{
    y->right = z;
  }
   
}



void inorder(Node n){
 
  if (n != NIL)
    {
      inorder(n->left);
      printf(" %d",n->key);
      inorder(n->right);
    }
}


 
void preorder(Node u){
 
  if (u != NIL)
    {
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }

  
}

Measured memory_bytes: 24040
N,K = map(int, input().split())
a_arr = list(map(int, input().split()))

k_idx = K - 1
ans_arr = []
for i in range(N - K):
    if a_arr[i] < a_arr[k_idx + 1]:
        ans_arr.append('Yes')
    else:
        ans_arr.append('No')
    k_idx += 1
for i in ans_arr:
    print(i)

Measured memory_bytes: 31760
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a; string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << "\n";
    else puts("red");
    return 0;
}

Measured memory_bytes: 256