akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

constexpr int N = 2505, INF = 1e9;
vector<pair<pair<int, int>, int>> edges;
vector<vector<int>> g(N), g2(N);
vector<bool> vis(N);
vector<bool> vis2(N);

void dfs(int u) {
    if(vis[u]) return;
    vis[u] = true;
    for(int v : g[u]) {
        dfs(v);
    }
}

void dfs2(int u) {
    if(vis2[u]) return;
    vis2[u] = true;
    for(int v : g2[u]) {
        dfs2(v);
    }
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, p;
    cin >> n >> m >> p;
    for(int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        edges.push_back({{a, b}, p - c});
        g[b].push_back(a);
        g2[a].push_back(b);
    }
    dfs(n);
    dfs2(1);
    vector<int> dist(n + 10, INF);
    dist[1] = 0;
    for(int i = 0; i < n - 1; ++i) {
        for(auto e : edges) {
            dist[e.fi.se] = min(dist[e.fi.fi] + e.se, dist[e.fi.se]);
        }
    }
    for(int i = 0; i < n - 1; ++i) {
        for(auto e : edges) {
            if(dist[e.fi.fi] + e.se < dist[e.fi.se]) {
                dist[e.fi.se] = dist[e.fi.fi] + e.se;
                int u = e.fi.fi;
                int v = e.fi.se;
                if(vis[u] && vis2[u]) {
                    cout << -1 << endl;
                    return 0;
                }
                if(vis[v] && vis2[v]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << max(-dist[n], 0ll) << '\n';
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<numeric>

using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vector<vector<int>> a(n, vector<int>(n));
	int l, r;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		l--;
		r--;
		a[l][r]++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			a[i][j] += a[i][j - 1];
		}
	}
	for (int j = 0; j < n; j++) {
		for (int i = j - 1; i >= 0; i--) {
			a[i][j] += a[i + 1][j];
		}
	}
	int pi, qi;
	for (int i = 0; i < q; i++) {
		cin >> pi >> qi;
		cout << a[pi - 1][qi - 1] << "\n";
	}

	return 0;
}

Measured memory_bytes: 1920
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn is_palindrome(s: &str) -> bool {
    // 長さ5のとき、
    // 0 1 2 3 4

    let end = if s.len() % 2 == 1 {
        (s.len() - 1) / 2
    } else {
        s.len() / 2
    };
    for i in 0..end {
        if s[i..i + 1] != s[(s.len() - 1 - i)..(s.len() - i)] {
            return false;
        }

    }
    return true;

}


fn is_strong_palindrome(s: &str) -> bool {
    if !is_palindrome(s) {
        return false;
    }


    let ins: &str = &s[..(s.len() - 1) / 2];
    if !is_palindrome(&ins) {
        return false;
    }


    let ins2: &str = &s[(s.len() + 3) / 2 - 1..s.len()];
    if !is_palindrome(&ins2) {
        return false;
    }


    return true;
}

fn main() {
    input! {
        s: String,
    }

    let ans = is_strong_palindrome(&s[..]);
    let yes = "Yes";
    let no = "No";
    println!("{}", if ans { yes } else { no });
}


Measured memory_bytes: 2100
import itertools
import math
N = int(input())
x, y = [0]*N, [0]*N
l = list(range(N))

for i in range(N):
  x[i], y[i] = map(int, input().split())

dis = 0
comb = list(itertools.permutations(l))
for i in range(0, len(comb)):
  for j in range(0, N-1):
    dis += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)

print(dis/len(comb))


Measured memory_bytes: 8100
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 1020000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD =1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;


ll v=0;
for(ll i=2;i<=10000;i++){
ll sum=i*(i-1)/2;
if(sum==n){
	v=i;
	break;
}
	if(sum>n){cout<<"No"<<endl;
	return 0;}
}

vector<ll> vec[v+1]{};

ll ind=1;
for(ll i=1;i<=v;i++){
	for(ll j=1;j<=v;j++){
if(i<j){vec[i].push_back(ind);
vec[j].push_back(ind);
ind++;}
	}
}

cout<<"Yes"<<endl;
cout<<v<<endl;
for(int i=1;i<=v;i++){
	cout<<vec[i].size()<<" ";
for(int j=0;j<vec[i].size()-1;j++){
	cout<<vec[i][j]<<" ";
}
cout<<vec[i][vec[i].size()-1]<<endl;
}


return 0;
}





