akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool used[10001];

struct Dinic{
    struct edge {
        int64_t to, cap, rev, id;
        edge(int64_t to, int64_t cap, int64_t rev, int64_t id):to(to), cap(cap), rev(rev), id(id){}
    };

    int N, S, T;
    int64_t flow = 0;
    const int64_t INF = 1e18;
    vector<int> level, iter;
    vector<vector<edge>> G;

    Dinic(int N, int S, int T):N(N), S(S), T(T){
        flow = 0;
        level.resize(N);
        iter.resize(N);
        G.resize(N);
    }

    void add_edge(int from, int to, int64_t cap, int id){
        G[from].emplace_back(to, cap, G[to].size(), id);
        G[to].emplace_back(from, 0, G[from].size()-1, -id);
    }

    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while(que.size()){
            int v = que.front(); que.pop();
            for(auto& e : G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    int64_t dfs(int v, int t, int64_t f){
        if(v == t) return f;
        for(int& i=iter[v]; i<G[v].size(); i++){
            auto& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                int64_t d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    vector<int> matching(){
        while(true){
            bfs(S);
            if(level[T] < 0) break;
            fill(iter.begin(), iter.end(), 0);
            while(true){
                int64_t f = dfs(S, T, INF);
                if(f == 0) break;
                flow += f;
            }
        }
        cerr << flow << endl;
        vector<int> ret;
        for(int i=0; i<100; i++) for(auto& e : G[i]) if(e.id > 0 && !used[e.id] && e.cap == 0){
            used[e.id] = true;
            G[e.to][e.rev].cap = 0;
            ret.push_back(e.id);
        }
        return ret;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    int A[100][100];
    int S = 200, T = 201;
    Dinic solver(T+1, S, T);
    for(int i=0; i<N; i++) for(int j=0; j<M; j++){
        cin >> A[i][j];
        solver.add_edge(i, 100 + (A[i][j]-1)/M, 1, A[i][j]);
    }
    
    for(int j=0; j<M; j++){
        for(int i=0; i<N; i++){
            solver.add_edge(S, i, 1, -S);
            solver.add_edge(100+i, T, 1, -T);
        }
        auto v = solver.matching();
        for(int i=0; i<N; i++) A[j][i] = v[i];
    }
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) cout << A[j][i] << " \n"[j==M-1];
    for(int j=0; j<M; j++) sort(A[j], A[j]+N);
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) cout << A[j][i] << " \n"[j==M-1];
    return 0;
}


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

int main(){
    int a, b, c, d, e, k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    
    if(e - a > k){
        cout << ":(";
    }else {
        cout << "Yay!";
    }

    return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> ve[N];
priority_queue<int> qe;
int n,m;
int main()
{
	cin>>n>>m;
	int x,y;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(m-x+1<1)
			continue;
		ve[m-x+1].push_back(y); 
	}
	int sum=0;
	for(int i=m;i>=1;i--)
	{
		for(int j=0;j<ve[i].size();j++)
			qe.push(ve[i][j]);
		if(!qe.empty())
			sum+=qe.top(),qe.pop();
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 8972
#Sの入力
s=input()

if s[0] == s[1]:
    if s[1] == s[2]:
        if s[2] == s[3]:
            print('No')
            exit()

if s[0] == s[3]:
    if s[1] == s[2]:
        print('Yes')
    else:
        print('No')

elif s[0] == s[2]:
    if s[1] == s[3]:
        print('Yes')
    else:
        print('No')

elif s[0] == s[1]:
    if s[2] == s[3]:
        print('Yes')
    else:
        print('No')

else:
    print('No')

Measured memory_bytes: 3188
import sys

lines = sys.stdin.readlines()
for line in lines:
    a, b, c, d, e, f = map(float, line.split())
    if a * e - b * d == 0:
        break
    x = (e * c + (-b) * f)/(a * e - b * d)
    y = ((-d) * c + a * f)/(a * e - b * d)
    print('{:.3f} {:.3f}'.format(x+0, y+0))

Measured memory_bytes: 7324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
#include <map>
#include <ctype.h>

using namespace std;

#define loop(i,n) for (i = 0; i < n; ++i) 
#define loop2(i,k,n) for (i = k; i <= n; ++i) 
#define loopb(i,k,n) for (i = k; i >= n; --i)
#define remove_space(x) x.erase(remove(x.begin(), x.end(), ' '), x.end())
typedef long long ll;

int main(){

	ios_base::sync_with_stdio(false);

	int a,b;
	cin >> a >> b;

	if(a < b){
		cout << 0;
	}

	else if(a <= b*2){
		cout << 0;
	}

	else{
		cout << a - (b*2);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false);cerr << "compiled" << endl

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  string S; cin >> S;
  if(S.size() % 2 != 0){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i < S.size(); i+=2){
    if(S[i] != 'h'){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = 1; i < S.size(); i+=2){
    if(S[i] != 'i'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

bool cmp(int &a,int &b) {
	int c = a%10,d=b%10;
	if(c==0)return false;
	if(d==0)return true;
	return c<d;
}

void solve(int test_case) {//236
	vi arr(5);
	for(int &i:arr)cin>>i;
	sort(arr.rbegin(),arr.rend(),cmp);
	int sum = 0;
	REP(i,0,3) {
		if(arr[i]%10==0)sum+=arr[i];
		else {
			arr[i]+=10-arr[i]%10;
			sum+=arr[i];
		}
	}
	sum+=arr[4];
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
long long a[86];
int main()
{
	
	string s;
	cin>>s;
	int a=s[0]-'0';
	int b=s[1]-'0';
	int c=s[2]-'0';
	int d=s[3]-'0';
	
	if(a+b+c+d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
		return 0;
	}
	if(a+b+c-d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
		return 0;	
	}
	if(a+b-c+d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;	
		return 0;
	}
	if(a-b+c+d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;	
		return 0;
	}
	if(a+b-c-d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<"7"<<endl;	
		return 0;
	}
	if(a-b-c-d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<"7"<<endl;	
		return 0;
	}
	if(a-b+c-d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
		return 0;	
	}
	if(a-b-c+d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;	
		return 0;
	}
	
	
}

Measured memory_bytes: 3628
import bisect
import sys
input=sys.stdin.readline
a,b,q=map(int,input().split())
s=[-999999999999]+[int(input()) for i in range(a)]+[999999999999]
t=[-999999999999]+[int(input()) for i in range(b)]+[999999999999]
x=[int(input()) for i in range(q)]
for i in range(q):
  a1=s[bisect.bisect_left(s,x[i])-1]
  a2=s[bisect.bisect_left(s,x[i])]
  b1=t[bisect.bisect_left(t,x[i])-1]
  b2=t[bisect.bisect_left(t,x[i])]
  l=[]
  for j in [a1,a2]:
    for k in [b1,b2]:
      l.append(abs(j-k)+min(abs(x[i]-j),abs(x[i]-k)))
  print(min(l))

Measured memory_bytes: 65628
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string N;cin>>N;
	bool ans = false;
	if(N[0] == '7')ans = true;
	if(N[2] == '7')ans = true;
	if(N[1] == '7')ans = true;
	cout<<((ans)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
int main(){
    char s[30];
    gets(s);
    int i=0;
    char *p;
    while(s[i]!='\0'){
     p=strchr(s+i+1,s[i]);
     if(p){
        printf("no");
        return 0;
     }
     i++;
    }
    printf("yes");
   return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int b[8][8];
void bomb(int x,int y){
  b[x][y] = 0; //爆弾処理
  int i;
  for(i=-3;i<=3;i++){
    if(x+i>=0&&x+i<=7){
      if(b[x+i][y]==1) bomb(x+i,y); //再帰
    }
    if(y+i>=0&&y+i<=7){
      if(b[x][y+i]==1) bomb(x,y+i); //再帰
    }
  }
}
int main(){
  int n;
  int x,y;
  int i,j,k;
  char c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<8;j++){
      for(k=0;k<8;k++){
	while(1){
	  scanf("%c",&c);//scanf()は改行も読み込んでしまうらしい（cinは改行を読み込まなかったはず）
	  if(c!='\n')
	    break;
	}
	b[k][j] = c - '0'; //char型をint型として扱う方法（※キャストをしてもよい）
	//※キャストは、知らなかったら自分でググってね
      }
    }
    scanf("%d%d",&x,&y);
    bomb(x-1,y-1);//添字（配列の番号）は0から始まるため、-1をする
    printf("Data %d:\n",i+1);
    for(j=0;j<8;j++){
      for(k=0;k<8;k++){
	printf("%d",b[k][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 604
# require 'pry'
@fact = []
def set_fact(max_n, mod = 10 ** 9 + 7)
  @fact[0] = 1
  (1..(max_n - 1)).each do |i|
    @fact[i] = @fact[i - 1] * i % mod
  end
end

def choose(n, r, mod = 10 ** 9 + 7)
  r = n - r if r > n - r
  @fact[n] * modpow(@fact[n - r], mod - 2, mod) % mod \
    * modpow(@fact[r], mod - 2, mod) \
    % mod
end

def modpow(n, p, mod = 10 ** 9 + 7)
  res = 1
  while p > 0
    if p & 1 == 1
      res = (res * n) % mod
    end
    n = (n ** 2) % mod
    p >>= 1
  end
  res
end

# MOD = 10 ** 12
N = gets.to_i
# set_fact(N + 100, MOD)
lists = Hash.new(0)
arr = gets.split.map do |x|
  t = x.to_i
  lists[t] += 1
  t
end
# p arr
# p lists
lists2 = Hash.new(0)
lists3 = Hash.new(0)
lists.each do |k, v|
  lists2[k] = v >= 3 ? (v-2) * (v-1) / 2 : 0
  lists3[k] = v >= 2 ? (v-1) * v / 2 : 0
end
lists3_sum = lists3.to_a.inject(0){|sum, item| sum + item[1]}
# p lists3_sum
# p lists2
# p lists3

# binding.pry
N.times do |i|
  # p arr[i]
  pre = lists3_sum
  pre += lists2[arr[i]]
  pre -= lists3[arr[i]]

  puts pre
end


Measured memory_bytes: 55716
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=510;
int c[N][N],rsum[N];
int main()
{
    
    sync;
    int a[10];
    fup(i,1,9)
    {
        cin>>a[i];
    }
    int n;
    cin>>n;
    fup(i,1,n)
    {
        int x;
        cin>>x;
        fup(i,1,9)
            if(x==a[i])
            {
                a[i]=0;
            }
    }
    if((a[1]==0&&a[2]==0&&a[3]==0)||(a[4]==0&&a[5]==0&&a[6]==0)||(a[7]==0&&a[8]==0&&a[9]==0)||(a[1]==0&&a[4]==0&&a[7]==0)||(a[2]==0&&a[8]==0&&a[5]==0)||(a[3]==0&&a[6]==0&&a[9]==0)||(a[1]==0&&a[5]==0&&a[9]==0)||(a[7]==0&&a[5]==0&&a[3]==0))
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());

        var i = 0;
        for (i = 0; i < s.Length; i++)
        {
            if (s[i] != '1')
            {
                break;
            }
        }

        if (i < n) Console.WriteLine(s[i]);
        else Console.WriteLine('1');
    }
}


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

using namespace std;

int main(){
	int K;
	vector<int> S(3);
	cin >> S[0] >> S[1] >> S[2] >> K;
	
	sort(S.begin(),S.end());
	
	cout << S[0]+S[1]+pow(2,K)*S[2] << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::cmp;

#[allow(unused_variables)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        M: u64,
        Q: usize,
        ABCD: [(Usize1, Usize1, u64, u64); Q],
    }

    let mut stack = Vec::new();
    stack.push(vec![0; 0]);

    let mut ans = 0;
    while let Some(arr) = stack.pop() {
        if arr.len() == N {
            let mut score = 0;
            for &(a, b, c, d) in ABCD.iter() {
                if arr[b] - arr[a] == c {
                    score += d;
                }
            }
            ans = cmp::max(ans, score);
            continue;
        }

        let min = if arr.len() > 0 { arr[arr.len() - 1] } else { 1 };

        for i in min..=M {
            let mut buf = arr.clone();
            buf.push(i);
            stack.push(buf);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2164
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


immutable long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    foreach (i; 0..N) A[i].sort();
    auto Amax = A.map!(a => a.reduce!max).reduce!max;
    auto Amin = A.map!(a => a.reduce!min).reduce!min;


    long solve1() { // Rmax, Rmin = Amax, Amin
        int cnt = 0;
        foreach (i; 0..N) if (A[i][0] == Amin || A[i][1] == Amax) cnt += 1;
        if (cnt <= 1) return INF;

        long Bmax = -INF;
        long Bmin = INF;
        foreach (i; 0..N) {
            if (A[i][0] == Amin) Bmax = max(Bmax, A[i][1]), Bmin = min(Bmin, A[i][1]);
            if (A[i][1] == Amax) Bmax = max(Bmax, A[i][0]), Bmin = min(Bmin, A[i][0]);
        }

        auto B = A.filter!(a => a[0] != Amin && a[1] != Amax).array;
        if (B.length == 0) return (Amax - Amin) * (Bmax - Bmin);
        B.sort();
        long bmax = B.back[0];
        long bmin = B.front[0];
        long ans = (Amax - Amin) * (max(Bmax, bmax) - min(Bmin, bmin));

        foreach (i; 0..B.length.to!int) {
            bmin = i == B.length.to!int - 1 ? INF : B[i+1][0];
            Bmax = max(Bmax, B[i][1]);
            Bmin = min(Bmin, B[i][1]);
            ans = min(ans, (Amax - Amin) * (max(Bmax, bmax) - min(Bmin, bmin)));
        }

        return ans;
    }


    long solve2() { // Rmax = Amax, Bmin = Amin
        long Rmin = A.map!(a => a[1]).reduce!min;
        long Bmax = A.map!(a => a[0]).reduce!max;
        return (Amax - Rmin) * (Bmax - Amin);
    }

    min(solve1, solve2).writeln;
}


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

using namespace std;

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

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

void exec(){
  string s, t;
  cin >> s >> t;
  int ans = INF;

  for (int i = 0; i < (int)s.length(); i++){
    if (i + t.length() > s.length()) {
      break;
    }

    int diff = 0;
    for (int j = 0; j < (int)t.length(); j++){
      if (t[j] != s[i + j]) {
        diff++;
      }
    }

    ans = min(ans, diff);
  }

  cout << ans << endl;

}

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

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


Measured memory_bytes: 3632
def main():
    x = int(input())
    ans, r = divmod(x, 11)
    if r == 0:
        print(2 * ans)
    elif 1 <= r <= 6:
        print(2 * ans + 1)
    else:
        print(2 * ans + 2)

if __name__ == '__main__':
    main()


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

using ll = long long;
ll P = 1000000007;
class C {
public:
  int n;
  vector<ll> fac, inv, facInv;
  ll power(ll e, ll x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n);
    inv.resize(n);
    facInv.resize(n);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  ll comb(ll N, ll K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
  ll hcomb(ll N, ll K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }
};

C comb(6010101);

int main() {
  while (true) {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (a == 0 && b == 0 && c == 0)
      break;
    ll ans = 0;
    for (int i = 0; i <= min(x - a, y - b); i++) {
      ll sa = x - i;
      ll sb = y - i;
      ll com = (comb.comb(a + b + c, a) * comb.comb(b + c, b)) % P;
      com *= comb.hcomb(a + b + c, i);
      com %= P;
      com *= comb.hcomb(a, sa - a);
      com %= P;
      com *= comb.hcomb(b, sb - b);
      com %= P;
      ans += com;
      ans %= P;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 143580
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

r,D,x=MAP()

for i in range(10):
    x=r*x-D
    print(x)


Measured memory_bytes: 3064
N, M = map(int,input().split())
H= input().split()
A =[1]*N
B= [0]*M
count=0
for i in range(M):
  B[i]= input().split()
for j in range(M):
    if int(H[int(B[j][0])-1]) > int(H[int(B[j][1])-1]):
      A[int(B[j][1])-1] = 0
    elif int(H[int(B[j][1])-1]) > int(H[int(B[j][0])-1]):
      A[int(B[j][0])-1] = 0
    else:
      A[int(B[j][1])-1] = 0
      A[int(B[j][0])-1] = 0
for i in range(N):
  if A[i] != 0:
    count += 1
print(count)
       
        

Measured memory_bytes: 46856
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int f=0;
	for(int i=0;i<=s.size();++i){
		if(s[i]=='C'&&f==0){
			++f;
		}
		if(s[i]=='F'&&f==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int a[200][200], r, c, sum;
    sum = 0;
    cin >> r >> c;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cout << a[i][j] << " ";
            sum += a[i][j];
        }
        a[i][c] = sum;
        cout << sum << endl;
        sum = 0;
    }
    for (int j = 0; j < c; j++) {
        for (int i = 0; i < r; i++) {
            sum += a[i][j];
            if (i == r - 1) {
                a[i + 1][j] = sum;
                cout << sum << " ";
                sum = 0;
            }
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            sum += a[i][j];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3156
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        int i,j;
        int a,b;
        while(true) {
            str = scan.nextLine();
            String[] num = str.split(" ", 0);
            a = Integer.valueOf(num[0]);
            b = Integer.valueOf(num[1]);
            if(a==0&&b==0){
                break;
            }

            for (i = 0; i < a; i++) {
                for (j = 0; j < b; j++) {
                    if((i==0||i==a-1)||(j==0||j==b-1)){
                    System.out.print("#");
    
                    }else{
                        System.out.print(".");
                    }
                        
                }
                System.out.println();
            }
            System.out.println();
        }
        scan.close();
    }
}


Measured memory_bytes: 34480
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
int a,b,c;
  cin>>a>>b>>c;
  if(a+b<=c)
    cout<<0<<' '<<0<<endl;
  else if(a<c){
    cout<<0<<' '<<b+a-c<<endl;
  }
  else{
  cout<<a-c<<' '<<b<<endl;
  }
}

Measured memory_bytes: 256
N=int(input())
 
F=[]
P=[]
 
for i in range(N):
    tmp=list(map(int, input().split()))
    F.append(tmp)
 
for i in range(N):
    tmp=list(map(int, input().split()))
    P.append(tmp)
 
max_sum=-1000000001
 
for i in range(1,1024):
    bin=[0]*10 #0,1で午前午後を表している
    now=i
    for j in range(10):
        bin[j]=now%2
        now=now//2
        #今回のパターンbinを作成完了
    ans_sum=0
    for j in range(N):
        ans=0
        for h in range(10):
            if F[j][h]*bin[h]==1:
                ans+=1
        ans_sum+=P[j][ans]
    if max_sum<ans_sum:
        max_sum=ans_sum
 
print(max_sum)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
using namespace std;
const int INF = 2000000005;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll=long long;
ll dp[202][202];
ll n;
char c[200];
const ll MOD = 1000000007;
int main()
{
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> c[i];
	}
	switch (c[0])
	{
	case 'U':
		dp[1][0] = 0;
		dp[1][1] = 1;
		break;
	case 'D':
		cout << 0 << endl;
		return 0;
	case '-':
		dp[1][0] = 1;
		dp[1][1] = 0;
	default:
		break;
	}
	for (size_t i = 2; i <= n; i++)
	{
		switch (c[i-1])
		{
		case '-':
			for (size_t j = 0; j < i; j++)
			{
				dp[i][j] = dp[i - 1][j];
			}
			break;
		case 'U':
			for (size_t j = 0; j < i; j++)
			{
				dp[i][j + 1] = dp[i - 1][j];
			}
			for (size_t j = 1; j < i; j++)
			{
				dp[i][j] += dp[i - 1][j] * j % MOD;
				dp[i][j] %= MOD;
			}
			break;
		case 'D':
			for (size_t j = 0; j < i; j++)
			{
				dp[i][j] = dp[i - 1][j] * j;
			}
			for (size_t j = 1; j < i; j++)
			{
				dp[i][j - 1] += dp[i - 1][j] * j * j % MOD;
				dp[i][j - 1] %= MOD;
			}
		default:
			break;
		}
	}
	cout << dp[n][0] << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> path(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        path[--a]++, path[--b]++;
    }

    rep(i, n) {
        cout << path[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5,mod=998244353;
char ch[M];
int n,sum,i,j,k,a,b,dp[M][3][3][2];
bool flag=1;
void spj()
{
    for(i=2;i<=n;++i)if(ch[i]!=ch[i-1]){flag=0;break;}
    if(flag)puts("1"),exit(0);
    if(n<=3)(n==2?puts("2"):((ch[1]!=ch[2]&&ch[1]!=ch[3]&&ch[2]!=ch[3])?puts("3"):((ch[1]==ch[3])?puts("7"):puts("6")))),exit(0);
}
bool check(){for(int i=1;i<=n;++i)if(ch[i]==ch[i-1])return 0;return 1;}
void in(){scanf("%s",ch+1);}
void ac()
{
    n=strlen(ch+1);spj();
    for(i=1;i<=n;++i)sum=(sum+ch[i]-'a')%3;
    for(i=0;i<=2;++i)dp[1][i][i][0]=1;
    for(i=1;i<=n-1;++i)for(j=0;j<=2;++j)for(k=0;k<=2;++k)for(a=0;a<=1;++a)for(b=0;b<=2;++b)
    (dp[i+1][(j+b)%3][b][a|(k==b)]+=dp[i][j][k][a])%=mod;
    printf("%d",(0ll+dp[n][sum][0][1]+dp[n][sum][1][1]+dp[n][sum][2][1]+check())%mod);
}
int main(){in();ac();}

Measured memory_bytes: 14464
a=input().split()
N=int(a[0])
K=int(a[1])

d=[]
A=[]
for i in range(K):
    d.append(int(input()))
    A.append([int(x) for x in input().split()])
ans=0
for i in range(1,N+1):
    index=0
    for j in range(K):
        if (i in A[j])==False:
            index+=1
    if index==K:
        ans+=1

print(ans)





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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  double d, t, s;
  cin >> d >> t >> s;

  cout << (d / s <= t ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e6) + 17;

int n;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    n = sz(s);

    for (char c = 'a'; c <= 'z'; ++c)
        if (!count(s.begin(), s.end(), c)) {
            cout << s << c << endl;
            return ;
        }

    for (int i = n - 1; i >= 0; --i) {
        for (char c = s[i] + 1; c <= 'z'; ++c)
            if (!count(s.begin(), s.begin() + i, c)) {
                cout << s.substr(0, i) << c << endl;
                return ;
            }
    }

    cout << -1 << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long  i = 0; i < (long long)(n); i++)






int main() {
	long long N;
	cin >> N;
	vector<int> vec(N);
	long long sm = 0;
	for (long long i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	long long an = 0;
	for (long long i = 0; i < N; i++) {
		
		if (2*sm<vec.at(i)) {
			an=i;
			
		}
		sm += vec.at(i);
		
		
	}
	cout << N-an << endl;
	


}

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

/*
int main(){
  int S;
  cin >> S;
  int h = S/3600;
  S -= h*3600;
  int m = S/60;
  S -= m*60;
  int s = S;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}
*/

int main(){
  int S;
  cin >> S;
  int s = S%60, m = S%3600/60, h = S/3600;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>

int main() {
    int a, b, c, i, count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (i = a; i <= b; i++) {
        if (c % i == 0) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


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

int c[3][3];
int main(){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      scanf("%d",&c[i][j]);
    }
  }
  int sum1=c[0][0]+c[1][1]+c[2][2];
  int sum2=c[0][1]+c[2][0]+c[1][2];
  int sum3=c[1][0]+c[0][2]+c[2][1];
  if(sum1==sum2&&sum2==sum3){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){ 
  string s1,s2,s3;cin>>s1>>s2>>s3;
  cout<<(char)(s1[0]-32)<<(char)(s2[0]-32)<<(char)(s3[0]-32)<<endl;
}




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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int a, b;
	cin >> a >> b;

	if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
		puts("Possible");
	}else{
		puts("Impossible");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> a(N);
    for (int i=0;i<N;++i) cin >> a[i];
    ll ans=-INF,sum;
    int s,t,cnt;
    for (int i=0;i<N;++i){
        sum=0,cnt=0;
        for (int j=i;j<N;j+=2){
            if (j!=i&&a[j]<0){++cnt; continue;}
            sum+=a[j];
            if (ans<sum){ans=sum; s=i,t=j;}
        }
    }
    cout << ans << '\n';
    cout << s+(N-1-t)+(t-s)/2 << '\n';
    for (int i=0;i<N-1-t;++i) cout << N-i << '\n';
    for (int i=0;i<s;++i) cout << 1 << '\n';
    int skip=0;
    for (int i=s;i<t;i+=2) if (a[i]<0){
        cout << i-s+1-2*skip << '\n';
        ++skip;
    }
    for (int i=0;i<(t-s)/2-skip;++i) cout << 2 << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int a, b;

  cin >> a >> b;
  cout << (b - a)*(b-a + 1)/2 - b << endl;

  return 0;
}

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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
def binarySearch(arr, key)
    left = -1
    right = arr.size
    while (right-left).abs > 1
        mid = (right+left) / 2
        if arr[mid] > key then
            right = mid
        else
            left = mid
        end
    end
    return left
end

a,b,n = gets.split.map(&:to_i)
a_book = gets.split.map(&:to_i)
b_book = gets.split.map(&:to_i)
a_ruikei = [0] 
b_ruikei = [0]
cnt = []

sum = 0
a_book.each do |i|
  sum += i
  a_ruikei << sum
end

sum = 0
b_book.each do |i|
  sum += i
  b_ruikei << sum
end

a_only = binarySearch(a_ruikei, n)
b_only = binarySearch(b_ruikei, n)
cnt << a_only
cnt << b_only

a_ruikei.each_with_index do |i, index|
   nokori = n - i
   if nokori >= 0
     b_sum = binarySearch(b_ruikei, nokori)
     cnt << index + b_sum
   else
     break
   end
end

b_ruikei.each_with_index do |i, index|
   nokori = n - i
   if nokori >= 0
     a_sum = binarySearch(a_ruikei, nokori)
     cnt << index + a_sum
   else
     break
   end
end

cnt = cnt.max
puts cnt
  
  

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

using namespace std;

#define int long long

pair < int, int > a[2005];
int dp[2005][2005];
int inf = 1e18;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, pos = 1;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    for (int j = 0; j <= n; ++j) dp[n + 1][j] = -inf;
    dp[n + 1][0] = 0;
    for (int i = n; i >= 1; --i) {
        for (int j = 0; j <= n - i + 1; ++j) {
            dp[i][j] = dp[i + 1][j] + a[i].first * abs(a[i].second - (i + j));
            if (j > 0) dp[i][j] = max(dp[i][j], dp[i + 1][j - 1] + abs(j - a[i].second) * a[i].first);
        }
    }
    int ans = 0;
    for (int j = 0; j <= n; ++j) ans = max(ans, dp[1][j]);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 26328
#![allow(dead_code)]

use std::io;
fn main() {
    solve_c();
}

fn solve_c() {
    let als = "abcdefghijklmnopqrstuvwxyz".to_string();
    let mut v = vec![0; 26];
    loop {
        let mut line = String::new();
        match io::stdin().read_line(&mut line) {
            Ok(x) => {
                if x == 0 {
                    break;
                }
            }
            _ => break,
        }

        for c in line.chars() {
            if c.is_alphabetic() {
                let cn = c.to_lowercase();
                for (i, x) in als.chars().enumerate() {
                    if x.to_string() == cn.to_string() {
                        v[i] += 1;
                    }
                }
            }
        }
    }
    for (i, x) in als.chars().enumerate() {
        println!("{} : {}", x, v[i]);
    }
}



Measured memory_bytes: 5064
#include<stdio.h>
#define N 10
int main(){
    int a[N];
    int i,j,tmp;
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<N-1;i++){
        for(j=i+1;j<N;j++){
            if(a[i]<a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    for(i=0;i<3;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

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

	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	ll *p, *q, *r, *s, *sum;
	p = new ll[a];
	q = new ll[b];
	r = new ll[c];
	rep(i, a) cin >> p[i];
	rep(i, b) cin >> q[i];
	rep(i, c) cin >> r[i];
	sort(p, p + a, [](ll &left, ll &right) {return left > right; });
	sort(q, q + b, [](ll &left, ll &right) {return left > right; });
	sort(r, r + c, [](ll &left, ll &right) {return left > right; });

	s = new ll[x + y];
	rep(i, x) s[i] = p[i];
	rep(i, y) s[i + x] = q[i];

	sort(s, s + x + y, [](ll &left, ll &right) {return left > right; });

	sum = new ll[x + y];
	sum[x + y - 1] = s[x + y - 1];
	rrep(i, x + y - 2) sum[i] = sum[i + 1] + s[i];

	REP(i, 1, c) r[i] += r[i - 1];

	ll ans = sum[0];
	rep(i, min(c, x + y)) {
		ans = max(ans, sum[0] - sum[x + y - 1 - i] + r[i]);
	}

	cout << ans << "\n";

	return 0; 
}


Measured memory_bytes: 5376
//disjoin-set
#include<bits/stdc++.h>
using namespace std;

class disjoinset {
	public:
		vector<int> rank,p;
	disjoinset (){}
	disjoinset(int size){
	rank.resize(size,0);
	p.resize(size,0);
	for(int i=0; i<size;i++)makeSet(i);
	}
	void makeSet(int x){
	p[x] = x;
	rank[x] =0;
	}
	bool same(int x,int y){
	return findSet(x) == findSet(y);
	}
	void unite(int x,int y){
		link(findSet(x),findSet(y));
	}
	void link(int x,int y){
		if(rank[x] > rank[y]){
		 p[y] = x;
		}else{
		 p[x] = y;
		 if(rank[x]==rank[y] )rank[y]++;
		}
	}
	int findSet(int x){
		if(x!=p[x])p[x] = findSet(p[x]);
		return p[x];
	}

};
 
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	disjoinset ds  = disjoinset(n);
	vector<int> a(n,0);
	bool flag = true;
	for(int i=0;i<k;i++){
		int t;
		cin>>t;
		if(!flag){
			int b,c;
			cin>>b>>c;
			continue;
		}
		if(t==1) {
			int b,c;
			cin>>b>>c;
			b--,c--;
			int bb = a[ds.findSet(b)] ;
			int cc = a[ds.findSet(c)] ;
			if( bb==0 || cc==0 ||bb==cc){
				ds.unite(b,c);
				a[ds.findSet(b)] = max(bb,cc);
			}else{
				cout<<i+1<<endl;
				flag = false;
			}
		}else if(t==2){
			int c,x;
			cin>>c>>x;
			c--;
			int root = ds.findSet(c);
			if( a[root] == x|| a[root] == 0){
					a[root] = x ;
			}else{
				cout<<i+1<<endl;
				flag = false;
			}
		}
	}
	if(flag)cout<<0<<endl;

	return 0;
}



Measured memory_bytes: 3876
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define findmax(a,b) (a)>(b)?(a):(b)
#define findmin(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}


int main() {
    
	//inout;

	int data,save;
	for(int i = 1; i <= 5 ;i++){
		scanf("%d", &data);
		if(data == 0){
			save = i;
			break;
		}

	}
	printf("%d", save);

}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int a,b,c,d,dp[3005][3005];
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    dp[a][b] = 1;
    rep(i,a,c) rep(j,b,d){
        if(i == a && j == b) continue;
        dp[i][j] = ((ll)dp[i-1][j] * j % mod + (ll)dp[i][j-1] * i % mod - (ll)dp[i-1][j-1] * (i-1) * (j-1) % mod + mod) % mod;
    }
    printf("%d\n",dp[c][d]);
    return 0;
}

Measured memory_bytes: 38816
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (A, B, X) = Read3Longs();

            if (A > X) return "NO";
            if (A + B > X) return "YES";
            return "NO";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28196
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    
    X = [x[i+1]-x[i] for i in range(n-1)]
    Y = [y[i+1]-y[i] for i in range(m-1)]
    
    mod = pow(10, 9)+7
    for i in range(n-1):
        X[i] = X[i]*(n-i-1)*(i+1)%mod
    
    sum_x = sum(X)%mod
    
    for i in range(m-1):
        Y[i] = Y[i]*(m-i-1)*(i+1)%mod
    
    sum_y = sum(Y)%mod
    
    
    ans = sum_x*sum_y%mod
    
    print(ans)
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 25332
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	if(10000*n<y || 1000*n>y)
	{
		cout<<"-1 -1 -1\n";
		return 0;
	}
	int s=y;
	for(int a=0;a<=n;a++)
	{
		for(int b=0;b<=n,a+b<=n;b++)
		{
			int c=n-a-b;
			if(a*10000+b*5000+c*1000==y) 
			{
				printf("%d %d %d\n",a,b,c);
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,T;
    cin>>n>>T;

    int answer=1001;

    for (int i=0;i<n;i++) {
        int c,t;
        cin>>c>>t;

        if(t<=T&&c<answer){
            answer=c;
        }
    }

    if(answer==1001){
        cout<<"TLE"<<endl;
    }

    else{
        cout<<answer<<endl;
    }
}


Measured memory_bytes: 256