akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
int a[N];
int b[N];
void solve(){
	int n,m; 
	cin>>n>>m; 
	for(int i=1;i<=n;i++)b[i]=1;
	a[1] = 1;
	for(int i=0;i<m;i++){
		int x,y; 
		cin>>x>>y; 
		if(a[x])a[y] = 1;
		b[x]--;
		b[y]++;
		if(b[x]==0)a[x] = 0;
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(a[i])ans++;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4412
from collections import deque

N, Q = map(int, input().split())
table = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    table[a].append(b)
    table[b].append(a)

p = []; x = []
ans = [0]*N
for i in range(Q):
    p0, x0 = map(int, input().split())
    p0 -= 1
    ans[p0] += x0
#print(table)
#print(ans)
visited = [0]*N
q = deque()
q.append(0)
while q:
    v = q.pop()
    x0 = ans[v]
    visited[v] = 1
    for u in table[v]:
        if visited[u]:
            continue
        q.append(u)
        ans[u] += x0
for i in range(N):
    print(ans[i])


Measured memory_bytes: 103884
package main

import (
	"fmt"
	"strconv"
)

var result = 2000000000
var ar = []int{}

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		ar = append(ar, v)
	}
	t := 1
	for i := 0; i < n; i++ {
		t *= 4
	}
	for i := 0; i < t; i++ {
		s := f(i, n)
		av, bv, cv, count := ff(s)
		if av == 0 || bv == 0 || cv == 0 {
			continue
		}
		aaa := abs(av-a) + abs(bv-b) + abs(cv-c)
		aaa += count * 10
		if aaa < result {
			result = aaa
		}
	}
	fmt.Println(result)
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

func ff(s string) (int, int, int, int) {
	a, b, c := 0, 0, 0
	count := 0
	ba, bb, bc := false, false, false
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
		} else if s[i] == '1' {
			if ba {
				count++
			}
			ba = true
			a += ar[i]
		} else if s[i] == '2' {
			if bb {
				count++
			}
			bb = true
			b += ar[i]
		} else if s[i] == '3' {
			if bc {
				count++
			}
			bc = true
			c += ar[i]
		}
	}
	return a, b, c, count
}

func f(i, n int) string {
	ret := ""
	for {
		g := fmt.Sprintf("%d", (i % 4))
		ret = g + ret
		i = i / 4
		if i == 0 {
			v, _ := strconv.Atoi(ret)
			s := "%0" + fmt.Sprintf("%d", n) + "d"
			return fmt.Sprintf(s, v)
		}
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        int pmin=min(p[i-1],min(p[i],p[i+1]));
        int pmax=max(p[i-1],max(p[i],p[i+1]));
        if((pmin==p[i-1]&pmax==p[i+1])||(pmax==p[i-1]&pmin==p[i+1])){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
S = list(S)

if len(set(S)) == 2:
    
    m = list(set(S))[0]
    n = list(set(S))[1]

    m_c, n_c = 0, 0
    c = False
    
    for i in range(len(S)):
        if S[i] == m:
            m_c += 1
        else:
            n_c += 1
            
    if m_c == n_c:
        c = True

    if c:
        print('Yes')
    else:
        print('No')

else:
    print('No')

Measured memory_bytes: 3064
N, A, B = gets.chomp.split.map(&:to_i)
nums = (1..N).map{ |n| n.to_s.split('').map(&:to_i).sum }

result = []
nums.each_with_index do |n, i|
  result << i + 1 if A <= n && n <= B
end
puts result.sum

Measured memory_bytes: 14456
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       int[] t= {sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};
       int sum=0;
       for(int i:t) {
           sum+=i<40?40:i;
       }
       System.out.println(sum/5);
    }
}


Measured memory_bytes: 26256
#include <stdio.h>
#define N 3.141592653589

int main(void)
{
	double r ,men ,enn;

	scanf("%lf", &r);
	men = r * r * N;
	enn = 2 * r * N;

	printf("%f %f\n", men, enn);
	
	return 0;
}


Measured memory_bytes: 2052
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();

		List<Integer> nums = new ArrayList<>(Arrays.asList(P,Q,R));
		Collections.sort(nums);

		System.out.println(nums.get(0)+nums.get(1));

	}

}


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