Measured memory_bytes: 3200
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#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> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N;
    cin >> N;

    //貪欲法で計算
    //正数は足して負数は引くのが最も効率がよい
    vll add, subtract;
    rep(_, N)
    {
        int a;
        cin >> a;

        if (a >= 0)
        {
            add.push_back(a);
        }
        else
        {
            subtract.push_back(a);
        }
    }

    //ただし全部足す、全部引くはできない
    sort(all(add), greater<ll>());
    sort(all(subtract));

    if (subtract.empty())
    {
        subtract.push_back(add.back());
        add.pop_back();
    }

    if (add.empty())
    {
        add.push_back(subtract.back());
        subtract.pop_back();
    }

    vector<pair<ll, ll>> v;
    ll res = subtract[0];

    //プラスを全部引く
    rep(i, add.size() - 1)
    {
        v.emplace_back(res, add[i]);
        res -= add[i];
    }

    //逆転
    //→引いたプラスが全部足し算になる
    v.emplace_back(add.back(), res);
    res = add.back() - res;

    //マイナスを全部引く
    repl(i, 1, subtract.size())
    {
        v.emplace_back(res, subtract[i]);
        res -= subtract[i];
    }

    cout << res << endl;

    for (auto x : v)
    {
        cout << x.first << " " << x.second << endl;
    }

    return 0;
}

Measured memory_bytes: 7136
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lb;
map<ll,ll> mp;
ll a,b,c,d;
ll solve(ll n)
{
    if(n==0)
    return 0;
    if(n==1)
    return d;
    if(mp[n]!=0)
    return mp[n];
    ll l21=(n/2)*2,l22=((n+1)/2)*2;
    ll l31=(n/3)*3,l32=((n+2)/3)*3;
    ll l51=(n/5)*5,l52=((n+4)/5)*5;
    ll ans=1e18;
    if(ans/d>n)
    ans=n*d;
    ans=min(ans,llabs(l21-n)*d+a+solve(l21/2));
    ans=min(ans,llabs(l22-n)*d+a+solve(l22/2));
    ans=min(ans,llabs(l31-n)*d+b+solve(l31/3));
    ans=min(ans,llabs(l32-n)*d+b+solve(l32/3));
    ans=min(ans,llabs(l51-n)*d+c+solve(l51/5));
    ans=min(ans,llabs(l52-n)*d+c+solve(l52/5));
    return mp[n]=ans;
}
int main()
{
    ll i,j,k,l,m,n,o,p,t;
    cin>>t;
    while(t--)
    {
        cin>>n>>a>>b>>c>>d;
        mp.clear();
        cout<<solve(n)<<endl;
    }
    return 0;
}


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

using namespace std;


void minimization()
{
  int n, k;
  cin >> n >> k;

  cout << ceil((float)(n - 1) / (float)(k - 1)) << "\n";
}


void linear_approximation()
{
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    b[i] = a - (i + 1);
  }

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

  int mid = b[n / 2];
  long long int ans = 0;
  for (int i = 0; i < n; ++i) ans += abs(mid - b[i]);
  cout << ans << "\n";

}


int main()
{
  //minimization();
  linear_approximation();
}


Measured memory_bytes: 1024
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def sub(w, v, b):
    """重みリストw, 価値リストv, 重さ上限bのナップサックを解く
    ※ 価値で回すパターン
    """
    sv = sum(v)
    n = len(w)
    dp = [float("inf")] * (sv+1) # iの価値を作るのに必要な重さの最小値
    dp[0] = 0
    for i in range(n):
        for j in range(sv, -1, -1):
            if j>=v[i]:
                dp[j] = min(dp[j], dp[j-v[i]]+w[i])
    return dp
n,w = map(int, input().split())
ws = [None]*n
vs = [None]*n
for i in range(n):
    ws[i], vs[i] = map(int, input().split())
dp = sub(ws, vs, w)
ans = 0
for i,item in enumerate(dp):
    if item<=w:
        ans = i
print(ans)

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

vector<P> g[100005];
int ans[100005];
int k=0;

void dfs(int used, int from, int now) {
  k=max(k,(int)g[now].size());
  int num=1;
  for (auto x: g[now]) {
    if (used==num) num++;
    if (x.second==from) continue;
    ans[x.second]=num;
    dfs(num,x.second,x.first);
    num++;
  }
}

