akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout << endl
#define sp(x) cout << setprecision(x);
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t; cin >> s >> t;
	int n = sz(s), m = sz(t);
	vvi dp(n + 1, vi(m + 1, 0));
	rep(i, n)rep(j, m)
	{
		if (s[i] == t[j])chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		else
		{
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}
	
	string ans="";
	int i = n, j = m;
	while (i > 0 && j > 0)
	{
		if (dp[i][j] == dp[i - 1][j])i--;
		else if (dp[i][j] == dp[i][j - 1])j--;
		else
		{
			ans = s[i - 1] + ans;
			i--; j--;
		}
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;

int main() {
    int n; cin >> n;
    int64_t k; cin >> k;
    vector<int> a(n);
    for (auto &e : a) cin >> e;

    int logk = 0;
    while ((1ll << logk) < k) ++logk;

    vector<vector<int>> doubling(logk, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        doubling[0][i] = a[i] - 1;
    }
    for (int i = 1; i < logk; ++i) {
        for (int j = 0; j < n; ++j) {
            doubling[i][j] = doubling[i - 1][doubling[i - 1][j]];
        }
    }

    int current = 0;
    for (int i = 0; i < 63; ++i) {
        if (!(k & (1ll << i))) continue;
        current = doubling[i][current];
    }

    cout << current + 1 << endl;
}



Measured memory_bytes: 51676
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBalancedNeighbors solver = new BBalancedNeighbors();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBalancedNeighbors {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            List<Pair<Integer, Integer>> ans = new ArrayList<>();
            int notTake;

            if (n % 2 == 1) {
                notTake = n - 1;
            } else {
                notTake = n;
            }

            for (int i = 1; i < n; i++) {
                for (int h = i + 1; h <= n; h++) {
                    if (h != notTake) {
                        ans.add(new Pair<>(i, h));
                    }
                }
                notTake--;
            }

            out.println(ans.size());
            for (int i = 0; i < ans.size(); i++) {
                out.println(String.format("%d %d", ans.get(i).fs, ans.get(i).sc));
            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    static class Pair<T, K> {

        T fs;
        K sc;

        public Pair(T fs, K sc) {
            this.fs = fs;
            this.sc = sc;
        }
    }
}



Measured memory_bytes: 31648
#include<stdio.h>
#include<ctype.h>

int main()
{
	char s1[11],s2[11],s3[11];
	scanf("%s %s %s",s1,s2,s3);
	printf("%c%c%c\n",toupper(s1[0]),toupper(s2[0]),toupper(s3[0]));

	return 0;
}


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

int Solve(const string& s) {
  string ACGT("ACGT");
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    for (int k = 0; i + k < s.size(); ++k) {
      int j = i + k;
      if (ACGT.find(s[j]) == string::npos)
        break;
      if (ret <= k)
        ret = k + 1;
    }
  }
  return ret;
}

int main() {
  string s;
  cin >> s;
  cout << Solve(s) << "\n";
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n,i,j;
    scanf("%d",&n);
    int v[n],c[n];
    for(i=0;i<n;i++) {
        scanf("%d",&v[i]);
    }
    for(i=0;i<n;i++) {
        scanf("%d",&c[i]);
    }
    int total=0;
    for(j=0;j<n;j++) {
        if(v[j]>c[j]) {
            total+=v[j]-c[j];
        }
    }
    printf("%d\n",total);
    return 0;
}



Measured memory_bytes: 128
def main():
    S = input()

    s1 = S.replace('x', '')
    s2 = s1[::-1]
    if s1 != s2:
        print(-1)
        exit()

    i1 = 0
    i2 = len(S) - 1
    cnt = 0
    while True:
        if S[i1] == 'x' and S[i2] != 'x':
            cnt += 1
            i1 += 1
        elif S[i1] != 'x' and S[i2] == 'x':
            cnt += 1
            i2 -= 1
        else:
            i1 += 1
            i2 -= 1
        if i2 - i1 < 1:
            break

    print(cnt)

main()


Measured memory_bytes: 3316
s = list(input())
try:
    bs = s.index('B')
except:
    bs=-1

while bs != -1:
    if bs == 0:
        del s[bs]
    else:
        del s[bs-1]
        del s[bs-1]
    try:
        bs = s.index('B')
    except:
        bs = -1

print(''.join(s))


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

int main() {
  int N;
  cin >> N;
  
  int a[N];
  
  for (int i=1; i<N+1; i++){
    cin >> a[i];
  }
  
  int i=1;
  for (int j=0; j<N; j++){
      //cout << a[i] << endl;
    
      if(a[i]==2){
        cout << j+1 <<endl;
        break;
      } 
      if(j==N-1){
        cout << -1 <<endl;
        break;
      }
      i=a[i];
  }
}

Measured memory_bytes: 640
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static long[] a;
        static long N;
        static long K;
        
        static void Main(string[] args)
        {
          //入力を受け取る
          long[] ABCD = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
          long A = ABCD[0];
          long B = ABCD[1];
          long C = ABCD[2];
          long D = ABCD[3];
          long temp = D/gcd(C,D);
          long ans = C*temp;
          //Console.WriteLine(ans);
          long F = B/C - (A-1)/C;
          long G = B/D - (A-1)/D;
          
          long H = B/ans - (A-1)/ans;
          
		  long res = B-(A-1)-(F+G-H);
          
          Console.WriteLine(res);
          
        }
  
  static long gcd(long a , long b){
    if(b>a){
      return gcd(b,a);
    }
    long r = b;
    while(r != 0){
      r = a%b;
      a = b;
      b = r;
    }
    return a;
  }
 }


Measured memory_bytes: 13268
from collections import Counter
S = input()
Sc = Counter(S)
if len(Sc.keys()) == 1:
    print("YES" if len(S)==1 else "NO")
elif len(Sc.keys()) == 2:
    if (list(Sc.values())[0] != list(Sc.values())[1]) or (list(Sc.values())[0] > 2 or  list(Sc.values())[1] > 2):
        print("NO")
    else:
        print("YES")
else:
    temp = list(Sc.values())
    if max(temp) - min(temp) <= 1:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3572
N = int(input())
a = list(map(int,input().split()))
count = 0
count_min = 100000

for i in a:
    while(i%2 == 0):
        count = count + 1
        i = i/2
    if (count < count_min):
        count_min = count
    count = 0
    
print(count_min)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[301],n,dp[301][301];
main(){
  while(cin>>n,n){
    int ans=0;
    r(i,n)cin>>a[i];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<n;i+=2)
      for(int j=0;j<n-i;j++){
        dp[j][j+i]=dp[j+1][j+i-1];
        for(int k=1;k<i;k+=2)dp[j][j+i]=max(dp[j][j+i],dp[j][j+k]+dp[j+k+1][j+i]);
        if(abs(a[j]-a[j+i])<2&&dp[j+1][j+i-1]==i-1)dp[j][j+i]=max(dp[j][j+i],i+1);
      }
    r(i,n)r(j,n)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
  }
}

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

