akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const MAX: usize = 1000000000000000000;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let A: Vec<usize> = sc.vec(N);
    let mut ans = 1usize;
    for i in 0..N {
        if A[i] == 0 {
            println!("{}", 0);
            return;
        }
    }
    for i in 0..N {
        if let Some(res) = ans.checked_mul(A[i]) {
            ans = res;
        } else {
            println!("-1");
            return;
        }
        if ans > MAX {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll                 long long
#define LL                 long long
#define pii                pair<int, int>
#define pll                pair<ll, ll>
#define pil                pair<int, ll>
#define pli                pair<ll, int>
#define vi                 vector<int>
#define vl                 vector<ll>
#define vii                vector<pii>
#define vll                vector<pll>
#define vil                vector<pil>
#define vli                vector<pli>
#define pb                 push_back
#define mp                 make_pair
#define ff                 first
#define ss                 second
#define sz(x)              (int)x.size()
#define TN                 typename
#define all(v)             v.begin(), v.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define endl               '\n'
#define Int                in()
#define Long               Lin()
#define policy_set         tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define policy_multiset    tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", " ;
    err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

const int mod        = (int)1e9 + 7;
const ll  Mod        = (ll)1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}

const int inf        = (int)2e9 + 5;
const ll  Inf        = (ll)1e18 + 5;
const int N          = 2e5 + 5;



int solve() {
    string s;
    cin>>s;
    if (s[s.length()-1]=='s')
    {
    	cout<<s<<'e'<<'s'<<endl;
    }
    else
    	cout<<s<<'s'<<endl;
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int test = 1, tc = 0;
    //scanf("%d", &test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=0;i<n;i++){
      int k = scan.nextInt();
      if (i%2 != 0){
        continue;
      }
      if (k%2 == 1){
        sum += 1;
      }
    }
    System.out.println(sum);
  }
}


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

