akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int i=1,x,y,z,dataset,work;
    scanf("%d",&dataset);
    while(i<=dataset){
        scanf("%d%d%d",&x,&y,&z);
        if(x<y){
            work=x;
            x=y;
            y=work;
        }
        if(x<z){
            work=x;
            x=z;
            z=work;
        }
        if(x*x==y*y+z*z)
            printf("YES\n");
        else
            printf("NO\n");
        i++;
    }
return 0;
}

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        N = cin.nextint;
        long p = 1;
        for (int i = 0; i < N; i++)
        {
            var t = cin.nextlong;
            p = t / gcd(p, t) * p;

        }
        WriteLine(p);
    }
    
    long gcd(long a, long b)
    {
        return (b != 0) ? gcd(b, a % b) : a;
    }


}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main(){
  int N,Q;
  string S;
  cin >> N >> S >> Q;
  vector<int> k(Q);
  for(int i=0;i<Q;i++){
	cin >> k[i];
  }

  for(int j=0;j<Q;j++){
	long long D=0,M=0,DM=0,DMC=0;
	for(int i=0;i<N;i++){
	  if(S[i]=='D'){
		D++;
	  }
	  if(S[i]=='M'){
		DM+=D;
		M++;
	  }
	  if(S[i]=='C'){
		DMC+=DM;
	  }
	  if(i-k[j]+1>=0){
		if(S[i-k[j]+1]=='D'){
		  D--;
		  DM-=M;
		}if(S[i-k[j]+1]=='M'){
		  M--;
		}
	  }
	}
	cout << DMC << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
using namespace std;
typedef long long ll;
ll a[55],b[55],c[55],d[55];
ll n,m,q;
ll ma=0;
void sou(ll wei,ll num,ll e[11])
{
	if(wei==n+1)
	{
		ll sum=0;
//		for(ll i=1;i<=n;i++) printf("%lld ",e[i]);
//		printf("\n");
		for(ll i=0;i<q;i++)
		{
			if(e[b[i]]-e[a[i]]==c[i]) sum+=d[i];
		}
		ma=max(sum,ma);
		return;
	}
	for(ll i=num;i<=m;i++)
	{
		e[wei]=i;
		sou(wei+1,i,e);
	}
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&m,&q);
	for(ll i=0;i<q;i++)
	{
		scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]);
	}
	ll e[11]={0};
	sou(1,1,e);
	printf("%lld\n",ma);
}

Measured memory_bytes: 3788
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#include <stdbool.h>

#define STACK_SIZE1 20000
#define STACK_SIZE2 10000

typedef struct stack2_tbl
{
	int i;
	int j;
} stack2_t;

const char NUL = '\0';
int stack1[STACK_SIZE1];
stack2_t stack2[STACK_SIZE2];
int sp1;
int sp2;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
push1(int x)
{
	if (sp1 >= STACK_SIZE1)
	{
		fprintf(stderr, "Stack1 area overflow. size:%d\n", STACK_SIZE1);
		cleanup(1);
	}

	stack1[sp1++] = x;
}

void
pop1()
{
	if (sp1 <= 0)
	{
		fprintf(stderr, "Stack1 underflow #1\n");
		cleanup(1);
	}

	sp1--;
}

int
top1()
{
	if (sp1 <= 0)
	{
		fprintf(stderr, "Stack1 underflow #2\n");
		cleanup(1);
	}

	return stack1[sp1 - 1];
}

void
push2(stack2_t* s)
{
	if (sp2 >= STACK_SIZE2)
	{
		fprintf(stderr, "Stack2 area overflow. size:%d\n", STACK_SIZE2);
		cleanup(1);
	}

	stack2[sp2].i = s->i;
	stack2[sp2].j = s->j;
	sp2++;
}

void
pop2()
{
	if (sp2 <= 0)
	{
		fprintf(stderr, "Stack2 underflow #1\n");
		cleanup(1);
	}

	sp2--;
}

void
top2(stack2_t* s)
{
	if (sp2 <= 0)
	{
		fprintf(stderr, "Stack2 underflow #2\n");
		cleanup(1);
	}

	s->i = stack2[sp2 - 1].i;
	s->j = stack2[sp2 - 1].j;
}

int
main(int argc, char** argv)
{
	stack2_t s;
	int x[STACK_SIZE2];
	int i;

	sp1 = 0;
	sp2 = 0;
	int sum = 0;
	for (i = 0;; ++i)
	{
		char c;

		scanf("%c", &c);
		if (c == '\n' || c == NUL)
			break;

		if (c == '\\')
			push1(i);

		else if (c == '/' && sp1 > 0)
		{
			int j = top1(); pop1();
			sum += i - j;
			int a = i - j;
			while (true)
			{
				if (sp2 <= 0)
					break;

				top2(&s);
				if (j > s.i)
					break;

				a += s.j; pop2();
			}

			s.i = j;
			s.j = a;
			push2(&s);
		}
	}

	int n = sp2;
	for (i = sp2 - 1; sp2 > 0; --i)
	{
		top2(&s); pop2();
		x[i] = s.j;
	}

	printf("%d\n", sum);
	printf("%d", n);
	for (i = 0; i < n; ++i)
		printf(" %d", x[i]);

	printf("\n");
	return 0;
}