int num[200005];
int cnt[1000005];
bool hobena[1000005];
bool ase[1000005];

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

    for(int i=1; i<=n; i++) cin >> num[i], ase[num[i]] = 1, cnt[num[i]]++;
    
    for(int i=1; i<=1000000; i++) {
        if(!ase[i]) continue;
        for(int j=2*i; j<=1000000; j+=i) 
            hobena[j] = 1;
    }

    int ans = 0;
    for(int i=1; i<=n; i++) 
        if(!hobena[num[i]] and cnt[num[i]]==1) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 10168
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {
	
	string S, ans;

	cin >> S;

	ans = S.substr(0, 4) + " " + S.substr(4, 8);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        nums: [isize;3],
    };

    println!("{}", solve(nums));
}

fn solve(mut nums: Vec<isize>) -> isize {
    nums.sort();
    return nums[2] - nums[0];
}
macro_rules! tests {
    ($($test_name:ident:$name:ident($( $args:expr ),*) => $expected:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $test_name() {
                    assert_eq!($expected,super::$name($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:solve(vec![1,6,3])=>5,
    test2:solve(vec![11,5,5])=>6,
    test3:solve(vec![100,100,100])=>0,
}


Measured memory_bytes: 4352
#include<stdio.h>
main(){
  char number[1001];
  int num,sum=0;
  int j;
  while(1){
    scanf("%s",number);
    if(number[0]=='0')
      break;
    for(j=0;number[j]!='\0';j++){
      num=number[j]-'0';
      sum=sum+num;
    }
    printf("%d\n",sum);
    sum=0;
  }
  return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <string.h>
#include <math.h>

using namespace std;

bool flag = true;


struct NODE {
	int x = 0;
	bool vis = false;

	//pair: opposite, distance
	vector<pair<int, int>> inf;
} node[200000];

void dfs(int ne, int x) {
	if (node[ne].vis) {
		if (node[ne].x != x)flag = false;
	}
	else {
		node[ne].vis = true;
		node[ne].x = x;
		for (auto it = node[ne].inf.begin(); it != node[ne].inf.end(); it++)
			dfs((*it).first, x + (*it).second);
	}
}


int main()
{
	int n, m;

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		node[l].inf.push_back(pair<int, int>(r, d));
		node[r].inf.push_back(pair<int, int>(l, -d));
	}

	for (int i = 0; i < n; i++) 
		if(!node[i].vis)dfs(i, 0);

	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 14592
def q_d():
    n = int(input())
    a = list(map(int, input().split()))

    break_num = 0
    current_index = 1
    for i in range(n):
        if a[i] == current_index:
            current_index += 1
        else:
            break_num += 1

    if break_num == n:
        print(-1)
    else:
        print(break_num)


if __name__ == '__main__':
    q_d()


Measured memory_bytes: 26012
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

struct Dice {
  int top;
  int front;
  int right;
  Dice() {;}
  Dice(int t, int f, int r) : top(t), front(f), right(r) {;}
};

const int dx[4] = { 1, -1, 0, 0 };
const int dy[4] = { 0, 0, 1, -1 };

Dice rotate(Dice dice, int i) {
  int top = dice.top;
  int front = dice.front;
  int right = dice.right;
  Dice d;
  int rtop = 7 - top;
  int rfront = 7 - front;
  int rright = 7 - right;
  if (i == 0) {
    d.top = rright;
    d.front = front;
    d.right = top;
  } else if (i == 1) {
    d.top = right;
    d.front = front;
    d.right = rtop;
  } else if (i == 2) {
    d.top = rfront;
    d.front = top;
    d.right = right;
  } else if (i == 3) {
    d.top = front;
    d.front = rtop;
    d.right = right; 
  }
  return d;
}

int encode(Dice d) {
  return d.top + d.front * 6 + d.right * 36;
}

struct State {
  int cost;
  int x;
  int y;
  Dice dice;
  State() {;}
  State(int c, int x, int y, Dice d) : cost(c), x(x), y(y), dice(d) {;}
  bool operator<(const State &rhs) const { return cost > rhs.cost; }
};

int field[20][20];
int dist[400][10][10];
bool visit[400][10][10];

int main() {
  int h, w;
  while (scanf("%d %d", &h, &w), h|w) {
    MEMSET(field, 0);
    MEMSET(visit, false);
    MEMSET(dist, 0x0f);
    REP(y, h) REP(x, w) {
      scanf("%d", &field[y][x]);
    }
    int sx, sy, gx, gy;
    scanf("%d %d %d %d", &sy, &sx, &gy, &gx);
    priority_queue<State> que;
    que.push(State(0, sx, sy, Dice(1, 2, 3)));
    while (!que.empty()) {
      State s = que.top();
      que.pop();
      int e = encode(s.dice);
      if (visit[e][s.y][s.x]) { continue; }
      visit[e][s.y][s.x] = true;
      if (s.x == gx && s.y == gy) {
        printf("%d\n", s.cost);
        break;
      }
      //cout << s.x << " " << s.y << endl;
      REP(i, 4) {
        int nx = s.x + dx[i];
        int ny = s.y + dy[i];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
        Dice ndice = rotate(s.dice, i);
        int ne = encode(ndice);
        int ncost = s.cost + (7 - ndice.top) * field[ny][nx];
        if (visit[ne][ny][nx] || ncost >= dist[ne][ny][nx]) { continue; }
        dist[ne][ny][nx] = ncost;
        que.push(State(ncost, nx, ny, ndice));
      }
    }
  }
}

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

typedef double ll;

int main() {
	int n,i,j,k;
	cin>>n>>k;
	int a[n+2];
	for(i=1;i<=n;i++)
	cin>>a[i];
	vector<int>dp(k+2,0);
	for(i=1;i<=k;i++)
	{
	    for(j=1;j<=n;j++)
	    {
	        if(i>=a[j])
	        {
	            //if(dp[i-a[j]]==0)
	            dp[i]=max(dp[i],1-dp[i-a[j]]);
	        }
	    }
	}
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}


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

int main(){
    long N;
    long a[5];
    long mini = 9223372036854775806;
    cin >> N;
    for(int i = 0;i < 5;i++)
    {
        cin >> a[i];
        mini = min(mini,a[i]);
    }
    
    cout << 4 + (N + (mini - 1)) / mini << endl;

}

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

using namespace std;

int main () {
	long long q, h, s, d;
	cin >> q >> h >> s >> d;
	long long n;
	cin >> n;
	h = min (h, q * 2);
	s = min (s, h * 2);
	d = min (d, s * 2);
	long long ans = 0;
	ans += (n / 2) * d; 
	n %= 2;
	ans += n * s;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){ 
    int n,i=0,a=0,b=0,c=0,d=0;
    scanf("%d",&n);
    char s[n];
    for(i=0;i<n;i++)scanf("%s",&s[i]);
    for(i=0;i<n;i++){
        if(s[i]=='A')a++;
        if(s[i]=='W')b++;
        if(s[i]=='T')c++;
        if(s[i]=='R')d++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
    return 0;
}


Measured memory_bytes: 1808
yr,mn,dy=map(int,input().split('/'))
if yr <2019:
  print("Heisei")
elif yr >2019:
  print("TBD")
else:
  if mn<4:
    print("Heisei")
  elif mn>4:
    print("TBD")
  else:
    print("Heisei")

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

int dr[] = {-1, 0, 1, 0};
int dc[] = {0, -1, 0, 1};

class Solution {
public:
	void solve() {
		int h, w;
		cin >> h >> w;
		vector<string> s(h);
		for(int i=0; i<h; i++)cin >> s[i];
		int ans = 0;
		int inf = 0x3f3f3f3f;
		for(int i=0; i < h; i++){
			for(int j=0; j < w; j++){
				if(s[i][j] == '#')continue;
				vector<vector<int>> d(h, vector<int>(w, inf));
				d[i][j] = 0;
				queue<pair<int, int>> q;
				q.push({i, j});
				while(!q.empty()){
					int r,c;
					tie(r, c) = q.front();
					q.pop();
					for(int dir=0; dir < 4; dir++){
						int nr = r + dr[dir];
						int nc = c + dc[dir];
						if(nr < 0 || nr >= h || nc < 0 || nc >= w || s[nr][nc] == '#' || d[nr][nc] != inf)continue;
						d[nr][nc] = d[r][c] + 1;
						ans = max(ans, d[nr][nc]);
						q.push({nr, nc});
					}
				}
			}
		}
		cout << ans << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long d[2010][2010]={1};
int main(){
  int n,m,i,j,a[2010],b[2010],M=1e9+7;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<m;i++)scanf("%d",&b[i]);
  for(i=0;i<=n;i++)d[i][0]=1;
  for(j=0;j<=m;j++)d[0][j]=1;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      d[i+1][j+1]=(d[i][j+1]+d[i+1][j]-d[i][j]+M)%M;
      if(a[i]==b[j])d[i+1][j+1]=(d[i+1][j+1]+d[i][j])%M;
    }
  }
  printf("%lld\n",d[n][m]);
  return 0;
}


Measured memory_bytes: 31616
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A = list(map(int, input().split()))

for i in range(5):
    if A[i] != i + 1:
        print(i + 1)

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin >>s;
    int n=s.length();

    for (int i = 0; i < n/2; i++){
        if(s[i] != s[n-1 -i])ans++;
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
void solve(){
    ll a=0,b=0,c=0;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}
int main()
{
    fastio;
//    ll t=0;
//    cin>>t;
//    while(t--)
        solve();
    return 0;
}


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

using namespace std;

int main() {

  int a[3];
  bool flg = 0;
  int ans[4] ={0};
  while(cin >>a[0] >> a[1] >> a[2]) {
   
    sort(a,a+3);

    if(a[0]+a[1] <= a[2] ) flg = 1;
    if(flg == 1) continue;

    
    if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]) ans[0]++;
    else if(a[0]*a[0]+a[1]*a[1] < a[2]*a[2]) ans[1]++;
    else ans[2]++;

    ans[3]++;

  }

  cout <<ans[3]<<" "<<ans[0]<<" "<<ans[2]<<" "<< ans[1]<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    int n;
    cin>>n;
    string s;
    cin>>s;
    stack<char> st;
    for(int i=0;i<s.size();i++){
        if(st.empty()){
            st.push(s[i]);
        }else if(st.top() == '('&&s[i]==')'){
            st.pop();
        }else{
            st.push(s[i]);
        }
    }
    int left = 0;
    int right = 0;
    while(!st.empty()){
        char c = st.top();
        st.pop();
        if(c=='(')left++;
        else right++;
    }
    rep(i,right){
        cout<<'(';
    }
    rep(i,s.size()){
        cout<<s[i];
    }
    rep(i,left){
        cout<<')';
    }


return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0173
{
    public class Program

    {
        public static void Main(string[] args)
        {
            for (int i = 0 ; i < 9 ; i++)
            {
                string[] items = RStAr();
                Console.WriteLine("{0} {1} {2}", items[0], int.Parse(items[1]) + int.Parse(items[2]), int.Parse(items[1]) * 200 + int.Parse(items[2]) * 300);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15892
x, n = map(int, input().split())
 
if n == 0:
  print(x)
else :
  pn = [int(num) for num in input().split()]
  answers = {}
  for i in range(102):
    if not i in pn:
      answers[i] = abs(i-x)
  print(min(answers, key=answers.get))

Measured memory_bytes: 9076
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int K, S;
    cin >> K >> S;
    int ret = 0;
    FOR(x, 0, K + 1) {
        if (x > S)
            break;

        // y + z = S - x
        int yMin = max(S - x - K, 0);
        int yMax = min(K, S - x);
        if (yMin <= yMax)
            ret += yMax - yMin + 1;
    }

    cout << ret << endl;
    return 0;
};


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

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

        vector<int> sum(N+1);
        for(int i=0;i<N;i++) sum[i+1]=sum[i]+a[i];

        int ans=N+1;
        for(int l=0, r=0;l<N;l++){
                int ng=l, ok=N+1;
                while(ok-ng>1){
                        int mid=(ok+ng)/2;
                        if(sum[mid]-sum[l]>=S) ok=mid;
                        else ng=mid;
                }
                if(ok<=N) ans=min(ans, ok-l);
        }
        cout<<(ans==N+1? 0:ans)<<endl;
        return 0;
}



Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int k,t;
  cin>>k>>t;
  int a[t];
  rep(i,t) cin>>a[i];
  sort(a, a + t);
  int sum = 0;
  int ans = 0;
  rep(i,t - 1) {
    sum += a[i];
  }
  if(sum >= a[t - 1]) {
    ans = 0;
  } else {
    ans = a[t - 1] - sum - 1;
  }
  cout << ans << endl;

  return 0;
}


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

int n;
int a[101][101];

set<int>s,t;

int main(){
	s = set<int>();
	t = set<int>();
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			scanf("%d",&a[i][j]);
		}
		if(i == 0){
			t.insert(i);
		}
		else{
			s.insert(i);
		}
	}
	int ans = 0;
	while(!s.empty()){
		int min_s=-1,min_t=-1,min_w=10000000;
		for(set<int>::iterator sit = s.begin(); sit != s.end(); sit++){
			for(set<int>::iterator tit = t.begin(); tit != t.end(); tit++){
				if(a[*sit][*tit] != -1 && a[*sit][*tit] < min_w){
					min_s = *sit;
					min_t = *tit;
					min_w = a[*sit][*tit];
				}
			}
		}
		s.erase(min_s);
		t.insert(min_s);
		ans += min_w;
	}
	printf("%d\n",ans);
	
	return 0;
}



Measured memory_bytes: 3232
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    lint n; cin>>n;
    vector<lint> a(5);
    REP(i,5){
        cin>>a[i];
    }
    sort(all(a));
    print((n+(a[0]-1))/a[0]+4);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
const long double dinf=10000000000000.0;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b;
cin>>a>>b;
cout<<max(0,a-2*b)<<endl;
}


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

string i_to_05b(unsigned int n){
	string s = "";
	do{
		char c = (n & 1U) + '0' ;
		s.push_back( c );
		n >>= 1;
	}while( n != 0 );

	while( s.size() < 5 ){
		s.push_back('0');
	}
	reverse( s.begin() , s.end() );
	
	return s;
}

void makeTable1(map<char,string>& table1){
	table1[' ']  = "101";
	table1['\''] = "000000";
	table1[',']  = "000011";
	table1['-']  = "10010001";
	table1['.']  = "010001";
	table1['?']  = "000001";
	table1['A']  = "100101";
	table1['B']  = "10011010";
	table1['C']  = "0101";
	table1['D']  = "0001";
	table1['E']  = "110";
	table1['F']  = "01001";
	table1['G']  = "10011011";
	table1['H']  = "010000";
	table1['I']  = "0111";
	table1['J']  = "10011000";
	table1['K']  = "0110";
	table1['L']  = "00100";
	table1['M']  = "10011001";
	table1['N']  = "10011110";
	table1['O']  = "00101";
	table1['P']  = "111";
	table1['Q']  = "10011111";
	table1['R']  = "1000";
	table1['S']  = "00110";
	table1['T']  = "00111";
	table1['U']  = "10011100";
	table1['V']  = "10011101";
	table1['W']  = "000010";
	table1['X']  = "10010010";
	table1['Y']  = "10010011";
	table1['Z']  = "10010000";
}

void makeTable2(map<string,char>& table2){
	char ch[6] = { ' ' , '.' , ',' , '-' , '\'' , '?' };
	for(char c = 'A' ; c <= 'Z' ; ++c){
		table2[ i_to_05b( (int)(c - 'A') ) ] = c;
	}
	for(int i = 0 ; i < 6 ; ++i ){
		table2[ i_to_05b( i+26 ) ] = ch[i];
	}
}

string encode(string p, map<char,string> table1){
	string c = "";
	for(int i=0 ; i<p.size() ; ++i ){
		c += table1[ p[i] ];
	}
	return c;
}
string decode(string c , map<string,char> table2){
	string p = "";
	while( c.size() % 5 != 0){
		c.push_back('0');
	}
	for(int i=0 ; i+5 <= c.size() ; i += 5 ){
		p.push_back( table2[ c.substr( i , 5 ) ] );
	}
	return p;
}

int main(){
	string p;
	map<char,string> table1;
	map<string,char> table2;
	makeTable1(table1);
	makeTable2(table2);

	while( getline( cin , p ) ){
		cout << decode( encode( p , table1 ) , table2 ) << endl;
	}
}

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

int main()
{
    // input
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }


    int count = 1;
    int i;
    // whether 1 exists
    bool oneExists = false;
    for (i = 0; i < N; i++) {
        if (a[i] == 1) {
            oneExists = true;
            break;
        }
    }
    if (oneExists == false) {
        cout << -1 << endl;
        return 0;
    }
    
    // when 1 exists
    for ( ; i < N; i++) {
        if(count + 1 == a[i]) {
            count++;
        }
    }
    cout << N - count << endl;

}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, ll> cnt;
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
        sum += cnt[a[i]]-1;
    }
    rep(i,n){
        ll ans = sum - cnt[a[i]] + 1;
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 11264
(defun count-RGB (s c)
  (let ((counter 0))
    (loop :for i :across s
          :do (if (string= i c) (incf counter)))
    counter))

(defun RGB-Triplets (n s)
    (let ((ans 0))
        (incf ans (* (count-RGB s "R") (count-RGB s "G") (count-RGB s "B")))
        (loop
            :for i :from 0 :to (- n 3)
            :do (loop
                    :for j :from i :to (- n 1)
                    :do (cond
                            ((/= (mod (- j i) 2) 0) ())
                            ((string= (char s i) (char s j)) ())
                            ((string= (char s i) (char s (/ (+ i j) 2))) ())
                            ((string= (char s j) (char s (/ (+ i j) 2))) ())
                            (t (decf ans)))))
        ans))

(princ (RGB-Triplets (read) (read-line)))

Measured memory_bytes: 77344
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

// matrix<集合> (集合, 加法における単位元, 加算, 乗算)
template<typename T>
struct matrix{
  function<T(T, T)> f, g;
  vector<vector<T>> mat;
  T unit;

  matrix(vector<vector<T>> v, T UNIT, function<T(T, T)> add_func,
  function<T(T, T)> multi_func):f(add_func), g(multi_func), unit(UNIT){
    mat = v;
  }

  matrix<T> t(){
    vector<vector<T>> ret(mat[0].size(), vector<T>(mat.size()));
    re(i, mat[0].size()) re(j, mat.size()) ret[i][j] = mat[j][i];
    return matrix<T>(ret, f, g);
  }

  matrix<T> operator * (matrix<T> B){
    vector<vector<T>> ret(mat.size(), vector<T>(B.mat[0].size(), unit));
    if(mat[0].size()!=B.mat.size()){
      std::cout << "matrix operator " << "*" << " error" << '\n';
      return matrix<T>(ret, unit, f, g);
    }
    re(i, mat.size()){
      re(j, B.mat[0].size()){
        re(k, mat[0].size()){
          ret[i][j] = f(ret[i][j], g(mat[i][k], B.mat[k][j]));
        }
      }
    }
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator * (ll num){
    vector<vector<T>> ret = mat;
    re(i, mat.size()) re(j, mat[0].size()) ret[i][j] *= num;
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator + (matrix<T> B){
    vector<vector<T>> ret = mat;
    if(mat.size()!=B.mat.size()||mat[0].size()!=B.mat[0].size()){
      std::cout << "matrix operator " << "+" << " error" << '\n';
      return matrix<T>(ret, unit, f, g);
    }
    re(i, mat.size()) re(j, mat[0].size()) ret[i][j] = f(mat[i][j], B.mat[i][j]);
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator ^ (ll num){
    matrix<T> ret(vector<vector<T>> (0, vector<T>(0)), unit, f, g);
    if(mat.size()!=mat[0].size()){
      std::cout << "matrix operator " << "^" << " error" << '\n';
      return ret;
    }
    matrix<T> tmp(mat, unit, f, g);
    bool flag = false;
    while(num>0){
      if(num%2){
        if(flag) ret = ret * tmp;
        else ret.mat = tmp.mat, flag = true;
      }
      num/=2, tmp = tmp * tmp;
    }
    return ret;
  }
  vector<T> & operator [](int n){
    return mat[n];
  }
};

#define P 1000000007
ll ad(ll a, ll b){return (a+b)%P;}
ll ml(ll a, ll b){return (a*b)%P;}

int main(){
  ll n;std::cin >> n;
  if(n<3){
    std::cout << 0 << '\n';
    return 0;
  }
  if(n==3){
    std::cout << 1 << '\n';
    return 0;
  }
  matrix<ll> A({{1}, {0}, {0}}, 0, ad, ml);
  matrix<ll> B({{1, 0, 1}, {1, 0, 0}, {0, 1, 0}}, 0, ad, ml);
  std::cout << ((B^(n-3)) * A)[0][0] << '\n';
}


Measured memory_bytes: 3592
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.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;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;


const ll MAX_V = 105;
struct edge {long long to, cap, rev; };  // 行き先、容量、逆辺

vector<edge> G[MAX_V];  // 隣接リスト表現
long long level[MAX_V];  // sからの距離
long long iter[MAX_V];  // どこまで調べたか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(long long from, long long to, long long cap) {
    G[from].push_back((edge){to, cap, (long long)G[to].size()});
    G[to].push_back((edge){from, 0, (long long)G[from].size()-1});
}

// sからの最短距離をBFSで計算
void bfs(long long s) {
    REP(i, MAX_V) level[i] = -1;
    queue<long long> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        long long v = que.front(); que.pop();
        for (int i=0; i<G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap>0 && level[e.to]<0) {
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスをDFSで探す
long long dfs(long long v, long long t, long long f) {
    if (v==t) return f;
    for (int i=iter[v]; i<G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap>0 && level[v]<level[e.to]) {
            long long d = dfs(e.to, t, min(e.cap, f));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
long long max_flow(long long s, long long t) {
    long long flow = 0;
    for (;;) {
        bfs(s);
        if (level[t] < 0) return flow;
        REP(i, MAX_V) iter[i] = 0;
        long long f;
        while ((f=dfs(s, t, HIGHINF))>0) flow += f;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n); REP(i, n) cin >> a[i];
    REP(i, n) {
        if (a[i] < 0) add_edge(0, i+1, -a[i]);
        else add_edge(i+1, MAX_V-1, a[i]);
    }
    rep(i, 1, n+1) {
        for (ll j=i; j<n+1; j+=i) {
            add_edge(i, j, HIGHINF);
        }
    }
    ll ans = 0;
    REP(i, n) if (a[i] > 0) ans += a[i];
    cout << ans - max_flow(0, MAX_V-1) << '\n';
    return 0;
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: chars,
    }
    let n = s.len();
    let mut dp = vec![vec![0; 4001]; 4001];
    dp[0][0] = 1;
    let mut r = 0;
    let mut b = 0;

    const MOD: usize = 998244353;

    for i in 0..n*2 {
        if i < n {
            match s[i] {
                '0' => {
                    r += 2;
                },
                '1' => {
                    r += 1;
                    b += 1;
                },
                '2' => {
                    b += 2;
                },
                _ => {}
            }
        }

        let k = i+1;
        for nr in 0..k+1 {
            let nb = k-nr;
            if !(nr <= r && nb <= b) {
                continue;
            }
            // debug!(i, nr, nb);

            if nr > 0 {
                dp[nr][nb] += dp[nr-1][nb];
            }
            if nb > 0 {
                dp[nr][nb] += dp[nr][nb-1];
            }
            dp[nr][nb] = dp[nr][nb] % MOD;
        }
    }

    let mut ans = 0;
    for nr in 0..2*n+1 {
        let nb = 2*n - nr;
        ans += dp[nr][nb];
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 151804
use proconio::input;

fn main() {
    input! {
        n: i64,
        m: usize,
        a: [i64; m],
    }

    let s: i64 = a.iter().sum();
    let ans = if s > n {
        -1
    } else {
        n - s
    };
    println!("{}", ans);
}


Measured memory_bytes: 2272
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define mo 1000000007
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,x,y,a[200005],vis[200005],gs1,gs2;
ll jc[200005],f[200005],d[200005],c[200005],e[200005],b[200005];
char s[200005];
int main()
{
    n=read();scanf("%s",s+1);jc[1]=1;reg int i,j;
    for(i=2;i<=n;++i)jc[i]=1ll*jc[i-1]*i%mo;
    if(s[1]=='W'){cout<<0<<"\n";return 0;}
    for(i=1;i<=n*2;++i)if(s[i]=='B')a[i]=1;f[1]=1;
    for(i=1;i<=n*2;++i)if(a[i]!=a[i-1])b[i]=1;
    for(i=2;i<=2*n;++i)
    {
        if(b[i]==0){if(f[i-1]==1)f[i]=2;else f[i]=1;}
        else{if(f[i-1]==1)f[i]=1;else f[i]=2;}
    }
    for(i=1;i<=2*n;++i)
    {
        if(f[i]==1)c[++gs1]=i;
        else d[++gs2]=i;
    }
    if(f[2*n]!=2||gs1!=n||gs2!=n){puts("0");return 0;}
    for(i=n,j=n;i>=1;--i)
    {
        while(d[j]>c[i])--j;
        e[i]=n-j;
    }
    reg ll ans=1;
    for(i=n;i>=1;--i)
    {
        ans=ans*(e[i]-(n-i))%mo;
    }
    cout<<ans*jc[n]%mo<<"\n";
	return 0;
}


Measured memory_bytes: 11264