int main() {
  int n;
  cin>>n;
  rep(i,n-1) {
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].push_back({b,i});
    g[b].push_back({a,i});
  }
  dfs(-1,-1,0);
  cout<<k<<endl;
  rep(i,n-1) {
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 8448
#include<stdio.h>
int t(int);
int main()
{
	int n,k,i,j,dp[100001],h[100001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	for(i=0;i<=n;i++) dp[i]=1000000000;
	dp[0]=0;
	for(i=0;i<n-1;i++){
		for(j=i+1;j<i+k+1;j++){
			if(j<n&&t(h[i]-h[j])+dp[i]<dp[j]){
				dp[j]=t(h[i]-h[j])+dp[i];
			}
		}
	}
	printf("%d\n",dp[n-1]);
	return 0;
}
int t(int x){
	if(x<0) x=-x;
	return x;
}

Measured memory_bytes: 2508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.awt.Point;
import java.util.*;
  
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
while(!(str=br.readLine()).equals("0 0")){
String[] value=str.split(" ");
int h=Integer.parseInt(value[0]);
int w=Integer.parseInt(value[1]);
char[][] map=new char[h][w];
for(int i=0;i<h;i++){
map[i]=br.readLine().toCharArray();
}
Deque <Point> fifo  =new  ArrayDeque<Point>();
            int ans=0;
            for(int m=0;m<h;m++){
                for(int n=0;n<w;n++){
            if(map[m][n]!='.'){
                ans++;
                Point p = new Point(n,m);
                fifo.addLast(p);
            while(fifo.peekFirst()!=null){
                p=fifo.pollFirst();
                int x=p.x;
                int y=p.y;
                char crop = map[y][x];
                map[y][x]='.';
                int [] dx ={0,1,0,-1};
                int [] dy ={1,0,-1,0};
                   
                for(int i=0;i<4;i++){
                    int nx =x+dx[i];
                    int ny =y+dy[i];
                    if(0<=nx&&nx<w&&0<=ny&&ny<h&&map[ny][nx]==crop&&map[ny][nx]!='.'){     Point np = new Point();
                        np.x=nx;
                        np.y=ny;
                     fifo.addLast(np);                       
}
}
}
}
}
}System.out.println(ans);
}
}
}

Measured memory_bytes: 25860
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
using namespace std;
int main(){
  ios;
	string str1,str2;
	cin>>str1>>str2;
	cout<<str2+str1<<endl;
	return 0;
}


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

int main() {
  int a, b; cin >> a >> b;
  //cout << a << " " << b << " " << abs(b-a) << endl;
  int n = abs(b-a);
  string number1, number2;
  int count = 0;
  for(int i = 0; i <= n; i++){
      //cout << a + i << endl;
    number1 = to_string(a + i);
    number2 = number1;
    reverse(number2.begin(), number2.end());
    
    if(number1 == number2){
      //cout << number1 << " " << number2 << endl;
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void bubbleSort(int[],int);

int main(){
  int N,i;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }    
  bubbleSort(A,N);

  return 0;
}

void bubbleSort(int A[],int N){
  int flag,j,a,i,n,count=0;

  flag = 1; 
  i = 0;

  while(flag){
    flag = 0;
    
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	a = A[j];
	A[j] = A[j-1];
	A[j-1] = a;
	flag = 1;
	count++;
      }
    }  
    i++;
  }
  for(n=0;n<N;n++){
    if(n>0)printf(" ");
      printf("%d",A[n]);
    }
    printf("\n");
    printf("%d\n",count);
}
     



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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int N) : par(N), siz(N, 1) {
    for ( int i = 0; i < N; i++ ) { par[i] = i; }
  }

  int root(int x) { 
    if ( par[x] == x ) { return x; }
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if ( rx == ry ) { return; }
    if ( siz[rx] < siz[ry] ) { swap(rx, ry); }
    par[ry] = rx;
    siz[rx] += siz[ry];
  }

  int size(int x) {
    return siz[root(x)];
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind tree(n+1);
  for ( int i = 0; i < m; i++ ) {
    int x, y, z;
    cin >> x >> y >> z;
    tree.unite(x, y);
  }

  set<int> ans;
  for ( int i = 1; i <= n; i++ ) {
    int par = tree.root(i);
    if ( ans.find(par) == ans.end() ) {
      ans.insert(par);
    }
  }
  cout << ans.size() << endl;
  return 0;
}

Measured memory_bytes: 8796
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

from collections import Counter

N = I()
A = LI()
sum = sum(A)
a = Counter(A)

Q = I()
for i in range(Q):
    b,c = LI()
    sum += a[b]*(c-b)
    print(sum)
    a[c] += a[b]
    a[b] = 0

Measured memory_bytes: 88532
#include<cstdio>
#include<cstring>
using namespace std;

const int N=61;
char s[N],t[N];

int main()
{
	scanf("%s%s",&s[1],&t[1]); int slen=strlen(s+1),tlen=strlen(t+1);
	bool flag=0; int maxn=0;
	for (int i=slen-tlen+1; i>=1; --i)
	{
		flag=1;
		for (int j=1; j<=tlen; ++j)
			if (s[i+j-1]!=t[j]&&s[i+j-1]!='?') {flag=0;break;}
		if (flag) {maxn=i;break;}
	}
	if (!flag) {printf("UNRESTORABLE");return 0;}
	for (int i=1; i<=tlen; ++i) s[maxn+i-1]=t[i];
	for (int i=1; i<=slen; ++i) if (s[i]=='?') s[i]='a';
	for (int i=1; i<=slen; ++i) printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 128
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    a=STR()
    if a==a.upper():
        print('A')
    else:
        print('a')
if __name__ == '__main__':
    do()

Measured memory_bytes: 9112
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, t) = (v[0], v[1]);
    let mut foods = vec![];
    for i in 0..n {
        let v = read_vec::<usize>();
        let (a, b) = (v[0], v[1]);
        foods.push((a, b));
    }

    foods.sort();
    let mut dp = vec![0; t + 1];
    for i in 0..n {
        for ti in (0..t).rev() {
            if foods[i].0 + ti >= t {
                dp[t] = max(dp[t], dp[ti] + foods[i].1);
            } else {
                let next_t = ti + foods[i].0;
                dp[next_t] = max(dp[next_t], dp[ti] + foods[i].1);
            }
        }
    }
    let ans = dp.iter().max().unwrap();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2216