int main(){
	/*input*/
	int n, m, X, Y;	cin >> n >> m >> X >> Y;
	vector<int>x(n);
	vector<int>y(m);
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	for(int i = 0; i < m; i++){
		cin >> y[i];
	}
	/*calculation*/
	int x_max, y_min;
	sort(x.rbegin(), x.rend());
	sort(y.begin(), y.end());
	x_max = x[0];
	y_min = y[0];
	/*output*/
	if(y_min > x_max && y_min > X && x_max < Y){
		cout << "No War" << endl;
	}else{
		cout << "War" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, A, B, C);
  rep(i, 0, B) {
    if (((i + 1) * A) % B == C) {
      print("YES");
      return;
    }
  }
  print("NO");
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    ll reg=1;
    rep(i,n){
        if(reg==vec[i]){
            reg++;
        }
    }
    if(reg==1){
        cout<<-1<<endl;
        return 0;
    }
    cout << n - reg+1 << endl;
}


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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<ll> &v){
    for(ll x: v){
        cout<<x<<" ";
    }
    newline;
}

const ll MOD = 1e9+7;
const ll nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    ll n, g; read(n, g);

    vector<pair<ll, ll> > v(n);

    for(ll i=0; i<n; i++){
        cin>>v[i].first>>v[i].second;
    }

    ll ans = MOD;

    for(ll mask = 0; mask < 1<<n; mask++){
        ll tot = 0, cnt = 0, nt_max = -1;
        for(ll i=0; i<n; i++){
            if(mask>>i & 1){
                tot += 100*(i+1)*v[i].first + v[i].second;
                cnt += v[i].first;
            }
            else{
                nt_max = i;
            }
        }
        if(tot<g){
            ll req = (g-tot + (100*(nt_max+1))-1)/(100*(nt_max+1));
            if(req>=v[nt_max].first){
                continue;
            }
            else{
                cnt += req;
            }
        }
        ans = min(ans, cnt);
    }

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

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


void solve(int N, string S){
    int r = 0, w = 0;
    for(int i = 0; i < N; ++i){
        if(S[i] == 'R') r++;
    }
    int ans = max(r, w);
    for (int i = 0; i < N; i++)
    {
        if(S[i] == 'R') r--;
        else w++;
        int now = max(r, w);
        ans = min(ans, now);
    }
    cout << ans << endl;
    return;
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3928
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <bitset>

using namespace std;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    //int64_t value = 0;

    /* そのまま購入(最大値) */
    //value = (A*X) + (B*Y);

    /*  */
    // for(int i=X; i>=0; i--){
    //     for(int j=Y; j>=0; j--){
    //         int64_t tmp_value = (A*i) + (B*j);
    //         int64_t tmp = C * max( (X-i), (Y-j) ) * 2;
    //         tmp_value = tmp_value + tmp;
    //         value = min(value, tmp_value);
    //     }
    // }

    /*  */

    int64_t val = A*X + B*Y;

    for(int i=0; i<=max(X, Y); i++){

        int64_t tmp  = (C*i*2) + (A * max(X-i, 0)) + (B * max(Y-i, 0));
        val = min(val, tmp);
    }

    cout << val << endl;

}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>
#include <stack>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};
#include <random>

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n;
vector<string> a;

bool check(i64 m) {
    if (!m) {
        return false;
    }

    return n / m == n % m;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    set<i64> q;
    for (i64 i = 1; i <= (i64)sqrt(n) + 2; i++) {
        if (n % i != 0) {
            continue;
        }

        i64 m1 = i - 1;
        i64 m2 = n / i - 1;

        if (check(m1)) {
            q.insert(m1);
        }

        if (check(m2)) {
            q.insert(m2);
        }
    }

    i64 R = 0;

    for (auto t : q) {
        R += t;
    }

    cout << R;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void) {
    int r,d,a,re;
    scanf("%d %d %d",&r,&d,&a);
    for(int i = 0; i < 10; i++) {
        re = r * a - d;
        a = re;
        printf("%d\n",re);
    }
    return 0;
}

