akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int INF=1e9;



int main(){
	int N,Ma,Mb;
	cin>>N>>Ma>>Mb;
	int a[41],b[41],c[41];
	rep1(i,N)cin>>a[i]>>b[i]>>c[i];
	
	//dp[i][j][k]はi番目まででj,kグラム使うときの最小
	int dp[41][402][402];
	rep(j,402)rep(k,402)dp[0][j][k]=INF;
	dp[0][0][0]=0;
	rep1(i,40)rep(j,402)rep(k,402){
		dp[i][j][k]=dp[i-1][j][k];
		if(j-a[i]>=0&&k-b[i]>=0)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
	}
	int ans=INF;
	int x=0,y=0;
	while(true){
		x+=Ma;y+=Mb;
		if(x>401||y>401)break;
		ans=min(ans,dp[N][x][y]);
	}
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}

Measured memory_bytes: 26112
# import bisect
# import heapq
# from copy import deepcopy
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
s = deque(input())
q = int(input())
rev = False
for i in range(q):
    que = input()
    if que[0] == '1':
        rev = not rev
    else:
        que = list(que.split())
        if (int(que[1])==1 and not rev) or (int(que[1])==2 and rev):
            s.appendleft(que[2])
        else:
            s.append(que[2])

if rev: ans = ''.join(reversed(s))
else: ans = ''.join(s)
print(ans)


Measured memory_bytes: 8564
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int w = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int answer = 0;

		if(a<b){
			if(a+w<b){
				answer = b - a - w;
			}
		}else if(b<a){
			if(b+w<a){
				answer = a - b - w;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y))
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;

const int N = 1e6+10 ;
const ll MOD = 1e9 + 7;
typedef pair<ll,ll >PII;

vector<int >g[N];

int T,n,b,c,r;
int x1,x2,ans;
int a[N],p,k;

int dp[N];

int main(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]+a[1]+a[2]>=22){
        cout<<"bust";
    }else{
        cout<<"win";
    }
}


Measured memory_bytes: 25344
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    
    int a[4]={};
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="AC"){
            a[0]++;
        }else if(s=="WA"){
            a[1]++;
        }else if(s=="TLE"){
            a[2]++;
        }else if(s=="RE"){
            a[3]++;
        }
    }

    cout<<"AC x "<<a[0]<<"\n";
    cout<<"WA x "<<a[1]<<"\n";
    cout<<"TLE x "<<a[2]<<"\n";
    cout<<"RE x "<<a[3]<<"\n";
    return 0;
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

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

int W, H, N, r, l, u, d;
int x[110];
int y[110];
int a[110];

void init()
{
	cin >> W >> H >> N;
	rep(i, N) cin >> x[i] >> y[i] >> a[i];
	r = W;
	l = 0;
	u = H;
	d = 0;
}

void solve()
{
	rep(i, N) {
		if (a[i] == 1) l = max(l, x[i]);
		if (a[i] == 2) r = min(r, x[i]);
		if (a[i] == 3) d = max(d, y[i]);
		if (a[i] == 4) u = min(u, y[i]);
	}
	if (r < l) r = l;
	cout << max((r - l) * (u - d), 0) << endl;
}



Measured memory_bytes: 256
using System;