import java.util.ArrayList;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    ArrayList<String> input = new ArrayList<String>();
    while (true) {
    	String s = sc.nextLine();
    	if (s.contains("?")) { break; }
    	input.add(s);
    }
    for (int i = 0; i < input.size(); i++) {
    	String[] ss = input.get(i).split(" ");
    	int a = Integer.parseInt(ss[0]);
    	String op = ss[1];
    	int b = Integer.parseInt(ss[2]);
    	switch (op) {
    		case "+":
    			System.out.println(a + b);
    			break;
    		case "-":
    			System.out.println(a - b);
    			break;
    		case "*":
    			System.out.println(a * b);
    			break;
    		case "/":
    			if (b == 0) { System.out.println("ゼロ除算"); }
    			else System.out.println(a / b);
    			break;
    	}
    }
  }
}


Measured memory_bytes: 26300
n = int(input())
ans = 0
for i in range(1,n//2-2):
  a = i * 2 + 1
  for j in range(i+1,n//2-1):
    b = j * 2 + 1
    for k in range(j+1,n//2):
      c = k * 2 + 1
      if a*b*c <= n : ans += 1
      else: break
print(ans)

Measured memory_bytes: 3064
// Tarun IIITA
   //Тарун Асудани 
   //Не читайте этот код
   
   #include<bits/stdc++.h>
   using namespace std;
   #define ll   long long
   #define pb push_back
   #define pf push_front
   #define MP make_pair
   #define all(v) v.begin(),v.end()
   #define F first
   #define lb lower_bound
   #define ub upper_bound
   #define bs binary_search
   #define S second
   #define P pair<ll,ll>
   #define vect vector<ll>
   #define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
   #define mod  1000000007
   #define int  long long


   void solve(){
      int n,k;
      cin>>n>>k;
      vector<int> v(n);
      for(int i=0;i<n;i++){
         cin>>v[i];
      }
      
      for(int i=k;i<n;i++){
        
         if(v[i]>v[i-k])
         cout<<"Yes\n";
         else
         cout<<"No\n";
         
         
      }
      
   }



   signed main(){
      boost;
      int t=1;
      //cin>>t;
      while(t--){
         solve();
      }
   }


Measured memory_bytes: 4776
n,l = list(map(int,input().split()))
n_l = []
for i in range(n):
    n_l.append(i+l)
    
min_i = n_l[0]
for i in n_l:
    if abs(i) < abs(min_i):
        min_i = i

print(sum(n_l) - min_i)


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N, S;

int f(int b, int n) { return n < b ? n : f(b, n / b) + n % b; }

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

    cin >> N >> S;
    if (N < S) {
        cout << -1 << endl;
        return 0;
    }
    if (N == S) {
        cout << N + 1 << endl;
        return 0;
    }

    for (int i = 2; i * i <= N; ++i) {
        if (f(i, N) == S) {
            cout << i << endl;
            return 0;
        }
    }

    int ans = INF;
    for (int p = 1; p * p < N; ++p) {
        if ((N - S + p) % p != 0) continue;
        int b = (N - S + p) / p;
        if (b == 1) continue;
        if (f(b, N) == S) {
            ans = min(ans, b);
        }
    }
    if (ans != INF) {
        cout << ans << endl;
        return 0;
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
int main() {
  std::cout.tie(0); std::ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto& v : A)cin >> v;
  int sum = accumulate(begin(A), end(A), 0);
  deque<int> divisors;
  for (int i = 1; i * i <= sum; ++i) {
    if (sum % i != 0)continue;
    divisors.push_back(i);
    if (i * i != sum)divisors.push_back(sum / i);
  }
  sort(rbegin(divisors), rend(divisors));
  for (auto& v : divisors) {
    deque<int> rs;
    for (int i = 0; i < N; ++i) {
      if (A[i] % v == 0)continue;
      rs.push_back(A[i] % v);
    }
    if (rs.empty()) {
      cout << v << endl;
      return 0;
    }
    sort(begin(rs), end(rs));
    int n = rs.size();
    vector<int64_t> csum(n + 1, 0);
    for (int i = 0; i < n; ++i)
      csum[i + 1] = csum[i] + rs[i];
    bool ans = false;
    for (int i = 1; i <= n - 1; ++i) {
      if (v * (int64_t)(n-i) - (csum[n] - csum[i]) != csum[i])continue;
      if (csum[i] <= K)ans = true;
      break;
    }
    if (!ans)continue;
    cout << v << endl;
    break;
  }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
keep=0
aa=["#"]*n
for i in range(m):
  s,c=map(str,input().split())
  s=int(s)
  if n>=2 and s==1 and c=="0":
    keep=1
    print(-1)
    break
  if aa[s-1]=="#":
    aa[s-1]=c
  elif aa[s-1] !=c:
    keep=1
    print(-1)
    break
if keep==0:
  moji=""
  if aa[0]=="#" and n>=2:
    moji+="1"
  elif n==1 and aa[0]=="#":
    moji+="0"
  else:
    moji+=aa[0]
  for i in range(1,n):
    if aa[i]=="#":
      moji+="0"
    else:
      moji+=aa[i]
  print(moji)

Measured memory_bytes: 3064
a = []
n, m = map(int, input().split())


for i in range(n):
    a.append(list(map(int, input().split())))
    a[i].pop(0)

for i in range(len(a)):
    if i == 0:
        match = set(a[i])
    else:
        target = set(a[i])
        match = set(match & target)

print(len(match))


Measured memory_bytes: 3060
while line = gets
  m, f, r = line.chomp.split.map(&:to_i)
  break if m == -1 && f == -1 && r == -1

  if m == -1 || f == -1
    puts "F"
    next
  end

  mf = m + f
  if mf >= 80
    puts "A"
    next
  end

  if mf >= 65 && mf < 80
    puts "B"
    next
  end

  if mf >= 50 && mf < 65
    puts "C"
    next
  end

  if mf >= 30 && mf < 50
    if r >= 50
      puts "C"
    else
      puts "D"
    end
    next
  end

  if mf < 30
    puts "F"
    next
  end
end



Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
#define op() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;

int main()
{
    op();
    map< int , int > mp;
    int n;
    cin >> n;
    while(n--)
    {
        int ar;
        cin >> ar;
        mp[ar]++;
    }

    int cnt = 0;
    for ( auto u : mp )
    {
        if(u.second >= u.first) cnt += ( u.second - u.first );
        else cnt += u.second;
    }
    cout << cnt << endl;

}


Measured memory_bytes: 8144
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

NN = 10 ** 6 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i
def prime_factorize(n):
    res = set([])
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.add(prime)
    return res

n = INT()
a = LIST()
b = []
for aa in a:
    b.append(prime_factorize(aa))
all_and = b[0]
for bb in b[1:]:
    all_and = all_and & bb
if len(all_and):
    print('not coprime')
    exit()
c = []
for bb in b:
    for tmp in bb:
        c.append(tmp)
d = set(c)
if len(c) != len(d):
    print('setwise coprime')
else:
    print('pairwise coprime')

Measured memory_bytes: 564244
import java.io.*;
class Baseball{
	private int point=0;
	private int out=0;
	private int[] Runner =new int[4];
	public Baseball(){}
	int HIT(){
		for(int i=3;i>0;i--){
			Runner[i]=Runner[i-1];
		}
		Runner[0]=1;
		point+=Runner[3];
		Runner[3]=0;
		return 0;
	}
	int HOMERUN(){
		for(int i=0;i<Runner.length;i++){
			point+=Runner[i];
			Runner[i]=0;
		}
		point++;
		return 0;
	}
	int OUT(){
		out++;
		if(out==3){
			for(int i=0;i<Runner.length;i++){
				Runner[i]=0;
			}
			out=0;
			return 1;
		}
		return 0;
	}
		
	int get(){
		int temp=point;
		point =0;
		return temp;
	}
	int acction(String s){
		if(s.equals("HIT")){
			return HIT();
		}else if(s.equals("OUT"))
			return OUT();
		else if(s.equals("HOMERUN"))
			return HOMERUN();
	return 0;
	}
}
class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br
			= new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		Baseball baseball=new Baseball();
		int i=0;
		while(true){
			int j;
			i+=j=baseball.acction(br.readLine());
			if(j==1)System.out.println(baseball.get());
			if(n==i)break;
		}
	}
}

Measured memory_bytes: 9340
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

// bool solve(int n, int a, int b) {
//   int diff = a ^ b;
//   int cnt = 0;
//   REP(i, n) {
//     if(diff & (1 << i)) {
//       ++cnt;
//     }
//   }
//   if(cnt % 2 == 0 || (n > 1 && cnt == n)) { // XXX 
//     return false;
//   }
//   int rot = 0;
//   REP(i, n) {
//     if(diff & (1 << i)) {
//       rot = i+1;
//       break;
//     }
//   }
//   puts("YES");
//   const int MASK = (1 << n) - 1;
//   REP(i, 1 << n) {
//     int g = i ^ (i >> 1);
//     int rg1 = (g << rot) & MASK;
//     int rg2 = (g >> (n-rot)) & MASK;
//     int rg = rg1 | rg2;
//     printf("%d%c", a ^ rg, i == (1 << n)-1 ? '\n' : ' ');
//   }
//   return true;
// }

inline int cutBit(int x, int n, int b) {
  const int MASK_ALL = (1 << n) - 1;
  const int MASK1 = (1 << b) - 1;
  int r1 = x & MASK1;
  int r2 = (x >> 1) & (MASK_ALL ^ MASK1);
  return r1 | r2;
}

inline int insertBit(int x, int n, int b, int v) {
  const int MASK_ALL = (1 << n) - 1;
  const int MASK1 = (1 << b) - 1;
  int r1 = x & MASK1;
  int r2 = (x & (MASK_ALL ^ MASK1)) << 1;
  return r1 | (v << b) | r2;
}

vector<int> solve(int n, int a, int b, int cnt) {
  // fprintf(stderr, "solve(%d, %d, %d, %d)\n", n, a, b, cnt);
  vector<int> res;
  assert(cnt % 2 == 1);
  if(n == 1) {
    assert(cnt == 1);
    res.push_back(a);
    res.push_back(b);
    return res;
  }
  int diff = a^b;
  REP(i, n) {
    if(diff & (1 << i)) {
      int aa = cutBit(a, n, i);
      int ab = -1, c1, c2;
      int bb = cutBit(b, n, i);
      if(cnt == 1) {
        c1 = 1;
        c2 = 1;
        ab = aa ^ 1;
      } else if((cnt-1) % 4 == 0) {
        c1 = (cnt-1) / 2 - 1;
        c2 = (cnt-1) / 2 + 1;
      } else {
        c1 = (cnt-1) / 2;
        c2 = (cnt-1) / 2;
      }
      if(ab < 0) {
        int dd = aa ^ bb;
        int hoge = c1;
        ab = aa;
        REP(j, n) {
          if(dd & (1 << j)) {
            if(hoge-- > 0) {
              ab ^= 1 << j;
            }
          }
        }
      }
      vector<int> r1 = solve(n-1, aa, ab, c1);
      vector<int> r2 = solve(n-1, ab, bb, c2);
      int v = (a >> i) & 1;
      REP(j, r1.size()) {
        res.push_back(insertBit(r1[j], n, i, v));
      }
      REP(j, r2.size()) {
        res.push_back(insertBit(r2[j], n, i, v^1));
      }
      break;
    }
  }
  // fprintf(stderr, "solve(%d, %d, %d, %d): ", n, a, b, cnt);
  // REP(i, res.size()) {
  //   fprintf(stderr, "%d, ", res[i]);
  // }
  // fprintf(stderr, "\n");
  return res;
}

int main(void) {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  int diff = A ^ B;
  int cnt = 0;
  REP(i, N) {
    if(diff & (1 << i)) {
      ++cnt;
    }
  }
  if(cnt % 2 == 0) {
    puts("NO");
    return 0;
  }
  vector<int> res = solve(N, A, B, cnt);
  puts("YES");
  REP(i, res.size()) {
    printf("%d%c", res[i], i == int(res.size())-1 ? '\n' : ' ');
  }
  return 0;
}


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


int main(){
    int n;
    cin>>n;
    int c=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x!=i)
        c++;
    }
    if(c==2 || c==0)
    cout<<"YES";
    else
    cout<<"NO";
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int V[N]; rep(i,N) cin >> V[i];
  int C[N]; rep(i,N) cin >> C[i];

  int result = 0;
  rep(i,N) if (V[i]-C[i]>0) result += V[i]-C[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; string s;
	cin >> n >> s;
	string res = {};
	for (int i = 0; i < s.size(); i++)
	{
		if(n <= 'Z' - s[i]) res += s[i] + n;
		else res += s[i] + n - 26;
	}
	cout << res << endl;
	return 0;
}


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

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

    vector<bool> cannot(L);
    for(int i = 0; i < L; ++i) {
        for(int j = i + 2; j < L; ++j) {
            if(s[i] != 'B' || s[j] != 'B') continue;
            bool found_b = false;
            int cnt = 0;
            for(int k = i + 1; k < j; ++k) {
                found_b |= s[k] == 'B';
                cnt += s[k] == '.';
            }
            if(found_b || cnt != 1) continue;
            for(int k = i + 1; k < j; ++k) {
                cannot[k] = true;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < L; ++i) {
        int tans = 0;
        if(s[i] != '.' || cannot[i]) continue;
        int cnt = 0;
        for(int j = i - 1; j >= 0; --j) {
            if(s[j] == '.') break;
            if(s[j] == 'W') {
                tans += cnt;
                break;
            }
            if(s[j] == 'B') {
                cnt += 1;
            }
        }
        cnt = 0;
        for(int j = i + 1; j < L; ++j) {
            if(s[j] == '.') break;
            if(s[j] == 'W') {
                tans += cnt;
                break;
            }
            if(s[j] == 'B') {
                cnt += 1;
            }
        }
        ans = max(ans, tans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3200
#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#include<set>
#include<unordered_set>
#include<algorithm>
#define int long long int
#define mod 1000000007
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int j,arr[n+1];
	for(j=1;j<=n;j++)
	   cin>>arr[j];
	for(j=k+1;j<=n;j++)
	{
		if(arr[j]>arr[j-k])
		{
			cout<<"Yes"<<endl;
		}
		else
		   cout<<"No"<<endl;
	}
}


Measured memory_bytes: 5188
#include<iostream>
#include<vector>
#include<utility>
#include<bitset>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n, min=100;
	cin >> n;
	for(int i=1; i<n; i++){
		int a=i, b=n-i, asum=0, bsum=0;
		while(a){
			asum += a%10;
			a/=10;
		}
		while(b){
			bsum += b%10;
			b/=10;
		}
		if(asum+bsum < min)
			min = asum+bsum;
	}
	cout << min << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;



const int MAX = 5e5+5; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
// driver code 
int main() 
{ 
    FAST
    int n,q;cin>>n>>q;
    int a[n]; f(i,0,n) cin>>a[i];
    Query queries[q];
    f(i,0,q)
    {
        int le,re;cin>>le>>re;
        queries[i].l=le-1;
        queries[i].r=re-1;
        queries[i].idx=i;
    }
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 

Measured memory_bytes: 17488
s = input()
dictionary = {}
pattern = 0
for c in s:
    if(c in dictionary):
        dictionary[c] += 1
    else:
        dictionary[c] = 1
        pattern += 1
    if(dictionary[c] > 2):
        print("No")
        exit()
    if(pattern > 2):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c==X:
                ans += 1
print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cout << *max_element(a.begin(),a.end())-*min_element(a.begin(),a.end()) << endl;
}

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

string s;

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

	int n,k=0;
	cin>>s;
	n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='0') k+=1;
	}
	cout<<n-abs(n-2*k)<<"\n";
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var hn = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var h = hn[0];

            var attacks = Console.ReadLine().Split(' ').Select(num => int.Parse(num))
                .OrderByDescending(x => x)
                .ToArray();

            for (var i = 0; i < attacks.Length; i++)
            {
                h -= attacks[i];
                if (h < 1)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}

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



int main() {
    ll N,W;
    cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,N){
        cin>>w.at(i)>>v.at(i);
    }
    vector<vector<ll>> dp(N,vector<ll>(100005,-1));
    
    dp.at(0).at(0)=0;
    dp.at(0).at(v.at(0))=w.at(0);
    for(int i=1;i<N;i++){
        rep(j,100005){
            dp.at(i).at(j)=dp.at(i-1).at(j);
        }
        rep(j,100005){
            if(dp.at(i-1).at(j)!=-1){
                ll ne=dp.at(i-1).at(j);
                ne+=w.at(i);
                if(dp.at(i).at(j+v.at(i))==-1){dp.at(i).at(j+v.at(i))=ne;}
                else{
                    if(dp.at(i).at(j+v.at(i))>ne){
                        dp.at(i).at(j+v.at(i))=ne;
                    }
                }
            }
        }
    }
    ll ans;
    rep(j,100005){
        if(dp.at(N-1).at(j)<=W && dp.at(N-1).at(j)>=0){ans=j;}
    }
    cout<<ans<<endl;

    /*
    rep(j,15){
        cout<<dp.at(N-1).at(j)<<" ";
    }
    cout<<endl;*/
}

Measured memory_bytes: 79488
import sys
sys.setrecursionlimit(10 ** 6)

def sum_d(l):
    s = 0
    for a,b,c,d in Qs:
        if l[b] - l[a] == c:
            s += d
    return s


def f(l,ans):
    if len(l) == N:
        s = sum_d(l)
        return s
    
    if len(l) == 0:
        pre = 0
    else:
        
        pre = l[-1]

    for i in range(1,M+1):
        if i < pre:
            continue
        ret = f(l+[i],ans)
        if ret > ans:
            ans = ret
    
    return ans


N,M,Q = map(int, input().split())
Qs = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    Qs.append([a-1,b-1,c,d])

ans = f([],0)
print(ans)

Measured memory_bytes: 9172
n=int(input())
dic={"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
  s=input()
  ss=s[0]
  if ss in ["M","A","R","C","H"]:
    dic[ss]=dic[ss]+1

keys=["M","A","R","C","H"]

i=0
result=0
while i<3:
  j=i+1
  while j<4:
    k=j+1
    while k<5:
      result+=dic[keys[i]]*dic[keys[j]]*dic[keys[k]]
      
      k+=1    
    j+=1  
  i+=1
print(result)

Measured memory_bytes: 46824
# frozen_string_literal: true

class Dice
  def initialize(params)
    @v = Array.new(6)
    (0..5).each do |i|
      @v[i] = params[i]
    end
    @right_side = {}
  end

  def slide(a, b, c, d)
    tmp = @v[a]
    @v[a] = @v[b]
    @v[b] = @v[c]
    @v[c] = @v[d]
    @v[d] = tmp
  end

  def rotate_atom(char)
    case char
    when 'N'
      slide(0, 1, 5, 4)
    when 'E'
      slide(0, 3, 5, 2)
    when 'W'
      slide(0, 2, 5, 3)
    when 'S'
      slide(0, 4, 5, 1)
    when 'D'
      slide(1, 3, 4, 2)
    when 'U'
      slide(1, 2, 4, 3)
    end
  end

  def rotate(string)
    string.chars.each do |c|
      rotate_atom(c)
    end
  end

  def top
    @v[0]
  end

  def register_z
    4.times do
      @right_side[[@v[0], @v[1]]] = @v[2]
      rotate_atom('D')
    end
  end

  def register
    4.times do
      register_z
      rotate_atom('S')
    end
    rotate_atom('W')
    register_z
    rotate_atom('E')
    rotate_atom('E')
    register_z
    rotate_atom('W')
  end

  def right_side(top, front)
    @right_side[[top,front]]
  end
end

dice = Dice.new(readline.split(' '))
dice.register
q = readline.chomp!.to_i
q.times do
  top, front = readline.split(' ')
  puts dice.right_side(top, front)
end



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

int main() {
    int n, v;
    cin >> n;
    map<int,int> odd, even;
    vector<P> oddmax(2, P(0,0)), evenmax(2, P(0,0));
    rep(i,n/2) {
        cin >> v;
        ++odd[v];
        cin >> v;
        ++even[v];
    }
    for (auto x : odd) {
        if (x.second > oddmax.at(0).first) {
            oddmax.at(0).first = x.second;
            oddmax.at(0).second = x.first;
            sort(oddmax.begin(), oddmax.end());
        }
    }
    for (auto x : even) {
        if (x.second > evenmax.at(0).first) {
            evenmax.at(0).first = x.second;
            evenmax.at(0).second = x.first;
            sort(evenmax.begin(), evenmax.end());
        }
    }
    if (oddmax.at(1).second != evenmax.at(1).second) {
        cout << n - oddmax.at(1).first - evenmax.at(1).first << endl;
    } else {
        cout << n - max(oddmax.at(1).first + evenmax.at(0).first, oddmax.at(0).first + evenmax.at(1).first) << endl;
    }
}


Measured memory_bytes: 8132
#include "bits/stdc++.h"
using namespace std;
double Distance(double x1, double x2, double y1, double y2) {
	double dis1 = (x1 - x2) * (x1 - x2), dis2 = (y1 - y2) * (y1 - y2);
	double ans = sqrt(dis1 + dis2);
	return ans;
}
int main() {
	double N;
	cin >> N;
	vector<double>P(N);
	for (double i = 0; i < N; i++) {
		P.at(i) = i;
	}
	vector<double>X(N), Y(N);
	for (double i = 0; i < N; i++) {
		cin >> X.at(i) >> Y.at(i);
	}
	double ans = 0;
	int num = 0;
	do {
		double sum = 0;
		for (double i = 1; i < N; i++) {
			sum += Distance(X.at(P.at(i)), X.at(P.at(i - 1)), Y.at(P.at(i)), Y.at(P.at(i - 1)));
		}
		ans += sum;
		num++;
	} while (next_permutation(P.begin(), P.end()));
	ans /= num;
	printf("%.10lf\n", ans);
}


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

int main(){
	string s;
	cin >> s;
	for(size_t i = 0; i < s.size(); i += 2){
		if(s[i] == '0' && s[i + 1] == 'U'){
			cout << "nn";
		}
		else{
			if(s[i] != '1'){
				cout << "w kstnhmyrw"[s[i] - '0'];
			}
			switch(s[i + 1]){
				case 'T':
					cout << 'a';
					break;
				case 'L':
					cout << 'i';
					break;
				case 'U':
					cout << 'u';
					break;
				case 'R':
					cout << 'e';
					break;
				case 'D':
					cout << 'o';
					break;
			}
		} 
	}
	cout << endl;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = INF;
	int sum = 0;
	rep(i, n)sum += a[i];
	int now = 0;
	rep(i, n) {
		now += a[i];
		sum -= a[i];
		chmin(ans, abs(sum - now));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256