Measured memory_bytes: 128
#include<math.h>
main(){
  int i,j=2,k=0,n,r,s[78499];
  s[k++]=j++;
  for(;j<999984;j+=2){
    r=(int)sqrt(j)+1;
    for(i=3;i<r;i+=2)
      if(j%i==0){
	r=0;
	break;
      }
    if(r)
      s[k++]=j;
  }
  s[78498]=1000000;
  while(scanf("%d",&n)!=-1){
    for(i=0;s[i]<=n;i++);
    printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;
import java.lang.Math;

class Point
{
    double x;
    double y;
    Point(double x1, double y1)
    {
        x = x1;
        y = y1;
    }
}

class Main
{
    public static double deal(double x)
    {
        if (Math.abs(x) < 1e-6) return 0;
        else return x;
    }
    public static Point solve(double a, double b, double c,
                              double d, double e, double f)
    {
        Point p = new Point(0, 0);
        if (b == 0)
        {
            p.x = c / a;
            p.y = (f - d * p.x) / e;
        }
        else
        {
            p.x = (b * f - e * c) / (b * d - e * a);
            p.y = (c - a * p.x) / b;
        }
        p.x = deal(p.x);
        p.y = deal(p.y);
        return p;
    }
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        while (input.hasNext())
        {
            double x[] = new double [6];
            for (int i = 0; i < 6; i++)
            {
                x[i] = input.nextDouble();
            }
            Point p = solve(x[0], x[1], x[2], x[3], x[4], x[5]);
            System.out.printf("%.3f %.3f\n", p.x, p.y);
        }
        input.close();
    }
}

Measured memory_bytes: 28420
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort(reverse=True)
    print(sum(a[1:2*n+1:2]))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 107536
#include<stdio.h>
#include<math.h>

int main(void){
	
	int i,j,k;
	int A,B,C,X;
	int re;
	int result=0;
	
	scanf("%d" ,&A);
	scanf("%d" ,&B);
	scanf("%d" ,&C);
	scanf("%d" ,&X);
	
	re = 0;
	
	for(i = 0; i<A+1 ; i++){
		for(j = 0; j<B+1; j++){
			for(k = 0; k< C+1; k++){
				
				re  = 500 * i + 100 * j + 50*k;
				if(re-X == 0) result++;
			}
		}
	}
			
	
	printf("%d\n" ,result);
	
}
	

Measured memory_bytes: 128
from collections import defaultdict

n = int(input())
v = list(map(int, input().split(" ")))

e = defaultdict(int)
o = defaultdict(int)

for i in range(0, len(v), 2):
    e[v[i]] += 1

for i in range(1, len(v), 2):
    o[v[i]] += 1

f = False
if len(e.keys()) == 1:
    o = sorted(o.items(), key=lambda x: x[1], reverse=True)
    for k, v in o:
        if k == list(e.keys())[0]:
            continue
        f = True
        print(n // 2 - v)
        break
    if not f:
        print(n // 2)
elif len(o.keys()) == 1:
    e = sorted(e.items(), key=lambda x: x[1], reverse=True)
    for k, v in e:
        if k == list(o.keys())[0]:
            continue
        f = True
        print(n // 2 - v)
        break
    if not f:
        print(n // 2)
else:
    e = sorted(e.items(), key=lambda x: x[1], reverse=True)
    o = sorted(o.items(), key=lambda x: x[1], reverse=True)

    if e[0][0] != o[0][0]:
        print(n // 2 - e[0][1] +  n // 2 - o[0][1])
    else:
        c1 = n // 2 - e[0][1] + n // 2 - o[1][1]
        c2 = n // 2 - e[1][1] + n // 2 - o[0][1]
        print(min(c1, c2))


Measured memory_bytes: 19928
/***************************************************
 *                                                 *
 *   author: raghav_0901 (Raghav Dalmia)           *
 *   updated on: Sunday, 14-06-2020, 18:21:36 pm   *
 *                                                 *
\***************************************************/

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

const int nmx = (1e6) + 1;
int arr[nmx], dp[nmx];
bool vis[nmx];
int n;

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

    scanf("%d", &n);
    int num_one = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        num_one += (arr[i] == 1);
    }
    if (num_one == 1)
        printf("1\n");
    else if (num_one > 1)
        printf("0\n");
    else
    {
        sort(arr, arr + n);
        memset(dp, 0, sizeof(dp));
        memset(vis, 1, sizeof(vis));
        for (int i = 0; i < n; i++) dp[arr[i]]++;
        for (int i = 0; i < n; i++)
        {
            int pos = arr[i];
            if (dp[pos] > 1)
                vis[pos] = 0;
            for (int i = (pos << 1); i <= arr[n - 1]; i += pos) { vis[i] = 0; }
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) cnt += (vis[arr[i]]);
        printf("%d\n", cnt);
    }
    return 0;
}


Measured memory_bytes: 9504
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

ll solve(ll a, ll b) { return (b - a) / 2; }

int main() {
    // source
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    if ((b - a) % 2 == 0) {
        ans = (b - a) / 2;
    } else {
        ans = min(solve(a, n + (n - b) + 1), solve(-a + 1, b));
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
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*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int h,w; cin >> h >> w;
    vvint c(10,vint(10));
    
    rep(i,10)rep(j,10)cin >> c[i][j];
    

    vint dist(10,INF);
    
    rep(k,10){
        rep(i,10){
            rep(j,10){
                chmin(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int res=0;
    rep(i,h){
        rep(j,w){
            int a; cin >> a;
            if(a==-1) continue;
            res+=c[a][1];
        }
    }
    cout<<res<<endl;

}

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

using namespace std;

long long int iler[200005],jler[200005],dizi[200005],pre[200005],n,k,ans;

map<int,int>cnt;

int main(){
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	scanf("%lld %lld",&n,&k);
	int fark;
	for(long long int i=1;i<=n;i++){
		scanf("%lld",&dizi[i]);
		pre[i]=( pre[ i-1 ] + dizi[ i ] ) % k;
		iler[ i ] = pre[ i ] - i;
		if(iler[i]<0){
			fark=0-iler[i];
			iler[i]+=((fark/k)+1)*k;
			iler[i]%=k;
		}
		if(i<k){
			cnt[ iler[ i ] ]++;
		}
		jler[ i ] = pre[ i - 1 ] - i + 1;
		if(jler[i]<0){
			fark=0-jler[i];
			jler[ i ] += ( (fark/k)+1 )*k;
			jler[ i ] %= k;
		}
	}

	for(long long int i=1;i<=n;i++){
		ans+=cnt[jler[i]];
		cnt[iler[i]]--;
		if((i+k-1)<=n){
			cnt[iler[i+k-1]]++;
		}
	}
	printf("%lld\n",ans );
}

Measured memory_bytes: 15872
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[][] a = new int[n][3];

        for (int i = 0; i < n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
            a[i][2] = sc.nextInt();
        }

        int[][] dp = new int[n][3];
        dp[0][0] = a[0][0];
        dp[0][1] = a[0][1];
        dp[0][2] = a[0][2];

        for (int i = 1; i < n; i++) {
            dp[i][0] = a[i][0] + Math.max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = a[i][1] + Math.max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = a[i][2] + Math.max(dp[i-1][0], dp[i-1][1]);
        }
        
        int max = Math.max(dp[n-1][0], dp[n-1][1]);
        max = Math.max(dp[n-1][2], max);
        
        System.out.println(max);
    }
}


Measured memory_bytes: 97688
/* 
 * Project: AtCoder Beginners Contest 148 B - Strings with the Same Length
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/31
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
char s[100];
char t[100];

void solve() {

    for (int i=0;i<n;i++) {
        printf("%c", s[i]);
        printf("%c", t[i]);
    }
    printf("\n");
    return;
}

int main() {

    scanf("%d", &n);
    scanf("%s", s);
    scanf("%s", t);

    solve();

}

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

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str[] = br.readLine().split("\\s+");
			int array[] = new int[str.length];

			for(int i = 0; i < str.length; i++){
				array[i] = Integer.parseInt(str[i]);
			}

			Dice dice = new Dice();
			dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);


			str = br.readLine().split("\\s+");
			for(int i = 0; i < str.length; i++){
				array[i] = Integer.parseInt(str[i]);
			}
			Dice dice2 = new Dice();
			dice2.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);

			if(dice.equals(dice2)){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class Dice{

	private int number[];
	private int work[];
	private final String order = "NNNNWNNNWNNNENNNENNNWNNN";

	Dice(){
		number = new int[6];
		work = new int[6];
	}


	public void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = number[i];
		switch(dst){
		case 'E':
			setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'N':
			setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'S':
			setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	public int query(int top_num,int front_num){

		int save_data[] = new int[6];
		for(int i = 0; i < number.length; i++){
			save_data[i] = number[i];
		}

		int ret = -1;

		for(int i = 0; i < order.length(); i++){
			roll(order.charAt(i));
			if(number[0] == top_num && number[1] == front_num){
				ret = number[2];
				break;
			}
		}

		for(int i = 0; i < save_data.length; i++){
			number[i] = save_data[i];
		}

		return ret;
	}

	public int getTop(){
		return number[0];
	}

	public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

	public boolean equals(Object object){

		if(object == this)return true;
		if(object == null)return false;
		if(!(object instanceof Dice))return false;

		Dice another = (Dice)object;

		boolean FLG;

		for(int i = 0; i < order.length(); i++){
			roll(order.charAt(i));
			FLG = true;
			for(int k = 0; k < 6; k++){
				if(this.number[k] != another.number[k]){
					FLG = false;
					break;
				}
			}
			if(FLG)return true;
		}

		return false;
	}
};



Measured memory_bytes: 24584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 666666666

ll n,m;
vector<int>g[100001];
vector<ll>pf[100001];
vector<ll>sf[100001];
ll UP[100001];
ll DOWN[100001];

void dfs(int c, int p = 0)
{
    DOWN[c]=1;

    for(auto&u:g[c])
        if(u!=p)
    {
        dfs(u,c);
        DOWN[c] = (DOWN[c] * (DOWN[u]+1)) % m;
    }
}

void dfs2(int c, int p=0, ll up = 1)
{
    UP[c]=up;

    for(int i=0; i<g[c].size(); i++)
        if(g[c][i]==p)
    {
        swap(g[c][i],g[c].back());
        g[c].pop_back();
        break;
    }

    pf[c][0]=sf[c][g[c].size()]=1;

    for(int i=0; i<g[c].size(); i++)
        pf[c][i+1]=(pf[c][i]*(DOWN[g[c][i]]+1))%m;

    for(int i=g[c].size()-1; i>=0; i--)
        sf[c][i]=(sf[c][i+1]*(DOWN[g[c][i]]+1))%m;

    for(int i=0; i<g[c].size(); i++)
    {
        ll ways = (pf[c][i] * sf[c][i+1])%m;
        ways = (ways * up)%m;
        dfs2(g[c][i],c,(ways+1)%m);
    }
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;

    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for(int i=1; i<=n; i++)
        pf[i].resize(g[i].size()+2),sf[i].resize(g[i].size()+2);

    dfs(1);
    dfs2(1);

    for(int i=1; i<=n; i++)
        {
            //cout<<i<<" "<<DOWN[i]<<" "<<UP[i]<<"\n";
            cout<<(DOWN[i]*UP[i])%m<<"\n";
        }
}


Measured memory_bytes: 27392
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

import collections

def first_search(graph, root, depth_array):
    seen, queue = set([root]), collections.deque([[root, 0],])
    while queue:
        vertex, depth = queue.popleft()  # popleft: 幅優先探索  /  pop: 深さ優先探索
        depth_array[vertex] = depth
        for node, length in graph[vertex]:
            if node not in seen:
                seen.add(node)
                queue.append([node, depth+length])

def main(): 
    N = II()

    from collections import defaultdict
    tree = defaultdict(list)

    for _ in range(N-1):
        a,b,c = LI()
        tree[a].append((b,c))
        tree[b].append((a,c))

    Q, K = LI()

    depth_array = [0 for _ in range(N+1)]
    # K を根とした木だと思って全点の depth を決める。
    first_search(tree, K, depth_array)


    for _ in range(Q):
        x,y = LI()
        print(depth_array[x]+depth_array[y])


main()

Measured memory_bytes: 60192
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

long getKey(int A, int B) {
  if (A < B) {
    return A * 100005 + B;
  } else {
    return B * 100005 + A;
  }
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> adj[N + 1];

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    adj[A].push_back(B);
    adj[B].push_back(A);
  }

  if (M % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }

  stack<pair<int, int>> treeEdgeStack;
  queue<int> bfsQueue;
  bool visited[N + 1];
  int count[N + 1];
  int parent[N + 1];
  vector<string> results;
  for (int i = 1; i <= N; i++) {
    visited[i] = false;
    count[i] = 0;
    parent[i] = 0;
  }

  bfsQueue.push(1);
  visited[1] = true;

  while (bfsQueue.size() > 0) {
    int u = bfsQueue.front();
    bfsQueue.pop();

    // cout << "u: " << u << endl;

    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (!visited[v]) {
        bfsQueue.push(v);
        treeEdgeStack.emplace(u, v);
        parent[v] = u;
        visited[v] = true;
      } else {
        // cout << "parent[v]: " << parent[v] << " v: " << v << " u: " << u
        //  << endl;
        if (v != parent[u] && v > u) {
          results.push_back(to_string(u) + " " + to_string(v));
          count[u] += 1;
          // cout << "u - v: " << u << " - " << v << endl;
        }
      }
    }
  }

  while (treeEdgeStack.size() > 0) {
    pair<int, int> e = treeEdgeStack.top();
    treeEdgeStack.pop();
    if (count[e.second] % 2 == 0) {
      results.push_back(to_string(e.first) + " " + to_string(e.second));
      count[e.first] += 1;
    } else {
      results.push_back(to_string(e.second) + " " + to_string(e.first));
      count[e.second] += 1;
    }
  }

  for (int i = 0; i < results.size(); i++) {
    cout << results[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 14708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;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 fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve(){
    
}

int main()
{
    IO;
    ll n;
    cin>>n;
    ll dp[n][n];
    memset(dp,-1,sizeof dp);
    vector<pair<ll , ll > > v;
    for(int i=0;i<n;i++){
        ll val;
        cin>>val;
        v.pb(make_pair(val,i));
    }
    sort(all(v));
    dp[0][n-1]=0;
    ll ans=0;
    
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i;j--){
            int p=j-i;
            if(p==0){
                dp[i][j]+=v[0].fi*abs(v[0].se-i);
                ans=max(ans,dp[i][j]);
                continue;
            }
            /*cout<<i<<" "<<j<<" ";
            cout<<p<<endl;*/
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[p].fi*abs(v[p].se-i));
            dp[i][j-1]=max(dp[i][j-1],dp[i][j]+v[p].fi*abs(v[p].se-j));
        }
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 34936
s = input()
n = len(s)
for i in range(n-1):
  if s[i] == s[i+1]:
    print(i+1,i+2)
    exit()
for i in range(n-2):
  if s[i] == s[i+2]:
    print(i+1,i+3)
    exit()
print(-1,-1)
    

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

int main()
{
    unsigned long long sum = 0;
    int n;
    cin >> n;
   for(int i = 1; i <= n; i++)
   {
       if(i % 15 == 0)
       {
           //sum += i;
       }
       else if(i % 3 == 0)
       {
           //sum -= i;
       }
       else if(i % 5 == 0)
       {

       }
       else
       {
           sum += i;
       }
   }
   cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3580
import math

N = int(input())

cs = set()
for m in range(1, int(math.sqrt(N))+1):
    q, r = divmod(N, m)
    if r != 0:
        continue
    cs.add(q-1)
    cs.add(m-1)

s = sum(c if N // c == N % c else 0 for c in cs if c > 0)
print(s) 


Measured memory_bytes: 3828
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputs = input.trim().split('\n');

const COLORS = ['r','g','b'];
class Worm {
  constructor(id, depth) {
    this.id = id;
    this.depth = depth;
    this.colors = id.split('');
  }
  getNextWormIds() {
    const nextWormIds = [];
    for (let i = 0; i < this.colors.length - 1; i++) {
      const [ current, next ] = this.colors.slice(i, i + 2);
      if (current === next) {
        continue;
      }
      const changed = COLORS.filter(s => s !== current && s !== next)[0];
      const changedColors = this.colors.slice(); // copy
      changedColors.splice(i, 2, changed, changed); // 置き換え
      nextWormIds.push(changedColors.join(''));
    }
    return nextWormIds;
  }
}

class Graph {
  constructor() {
    this.map = new Map();
  }
  bfs(wormId) {
    this.queue = [];
    this.map.set(wormId, new Worm(wormId, 0));
    this.queue.push(wormId);
    while(this.queue.length) {
      const wormId = this.queue.shift();
      const worm = this.map.get(wormId);
      const wormIds = worm.getNextWormIds();
      if (!wormIds.length) {
        return worm;
      }
      wormIds.forEach(wormId => {
        if (this.map.has(wormId)) {
          return;
        }
        this.map.set(wormId, new Worm(wormId, worm.depth + 1));
        this.queue.push(wormId);
      })
    }
  }
}

inputs.forEach(wormId => {
  if (wormId === '0') {
    return;
  }
  const graph = new Graph();
  const worm = graph.bfs(wormId);
  console.log(worm ? worm.depth : 'NA');
});



Measured memory_bytes: 61484
X, N = map(int, input().split())
 
p = list(map(int, input().split()))
 
p_none = [i for i in range(110) if i not in p]
p_none_sa = [abs(p_none[i]-X) for i in range(len(p_none))]
 
import sys
 
min_p_none = min(p_none_sa)
for i in range(len(p_none_sa)):
    if p_none_sa[i] == min_p_none:
        print(p_none[i])
        sys.exit()

Measured memory_bytes: 9192
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <map>
using namespace std;


void func148c() {
  int a, b;
  cin >> a >> b;
  long long ans = a;
  //cout << "ans: " << ans << "\n";
  while (ans % b != 0) {
    ans += a;
    //cout << "ans: " << ans << "\n";
  }
  cout << ans << "\n";
}


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

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

if max(a) <= 1:
    print(sum(t))
    sys.exit(0)

ans = 0
for i in range(0, max(a) - 1):
    ans = max(ans, t[i] + t[i+1] + t[i+2])

print(ans)


Measured memory_bytes: 85012
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>

using namespace std;

template<class T = int,T divided_by = 10>
constexpr T PINF(){ return std::numeric_limits<T>::max()/divided_by; }
template<class T = int,T divided_by = 10>
constexpr T MINF(){ return std::numeric_limits<T>::lowest()/divided_by; }

template<class T = int> T gcd(T a, T b){ return b ? gcd(b,a%b) : a; }
template<class T = int> T lcm(T a, T b){ return a / gcd(a,b) * b; }
template<class T = int> T lcm_safe(T a, T b){ T p = a/gcd(a,b); return (b <= PINF<T>()/p) ? p*b:PINF<T>(); }
//オーバーフローするとき+INFを返す
//
//

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<string> strs(n);
    vector<int> rows(n, 0), cols(n, 0);
    int canClear = false;

    int filledCols = 0;
    for(int i = 0; i < n; ++i){
        cin >> strs[i];
        for(int j = 0; j < n; ++j){
            if (strs[i][j] == '#') {
                rows[i] += 1;
                cols[j] += 1;
                canClear = true;
            }
        }
    }

    if(!canClear) {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 0; i < n; ++i){
        if (cols[i] == n) {
            filledCols += 1;
        }
    }
    int bestScore = 100000000;
    for(int i = 0; i < n; ++i){
        int blacks = rows[i];
        if(cols[i]!=0) {
            int score = n - blacks;
            score += n - filledCols;

            // cout << "row" << i << "can clear at" << score << endl;
            bestScore = min(bestScore, score);
        } else {
            // cout << "there is no taikaku" << endl;
            if(rows[i]!=0) {
                // cout << "but..";
                int score = n - blacks + 1;
                score += n - filledCols;
                // cout << "row" << i << "can clear at" << score << endl;
                bestScore = min(bestScore, score);
            }
        }
    }

    cout << bestScore << endl;


    return 0;
}

Measured memory_bytes: 512
use proconio::{input, fastout};
 
pub const arr: [i32; 29] = [
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
];

#[fastout]
fn main(){
    input!{
        ax: [usize; 3],
    }
    
    let m = (ax[0] + ax[1] + ax[2]) % 29;
    println!("{}", arr[m]);
    return;
}

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

string divide[4] = {"dream" , "dreamer" , "erase" , "eraser"};

int main() {
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for (int i = 0;i < 4; i++) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i = 0;i < s.size();) {
        bool can2 = false;
        for (int j = 0; j < 4; j++) {
            string d = divide[j];
            if (s.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define er erase
#define bg begin()
#define ed end()
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define enter cout << "\n"
#define space cout << " "
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (n); i++)
#define fj(st,n) for (int j = (st); j <= (n); j++)
#define fk(st,n) for (int k = (st); k <= (n); k++)
#define fq(st,n) for (int q = (st); q <= (n); q++)
#define fw(st,n) for (int w = (st); w <= (n); w++)
#define ff(i, st, n) for (int (i) = (st); (i) <= (n); (i)++)
#define ei(st,n) for (int i = (st); i >= (n); i--)
#define ej(st,n) for (int j = (st); j >= (n); j--)
#define ek(st,n) for (int k = (st); k >= (n); k--)
#define ri(st,n) for (int i = (st); i < (n); i++)
#define rj(st,n) for (int j = (st); j < (n); j++)
#define rk(st,n) for (int k = (st); k < (n); k++)
#define rq(st,n) for (int q = (st); q < (n); q++)
#define rf(i, st, n) for (int (i) = (st); (i) < (n); (i)++)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = (int)1e9;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 1000000007;
const int maxn = (int) 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0))

ll x, d[maxn][2];
int n, a[maxn];

int main()
{
//	fin("t.in");
	sync;
	cin >> n;
	fi(1, n)
	{
		cin >> a[i];
	}
	d[0][0] = 0;
	d[0][1] = -(ll)inf * (ll)inf;
	fi(1, n)
	{
		if (a[i] == 0)
		{
			d[i][1] = -(ll)inf * (ll)inf;
			d[i][0] = max(d[i - 1][0], d[i - 1][1]);
			continue;
		}
		d[i][0] = max(d[i - 1][0], d[i - 1][1]) + a[i] / 2;
		if (a[i] % 2 == 1)
		{
			d[i][0] = max(d[i][0], d[i - 1][1] + 1 + a[i] / 2);
			d[i][1] = max(d[i - 1][0], d[i - 1][1]) + a[i] / 2;
		}
		else
		{
			d[i][1] = max(d[i - 1][0], d[i - 1][1]) + a[i] / 2 - 1;
			d[i][1] = max(d[i][1], d[i - 1][1] + a[i] / 2);
		}
	}
	cout << max(d[n][0], d[n][1]) << endl;
 	return 0;
}


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

s = input().split()


flag = 0

for i in s:
    if(int(i)%2 == 0):
        if(int(i)%3 != 0 and int(i)%5 != 0):
            flag = 1


if(flag == 1):
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int n ,i ,j ,total = 0, max = 0;
  scanf("%d",&n);
  int a[2][n];
  for(i = 0; i < 2;i++){
    for(j = 0; j < n ;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i = 0; i < n; i++){         // i<=jなら二段目の計算
    for(j = 0; j < n; j++){
      if(i <= j){
        total += a[1][j];
      }else{
        total += a[0][j];
      }
    }
      total += a[0][i];
      max = (max > total) ? max : total;
      total = 0;
    }
    printf("%d",max);

  return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let a:i32 = read();
    let b:i32 = read();
    let t:i32 = read();

    println!("{}", t/a*b);
    
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
	int x, y, i, c;
	
	for (i = 0; 1; i++){
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0) {
			break;
		}
		if (x > y){
			c = x;
			x = y;
			y = c;
		}
		printf("%d %d\n", x, y);
	}
	return(0);
}
		

Measured memory_bytes: 600
n=int(input())
l=list(map(int, input().split()))
s=sum(l)

j=0

for i in range(n):
  j+=l[i]
  if j*2==s:
    print(0)
    break
  elif j*2>s:
    print(min((j*2-s),(s-(j-l[i])*2)))
    break

Measured memory_bytes: 26060
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n){
		if(n%10==9){
			cout<<"Yes"<<endl;
			return 0;
		}
		else n/=10;
	}
	cout<<"No"<<endl;
	return 0;
}

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

public class Main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer = null;
    int totalCases, testNum;

    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    void solve() throws IOException {

    }

    void execute() throws IOException {
        int n = ni();
        int targetWeight = ni();
        long[] dp = new long[targetWeight + 1];
        for (int i = 0; i < n; i++) {
            int w = ni();
            int v = ni();
            for (int j = targetWeight; j - w >= 0; j--) {
                dp[j] = Math.max(dp[j], Math.max(dp[j - 1], dp[j - w] + v));
            }
        }
        long res = 0;
        for (long num : dp) {
            res = Math.max(res, num);
        }
        out.print(res);

        out.close();
    }

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

    void debug(Object... os) {
        System.out.println(Arrays.deepToString(os));
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String ns() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(br.readLine());
        }
        return tokenizer.nextToken();
    }

    String nline() throws IOException {
        tokenizer = null;
        return br.readLine();
    }

    boolean input() throws IOException {
        return true;
    }

}


Measured memory_bytes: 27356
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
				
			ArrayList<HashSet<Integer>> adj = new ArrayList<HashSet<Integer>>();
			for(int i = 0; i < N; i++) { adj.add(new HashSet<Integer>()); }
			
			int[] b_array = new int[N];
			for(int i = 0; i < M; i++) {
				final int a = sc.nextInt() - 1;
				final int b = sc.nextInt() - 1;
				
				
				adj.get(a).add(b);
				b_array[b]++;
			}
			
			int answer = 0;
			ArrayList<Integer> remove = new ArrayList<Integer>();
			
			for(int i = 0; i < N; i++) {
				if(b_array[i] > 0 && !remove.isEmpty()) {
					answer++;
					
					for(final int x : remove) { b_array[x]--; }
					remove.clear();
				}
				
				if(!adj.get(i).isEmpty()) { remove.addAll(adj.get(i)); }
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 67580