namespace oasobi
{
    static class MainClass
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int a = int.Parse(Console.ReadLine());
            while( n >= 500)
            {
                n = n - 500;
            }
            if(n <= a)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	c := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&c[i])
	}
	for i := range c {
		for j := 0; j < 2; j++ {
			fmt.Println(c[i])
		}
	}
}


Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

	static final long DIV_INF = 998244353l;

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

		double a = readInt(sc);
		double b = readInt(sc);
		double h = readInt(sc);
		double m = readInt(sc);

		double rad_m = 2d * Math.PI * m / 60d;
		double rad_h = 2d * Math.PI * (h / 12d + m / 720d);

		double x_h = a * Math.cos(rad_h);
		double y_h = a * Math.sin(rad_h);
		double x_m = b * Math.cos(rad_m);
		double y_m = b * Math.sin(rad_m);

		System.out.println(Math.sqrt(Math.pow((y_h - y_m), 2) + Math.pow((x_h - x_m), 2)));

	}

	static long div(long x) {
		return x % DIV_INF;
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static Long readLong(Scanner sc) {
		return Long.parseLong(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class KrmlUtil {
	// a >= b
	static int gcd(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// a >= b
	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	// a >= b
	static long gcd(long a, long b) {
		while (true) {
			if (b == 0)
				break;

			long mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// a >= b
	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static BigInteger gcd(BigInteger a, BigInteger b) {
		return a.gcd(b);
	}

	static BigInteger lcm(BigInteger a, BigInteger b) {
		return a.divide(a.gcd(b)).multiply(b);
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 35912
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define mod 1000000007
#define ll long long
ll n,b[2000005],tot,id[2000005],l[2000005],r[2000005],f[2000005],sum[2000005],le;
struct l1{
	ll x,v;
}s[2000005];
ll add(ll x){
	return x>=mod?x-mod:x;
}
ll cmp(l1 a,l1 b){
	return a.v<b.v;
}
int main(){
//	freopen("random.in","r",stdin);
//	freopen("count.out","w",stdout);
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lld%lld",&s[i].x,&s[i].v);
		b[++tot]=s[i].x;
	}
	sort(s+1,s+n+1,cmp);
	sort(b+1,b+tot+1);
	for(ll i=1;i<=n;i++){
		s[i].x=lower_bound(b+1,b+tot+1,s[i].x)-b;
		id[s[i].x]=i;
	}
	for(ll i=1;i<=n;i++) r[i]=max(r[i-1],id[i]);
	l[n]=id[n];
	for(ll i=n-1;i>=1;i--) l[i]=min(l[i+1],id[i]);
	f[0]=sum[0]=1;le=0;
	for(ll i=1;i<=n;i++){
		while(le<r[i]) le++,sum[le]=sum[le-1];
		sum[le]=(sum[le]+sum[le]-((l[i]==1)?0:sum[l[i]-2])+mod)%mod;
	}
	printf("%lld",(sum[n]-sum[n-1]+mod)%mod);
}

Measured memory_bytes: 14776
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    int n,k,ans=0;
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<n-1;i++)
        if(s[i]==s[i+1])
        ans++;
    cout<<min(n-1,ans+2*k)<<endl;


    return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        double b;
        cin >> b;
        b *= 1000000000;
        a[i] = (ll)(b+0.0005);
    }
    map<Pi,int> cnt;
    rep(i,n){
        ll now = a[i];
        int cnt2 = 0;
        while(now%2 == 0){
            cnt2++;
            now /= 2;
        }
        now = a[i];
        int cnt3 = 0;
        while(now%5 == 0){
            cnt3++;
            now /= 5;
        }
        cnt[Pi(cnt2,cnt3)]++;
    }
    ll ans = 0;
    ll ans2 = 0;
    for(auto p1: cnt){
        for(auto p2: cnt){
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18){
                if(p1 == p2){
                    ans2 += (ll)p1.second*(p1.second-1)/2;
                }
                else ans += (ll)p1.second*p2.second;
            }
        }
    }
    ans = ans/2+ans2;
    cout << ans << endl;
}



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

int main(){
    int L;
    int R;
    int d;
    cin >> L >> R >> d;
    int count=0;
    for(int i=L;i<=R;i++){
        if(i%d==0) count++;
    }
    cout << count << endl;
    return 0;

    
}

Measured memory_bytes: 3584
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto xt = readln.chomp.split.map!(to!int);
  writeln(max(xt[0]-xt[1],0));
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000000];
vector<int> primes;

int main()
{
	fill(isPrime, isPrime+1000000, true);
	for (int i = 2; i < 1000000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				isPrime[j] = false;
			primes.push_back(i);
		}
	}

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		while (n--)
		{
			int p, m;
			scanf("%d %d", &p, &m);
			int X = upper_bound(primes.begin(), primes.end(), p+m)
				- lower_bound(primes.begin(), primes.end(), p-m);
			if (X)
				ans += X - 1;
			else
				--ans;
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
	int main(void){
		int n,x,i,j,k,count,sum=0;
		count=0;
		while(1){

			scanf("%d %d",&n,&x);

			if(n==0 && x==0) break;

			for(i=1;i<=n;i++){
				for(j=i+1;j<=n;j++){
					for(k=j+1;k<=n;k++){
						sum=i+j+k;
						if(sum==x){
							count++;
						}
					}
				}
			}
			printf("%d\n",count);
			count=0;
		}
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var list = new Dictionary<string, long>();
            for (var i = 0; i < n; i++)
            {
                var c = Console.ReadLine().ToCharArray();
                Array.Sort(c);
                var s = new string(c);
                if (list.ContainsKey(s)) list[s]++;
                else list.Add(s, 1);
            }
            var sum = 0L;
            foreach (var count in list.Values)
            {
                if (count > 1) sum += CombinationCount(count, 2);
            }
            Console.WriteLine(sum);
        }

        static long CombinationCount(long n, long k)
        {
            if (n < k) throw new ArgumentException();
            k = Math.Min(k, n - k);
            return PermutationCount(n, k) / PermutationCount(k, k);
        }

        static long PermutationCount(long n, long k)
        {
            if (n < k) throw new ArgumentException();
            var result = 1L;
            for (var i = 0; i < k; i++)
                result *= (n - i);
            return result;
        }
    }
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  ll k;cin>>k;

  set<char> st;
  for(int i=0;i<s.size();i++) st.insert(s[i]);
  if(st.size() == 1 || s[0] != '1') {cout<<s[0]<<endl;return 0;}

  for(int i=0;i<s.size();i++){
    if(s[i] != '1'){cout<<s[i]<<endl;return 0;}
    if(i == k-1){cout<<'1'<<endl;return 0;}
  }
  return 0;
}


Measured memory_bytes: 256
// Author : Chi
// created :
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <pair<int,int>, null_type, greater<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         1000000007
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
int dp[10010][101][2];
int n;
string k;
ll solve(int D,int p,int sum,int tight){
    int &mem=dp[p][sum][tight];
    int ub=(tight ? k[p]-'0' : 9);
    if(p == n-1){
        ll ans=0;
        for(int i=0;i <= ub;i++)
            if(sum == i%D)
                ans++;
        return ans;
    }
    if(mem!=-1)
        return mem%mod;
    ll ans=0;
    for(int i=0;i<=ub;i++)
        ans=(ans+solve(D,p+1,(D+sum-i%D)%D,(tight && i==ub))%mod)%mod;
    return mem=ans%mod;
}
void solve(){
    int d;
    cin>>k>>d;
    n=k.length();
    memset(dp,-1,sizeof dp);
    cout<<(mod+solve(d,0,0,1)-1)%mod;
    }
// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}


Measured memory_bytes: 9216
import scala.collection.mutable.PriorityQueue
import scala.collection.mutable.Set

object Main {

  def main(args: Array[String]) = {
    val lines = scala.io.Source.stdin.getLines.toStream

    val Array(num_x, num_y, num_z, num_k) = lines(0).split(" ").map(_.toLong)
    var xs = lines(1).split(" ").map(_.toLong)
    var ys = lines(2).split(" ").map(_.toLong)
    var zs = lines(3).split(" ").map(_.toLong)
    java.util.Arrays.sort(xs)
    java.util.Arrays.sort(ys)
    java.util.Arrays.sort(zs)
    xs = xs.reverse
    ys = ys.reverse
    zs = zs.reverse

    var x = xs(0)
    var y = ys(0)
    var z = zs(0)

    var cnt = 0L
    val pq = PriorityQueue[((Long, Char), (Int, Int, Int))]()(scala.math.Ordering.by((v: ((Long, Char), (Int, Int, Int))) => v._1))
    pq.enqueue((x + y + z, 'w') -> (0, 0, 0))
    dfs(pq, xs, ys, zs, num_k)
  }

  def dfs(
    q: PriorityQueue[((Long, Char), (Int, Int, Int))], 
    xs: Array[Long], 
    ys: Array[Long], 
    zs: Array[Long], 
    max: Long = 3000, 
    count: Long = 1, 
    checked: Set[(Int, Int, Int)] = Set()): Unit = {
    val ((value, c), (lx, ly, lz))  = q.dequeue
    println(value)
    if (xs.length > lx+1 && !checked.contains((lx + 1, ly, lz))) {
      checked += ((lx + 1, ly, lz))
      q.enqueue((value - xs(lx) + xs(lx + 1), 'x') -> (lx + 1, ly, lz))
    }
    if (ys.length > ly+1 && !checked.contains((lx, ly+1, lz))) {
      checked += ((lx, ly+1, lz))
      q.enqueue((value - ys(ly) + ys(ly+1), 'y') -> (lx, ly+1, lz))

    }
    if (zs.length > lz+1 && !checked.contains((lx, ly, lz+1))) {
      checked += ((lx, ly, lz+1))
      q.enqueue((value - zs(lz) + zs(lz+1), 'z') -> (lx, ly, lz+1))
    }

    if (count < max && (zs.length > lz+1 || ys.length > ly+1 || xs.length > lx+1)) {
      dfs(q, xs, ys, zs, max, count + 1, checked)
    }
  }
}


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

typedef long long Long;
int main(){
	cin.tie(0);ios::sync_with_stdio(0);
	Long N;
	cin >> N;
	if( N&1 )
		cout << N*2 << '\n';
	else
		cout << N << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int[] tmp=new int[3];
		tmp[0]=youso[1][0]-youso[0][0];
		tmp[1]=youso[2][0]-youso[1][0];
		tmp[2]=youso[2][0]-youso[0][0];
		int aa[][]= {{1,0},{2,1},{2,0}};
		boolean[] vali=new boolean[3];
		for(int i=0; i<3; i++) {
			vali[i]=true;
		}
		for(int i=0; i<3; i++) {
			for(int j=0; j<3; j++) {
				if(youso[aa[i][0]][j]-youso[aa[i][1]][j]!=tmp[i]) {
					System.out.println("No");
					System.exit(0);
				}
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23892
#include <iostream>

using namespace std;

int main()
{
	char s[100];
	int a, b;
	cin >> a >> b;
	cin >> s;

	if (s[a] == '-')
	{
		for (int i = 0; i < a; i++)
		{
			if (s[i] != '-') {

			}
			else
				goto b;

		}
		for (int n = a + 1; n < a + b; n++)
		{
			if (s[n] != '-') {

			}
			else
				goto b;
		}
	}
	else
		goto b;

	goto a;
a:
	cout << "Yes" << endl;
	return 0;
b:
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
    if(0+r<=x&&x<=W-r&&0+r<=y&&y<=H-r){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
        
    return 0;
}


Measured memory_bytes: 2112
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = input()
if len(S) == len(set(S)):
	print("yes")
else:
	print("no")

Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d;
  e = (b < d ? b : d) - (a > c ? a : c);
  cout << (e < 0 ? 0 : e);
  return 0;
}

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

vector<ll> solve (ll N, vector<ll> A) {
   vector<ll> tmp1(N, 0), tmp2(N, 0);
   vector<ll> ans(N, 0);
   ll sum = 0;
   for (ll i = 0; i < N; i++) tmp1.at(A.at(i) - 1)++;
   for (ll i = 0; i < N; i++) {
       if (tmp1.at(i)) tmp2.at(i) = tmp1.at(i) * (tmp1.at(i) - 1) / 2;
       sum += tmp2.at(i);
   }
   for (ll i = 0; i < N; i++) {
       if (tmp1.at(A.at(i) - 1) < 2) ans.at(i) = sum;
       //else if (tmp1.at(A.at(i) - 1) == 2) ans.at(i) = sum - 2;
       else ans.at(i) = sum - (tmp1.at(A.at(i) - 1) * (tmp1.at(A.at(i) - 1) - 1)) / 2 + ((tmp1.at(A.at(i) - 1) - 1) * (tmp1.at(A.at(i) - 1) - 2)) / 2;
   }
   return ans;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A.at(i);
  vector<ll> ans = solve(N, A);
  for (ll i = 0; i < N; i++) cout << ans.at(i) << endl;
  return 0;
}


Measured memory_bytes: 8064
#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 < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, y;
    ll tmp;
    bool check = false;
    sc(n) sc(y)
    for (int i = 0; i <= y / 10000; i++){
        for (int j = 0; j <= (y - 10000*i) / 5000; j++){
            if (i + j > n) break;
            tmp = y - 10000*i - 5000*j;
            if (tmp % 1000 == 0 && i + j + (tmp / 1000) == n){
                check = true;
                cout << i << " " << j << " " << tmp / 1000 << endl;
                break;
            }
        }
        if (check) break;
    }
    if (!check) cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    if (2 * x == W && 2 * y == H) {
        cout << setprecision(12) << W * H / 2 << " 1" << endl;
    } else {
        cout << setprecision(12) << W * H / 2 << " 0" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;

long long split10(long long a) {//aで10^(100)を割る
	long long ans = 10000000000 % a;
	long long ret = ans;
	for (int i = 0; i < 9; i++)
	{
		ret=(ans*ret%a);
	}
	return ret;
}


int n, m;
string s;

int main() {
	cin >> s;
	int siz = s.size();
	n = siz;
	VI ans(siz,0);
	int stait = 0;
	s += 'R';
	while (stait < n) {
		long long Rcnt = 0;
		long long Lcnt = 0;
		int i;
		for (i = stait; i < n; i++)
		{
			if (s[i] == 'R') { Rcnt++; }
			else {
				break;
			}
		}
		for (; i < n; i++)
		{
			if (s[i] == 'L') { Lcnt++; }
			else {
				break;
			}
		}
		int mae = 0;
		int usiro = 0;
		/*if (split10(Rcnt) % 2) {
			usiro += (Rcnt + 1) / 2;
			mae += (Rcnt) / 2;
		}
		else {
			usiro += (Rcnt) / 2;
			mae += (Rcnt + 1) / 2;
		}
		*/
		mae += (Rcnt + 1) / 2;
		usiro += (Rcnt) / 2;
		/*if (split10(Lcnt) % 2) {
			usiro += (Lcnt) / 2;
			mae += (Lcnt + 1) / 2;
		}
		else {
			usiro += (Lcnt + 1) / 2;
			mae += (Lcnt) / 2;
		}
		*/
		usiro += (Lcnt + 1) / 2;
		mae += (Lcnt) / 2;
		ans[stait + Rcnt - 1] = mae;
		ans[stait + Rcnt] = usiro;
		stait = i;
	}
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 1024
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
const ll MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;
    vector<ll> values(n);
    rep(i, 0, n)
        cin >> values[i];

    ll res = 0;
    ll base = 1;
    for(;;)
    {
      bool go_next = false;

      // count one and zeros
      ll ones = 0;
      for (auto& value: values)
      {
          if (value&1)
            ++ones;
          if (value > 0)
            go_next = true;
          value >>= 1;
      }
      // update
      ll nums = ones*(n-ones) %MOD;
      res += (ll)((base%MOD)*nums)%MOD;
      res %= MOD;

      if (res<0)
        res += MOD;

      base <<= 1LL;
      base %= MOD;
      // break check
      if (!go_next)
        break;
    }

    cout << res << endl;
    return 0;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	int a[N];
	int is4=0,is2=0;
	REP(i,N){
		a[i]=read();
		if(a[i]%4==0) is4++;
		else if(a[i]%2==0) is2++;
	}
	if(is4>=N/2) cout << "Yes" << endl;
	else if(is2 >= N-is4*2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int pr=0;
	int ans=0;
	for(int i=0;i<n;++i){
		int d;
		cin>>d;
		if(d<pr){
			ans+=pr-d;
		}
		else{
			pr=d;
		}
	}
	cout<<ans;
	#ifdef ANIKET_GOYAL
		// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(){
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};	   
  int w,h,i,j,ny,nx,k,l,x[3000],y[3000],t,r;
  while(scanf("%d %d",&w,&h),w||h){
    char s[55][55]={0};
    int c[4]={0};
    int e[55][55]={0};
    for(i=0;i<h;i++)scanf("%s",s[i+1]+1);
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(s[i][j]=='.')continue;
	if(s[i][j]=='W')k=2;
	else            k=1;
	y[0  ]=i;
	x[t=0]=j;
	for(r=1;r-t;t++){//printf("%d\n",r);
	  for(l=0;l<4;l++){
	    ny=y[t]+Y[l];
	    nx=x[t]+X[l];
	    if(s[ny][nx]-'.'||e[ny][nx]==k||e[ny][nx]==3)continue;
	    e[y[r]=ny][x[r]=nx]+=k;
	    r++;
	  }
	}
      }
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++)c[e[i+1][j+1]]++;//,printf("%d",e[i+1][j+1]);printf("\n");
    }
    printf("%d %d\n",c[1],c[2]);
  }
  return 0;
}

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

md=1000000007
fac=[0]*(M+1)
inv=[0]*(M+1)
ifac=[0]*(M+1)
inv[1]=1
for i in range(2,M+1):
	inv[i] = (md - (md//i) * inv[md%i] % md) % md;
fac[0]=1
ifac[0]=1
for i in range(1,M+1):
    fac[i]=fac[i-1]*i%md;
    ifac[i]=ifac[i-1]*inv[i]%md;

def choose(n,k):
    return fac[n]*ifac[k]*ifac[n-k]%md
def perm(m,n):
    return fac[m]*ifac[m-n]%md
ans=0
for k in range(N+1):
    if k%2==0:
        ans+=choose(N,k)*perm(M,k)*perm(M-k,N-k)**2
        ans%=md
    else:
        ans-=choose(N,k)*perm(M,k)*perm(M-k,N-k)**2
        ans%=md
print(ans)

Measured memory_bytes: 68132
l, r = map(int,input().split())

a = 0
while a < l:
    a += 2019
if r - a >= 2019:
    print(0)
    exit()

d = 2019
for i in range(l, r+1):
    for j in range(l, r+1):
        if i == j:
            continue
        d = min(d, i*j % 2019)

print(d)

Measured memory_bytes: 9128
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
N = int(input())
tmp = prime_factorize(N)
import collections
C = collections.Counter(tmp)
count = 0
for key in C.keys():
    tmp = C[key]
    i = 0
    while True:
        i += 1
        if tmp >= i:
            tmp -= i
            count += 1
        else:
            break
print(count)

Measured memory_bytes: 9464
def check(N,A,B,h,K):
    sum = 0
    for i in range(N):
        x = -((-h[i]+B*K)//(A-B))
        sum += x if x>0 else 0
    return sum<=K

N, A, B = list(map(int,input().split()))
h=[0]*N
for i in range(N):
    h[i] = int(input())

ok = 1000000000
ng = 0
while abs(ok -ng)>1:
    mid = (ok+ng)//2
    if check(N,A,B,h,mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 6900
from operator import mul

def getMatrixProduct(Ass, Bss, MOD):
    BssTr = [list(Bs) for Bs in zip(*Bss)]  # 転置
    ansss = [[sum(map(mul, As, Bs)) % MOD for Bs in BssTr] for As in Ass]
    return ansss

def getMatrixPower(Ass, n, MOD):
    sizeA = len(Ass)
    ansss = [[0]*(sizeA) for _ in range(sizeA)]
    for i in range(sizeA):
        ansss[i][i] = 1
    while n:
        if n & 1:
            ansss = getMatrixProduct(ansss, Ass, MOD)
        Ass = getMatrixProduct(Ass, Ass, MOD)
        n //= 2
    return ansss

L, A, B, M = map(int, input().split())

As = [[A%M], [A%M], [1]]
iPrev = 0
d = 1
while True:
    i = (10**d-1-A) // B
    if i > L-1:
        i = L-1
    num = i-iPrev
    if num > 0:
        Css = [[10**d,1,B%M], [0,1,B%M], [0,0,1]]
        PowCss = getMatrixPower(Css, num, M)
        As = getMatrixProduct(PowCss, As, M)
    if i == L-1:
        break
    iPrev = max(0, i)
    d += 1

print(As[0][0])


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

int main() {
  string s;
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
let n = Int(readLine()!)!
var dpTable = [Int](repeating: 0, count: 1000000+1) // dpTable
var cutter = [Int](repeating: 0, count: 1000000+1) // divisor count
dpTable[2] = 1 

for it in 1...1000000 {
  var k = 1
  while k * it <= 1000000 {
    cutter[k*it] += 1
    k += 1
  }
}

if n > 2 {
  for it in 3...n {
   dpTable[it] = dpTable[it-1] + cutter[it-1]
  }
}

print(dpTable[n])

Measured memory_bytes: 23472
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1e6 + 9, M = 1e9 + 7;
int main() {
string s;
cin>>s;
int a;
cin>>a;
string nw="";
for(int i=0;i<s.size();){
nw+=s[i];
i+=a;
}
cout<<nw<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <cstdlib>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

template <class T>
struct prop_segtree {
  int n;
  vector<T> data;
  vector<bool> propFlag;

  prop_segtree(const int s) {
    init(s);
  }

  prop_segtree(const int s, const T u) {
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = u;
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = 0;
    }
  }

  prop_segtree(const vector<T> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = v[i];
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = 0;
    }
  }

  void init(const int s) {
    n = 1;
    while (n < s) n <<= 1;
    data = vector<T>(2*n-1);
    propFlag = vector<bool>(2*n-1);
  }

  void propagate(int p, int a, int b) {
    if (propFlag[p]) {
      if (b - a > 1) {
        data[p*2+1] = data[p];
        data[p*2+2] = data[p];
        propFlag[p*2+1] = true;
        propFlag[p*2+2] = true;
        data[p] = 0;
      }
      propFlag[p] = false;
    }
  }

  void update(int l, int r, T v, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // propagate value
    propagate(p, a, b);

    if (r <= a || b <= l) return; // out of range
    if (l <= a && b <= r) { // fully covered
      data[p] = v;
      propFlag[p] = true;
      propagate(p, a, b);
    }
    else {
      update(l, r, v, p*2+1, a, (a + b) / 2); // left
      update(l, r, v, p*2+2, (a + b) / 2, b); // right
    }
    return;
  }

  T query(int x, T p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // propagate value
    propagate(p, a, b);

    if (b - a == 1) return data[p];// reached to bottom

    if (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // left
    else return query(x, p*2+2, (a + b) / 2, b); // right
  }
};

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

  int n, q;
  cin >> n >> q;
  vector<vector<int> > query(q, vector<int>(4));
  for (int i = 0; i < q; i++) {
    cin >> query[i][0] >> query[i][1];
    if (query[i][0] == 0) cin  >> query[i][2] >> query[i][3];
  }

  prop_segtree<int> pst(n, 0x7fffffff);
  vector<ll> ans;
  for (int i = 0; i < q; i++) {
    if (query[i][0] == 0) { // update
      pst.update(query[i][1], query[i][2]+1, query[i][3]);
    }
    else { // get
      ans.push_back(pst.query(query[i][1]));
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}



Measured memory_bytes: 10444
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	string S;
	cin >> S;
	rep(i, S.size()) {
		char tmp = S[i] - 'A';
		tmp = (tmp + N) % 26;
		S[i] = tmp + 'A';
	}
	cout << S << endl;
	return 0;
}

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

int main() {
    int n;cin >> n;
    int waa,wab,sa,saa;
    int sum;sum = 0;
    vector<int> w(n);
    for(int i=0;i<n;i++){
        cin >> w[i];
        sum += w[i];
    }

    waa = w[0];
    for(int m=1;m<n;m++){
        wab += w[m];
    }
    sa = abs(waa-wab);

    for(int l=0;l<n-2;l++){
        waa = 0;
        wab = 0;
        for(int k=0;k<l+2;k++){
            waa += w[k];
        }
        wab = sum - waa;
        saa = abs(waa-wab);
        sa = min(sa,saa);
    }

    cout << sa << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int x[5];
    REP(i, 5) cin >> x[i];
    REP(i, 5) if (x[i] == 0) {
        cout << i + 1 << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int sum=0,amount=0;
  for(int i=1;i <= n;i++){
    sum=0;
    if(i%2==0) continue;
    for(int j=1;j <= i;j++){
      if(i % j ==0)sum++;
    }
    if(sum == 8)amount++;
  }
  cout<< amount<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1234567890;

int D;
int x[100000];

const int B = 250;
const int SZ = 4000;

// default,sorted
vector<int> d[B],s[B];

int f(int l, int r, int p, int q)
{
    int ret = r-l+1;
    for(int i=l; i<=r; ++i)if(p<=x[i] && x[i]<=q) --ret;
    return ret;
}

int g(int bid, int p, int q)
{
    int lidx = lower_bound(all(s[bid]), p) - s[bid].begin();
    int ridx = upper_bound(all(s[bid]), q) - s[bid].begin();
    int ct = ridx - lidx;
    return SZ - ct;
}

int query(int l, int r, int e)
{
    int a = min(x[l],x[r]), b = max(x[l],x[r]);
    int lb = l/SZ, rb = r/SZ;
    int ret = 0;
    if(lb==rb) ret += f(l,r,a-e,b+e);
    else
    {
        ret += f(l,SZ*(lb+1)-1,a-e,b+e);
        for(int i=lb+1; i<rb; ++i) ret += g(i,a-e,b+e);
        ret += f(SZ*rb,r,a-e,b+e);
    }
    return ret;
}

int main()
{
    scanf(" %d", &D);
    rep(i,D) scanf(" %d", &x[i]);

    rep(i,B)
    {
        d[i] = vector<int>(SZ,INF);
        rep(j,SZ)
        {
            int id = i*SZ+j;
            if(id<D) d[i][j] = x[id];
        }

        s[i] = d[i];
        sort(all(s[i]));
    }

    int Q;
    scanf(" %d", &Q);
    while(Q--)
    {
        int l,r,e;
        scanf(" %d %d %d", &l, &r, &e);
        --l; --r;
        printf("%d\n", query(l,r,e));
    }
    return 0;
}

Measured memory_bytes: 11248
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
	int a, b;
	cin >> a >> b;
	if (b >= a){
		cout << a << endl;
	}
	else{
		cout << a - 1 << endl;
	}

	return 0;
}



Measured memory_bytes: 256
class Tree_with_edge_cost:
    def __init__(self, n, edge):
        self.n = n
        self.nexts = [[] for _ in range(n)]
        for u, v, c in edge:
            self.nexts[u].append((v, c))
            self.nexts[v].append((u, c))
        self.parent = [-1] * self.n
        self.children = [[] for _ in range(self.n)]
        self.cost = [0] * self.n
        self.dist = [0] * self.n  # 根からの距離
        self.depth = [0] * self.n  # 根からの深さ(cost=1での距離)
        self.order = []

    def set_root(self, root):  # O(n)
        self.order.append(root)
        stack = [root]
        while stack:
            v = stack.pop()
            for child, cost in self.nexts[v]:
                if child == self.parent[v]:
                    continue
                else:
                    self.parent[child] = v
                    self.children[v].append(child)
                    self.depth[child] = self.depth[v] + 1
                    self.dist[child] = self.dist[v] + cost
                    self.cost[child] = cost
                    self.order.append(child)
                    stack.append(child)

    def get_diameter(self, restore=False):  # double-sweepで求める  O(n)
        u = self.dist.index(max(self.dist))  # 根から一番遠いものを根とし、そこから一番遠いものを見つける
        dist_u = [-1] * self.n
        dist_u[u] = 0
        stack = [u]
        parent_u = [None for _ in range(self.n)]
        while stack:
            v = stack.pop()
            for child, cost in self.nexts[v]:
                if dist_u[child] == -1:
                    dist_u[child] = dist_u[v] + cost
                    parent_u[child] = v
                    stack.append(child)
        diameter = max(dist_u)
        v = dist_u.index(diameter)
        if restore:
            path = [v]
            while v != u:
                v = parent_u[v]
                path.append(v)
            path.reverse()  # [u,...,v]
            return diameter, path
        else:
            return diameter, u, v

# ---------------------- #

n = int(input())
edges = []
for _ in range(n-1):
    a, b, c = (int(x) for x in input().split())
    a -= 1
    b -= 1
    edges.append((a, b, c))
q, k = (int(x) for x in input().split())
queries = [tuple(int(x) for x in input().split()) for _ in range(q)]
tree = Tree_with_edge_cost(n, edges)
tree.set_root(k-1)

for x, y in queries:
    x -= 1
    y -= 1
    print(tree.dist[x] + tree.dist[y])


Measured memory_bytes: 153672
import java.util.*;
public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
}

Measured memory_bytes: 21972
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
K = int(input())

res = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def dfs(x, k):
  global res
  if k == 0:
    res.append(x)
    return
  for i in range(3):
    y = i - 1 + (x % 10)
    if y in range(10):
      dfs(x * 10 + y, k - 1)
for t in range(1, 11):
  for x in range(1, 10):
    dfs(x, t)
res.sort()
print(res[K - 1])

Measured memory_bytes: 92344
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	k := intScanner()
	t := intScanner()
	as := intSliceScanner(t)
	sort.Ints(as)
	x := as[t-1]
	if x <= k/2 {
		fmt.Println(0)
	} else {
		fmt.Println(2*x - k - 1)
	}
}


Measured memory_bytes: 640
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        
        int x, y, z;
        int count = 0;
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        
        x = Integer.parseInt(str[0]);
        y = Integer.parseInt(str[1]);
        z = Integer.parseInt(str[2]);
        
        for(int i=x; i<=y; i++){
            if(z%i == 0){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24352