Measured memory_bytes: 628
import java.util.*;

class Main {

	private static final String SPLIT_STR = " ";

	public static void main(String[] args) {

		String input = null;

		Scanner sc = new Scanner(System.in);

		input = sc.nextLine();
		String[] split = input.split(SPLIT_STR);
		int total = Integer.parseInt(split[0]);
		int num1 = Integer.parseInt(split[1]);
		int yen1 = Integer.parseInt(split[2]);
		int num2 = Integer.parseInt(split[3]);
		int yen2 = Integer.parseInt(split[4]);

		sc.close();

		int cnt = 0;
		int result = 0;

		int total1 = 0;
		while (total1 < total) {
			total1 += num1;
			cnt++;
		}
		result = cnt * yen1;

		cnt = 0;
		int total2 = 0;
		while (total2 < total) {
			total2 += num2;
			cnt++;
		}
		result = (cnt * yen2 < result) ? cnt * yen2 : result;

		System.out.println(result);
	}
}



Measured memory_bytes: 26228
# 行数Hおよび列数Wを入力する
H, W = map(int, input().split())
# マスを初期化する（ワンサイズ大きめに作成する）
s = ["." * (W + 2) for _ in range(H + 2)]
# マスを入力する
for i in range(1, H + 1):
    s[i] = "." + input() + "."
# 判定を初期化する
judge = "Yes"
# 各マスについて、黒く塗れるかを調べる
for i in range(1, H + 1):
    for j in range(1, W + 1):
        # 黒く塗らないマスの場合、以降の処理は行わずに次のマスに移る
        if s[i][j] == ".":
            continue
        # 上下左右に黒く塗るべきマスがない場合、塗り分け不可能
        if s[i - 1][j] + s[i][j - 1] + s[i][j + 1] + s[i + 1][j] == "....":
            # 判定を更新する
            judge = "No"
            # マスの調査を終了する
            break