int main()
{
  string s; cin >> s;
  int n = s.size();
  string ans;
  for(int i = 0; i < n; i += 2)
  {
    ans += s[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>

using namespace std;

int main() {
	string s;
	int cnt; //1の数を数えるカウンター
	cin >> s;
	
	if(s[0] == '1') ++cnt;
	if(s[1] == '1') ++cnt;
	if(s[2] == '1') ++cnt;
	
	cout << cnt <<endl;
	
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
vector<string> s;
vector<vector<int>> d;
int dh[4] = {1,0,-1,0}, dw[4] = {0,1,0,-1};

//(sx, sy)からその他の点への最短経路を求める
int bfs(int sh, int sw){
    queue<P> que;
    rep(i,0,h-1)rep(j,0,w-1)d[i][j] = INF;
    que.push(P(sh,sw));
    d[sh][sw] = 0;
    while(!que.empty()){
        P p = que.front();que.pop();
        rep(i,0,3){
            //移動した後の点を(nx, ny)とする
            int nh = p.first + dh[i], nw = p.second + dw[i];

            //移動が可能かの判定とすでに訪れたことがあるかの判定
            //d[nx][ny]==INFなら未探索
            if(0<=nh && nh<h && 0<=nw && nw<w && s[nh][nw]!='#' && d[nh][nw]==INF){
                que.push(P(nh,nw));
                d[nh][nw]=d[p.first][p.second] + 1;
            }
        }
    }
    return 0;
}

int main(){

    cin >> h >> w;
    s.resize(h);
    d.resize(h);
    rep(i,0,h-1){
        cin >> s[i];
        d[i].resize(w);
    }
    int max_d=0,ans=0;
    rep(i,0,h-1)rep(j,0,w-1){
        if(s[i][j] == '#')continue;
        bfs(i,j);
        max_d = 0;
        rep(i,0,h-1)rep(j,0,w-1)if(d[i][j]!=INF)max_d = max(max_d,d[i][j]);
        ans = max(ans,max_d);
    }



    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i

puts 0
$stdout.flush
l_seat = gets.chomp
l = 0
r = n

20.times do
  mid = (l + r) / 2

  puts mid
  $stdout.flush
  mid_seat = gets.chomp
  exit if mid_seat == 'Vacant'

  if (mid - l).even? ^ (l_seat != mid_seat)
    l = mid
    l_seat = mid_seat
  else
    r = mid
  end
end


Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
main(){
  int n,ac,wa,lte,re;
  cin >>n;
  string S;
  ac=0;
  wa=0;
  lte=0;
  re=0;
  for(int i=0;i<n;i++){
    cin >> S;
    if(S=="AC"){
    ac++;
      continue;
    }
    if(S=="WA"){
    wa++;
      continue;
    }
    if(S=="TLE"){
    lte++;
      continue;
    }
    if(S=="RE"){
    re++;
      continue;
    }
  }
   cout<<"AC x "<<ac<<  endl;
     cout<<"WA x "<<wa<<  endl;
     cout<<"TLE x "<<lte<<  endl;
     cout<<"RE x "<<re<<  endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>

using namespace std;

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

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	if (S.at(K - 1) == 'A') {
		S.at(K - 1) = 'a';
	}
	else if (S.at(K - 1) == 'B') {
		S.at(K - 1) = 'b';
	}
	else {
		S.at(K - 1) = 'c';
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b) ((a)<(b) ? (a):(b))
static const int INFTY = (1<<29);
int dp[50010];
int main(void){
    int n,m,c[20];
    int i,j;

    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&c[i]);
    }

    dp[1]=1;
    for(i=2;i<=n;i++) dp[i]=INFTY;

    for(i=0;i<m;i++){
        for(j=0;j+c[i]<=n;j++){
            dp[j+c[i]]=min(dp[j+c[i]],dp[j]+1);
        }
    }

    printf("%d\n",dp[n]);

    return 0;
}

Measured memory_bytes: 788
#include<iostream>
#include<vector>

struct union_find{
  int n;
  std::vector<int> par;
  union_find(){}
  union_find(int _n):n(_n),par(n,-1){}
  int root(int k){
    if(par[k]<0)return k;
    return par[k] = root(par[k]);
  }
  void unite(int u,int v){
    u = root(u);
    v = root(v);
    if(u==v)return;
    par[u] += par[v];
    par[v] = u;
  }
  bool same(int u,int v){return root(u)==root(v);}
};

signed main(){
  int n,m;
  std::cin>>n>>m;
  std::vector<int> p(n);
  for(auto& pi:p)std::cin>>pi,pi--;
  union_find uni(n);
  for(int _=0;_<m;++_){
    int a,b;
    std::cin>>a>>b;
    a--;b--;
    uni.unite(p[a],p[b]);
  }
  int ans = 0;
  for(int i=0;i<n;++i)if(uni.same(p[i],i))ans++;
  std::cout<< ans <<std::endl;
}


Measured memory_bytes: 3996
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long[] h = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long max = 0;
            string res = "Yes";
            for (int i = 0; i < n; i++)
            {
                if (max>h[i])
                {
                    res = "No";
                    break;
                }
                max = Math.Max(max, h[i] - 1);
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 29404
#include <iostream>

using namespace std;

int main()
{
    int a , b , c;
    cin >> a >> b >> c;
    if (1 <= a && a <= 100 && 1 <= b && b <= 100 && 1 <= c && c <= 100)
    {
        if (a + b == c )
            cout << "Yes";
        else if ( a + c == b )
            cout << "Yes";
        else if ( b + c == a)
            cout << "Yes";
        else
            cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
class Node():
    def __init__(self, parent =None ,left =None ,right = None):
        self.parent = parent
        self.left = left
        self.right = right

def preorder_walk(i, tree_list):
    if i == -1:
        return
    print(' {}'.format(i),end='')
    preorder_walk(tree_list[i].left,tree_list)
    preorder_walk(tree_list[i].right,tree_list)

def inorder_walk(i, tree_list):
    if i == -1:
        return
    inorder_walk(tree_list[i].left,tree_list)
    print(' {}'.format(i),end='')
    inorder_walk(tree_list[i].right,tree_list)

def postorder_walk(i, tree_list):
    if i == -1:
        return
    postorder_walk(tree_list[i].left,tree_list)
    postorder_walk(tree_list[i].right,tree_list)
    print(' {}'.format(i),end='')

if __name__ == "__main__":
    n = int(input())

    tree_list = [Node(-1,-1,-1) for m in range(n)]
    for i in range(n):
        l = input().split()
        v = int(l[0])
        c_list = [int(l[m]) for m in range(1,len(l))]
        tree_list[v].left = c_list[0]
        tree_list[v].right = c_list[1]
        if c_list[0] != -1:
            tree_list[c_list[0]].parent = v
        if c_list[1] != -1:
            tree_list[c_list[1]].parent = v

    root = -1
    for i,t in enumerate(tree_list):
        if t.parent == -1:
            root = i
            break

    print('Preorder')
    preorder_walk(root,tree_list)
    print()
    print('Inorder')
    inorder_walk(root,tree_list)
    print()
    print('Postorder')
    postorder_walk(root,tree_list)
    print()




Measured memory_bytes: 5624
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define ret return 
#define elif else if
#define p(x) cout<<x<<endl;
ll inf=100001;
using namespace std;
int main(){
	while(1){
	ll n;cin>>n;ll a[n],b[n];
	r(i,n){
		cin>>a[i];b[i]=a[i];
		a[i]=a[i]-i;
		}
	sort(a,a+n);ll ans=0;
	// OPTIMAL VAL==a[n/2]
	r(i,n){
		ans+=abs(a[i]-a[n/2]);
	}p(ans)ret 0;
	}	
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r ;
    
    if ((x -r) < 0 || (x + r) >W){
        cout << "No" << endl;
    }else if ((y-r) < 0 || (y+ r)> H){
        cout << "No" << endl;
    }else if ((x-r)>=0 && (x+r)<=W){
        cout << "Yes" << endl;
    }else if ((y-r)>=0 && (y+r) <=H){
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
#define yes cout<<"Yes";
#define no cout<<"No";
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  string s;
  cin>>s;
  if(s=="RRR") cout<<3;
else if(s=="RRS"||s=="SRR") cout<<2;
else if(s=="SSS") cout<<0;
else cout<<1;
return 0;
}


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

bool used[10][10];

int main() {/*
#ifdef __linux__
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
    //freopen("cowrun.in", "r", stdin); freopen("cowrun.out", "w", stdout);
#endif*/
    ios::sync_with_stdio(0); //cin.tie(NULL); cout.tie(NULL);

    int n, m;
    cin >> n >> m;

    char a[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int x = 0, y = 0;

    if (a[x][y] != '#') {
        cout << "Impossible\n";
        return 0;
    }

    bool fl = true;

    while (true) {
        used[x][y] = true;
        if (x == n - 1 && y == m -1) {
            break;
        }
        if (x < n - 1 && a[x + 1][y] == '#') x++;
        else if (y < m - 1 && a[x][y + 1] == '#') y++;
        else {
            fl = false;
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '#' && !used[i][j]) {
                fl = false;
                break;
            }
        }
    }

    if (fl) {
        cout << "Possible\n";
    } else {
        cout << "Impossible\n";
    }

    return 0;
}

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

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

void qread(int &x){
	int neg=1;x=0;
	char c=getchar(); 
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	int test;
	scanf("%d",&test);
	while(test--){
		ll A,B,C,D,a,b,c,d,mx;
		scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
		a=A%B,b=D%B,c=gcd(B,b),d=(B-1-a)/c,mx=a+d*c;
		puts((A<B||mx>C||B>D)?"No":"Yes"); 
	}
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int h, w;
  scanf("%d %d", &h, &w);

  vector<string> grid(h);

  REP (i, h) {
    cin >> grid[i];
  }

  int d[5] = {1, 0, -1, 0, 1};

  REP (i, h) {
    REP (j, w) {
      if (grid[i][j] == '#') {
        bool flag = false;
        REP (k, 4) {
          int dx = j + d[k + 1];
          int dy = i + d[k];
          if (0 <= dx && dx < w && 0 <= dy && dy < h && grid[dy][dx] == '#') {
            flag = true;
          }
        }
        if (!flag) {
          printf("No\n");
          exit(0);
        }
      }
    }
  }
  printf("Yes\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,a,b;
  cin >> n >> a >> b;
  vector<int> h(n);
  REP(i,n) cin >> h[i];

  sort(ALL(h));

  int ng = 0, ok = h[n-1]/b+1;
  while(abs(ok-ng) > 1) {
    ll mid = (ok+ng)/2;
    ll key = mid * b;
    auto it = upper_bound(ALL(h), key);

    ll sum = mid;
    for (int j = it-h.begin(); j < n; j++) {
      ll nh = h[j]-key;
      sum -= nh/(a-b) + (nh%(a-b) > 0);
    }

    if (0 <= sum) ok = mid;
    else ng = mid;
  }

  COUT(ok);
  return 0;
}

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


int main(){
	int N;
	cin >> N;
	vector<int> T(N);
	int res = 0;
	rep(i,N){
		cin >> T[i];
		res += T[i];
	}
	int M;cin >> M;
	rep(i,M){
		int P, X;cin >> P >> X;
		int ans = res - T[P-1] + X;
		cout << ans << endl;
	}
	return 0;

}












Measured memory_bytes: 3624
from collections import deque

N, Q = map(int, input().split())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
PX = [tuple(map(int, input().split())) for _ in range(Q)]
counter = [0] * (N + 1)
for px in PX:
    p, x = px
    counter[p] += x

q = deque()
visited = [-1] * (N+1)
visited[1] = 1
q.append(1)

while q:
    parent = q.pop()
    nodes = graph[parent]
    for node in nodes:
        if visited[node] == -1:
            visited[node] = 1
            q.append(node)
            counter[node] += counter[parent]

for i in range(1, N+1):
    print(counter[i], end=' ')

Measured memory_bytes: 80288
A,B,M = map(int,input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = map(int,input().split())
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)

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

const long long MOD = 1000000007;

void solve(long long N, long long K, std::vector<long long> a){
    ll dp[N][K+1] = {};
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<=K;j++){
            // cerr << "i=" << i << "j=" <<j << endl;
            if(i == N-1){
                if(j<=a[i]){
                    dp[i][j] =1;
                }
                continue;
            }
            if(j==0){
                dp[i][j] = 1;
                continue;
            }
            if(j<=a[i]){
                dp[i][j] = (dp[i][j-1] + dp[i+1][j])%MOD;
                continue;
            }
            dp[i][j] = (dp[i][j-1] -dp[i+1][j-a[i]-1] +  dp[i+1][j]+MOD)%MOD;
        }
    }

    // for(int i=N-1;i>=0;i--){
    //     for(int j=0;j<=K;j++){
    //         cerr << "i=" << i << "j=" << j << "val=" << dp[i][j] << endl;
    //     }
    // }

    cout << dp[0][K]%MOD << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M;
    cin >> N >> M;
    ll D[N];
    D[0] = 0;
    rep(i, N-1){
        ll A; cin >> A;
        D[i+1] = D[i]+A;
    }
    ll B[M][N];
    rep(j, N){
        rep(i, M) cin >> B[i][j];
    }
    vector<vector<ll>> cnt(N+1, vector<ll>(N+1, 0));
    vector<pli> v;
    set<int> s;
    set<int>::iterator it;;
    rep(i, M){
        rep(j, N) v.pb(pli(B[i][j], j));
        sort(all(v), greater<pli>());
        s.insert(-1), s.insert(N);
        rep(j, N){
            int m = v[j].second;
            it = s.upper_bound(m);
            int r = *it--, l = *it+1;
            s.insert(m);
            cnt[l][r] += v[j].first;
            cnt[l][m] -= v[j].first;
            cnt[m+1][r] -= v[j].first;
        }
        v.clear(), s.clear();
    }
    rep(j, N+1){
        rep2(i, 1, j) cnt[i][j] += cnt[i-1][j];
    }
    ll ans = 0;
    rep(i, N){
        ll now = 0;
        rep3(j, N, i+1){
            now += cnt[i][j];
            chmax(ans, now-D[j-1]+D[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 207320
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int q1 = sc.nextInt();
			if (q1==0) {
				break;
			}
			int b = sc.nextInt();
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			int q2 = sc.nextInt();
			int aizuJMax = min(q2,b/c1);
			if (aizuJMax<1) {
				System.out.println("NA");
				continue;
			}
			int ans1 = 0,ans2 = 0;
			for (int aj = 1;aj <= aizuJMax;aj++) {
				int tori = (b - (aj * c1))/c2;
				if (tori+aj>=q1) {
					ans1 = aj;
					ans2 = tori;
				}else{
					break;
				}
			}
			if (ans1+ans2>0) {
				System.out.println(ans1+" "+ans2);
			}else{
				System.out.println("NA");
			}
		}
	}
	public static int min(int a,int b) {
		return a<b ? a : b;
	}
}

Measured memory_bytes: 18236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    ll N; cin>>N;
    if(N<105){cout<<0<<endl;return 0;}
    else{
        ll ans=0; ll cnt=0;
        for(int j=1;j<N+1;j+=2){
            for(int i=1;i<j+1;i+=2){
                if(j%i==0){
                    cnt++;
                    //cout<<cnt<<endl;
                }
            }
            if(cnt==8)ans++;
            cnt=0;
        }
        cout<<ans<<endl;
        return 0;
    }
}

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

int main() {
    int n,ans = 0;
    cin >> n;
    vector<long long> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    long long s = 0;
    vector<long long> v;
    rep(i,n){
        if (a[i] < b[i]){
            s+=b[i]-a[i];
            ans++;
        }
        else v.push_back(a[i]-b[i]);
    }
    if (ans){
        sort(v.begin(),v.end(),greater<>());
        long long ds = 0;
        rep(i,v.size()){
            s-=v[i];
            ans++;
            if (ds >= s) break;
        }
        if (ds < s) cout << -1 << endl;
        else cout << ans << endl;
    }
    else cout << 0 << endl;
}

Measured memory_bytes: 5764
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,sum=0;
    cin>>n;
    vector<long long> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        sum+=v[i];
    }
    sort(v.begin(),v.end());
    cout<<v[0] << " " << v[n-1] << " " << sum <<endl;
}


Measured memory_bytes: 3192
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    vector<int> l (n);
    F0R(i, n) cin >> l[i];
    vector<int> b (5e6, 0);
    b[0]++;
    int prev = 0;
    F0R(i, sz(l))
    {
        b[l[i] + prev]++;
        prev += l[i];
    }
    ll res = 0;
    F0R(i, x + 1)
    {
        res += b[i];
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 19840
S = input()
Q = int(input())

reverse = False
add = [[], []]

for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        reverse = not reverse
    else:
        add[reverse ^ (int(query[1]) - 1)].append(query[2])

if reverse:
    ans = ''.join(add[1][::-1]) + S[::-1] + ''.join(add[0])
else:
    ans = ''.join(add[0][::-1]) + S + ''.join(add[1])
print(ans)

Measured memory_bytes: 6216
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    if 0 in A:
        print(0)
        exit()
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)

main()


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

void extgcd(ll a, ll b, ll &x, ll &y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return;
  }
  extgcd(b, a%b, y, x);
  y -= a/b*x;
  return; 
}

ll mod_inverse(ll a, ll m) {
  ll x, y;
  extgcd(a,m,x,y);
  return (m + x % m) % m;
}

int main(){
  int n;
  cin >> n;
  ll x[n];
  rep(i,n) cin >> x[i];
  ll ans = 0;
  ll s = 0;
  for(ll i = 1; i < n; i++) {
    s += mod_inverse(i,mod);
    (ans += (x[i]-x[i-1])*s) %= mod;
  }
  for(ll i = 1; i < n; i++) (ans *= i) %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
ignore = input()
l = map(int, raw_input().split())
temp = []
counter = 0
if ignore == 1:
    print 1, 1
    exit()
for i in range(len(l)):
    if (1 <= l[i] <= 399) and ("Grey" not in temp):
        temp.append("Grey")
    elif (400 <= l[i] <= 799) and ("Brown" not in temp):
        temp.append("Brown")
    elif (800 <= l[i] <= 1199) and ("Green" not in temp):
        temp.append("Green")
    elif (1200 <= l[i] <= 1599) and ("Water" not in temp):
        temp.append("Water")
    elif (1600 <= l[i] <= 1999) and ("Blue" not in temp):
        temp.append("Blue")
    elif (2000 <= l[i] <= 2399) and ("Yellow" not in temp):
        temp.append("Yellow")
    elif (2400 <= l[i] <= 2799) and ("Turq" not in temp):
        temp.append("Turq")
    elif (2800 <= l[i] <= 3199) and ("Red" not in temp):
        temp.append("Red")
    elif (l[i] >= 3200):
        counter+=1
if counter == 0:
    print len(temp), len(temp)
elif len(temp) == 0:
    print 1 , (len(temp) + counter)
else:
    print len(temp), (len(temp) + counter)


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

int main(){
  int N;
  cin >> N;
  if(N>=100000){
    cout << 90909 << endl;
  }else if(N>=10000 && N<100000){
    cout << N-10000+1+909 << endl;
  }else if(N>=1000 && N<10000){
    cout << 909 << endl;
  }else if(N>=100 && N<1000){
    cout << N-100+1+9 << endl;
  }else if(N>=10 && N<100){
    cout << 9 << endl;
  }else if(N>=0 && N<10){
    cout << N << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define WMAX 1000000
#define WMIN 0


typedef struct _P{
	int x;
	int y;
}POINT;
POINT BASE[200];
POINT TRGT[1000];



int main(){
	int m,n;
	int x,y;
	int i;
	int xmax,xmin,ymax,ymin;
	int xdiff,ydiff;
	int j,k;
	int cnt,cnt0;
	while(1){
		scanf("%d\n",&m);
		if(!m)break;
		xmax=xmin=ymax=ymin=0;
		for(i=0;i<m;i++){
			scanf("%d %d\n",&x,&y);
			BASE[i].x=x;
			BASE[i].y=y;
			if(x<=xmin)xmin=x;
			if(x>=xmax)xmax=x;
			if(y<=ymin)ymin=y;
			if(y>=ymax)ymax=y;
		}
		scanf("%d\n",&n);
		for(i=0;i<n;i++){
			scanf("%d %d\n",&x,&y);
			TRGT[i].x=x;
			TRGT[i].y=y;
		}
		xdiff=ydiff=0;
		//search one by one;
		for(i=0;i<n;i++){
			xdiff=TRGT[i].x-BASE[0].x;
			ydiff=TRGT[i].y-BASE[0].y;
			if(xmax+xdiff<=WMAX && ymax+ydiff<=WMAX && xmax+xdiff>=WMIN && ymax+ydiff>=WMIN){
				cnt=1;
				for(j=1;j<m;j++){
					cnt0=0;
					for(k=0;k<n;k++){
						if(BASE[j].x+xdiff==TRGT[k].x && BASE[j].y+ydiff==TRGT[k].y){
							cnt++;
							cnt0++;
						}
					}
					if(cnt0==0)break;
				}
			}
			if(cnt==m)break;
		}
		printf("%d %d\n",xdiff,ydiff);
	}
	return 0;
}

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


int main () {

 int N,ans=0,tmp=0;
 cin >> N;
 char S[N];
 for(int i = 0; i < N; i++) {
  cin >> S[i];
 }

 for(int i = 0; i < N; i++) {
  if(S[i] == 'I') {
   tmp ++;
  }else if(S[i] == 'D') {
   tmp --;
  }
  ans = max(ans,tmp);
 }
 
 cout << ans << endl;


 return 0;
}

Measured memory_bytes: 256
var main = (lines) => {
	var [N,Vs,Cs] = lines.map(x=>x.split(" ").map(Number))
    const profits = Vs.map((x,i)=>{
      return x-Cs[i] > 0 ? x-Cs[i] : 0
    }).reduce((acc,x)=>acc+x)
    console.log(profits)
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Measured memory_bytes: 7372
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <string>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  for (int i = 0; i <= 10000; ++i) {
    int i8 = i * 8 / 100;
    int i10 = i * 10 / 100;
    if (i8 == a && i10 == b)
      return !printf("%d\n", i);
  }
  puts("-1");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    ll n=in(),k=in();
    ll ans=0;
    if(k==0){
        cout<<n*n<<endl;
        return 0;
    }
    rep2(b,k+1,n){
        ans+=n/b*(b-k)+max(0ll,n%b-k+1);
    }
    cout<<ans<<endl;
}


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

int main(){
	int N;
	cin >> N;
	int L[N], sum = 0, mx = 0;
	for(int i=0; i<N; i++){
		cin >> L[i];
		sum += L[i];
		if(mx < L[i]){
			mx = L[i];
		}
	}
	if(sum - mx > mx){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
imos = [[0 for i in range(k)] for j in range(k)]
white = 0
for i in range(n):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    if c == "W":
        c = 1
    else:
        c = 0
    x %= 2*k
    y %= 2*k

    if x > k-1:
        x -= k
        c += 1
    if y > k-1:
        y -=k
        c += 1
    c %= 2

    if c == 1:
        white += 1
        imos[x][y] -= 1
    else:
        imos[x][y] += 1

for i in range(k):
    for j in range(k-1):
        imos[i][j+1] += imos[i][j]

for j in range(k):
    for i in range(k-1):
        imos[i+1][j] += imos[i][j]

ans = 0
for i in range(k):
    for j in range(k):
        exp = imos[k-1][k-1] - imos[k-1][j] - imos[i][k-1] + 2 * imos[i][j] + white
        ans = max(ans, max(exp, n - exp))

print(ans)

Measured memory_bytes: 59868
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int i, cnt = 0;
	string s;
	cin >> s;
	for (i = 0; i < s.size() - 1; i++){
		if (s[i] != s[i + 1]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

Int iceil(Int x, Int y) {
    return (x + y - 1) / y;
}

int main() {
    Int n, d;
    std::cin >> n >> d;
    std::cout << iceil(n, d * 2 + 1) << std::endl;
    return 0;
}


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

using namespace std;
using ll  = long long;
using vll = vector<ll>;

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

    int n, m;
    ll  k;
    cin >> n >> m >> k;

    int ai, bi;
    vll prea(n + 1), preb(m + 1);

    for (int i = 1; i <= n; i++)
    {
        cin >> ai;
        prea[i] += (prea[i - 1] + ai);
    }

    for (int i = 1; i <= m; i++)
    {
        cin >> bi;
        preb[i] += (preb[i - 1] + bi);
    }

    int j = m, ans = 0;
    for (int i = 0; i <= n; i++)
    {
        while (j > 0 and preb[j] + prea[i] > k)
            --j;
        if (prea[i] + preb[j] <= k)
            ans = max(ans, i + j);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6332
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t, n,k,m,a,b;char c;
    cin>>n>>m>>k;char A[n+1][m+1];
    int ans=0,count=0,c1=0,c2=0,c3,l=0,L;vi R(n+1,0),C(m+1,0);
    rep(i,1,n+1){
        rep(j,1,m+1){
            cin>>c;A[i][j]=c;
            if(c=='#'){count++;R[i]++;C[j]++;}
        }
    }
    if(count<k)cout<<0;
    else{
        int l1=(2<<(n-1))-1,l2=(2<<(m-1))-1;
        rep(i,0,l1+1){
            rep(j,0,l2+1){
                a=j;b=i;l=1;c1=0,c2=0,c3=0;
                while(a){
                    if(a%2){c1+=C[l];}
                    l++;a/=2;
                }
                l=1;
                while(b){
                    if(b%2){c2+=R[l];}
                    l++;b/=2;
                }
                a=j;b=i;l=1;L=1;
                while(b){
                    L=1;a=j;
                    if(b%2){
                        while(a){
                            if(a%2){if(A[l][L]=='#')c3++;
                            }
                            a/=2;L++;
                        }
                    }
                    b/=2;l++;
                }
                if(count-(c1+c2-c3)==k)ans++;
                //cout<<i<<" "<<j<<" "<<ans<<" "<<c1<<" "<<c2<<' '<<c3<<"\n";
            }
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3604
#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];
  int ans=0;
  for(int i=0;i<n;i++)ans+=a[i]-1;
  cout<<ans<<endl;
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, t;
ll os, es, res;
vl a;
vi od, ev, need, ans;

void solve() {
	bool ud = true;
	while (ud) {
		ud = false;
		while (!need[0]) ans.pb(1), need.erase(need.begin()), ud = true;
		while (!need[need.size()-1]) ans.pb(need.size()), need.erase(need.end()-1), ud = true;
		reps(i,1,need.size()-1) {
			if ((need[i-1] && need[i+1]) || (!need[i] && !need[i-1] && !need[i+1])) {
				ud = true;
				if (need[i-1] && need[i+1]) need[i] = 1;
				need.erase(need.begin()+i+1), need.erase(need.begin()+i-1);
				ans.pb(i+1);
				break;
			}
		}
	}
}

signed main() {
	cin >> n;
	a.resize(n), need.resize(n);
	rep(i,n) {
		cin >> a[i];
		if (a[i]<=0) continue;
		if (i%2==0) os += a[i], od.pb(i);
		else es += a[i], ev.pb(i);
	}
	if (od.empty() && ev.empty()) {
		int mx = -inf, mi = 0;
		rep(i,n) if (mx<a[i]) mx = a[i], mi = i;
		need[mi] = 1;
		res = mx;
	} else if (os<es) {
		each(i,ev) need[i] = 1;
		res = es;
	} else {
		each(i,od) need[i] = 1;
		res = os;
	}
	cout << res << ln;
	solve();
	cout << ans.size() << ln;
	each(i,ans) cout << i << ln;
}

Measured memory_bytes: 256
#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);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<pair<int, int>> rng(n);
		for(int i=0; i < n; i++){
			int x, l;
			cin >> x >> l;
			rng[i] = make_pair(x+l, x-l);
		}
		sort(rng.begin(), rng.end());
		int ans = 0;
		int p = numeric_limits<int>().min();
		for(int i=0; i < n; i++){
			if(rng[i].second >= p){
				ans++;
				p = rng[i].first;
			}
		}
		cout << ans << "\n";
		
		
		return;
	};
};

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  while(cin>>n>>m,n){
    vector<Int> a(n);
    for(Int i=0;i<n;i++) cin>>a[i];
    Int ans=0;

    set<Int> s;
    s.emplace(0);
    for(Int i=0;i<n;i++){
      if(i){
	s.emplace(a[i-1]);
	a[i]+=a[i-1];
      }
      a[i]%=m;
      chmax(ans,a[i]);
      if(s.upper_bound(a[i])!=s.end()){
	Int k=*s.upper_bound(a[i]);
	chmax(ans,(a[i]+m-k)%m);
      }
    }

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



Measured memory_bytes: 4420
#include <cstdio>

int n;
int v[9];
int ans;

int color(int r){
	if(r < 400) return 0;
	if(r < 800) return 1;
	if(r < 1200) return 2;
	if(r < 1600) return 3;
	if(r < 2000) return 4;
	if(r < 2400) return 5;
	if(r < 2800) return 6;
	if(r < 3200) return 7;
	return 8;
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i){
		int a;
		scanf("%d", &a);
		++v[color(a)];
	}
	for(int i=0; i<8; ++i)
		if(v[i] > 0)
			++ans;
	if(v[8] == 0) printf("%d %d\n", ans, ans);
	else{
		if(ans > 0) printf("%d %d\n", ans, ans+v[8]);
		else printf("1 %d\n", ans+v[8]);
	}
}

Measured memory_bytes: 128
N = int(input())
D_list = list(tuple(map(int, input().split())) for _ in range(N))
i = 0
for d1, d2 in D_list:
    if d1 == d2:
        i += 1
    else:
        i = 0
    if i > 2:
        break
    
print('Yes' if i > 2 else 'No')


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

using namespace std;

int main() {
	long long n, m, d;
	cin >> n >> m >> d;
  double ans = 2.0 * (n - d) * (m - 1) / (1.0 * n * n);
  if(d == 0) ans /= 2.0;
  printf("%.10f\n", ans);
}

Measured memory_bytes: 256