# 判定を出力する
print(judge)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<vector<long>> tree(1e5+1);
void f(long k,vector<long>& d){
    queue<long> q;
    q.push(k);
    while(!q.empty()){
        long t=q.front(); q.pop();
        for(auto x:tree[t]){
            if(x!=k&&d[x]==0){
                d[x]=d[t]+1;
                q.push(x);
            }
        }
    }
}
int main(){
    long n; cin>>n;
    for(int i=0;i<n-1;i++){
        long a,b; cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<long> df(n+1,0),ds(n+1,0);
    f(1,df);
    f(n,ds);
    long sum=0;
    for(int i=1;i<=n;i++)
        sum+=df[i]<=ds[i]?1:-1;
    if(sum>0)
        cout<<"Fennec";
    else
        cout<<"Snuke";
}


Measured memory_bytes: 8004
#include <iostream>
#include <vector>
#include <utility>
#include <cassert>
using namespace std;
#define INF 1000000000000001

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

    vector<pair<pair<int,int>,long long>> edge;
    for(int i=0;i<M;i++){
        int a,b;
        long long c;
        cin >> a >> b >> c;
        edge.push_back(make_pair(make_pair(a,b),c));
    }

    bool update=true;
    long long pt[1001];
    for(int i=1;i<=1000;i++) pt[i]=(-INF);
    pt[1]=0;
    int cnt=0;
    while(update){
        update=false;
        for(pair<pair<int,int>,long long> x:edge){
            if(pt[x.first.first]!=-INF && pt[x.first.second]<pt[x.first.first]+x.second){
                pt[x.first.second]=pt[x.first.first]+x.second;
                update=true;
            }
        }
        if(cnt>N){
            long long vn=pt[N];
            for(int i=0;i<=N;i++){
                for(pair<pair<int,int>,long long> x:edge){
                    if(pt[x.first.first]!=-INF && pt[x.first.second]<pt[x.first.first]+x.second){
                        pt[x.first.second]=pt[x.first.first]+x.second;
                    }
                }
            }
            if(pt[N]>vn) cout << "inf" << endl;
            else cout << pt[N] << endl;
            return 0;
        }
        cnt++;
    }

    cout << pt[N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>

using namespace std;

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

  int x, tmp;
  x = 0;
  for(int i=0; i<N; i++){
    cin >> tmp;
    x += tmp;
  }

  if(x >= H) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main() {

	int n;
	cin >> n;
	
	int arr[n+1];
	int brr[n];
	
	for (int i=0; i<n+1; i++) cin >> arr[i];
	for (int i=0; i<n; i++) cin >> brr[i];
	
	long long take = 0;
	
	for (int i=0; i<n; i++) {
		int can = min(arr[i], brr[i]);
		take += can;
		arr[i] -= can;
		brr[i] -= can;
		int can2 = min(arr[i+1], brr[i]);
		take += can2;
		arr[i+1] -= can2;
		brr[i] -= can2;
	}
	
	cout << take << endl;
	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

// Nを与えると素因数分解をし、{素数:個数}のmapを返す
map<long long, long long> prime_factorize(long long n) {
    map<long long, long long> mp;
    for (long long a = 2; a * a <= n; a++) {
        if (n % a != 0) continue;
        long long exp = 0;  // 指数

        // 割れる限り割り続ける
        while (n % a == 0) {
            exp++;
            n /= a;
        }

        mp[a] = exp;
    }

    // 最後に残った数が1でないのならN自身が素数
    if (n != 1) mp[n] = 1;
    return mp;
}

int main() {
    long long n;
    cin >> n;
    map<long long, long long> prime;

    // nを素因数分解する
    prime = prime_factorize(n);

    long long count = 0;

    // 各素因数に対して
    for (auto itr : prime) {
        // 指数を1, 2, 3, と減らしていってどこまで引けるか
        long long k = 1;
        while (true) {
            itr.second -= k;
            if (itr.second >= 0) {
                // 指数部分が0以上なら操作できたことになる
                count++;
                k++;
            } else {
                // 指数部分が0より小さい
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int main(){
	int n;
	cin >> n;
	int i, t, A[n+1];
	cin >> A[0] >> A[1];
	for(i = 2; i <= n; i++){
		cin >> t >> A[i];
	}

	//dp[l][r] -> min(A[l]*...*A[r])
	int dp[n][n+1]{}, dplr, l, r;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < n-i; j++){
			l = j;
			r = j+i;
			dplr = INT_MAX;
			for(int k = l; k < r; k++){
				dplr = min(dplr, dp[l][k] + dp[k+1][r] + A[l]*A[k+1]*A[r+1]);
			}
			dp[l][r] = dplr;
			//printf("[%d, %d]=%d ", l, r, dplr);
		}
		//printf("\n");
	}

	printf("%d\n", dp[0][n-1]);
}



Measured memory_bytes: 3216
#include <iostream>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

char primes[1<<15];

void make_prime(){
	primes[0]=primes[1]=1;
	for(int i=4; i<(1<<15); i+=2)primes[i]=1;
	for(int i=3; i*i<=(1<<15); i+=2)if( !primes[i] )
		for(int j=i*3; j<(1<<15); j+=i)primes[j]=1;
}

int main(){
	int n;
	
	make_prime();
	
	while(cin>>n,n){
		int ans = 0;
		for(int i=n-2; i>=n/2; i--)if( !primes[i] && !primes[n-i] ){
			//printf("%d %d\n",i,n-i);
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque

def pr(a):
    for i in range(len(a)):
        if i == len(a)-1:
            print(a[i])
        else:
            print(a[i],end = " ")

n = int(input())
q = deque()
for i in range(n):
    x = input()
    l = len(x)
    if x[0] == "i":
        q.insert(0,x[7:])
    elif x[6] == " ":
        try:
            q.remove(x[7:])
        except:
            pass
    elif l > 10:
        q.popleft()
    elif l > 6:
        q.pop()

print(*q)


Measured memory_bytes: 69736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

ll n, x, m;
int main(){
    IN(n, x, m);
    vector<int> id(m, -1), graph;
    ll cnt, tot; cnt = tot = 0;
    while(id[x] == -1){
        id[x] = cnt; cnt++;
        tot += x;
        graph.push_back(x);
        x = (x*x)%m;
    }

    if(n <= cnt){
        ll ans = 0;
        rep(i, 0, n) ans += graph[i];
        cout << ans << el;
        return 0;
    }

    ll cycle = cnt - id[x];
    ll sum = 0; rep(i, id[x], cnt) sum += graph[i];

    ll ans = tot;
    n -= cnt;
    ans += sum*(n/cycle);
    n %= cycle;
    rep(i, 0, n) ans += graph[id[x]+i];
    cout << ans << el;

    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n, k;
    string s, ans = "";
    cin>>n>>k>>s;
    REP(i,n) {
        if (i == k - 1)
            ans += (s[i] - 'A' + 'a');
        else
            ans += s[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef unsigned long ul;

int main() {
    int N {};
    string s {};
    cin >> N;
    cin >> s;
    if (N % 2 == 1) {
        cout << "No" << '\n';
    } else {
        bool flag = true;
        int k = N / 2;
        for (int i = 0; i < k; ++i) {
            if (s[i] != s[k + i]) {
                flag = false;
            }
        }

        string ans = flag ? "Yes" : "No";
        cout << ans << '\n';
    }
    return 0;
}

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

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
char field[1000][1000];
bool flg[1000][1000] = {{0}};

class Data {
   public:
    int x, y, count;
    Data() {}
    Data(int x, int y, int count) : x(x), y(y), count(count) {}
};
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    Data start;
    int ans = 0;
    for (int i = 0; i < h; i++) {
        cin >> field[i];
        for (int j = 0; j < w; j++) {
            if (field[i][j] == 'S') {
                start = Data(j, i, 0);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        queue<Data> Q;
        Q.push(start);
        memset(flg, 0, sizeof(flg));
        while (!Q.empty()) {
            Data d = Q.front(); Q.pop();
            if (field[d.y][d.x] == i + '0') {
                start = Data(d.x, d.y, d.count);
                break;
            }
            if (flg[d.y][d.x]) continue;
            flg[d.y][d.x] = true;
            for (int j = 0; j < 4; j++) {
                int px = d.x + dx[j], py = d.y + dy[j];
                if (px < 0 || py < 0 || px >= w || py >= h) continue;
                if (field[py][px] == 'X') continue;
                Q.push(Data(px, py, d.count + 1));
            }
        }
        ans = start.count;
    }

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

Measured memory_bytes: 4968
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int cnt[N] = {};
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, x;
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> x;
        cnt[x]++;
    }
    for (int i = 1; i <= n; i++)
        cout << cnt[i] << '\n';
    return 0;
}

Measured memory_bytes: 4424
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    TXY = [[0, 0, 0]]
    TXY.extend([list(map(int, input().split())) for _ in range(N)])

    result = 'Yes'
    for i in range(N):
        t1, x1, y1 = TXY[i - 1]
        t2, x2, y2 = TXY[i]
        td = abs(t1 - t2)
        xyd = abs(x1 - x2) + abs(y1 - y2)
        if xyd <= td and xyd % 2 == td % 2:
            continue
        else:
            result = 'No'
            break
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 28092
import java.util.*;
public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
}

Measured memory_bytes: 21716
#include <cstdio>
using namespace std;
int A, B;
int main() {
  scanf("%d %d", &A, &B);
  int ans = -1;
  for(int i = 1; i < 1e7; ++i) {
    int i08 = i*0.08, i10 = i*0.1;
    if(i08 == A && i10 == B) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
}

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

int main() {
  int n;cin>>n;
  vector<int>vec(n);
  rep(i,n)cin>>vec[i];
  int ans=1e9;
  for(int i=1;i<n;i++){
    int l=0,r=0;
    for(int j=0;j<i;j++)l+=vec[j];
    for(int j=i;j<n;j++)r+=vec[j];
    ans=min(ans,abs(l-r));
  }
  cout<<ans<<endl;
}

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

//int _; 

int a;
long long b,n;
 
int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> a >> b >> n;
	cout << a*min(n,b-1)/b << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
  int a,ans=0;
   cin>>a;
  int aa[a];
  for(int i=0;i<a;i++)
  {
   cin>>aa[i];
    if(aa[i]%2==1 && i%2!=1)
      ans++;
  }
  cout<<ans<<endl;
}


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


int main() {

    int N;
    cin >> N;

    int num = 0;
    int ans = 0;

    for (int i = 1; i <= N; i++) {

        if (i%2 == 0) continue;

        num = 0;

        for (int j = 1; j <= i; j++) {
            if (i % j == 0) num += 1;
        }

        if (num == 8) ans +=1;
    
    }
    


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

Measured memory_bytes: 256
n = int(input())
from math import sqrt
points = []
for i in range(n):
  a,b = map(int,input().split())
  points.append([a,b])
res = 0
for i in range(n):
  for j in range(i+1,n):
    res += sqrt((points[j][1]-points[i][1])**2+(points[j][0]-points[i][0])**2)
print((res*2)/n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  string s;
  cin>>n>>s;
  set<int> r,g,b;
  for(int i = 0; i<n; i++){
    if(s[i] == 'B')b.insert(i);
    if(s[i] == 'G')g.insert(i);
    if(s[i] == 'R')r.insert(i);
    
  }
  ll ans = (r.size()*g.size()*b.size());
   for(auto it:b){
    for(auto itr:g){
        int z = max(it,itr);
        auto itrr = r.find(2*z-min(it,itr));
        if(itrr == r.end())continue;
        else if(*itrr>z)ans-=1;
    }
  }
  for(auto it:r){
    for(auto itr:b){
        int z = max(it,itr);
        auto itrr = g.find(2*z-min(it,itr));
        if(itrr == g.end())continue;
        else if(*itrr>z)ans-=1;
    }
  }

   for(auto it:r){
    for(auto itr:g){
        int z = max(it,itr);
        auto itrr = b.find(2*z-min(it,itr));
        if(itrr == b.end())continue;
        else if(*itrr>z)ans-=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3788
n = int(input())
s = input()
ans = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      a, b, c = str(a), str(b), str(c)
      a_find = s.find(a)
      if a_find == -1:
        continue
      b_find = s.find(b, a_find + 1)
      if b_find == -1:
        continue
      c_find = s.find(c, b_find + 1)
      if c_find == -1:
        continue
      ans += 1
print(ans)

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

int main() {
  uint32_t N = 0;
  std::cin >> N;

  uint32_t R_0 = 0, R_1 = 0;
  std::cin >> R_0 >> R_1;

  uint32_t minR = (R_0 < R_1) ? R_0 : R_1;
  int32_t max_profit = R_1 - R_0;
  for (size_t i = 2; i < N; i++) {
    uint32_t R_i = 0;
    std::cin >> R_i;

    int32_t profit = R_i - minR;
    if (max_profit < profit) max_profit = profit;
    if (minR > R_i) minR = R_i;
  }

  std::cout << max_profit << std::endl;

  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;

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

    int T, P, R;
    while (1)
    {
        cin >> T >> P >> R;
        if (T == 0)
            break;
        vector<PP> score(T);
        int wa_cnt[60][20] = {};
        rep(i, T) score[i].second = i + 1;
        rep(i, R)
        {
            int tID, pID, t;
            string mes;
            cin >> tID >> pID >> t >> mes;
            tID--, pID--;
            if (mes == "CORRECT")
            {
                score[tID].first.first++;
                score[tID].first.second += t + wa_cnt[tID][pID] * 1200;
            }
            else
            {
                wa_cnt[tID][pID]++;
            }
        }
        rep(i, T) score[i].first.first *= -1;
        sort(all(score));
        rep(i, T) cout << score[i].second << " " << -score[i].first.first << " " << score[i].first.second << endl;
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  string s;
  bool flag = false;
  cin >> s;
  int count = 0;
  rep(i,3) {
    if(s.at(i) == 'R') {
      if(!flag) {
        flag = true;
        count = 1;
      }
      else if(flag) {
        count++;
      }
    }

    if(flag && s.at(i) == 'S') flag = false;
  }

  cout << count << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

void test();

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    f(i,0,n){
        cin >> s[i];
    }
    sort(all(s));
    for(auto &i : s){
        cout << i;
    }
    return 0;
}

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

int main()
{
	int n,m;
	cin>>n>>m;
	
	for(int i=0;i<=n;i++)
	{
		int j=n-i;
		if(i*2+j*4==m)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		System.out.println(S / 3600 + ":" + S % 3600 / 60 + ":" + S % 60);
		sc.close();
	}
}

Measured memory_bytes: 26248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fr first
#define se second
const ll mod = 1e9+7;

ll power(ll x,ll y){
    if(x==0) return 1;
    ll ans=1;
    x%=mod;
    while(y>0){
        if(y&1)
            ans = (ans*x)%mod;
        x = (x*x)%mod;
        y = y>>1;
    }
    return (ans+mod)%mod;
}

// void solve(ll cas){
//     ll n;cin>>n;
//     vector<ll> a(n),b(n);
//     map<ll,ll> mpa,mpb;
//     for(ll i=0;i<n;i++){
//         cin>>a[i];
//         mpa[a[i]]++;
//     }
//     for(ll j=0;j<n;j++){
//         cin>>b[i];
//         mpb[b[i]]++;
//     }
//     ll mxa=0,mxb=0;
//     ll ca=0,cb=0;
//     for(auto it = mpa.begin();it!=mpa.end();++it){
//         if(it->second>mxa){
//             mxa = it->second;
//             ca = it->first;
//         }
//     }
//     for(auto it = mpb.begin();it!=mpb.end();++it){
//         if(it->second>mxb){
//             mxb = it->second;
//             cb = it->first;
//         }
//     }
//     if(mxb+mxa>n and ca==cb){
//         cout<<"No"<<endl;
//     }
// }

ll fac[5000];

ll modinv(ll x){
    return power(x,mod-2)%mod;
}

ll ncr(ll n,ll r){
    return ((fac[n] * modinv(fac[r]))%mod * modinv(fac[n-r]))%mod;
}

void solve(ll cas){
    fac[0]=1;
    for(ll i=1;i<5000;i++) fac[i] = (fac[i-1]*i)%mod;
    ll s;cin>>s;
    ll t=s/3,ans=0;
    for(ll i=1;i<=t;i++){
        ll x = s-3*i;
        ans = (ans%mod + ncr(x+i-1,i-1)%mod)%mod;
    }
    cout<<(ans+mod)%mod<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll qu=1;
    // cin>>qu;
    for(ll cas=1;cas<=qu;cas++){
        solve(cas);
    }
}

Measured memory_bytes: 3612
//nexus01
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
 
#define fla(i,c,b) for(int i=c; i<b; i++)
#define flra(i,c,b) for(int i=c; i>b; i--)
#define fl(i,c) for(int i=0; i<(c); ++i)
 
#define endl "\n"
#define prec(x) cout<<fixed<<setprecision(x)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
 
#define data data__
#define SET(c, v) memset(c, v, sizeof c)
#define rank abcdef
#define count uvwxyz
#define union gdarawas
#define digit(x) (int)floor(1+log10((double)x))
const int inf = numeric_limits<int>::max();
const lli linf = numeric_limits<lli>::max();
#define Case cout<<"Case #"<<countt++<<": "<<
const lli MOD= (lli)1e9 + 7;
// const lli MOD=998244353;
lli fast_mod(lli abcd, lli expp)
{
    lli res=1;
    while(expp>0) 
    {
       if(expp%2==1)res=(res*abcd)%MOD;
       abcd=(abcd*abcd)%MOD;
       expp/=2;
    }
    return res%MOD;
}
lli gcd(lli a, lli b) 
{   lli temppp=max(a, b);
    b=min(a, b);
    a=temppp;
    if(b==0)return a; 
    return gcd(b, a%b);
} 
 
//////////////////////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    fla(i, 1, 10)
    {
        if(n%i==0)
        {
            if(n/i<10)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    /*submit karne se pehle idhar dekh
        1)Integer Overflow to nahi kar raha??
        2)Loop to sahi chal raha hai na??
        3)Koi edge case miss to nahi ho raha?? 
        4)Algorithm sahi hai na??
    */   
    return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int n;
const int max_n = 1e4+10;
queue<int> q;

int d[max_n];

vector<int> g[max_n];

void dfs(int i, int p){

  for(auto nv : g[i]){

    if(nv == p) continue;

    dfs(nv, i);

  }

  int now = q.front();
  q.pop();
  d[i] = now;

}



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

  cin >> n;

  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> c(n);
  rep(i, n) cin >> c[i];

  sort(c.begin(), c.end());

  ll ans = 0;
  rep(i, n-1){
    ans += c[i];
  }

  rep(i, n){
    q.push(c[i]);
  }

  int ind = -1;
  rep(i, n){
    if(g[i].size() >= 2){
      ind = i;
      break;
    }
  }

  dfs(ind, -1);

  cout << ans << endl;
  rep(i, n){
    cout << d[i] << " ";
  }
  cout << endl;

  
  
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{    
    ll n; cin>>n;
    string s;
    cin>>s;
    ll red = 0,white = 0;
    REP(i,0,s.size()){
        if(s[i] == 'W'){
            white++;
        }
        else red++;
    }
    string s1;
    REP(i,0,red) s1.push_back('R');
    REP(i,0,white) s1.push_back('W');

    ll diff1 = 0,diff2 = 0;
    REP(i,0,s.size()){
        if(s[i] == 'R' && s1[i] == 'W'){
            diff1++;
        }
        else if(s[i] == 'W' && s1[i] == 'R'){
            diff2++;
        }
    }
    cout<<max(diff1,diff2)<<endl;
    return 0;
}

Measured memory_bytes: 3836
#include <cstddef>
#include <iostream>
#include <vector>
#include <set>

#include <signal.h>
#define BOOST_STACKTRACE_USE_ADDR2LINE
#ifdef DEBUG
#include <boost/stacktrace.hpp>
#endif

#define rep(i, n) for (size_t i = 0; i < n; ++i)
#define rev(i, n) for (size_t i = n - 1; i < n; --i)
#define as static_cast
typedef long long ll;
using namespace std;

void handler(int signum) {
  ::signal(signum, SIG_DFL);
#ifdef DEBUG
  cout << boost::stacktrace::stacktrace();
#endif
  ::raise(SIGABRT);
}

int main(int, char const *[])
{
  ::signal(SIGSEGV, &handler);
  ::signal(SIGABRT, &handler);

  size_t n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  ll ans=0;
  set<size_t> s;
  vector<size_t> ix(n);
  rep(i, n) ix[as<size_t>(p[i]-1)]=i;
  rev (j, n) {
    size_t i=ix[j];
    ll c=0;

    s.insert(i);
    int w,x,y,z;

    { // find w, x
      vector<int> wx(2, -1);
      auto it=s.find(i);
      rev(k, 2) {
        if (it == s.begin()) break;
        --it;
        wx[k]=as<int>(*it);
      }
      w=wx[0];x=wx[1];
    }

    { // find y, z
      vector<int> yz(2, as<int>(n));
      auto it=s.find(i);
      rep(k, 2) {
        ++it;
        if (it == s.end()) break;
        yz[k]=as<int>(*it);
      }
      y=yz[0];z=yz[1];
    }

    c=(x-w)*(y-as<int>(i))+(as<int>(i)-x)*(z-y);
    ans+=as<int>(j+1)*c;
  }

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


Measured memory_bytes: 6144
n, q = map(int, input().split())
s = input()
total = [0] * len(s)
for i in range(1, len(s)):
    if s[i] == 'C' and s[i - 1] == 'A':
        total[i] = total[i - 1] + 1
    else:
        total[i] = total[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    if l == 1:
        print(total[r - 1])
    else:
        print(total[r - 1] - total[l - 1])

Measured memory_bytes: 6060
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int R = 0, B = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') ++R;
        else ++B;
    }
    cout << ((R > B) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;
    int a, b;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int j = s.size() - 1; j >= 0; j--){
        if(s[j] == 'Z'){
            b = j;
            break;
        }
    }
    cout << b - a + 1 << endl;
}

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

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

    map<int, int> odds, evens;
    rep(i, n) {
        if (i&1) odds[v[i]]++;
        else evens[v[i]]++;
    }

    vector<P> odds2, evens2;
    for (auto p : odds) odds2.push_back({p.second, p.first});
    for (auto p : evens) evens2.push_back({p.second, p.first});

    sort(odds2.rbegin(), odds2.rend());
    sort(evens2.rbegin(), evens2.rend());

    // for (auto x : odds2) cout << "odds2: " << x.first << " " << x.second << endl;
    // for (auto x : evens2) cout << "evens2: " << x.first << " " << x.second << endl;

    int res = 0;
    if (n == 2) {
        if (v[0] == v[1]) cout << 1 << endl;
        else cout << 0 << endl;
    }
    if (n == 3) {
        if (v[0] == v[2]) cout << 0 << endl;
        else cout << 1 << endl;
    }
    if (odds2[0].second == evens2[0].second) {
        res = n;
        if (odds2[1].first >= evens2[1].first) {
            res -= odds2[1].first;
            res -= evens2[0].first;
        } else {
            res -= odds2[0].first;
            res -= evens2[1].first;
        }
    }
    else {
        // cout << "here?" << endl;
        res = n;
        res -= odds2[0].first;
        res -= evens2[0].first;
    }

    cout << res << endl;
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n,m,a,h,p,q;
  while(cin>>n>>m>>a,(n|m|a)!=0){
    map<int,vector<pair<int,int> >,greater<int> > lines;
    REP(i,m){
      cin>>h>>p>>q;
      lines[h].push_back(make_pair(p,q));
    }
    for(auto hlines:lines){
      for(auto l:hlines.second){
	if(l.first==a) a=l.second;
	else if(l.second==a) a=l.first;
      }
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	while(n){
		n/=k;	
		++cnt;
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	private void doit(){
		while(sc.hasNext()){
			int sum = 0;
			for(int i = 0; i < 10; i++){
				sum += sc.nextInt();
			}
			System.out.println(sum);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 17332
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main() {
    int N; cin >> N;
    map<string,int> mBlue;
    for (int i=0;i<N;i++){
        string s_i; cin >> s_i;
        mBlue[s_i]++;
    }
    int M; cin >> M;
    map<string,int> mRed;
    for (int i=0;i<M;i++){
        string t_i; cin >> t_i;
        mRed[t_i]++;
    }

    int ans = 0;
    for (auto i=mBlue.begin();i!=mBlue.end();i++){
        int diff_tmp = i->second - mRed[i->first];
        if (diff_tmp > ans) ans = diff_tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,m = rl()
a = rl()

li=dict(Counter(a))
for _ in range(m):
    b, c = rl()
    if c in li:
        li[c]+=b
    else:
        li[c]=b
li=sorted(li.items(),key=lambda x: -x[0])
ans=0
res=n
for pair in li:
    if res<=0:
        continue
    if res>=pair[1]:
        ans+=pair[0]*pair[1]
        res-=pair[1]
    else:
        ans+=pair[0]*res
        res=0
print(ans)

Measured memory_bytes: 120484
N = int(input())
A = list(map(int, input().split()))
m_cnt = 0
for a in A:
    if a < 0:
        m_cnt += 1

for i in range(N):
    A[i] = abs(A[i])

ans = 0
for a in A:
    ans += abs(a)

if m_cnt % 2 == 1:
    ans -= abs(min(A))*2

print(ans)


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

const ll mod = 1000000007;

template <class Abel> struct BIT2D {
    int H, W;
    vector<vector<Abel>> data;
    Abel UNITY = 0;

    BIT2D(int H_, int W_) { init(H_, W_); }
    void init(int H_, int W_) {
        H = H_ + 1; W = W_ + 1;
        data.assign(H, vector<Abel>(W, UNITY));
    }
 
    void add(int h, int w, Abel x) {
        for (int i = h; i < H; i += i & -i) {
            for (int j = w; j < W; j += j & -j) {
                data[i][j] += x;
                data[i][j] %= mod;
            }
        }
    } // 1-index
    Abel sum(int h, int w) {
        Abel res = UNITY;
        for (int i = h; i > 0; i -= i & -i) {
            for (int j = w; j > 0; j -= j & -j) {
                res += data[i][j];
                res %= mod;
            }
        }
        return res;
    } // 1-index
    /*
    Abel query(int h1, int w1, int h2, int w2) {
        return sum(h2-1, w2-1) - sum(h2-1, w1-1) - sum(h1-1, w2-1) + sum(h1-1, w1-1);
    } // [h1,h2) * [w1,w2) 1-index
    */
};

int main(){
    int n, m; cin >> n >> m;
    vector<int> s(n); rep(i,n) cin >> s[i];
    vector<int> t(m); rep(i,m) cin >> t[i];

    BIT2D<ll> dp(n,m);
    rep(i,n) rep(j,m) if(s[i] == t[j]) dp.add(i+1,j+1,dp.sum(i,j)+1);
    cout << dp.sum(n,m) + 1 << endl;
    return 0;
}

Measured memory_bytes: 34556
from collections import Counter
N = int(input())
As = input().split()
Bs = input().split()

allct = Counter(As + Bs)
if allct.most_common(1)[0][1] > N:
    print('No')
    exit()

lastInA = {}
firstInB = {}

for i, a in enumerate(As):
    lastInA[a] = i

for i, b in enumerate(Bs):
    if b not in firstInB:
        firstInB[b] = i

offset = 0
for k, v in lastInA.items():
    if k not in firstInB:
        continue
    tmp = v - firstInB[k] + 1
    offset = offset if offset > tmp else tmp

print('Yes')
print(' '.join(Bs[-offset:] + Bs[:-offset]))


Measured memory_bytes: 178964
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N 10005
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
int A[N];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d\n",n-k+1);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0] * (n+1)
d[0] = 0
for i in range(1,n+1):
    d[i] = d[i-1] + l[i-1]
print(len([i for i in d if i <= x]))

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
  int i;
  char s[110];
  scanf("%s",s);
  for(i=0;s[i]!='\0';i++){
    if((i%2==0)&&s[i]=='L'){
      printf("No\n");
      return 0;
      }
    else if((i%2==1)&&(s[i]=='R')){
        printf("No\n");
        return 0;
        }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
import sys
import collections
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
import math
S = raw_input()
S = list(S)
for idx, val in enumerate(S):
    if idx & 1:
        if val not in ('L', 'U', 'D'):
            print('No')
            exit()
    else:
        if val not in ('R', 'U', 'D'):
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 2812
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353
#define invp(a,p)pom(a,p-2,p)

//*
ll fact[100010];
ll invfact[100010];
void makefact(int n,ll m){
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}
//*/

ll dp[1010];
int main(){
	ll m,n,k;
	scanf("%lld%lld%lld",&m,&n,&k);
	makefact(2010,MOD);
	dp[1]=1;
	rep(i,2,k){
		dp[i]=pom(i,n,MOD);
		rep(x,1,i)dp[i]-=choose(i,x,MOD)*dp[x]%MOD;
		dp[i]%=MOD;
	}
	ll ans=pom(m,n,MOD);
	ll coe=m%MOD;
	rep(x,1,k){
		ans-=coe*dp[x]%MOD;
		coe=(m-x)%MOD*coe%MOD*invp(x+1,MOD)%MOD;
	}
	printf("%d\n",(ans%MOD+MOD)%MOD);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n;
  cin >> n;
  vector<ll>ar(n);
  ll x = 0;
  for (int i = 0; i < n; i++){
    cin >> ar[i];
    x ^= ar[i];
  }
  for (int i = 0; i < n; i++){
    cout << (x ^ ar[i]) << " ";
  }
  return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll V, E;
ll d[105][105];

void init(){
  for(int i = 0; i < 105; i++){
    for(int j = 0; j < 105; j++){
      if(i == j) d[i][j] = 0;
      else d[i][j] = LLONG_MAX / 10;
    }
  }
}

string out(ll n){
  if(n == LLONG_MAX/10)return "INF";
  else return to_string(n);
}

bool is_negative_roop(){
  for(int i = 0; i < V; i++){
    if(d[i][i] < 0) return true;
  }
  return false;
}

int main(){
  init();
  cin >> V >> E;
  for(int i = 0; i < E; i++){
    ll s, g, c;
    cin >> s >> g >> c;
    d[s][g] = min(d[s][g], c);
  }

  for(int k = 0; k < V; k++){
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++){
	if(d[i][k] != LLONG_MAX/10 && d[k][j] != LLONG_MAX/10) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  if(is_negative_roop()){
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for(int i = 0; i < V; i++){
    for(int j = 0; j < V; j++){
      if(j == 0) cout << out(d[i][j]);
      else cout << " " << out(d[i][j]);
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3368