akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,a[maxn];
int main()
{
    int i,j;
    scanf("%d",&n);
    ll ret=0,ok=0;
    rep(i,1,n)scanf("%d",&a[i]),ret+=a[i],ok+=i;
    if(n==1)return 0*puts("YES");
    if(ret%ok!=0)return 0*puts("NO");
    ll x=ret/ok;
    rep(i,1,n)if(x>a[i])return 0*puts("NO");
    ll p=0;
    rep(i,1,n-1)
    {
        ll q=a[i]-a[i+1],qq=(q+x)/n;;
        if(qq*n-x!=q)return 0*puts("NO");
        if(qq<0||qq>x)return 0*puts("NO");
        p+=qq;
    }
    ll q=a[n]-a[1],qq=(q+x)/n;
    if(qq*n-x!=q)return 0*puts("NO");
    if(qq<0||qq>x)return 0*puts("NO");
    p+=qq;
    if(p!=x)return 0*puts("NO");
    puts("YES");
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<set>

using namespace std;

int n, x, biras;
set <int> s;

void f () {
	if (1<=x && x<=399) {
		s.insert(1);
	} else if (400<=x && x<=799) {
		s.insert(2);
	} else if (800<=x && x<=1199) {
		s.insert(3);
	} else if (1200<=x && x<=1599) {
		s.insert(4);
	} else if (1600<=x && x<=1999) {
		s.insert(5);
	} else if (2000<=x && x<=2399) {
		s.insert(6);
	} else if (2400<=x && x<=2799) {
		s.insert(7);
	} else if (2800<=x && x<=3199) {
		s.insert(8);
	} else {
		biras++;
	}
}

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> x;
		f();
	}
	int br=s.size();
	if (br>0) {
		cout << br << " ";
		cout << biras+br;
	} else {
		cout << 1 << " ";
		cout << biras;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

int main() {
  string s; cin >> s;
  
  ll ans = 0LL;
  REP(i, bit(s.size()-1)){
    vector<string> v;
    for(int j=0, k=0; j<(int)s.size(); j++){
      if((i >> j) & 1) {
        v.push_back(s.substr(k, j-k+1));
        k = j + 1;
      }

      if(j == (int)s.size() - 1) v.push_back(s.substr(k, s.size()-k));
    }

    ans += accumulate(v.begin(), v.end(), 0LL, [](ll cum, string x){
      return cum + stol(x);
    });
  }

  cout << ans << endl;

  return 0;
}


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

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll t=ppow(2,MOD-2);
ll calc(ll h,ll w){
	ll a=(0+h-1)*h%MOD*t%MOD;
	return (a+(a+h*(w-1)%MOD))*w%MOD*t%MOD;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
			inv[i]=ppow(fact[i],MOD-2);
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
int main(){
	int n,m,K;cin>>n>>m>>K;
	ll sum=0;
	Fact fac(n*m);
	rep(i,n)rep(j,m){
		(sum+=calc(i+1,j+1)+calc(n-i,j+1)+calc(i+1,m-j)+calc(n-i,m-j))%=MOD;
		ll a=(calc(1,i+1)+calc(1,j+1)+calc(1,n-i)+calc(1,m-j))%MOD;
		sum=(sum+MOD-a)%MOD;
	}
	(sum*=t)%=MOD;
	//~ cout<<sum<<' '<<fac.nCr(n*m,K-2)<<endl;
	cout<<sum*fac.nCr(n*m-2,K-2)%MOD<<endl;
}

Measured memory_bytes: 6528
# C
import copy
n = int(input())
preX = [0,0,0]
ans = True
for i in range(n):
    curX = list(map(int, input().split()))
    dt = curX[0] - preX[0]
    dx = abs(curX[1] - preX[1])
    dy = abs(curX[2] - preX[2])
    if dt < dx + dy  or (dt % 2) != ((dx + dy) % 2):
        ans = False
    preX = copy.copy(curX)
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	s := getRunes()

	ans := 0
	for i := 1; i < n; i++ {
		if s[i] == 'E' {
			ans++
		}
	}

	now := ans
	for i := 1; i < n; i++ {
		if s[i-1] == 'W' {
			now++
		}
		if s[i] == 'E' {
			now--
		}

		ans = min(ans, now)
	}

	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	buf := 300001
	sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,L;
const int MN=100;
int x[MN+1],y[MN+1];
int ranp[MN][MN+1];
int dp[MN+2][MN+2];
int inf = 1e9;
int main(){
	cin>>N>>L;
	rep(i,N) cin>>x[i]>>y[i];
	x[N]=inf;
	rep(l,N){
		for(int r=l+1;r<=N;r++){
			int usep = 0;
			int nowx = x[l];
			for(int v=l;v<r;v++){
				int need = max(0,y[v]-nowx);
				usep+=need;
				nowx = max(0,x[v+1]-need);
			}
			ranp[l][r]=usep;
		}
	}
	rep(i,N+2) rep(j,N+2) dp[i][j]=inf;
	dp[0][0]=0;
	rep(i,N) rep(k,N+1) if(dp[i][k]!=inf){
		chmin(dp[i+1][k],dp[i][k]);
		for(int r=i+1;r<=N;r++){
			int ni = r+1;
			chmin(dp[ni][k+(r-i)],dp[i][k]+ranp[i][r]);
		}
	}
	int ans = 0;
	rep(i,N+2) rep(k,N+2) if(dp[i][k]<=L) chmax(ans,k);
	cout<<ans<<endl;
}

Measured memory_bytes: 3152
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
    int x;
    _Bool isPrime = 1;
    scanf("%d", &x);
    while (1) {
        isPrime = 1;
        for (int i = 2; i <= sqrt(x); i++) {
            if ((x % i) == 0) {
                isPrime = 0;
                break;
            }
        }
        if (isPrime) {
            break;
        }
        x++;
    }
    printf("%d", x);
    return 0;
}

Measured memory_bytes: 128
function Main(input){
  var inp = input.split('\n');  // Windows版Nodejsでは \n -> \r\nにする
  var s = inp[0].split('');
  var t = inp[1].split('');

  var sortS = s.sort((a, b) => {
    return a < b ? -1 : 1;
  });
  sortS = sortS.join('');

  var sortT = t.sort((a, b) => {
    return a < b ? 1 : -1;
  });
  sortT = sortT.join('');
  
  sortS < sortT ? console.log('Yes') : console.log('No');
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22208
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        cc: [Chars;h]
    }
    let mut res = 0;
    for hb in 0..(1u64 << h) {
        for wb in 0..(1u64 << w) {
            let mut cnt = 0;
            for i in 0..h {
                for j in 0..w {
                    if hb & (1 << i) == 0 &&
                       wb & (1 << j) == 0 &&
                       cc[i][j] == '#' {
                       cnt += 1;
                    }
                }
            }
            if cnt == k {
                res += 1;
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2196
A, B, M = map(int, input().split())

a = list(map(int, input().split())) 
b = list(map(int, input().split()))

ans = min(a) + min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x - 1] + b[y - 1] - c)

print(ans)

Measured memory_bytes: 18736
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
// 他人の提出を参考に
#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int a[1000][1000], x[1000001], y[1000001];
int f[1000][1000] = {};

int main(){
    int h, w;
    cin >> h >> w;
    int a[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
            x[a[i][j]] = i;
            y[a[i][j]] = j;
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            bool ok = true;
            for(int k = 0; k < 4; k++){
                int ni = i+di[k], nj = j+dj[k];
                if(inRange(ni,0,h)&&inRange(nj,0,w)&&a[ni][nj]<a[i][j]) ok = false;
            }
            if(ok)  f[i][j] = a[i][j];
        }
    }
    int ans = 0;
    for(int i = 1; i <= h*w; i++){
        for(int k = 0; k < 4; k++){
            int ni = x[i]+di[k], nj = y[i]+dj[k];
            if(inRange(ni,0,h)&&inRange(nj,0,w)&&a[ni][nj]<a[x[i]][y[i]]){
                if(f[x[i]][y[i]] == 0)  f[x[i]][y[i]] = f[ni][nj];      // 新しく逆フローを流す
                else if(f[x[i]][y[i]] != f[ni][nj]) f[x[i]][y[i]] = -1; // 既に別の場所から逆フローが流れてきている...!
            }
        }
        if(f[x[i]][y[i]] == -1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] > C[i]) {
            sum += V[i] - C[i];
        }
    }
    cout << sum << endl;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

bool is_nCk_odd(ll n, ll k) { return (n & k) == k; }

int main() {
source:
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll a[n];
    rep(i, n) { a[i] = s[i] - '1'; }
    bool is_odd = false;
    rep(i, n) {
        if (a[i] % 2 == 0) {
            continue;
        }
        is_odd ^= is_nCk_odd(n - 1, i);
    }
    if (is_odd) {
        cout << 1 << endl;
        return 0;
    }

    bool one_exist = false;
    rep(i, n) {
        if (a[i] == 1) {
            one_exist = true;
        }
    }
    if (one_exist) {
        cout << 0 << endl;
        return 0;
    }

    rep(i, n) { a[i] /= 2; }

    is_odd = false;
    rep(i, n) {
        if (a[i] % 2 == 0) {
            continue;
        }
        is_odd ^= is_nCk_odd(n - 1, i);
    }
    if (is_odd) {
        cout << 2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}



Measured memory_bytes: 9220
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
//typedef long long int LL;
//typedef __int64 LL;

char S[1000];

int main()
{
	scanf("%s", S);
	int len = strlen(S);
	int flag = 0;
	for (int i = 0; i < len; i++) {
		for (int j = i + 1; j < len; j++) {
			if (S[i] == 'C' && S[j] == 'F')
				flag = 1;
		}
	}
	printf("%s\n", flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 384
import sys
input()
pt, px, py = 0, 0, 0
for e in sys.stdin:
    ct, cx, cy = map(int, e.split())
    d = (ct - pt) - abs(cx - px) - abs(cy - py)
    if d < 0 or d % 2 == 1:
        print('No')
        break
    pt, px, py = ct, cx, cy
else:
    print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <map>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main()
{
    int n, m;
    cin >> n >> m;
    string ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            string s;
            cin >> s;
            if(s=="snuke"){
                cout << ch[j] << i + 1 << endl;
                return 0;
            }
        }
        }
    
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int n;

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

Measured memory_bytes: 128
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    vector<int> a;
    int temp;
    for(int i=0; i!=N; i++){
        scanf("%d", &temp);
        a.push_back(temp);
    }
    sort(a.begin(), a.end());
    printf("%d\n", a[a.size()-1]-a[0]);
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n;
  cin >> n;
  vector<vector<P>> g(n);
  rep(i,n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(make_pair(b, i));
    g[b].emplace_back(make_pair(a, i));
  }
  vector<int> color(n - 1, 0);

  auto dfs = [&](auto& f, int u, int p, int pc)->void{
    int c = 1;
    for (auto e : g[u]) {
      int v = e.first, id = e.second;
      if (p == v) continue;
      if (c == pc) c++;
      color[id] = c;
      f(f, v, u, c);
      c++;
    }
  };
  dfs(dfs, 0, -1, 0);
  cout << *max_element(color.begin(), color.end()) << endl;
  for (auto e : color) cout << e << endl;
  return 0; 
} 


Measured memory_bytes: 12136
char s[9999],c,d;
i;
main(){
	for(;c=~getchar();){
		if(~c<33){
			s[i++]='0'+d;
			d=0;
			if(~c==10)
				s[i++]=10;
		}else{
			d++;
		}
	}
	s[i-5]=0;
	i=!puts(s);
}

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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n;
int a,b;

int main(){
    INIT;
    cin >> a;
    if(a == 1) cout << "Hello World" << "\n";
    else {
        cin >> a; cin >> b;
        cout << a + b << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=2e5+10,M=4000+10,mod=1e9+7;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}
int ginv(int a){return fpow(a,mod-2);}
int n,a[N],b[N],f[M][M],fac[M<<1],iac[M<<1];
int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}

int main()
{
	n=rd();
	for(int i=1;i<=n;++i)
	{
		a[i]=rd(),b[i]=rd();
		ad(f[2000-a[i]][2000-b[i]],1);
	}
	fac[0]=1;
	for(int i=1;i<=M+M-5;++i) fac[i]=1ll*fac[i-1]*i%mod;
	iac[M+M-5]=ginv(fac[M+M-5]);
	for(int i=M+M-5;i;--i) iac[i-1]=1ll*iac[i]*i%mod;
	for(int i=0;i<=M-5;++i)
		for(int j=0;j<=M-5;++j)
		{
			if(i) ad(f[i][j],f[i-1][j]);
			if(j) ad(f[i][j],f[i][j-1]);
		}
	int ans=0;
	for(int i=1;i<=n;++i) ad(ans,f[2000+a[i]][2000+b[i]]),ad(ans,mod-C(a[i]+b[i]+a[i]+b[i],a[i]+a[i]));
	ans=1ll*ans*(mod+1)/2%mod;
	printf("%d\n",ans);
    return 0;
}




Measured memory_bytes: 64640
program abc121_d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: a,b,i,ans,d

    read*, a,b
    i=2
    ans=0
    d = b-a+1
    do while(i/2 <= b)
        if(btest(count_m(b,i)-count_m(a-1,i),0)) ans=ans+i/2
        i=i*2
    end do
    print'(i0)', ans
contains
    function count_m(x,b) result(ret)
        integer(int64):: x,b,hb,ret
        hb = b/2
        ret = hb*(x/b) + max(mod(x,b)-(hb-1),0_8)
    end function
end program abc121_d

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

int main () {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int count = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if ((500 * i) + (100 * j) + (50 * k) == x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll A, B;
  cin >> A >> B;

  ll ans = A - (2 * B);
  ans = max(0LL, ans);

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


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = min(b / a, c);
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N;
  cin >> N;
  double tmp;
  double ans = 0.0;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    ans += 1.0/tmp;
  }
  cout << 1.0/ans;
}
  /*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> grid(H,vector<char>(W));
    vector<vector<int>> cnt_W(H, vector<int>(W, 0));
    vector<vector<int>> cnt_H(H, vector<int>(W, 0));

    rep(h,H){
        rep(w, W){
            cin >> grid[h][w];
            if(grid[h][w] == '.') {
                cnt_W[h][w]++;
                cnt_H[h][w]++;
            }
        }
    }

    rep(h, H){
        for(int w = 1;  w < W; w++){
            if(grid[h][w] == '#') continue;
            cnt_W[h][w] += cnt_W[h][w-1];
        }
        for(int w = W-2; w >= 0; w--){
            if(grid[h][w] == '#') continue;
            cnt_W[h][w] = max(cnt_W[h][w], cnt_W[h][w+1]);
        }
    }

    rep(w, W){
        for(int h = 1; h < H; h++){
            if(grid[h][w] == '#') continue;
            cnt_H[h][w] += cnt_H[h-1][w];
        }
        for(int h = H - 2; h >= 0; h--){
            if(grid[h][w] == '#') continue;
            cnt_H[h][w] = max(cnt_H[h][w], cnt_H[h+1][w]);
        }
    }

    int ans = 0;
    rep(h, H){
        rep(w ,W){
            if(grid[h][w] == '#') continue;
            ans = max(ans, cnt_W[h][w] + cnt_H[h][w] - 1);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 37632
#include<bits/stdc++.h>
using namespace std;
 
//#define USING_LONG_LONG
#ifdef USING_LONG_LONG
    #define int long long
    const int INF=1001001001001001001ll;
#else
    const int INF=1001001001;
#endif
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define clr(a) memset((a),0,sizeof(a))
#define CLR(a) memset((a),-1,sizeof(a))
#define each(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define minv(a,b) (a)=min((a),(b))
#define maxv(a,b) (a)=max((a),(b))
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<string>vs;
typedef pair<int,int>pii;
#define fi first
#define se second
 
int N,Y;
int y[100];string n[100];
signed main(){
    cin>>N>>Y;
    rep(i,N)cin>>y[i+1]>>n[i+1];
    n[0]="kogakubu10gokan";
    y[N+1]=INF;
 
    rep(i,N+1){
        if(y[i]<=Y&&Y<y[i+1]){
            cout<<n[i]<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    vector<int> a(4);
    REP(i,4) cin >> a[i];
    sort(a.begin(), a.end());
    bool f = false;
    do {
        if(a[0] == 1 && a[1] == 9 && a[2] == 7 && a[3] == 4) f = true;
    } while (next_permutation(a.begin(), a.end()));
    if(f) cout << "YES" << std::endl;
    else cout << "NO" << std::endl;
    return 0;
}

Measured memory_bytes: 256
//gauravsinghh
#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 int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    string s;
    cin >> s;
    unordered_map < char, ll > mpp;
    rep(i, sz(s)){
        mpp[s[i]]++;
    }
    if(sz(mpp) == 2){
        ll f = 0;
        for(auto it : mpp){
            if(it.ss != 2){
                f=1;
                break;
            }
        }
        if(f){
            cout << "No\n";
        }
        else{
            cout << "Yes\n";
        }
    }
    else{
        cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 30
#define ll long long
#define ull unsigned long long
#define RNG mt19937
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;


int main(){
	fast_io();
	int n,k,q;
	cin >> n >> k >> q;
	int a[n];
	bool b[n] = {};
	vector<pii> v;
	cu(i,0,n){cin >> a[i];v.pb({a[i], i});}
	sort(all(v));
	int ans = INF;
	cu(s,0,n){
		priority_queue<int, vector<int>, greater<int>> pq, tm;
		int p = -1;
		fu(i,0,n){
			if(i == n || b[i] == 1){
				int num = i - p - 1 - k + 1;
				while(num-- > 0){
					pq.push(tm.top());
					tm.pop();
				}
				while(tm.size())tm.pop();
				p = i;
			}
			else{
				tm.push(a[i]);
			}
		}
		if(pq.size() >= q){
			int st = pq.top();
			int nd = 0;
			cu(i,0,q){nd = pq.top();pq.pop();}
			gmin(ans,nd - st); 
		}
		b[v[s].S] = 1;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9
#define rep(i,N) for(int i=0;i<N;i++)

int main(){
    int n,m;
    cin>>n>>m;
    int e[m];
    bool ee[n+1];
    rep(i,n+1)ee[i]=false;
    int a;
    int c = 0 ;
    rep(i,m){
        cin>>e[i];
    }
    for(int i = m-1;i>=0;i--){
        if(ee[e[i]]){
            //cout<<"ee:"<<e[i]<<endl;
            continue;
        }
        cout<<e[i]<<endl;
        ee[e[i]] = true;
    }
    for(int i = 1; i<n+1;i++){
        if(ee[i])continue;
        cout<<i<<endl;
    }
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  int res = 0;
  cin >> n >> k;
  vector<int> l(n);
  for (int i=0; i<n;i++) cin >> l[i];
  sort(l.rbegin(),l.rend());
  for (int i=0; i<k; i++) res+=l[i];
  cout << res << endl;
  return 0;
}


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

int main(void) {
	int A, B, C;
	string ans;

	cin >> A >> B >> C;
	if (A % 2 == 0 && B % 2 == 0 && C % 2 == 1)
		ans = "NO";
	else if (A == 1)
		ans = "YES";
	else {
		ans = "NO";
		for (int i = 1; i <= B; ++i) {
			if ((i * A) % B == C) {
				ans = "YES";
				break;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, a, b, d[100009]; vector<int> g[100009];
int solve(int pos, int pre) {
	int ret = 0, r1 = 0, r2 = 0;
	for (int i : g[pos]) {
		if (i != pre) {
			ret = max(ret, solve(i, pos));
			if (r1 < d[i]) r2 = r1, r1 = d[i];
			else if (r2 < d[i]) r2 = d[i];
		}
	}
	d[pos] = r1 + (g[pos].size() == 2 ? 1 : 0);
	return max(ret, d[pos] + r2);
}
int main() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		scanf("%d %d", &a, &b); a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ret = 0;
	for (int i = 0; i < N; i++) ret += (g[i].size() == 1 ? 1 : 0);
	printf("%d\n", ret + solve(0, -1));
	return 0;
}

Measured memory_bytes: 6144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			System.out.println((x - a) % b);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main () {
  string A, B, C;
  cin >> A >> B >> C;
  if(A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0))cout << "YES" << endl;
  else cout << "NO" << endl; 
  return 0;
}

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

using namespace std;


typedef long long ll;
int const inf = INT_MAX / 2;

enum query_type { min_query, max_query, sum_query };

template<class T> struct segtree {
  int N;
  vector<T> dat, sum;
  function<T(T, T)> func;
  T ngvalue;

  void init(int n, function<T(T, T)> const& f, T ng) {
    N = 1;
    while(N < n) N <<= 1;
    dat.assign(2 * N - 1, 0);
    sum.assign(2 * N - 1, 0);
    func = f;
    ngvalue = ng;
  }

  segtree() = default;

  segtree(int n, query_type qtype) {
    if(qtype == min_query) {
      init(n, [](T a, T b){return min(a, b);}, numeric_limits<T>::max());
    }
    else if(qtype == max_query) {
      init(n, [](T a, T b){return max(a, b);}, numeric_limits<T>::min());
    }
    else if(qtype == sum_query) {
      init(n, [](T a, T b){return a + b;}, 0);
    }
    else {
      runtime_error("no matching query type");
    }
  }

  void add(int i, T x) {
    add(i, i + 1, x);
  }

  void add(int a, int b, T x) {
    add(a, b, x, 0, 0, N);
  }

  T add(int a, int b, T x, int k, int l, int r) {
    if(b <= l || r <= a) return dat[k];
    if(a <= l && r <= b) {
      sum[k] += x;
      return dat[k] += x;
    }
    int m = (l + r) / 2;
    return dat[k] = func(add(a, b, x, 2 * k + 1, l, m), add(a, b, x, 2 * k + 2, m, r)) + sum[k];
  }

  T operator()(int a, int b) {
    return query(a, b, 0, 0, N);
  }

  T query(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return ngvalue;
    if(a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return func(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)) + sum[k];
  }
};


int main() {
  int N; 
  cin >> N;
  string S; 
  cin >> S;
  vector<segtree<int>> v(26);

  for(int i = 0; i < 26; i++){
    v.at(i) = segtree<int>(N, sum_query);
  }
  for(int i = 0; i < S.size(); i++){
    int num = S[i] - 'a';
    v.at(num).add(i, 1);
  }

  int Q;
  cin >> Q;
  while(Q--){
    int a;
    cin >> a;
    if(a == 1){
      // update
      int b;
      char c;
      cin >> b >> c;
      b--;
      int tmp = S[b] - 'a';
      int tmp2 = c - 'a';
      v.at(tmp).add(b, -1);
      S[b] = c;
      v.at(tmp2).add(b, 1);
    } else if(a == 2){
      // query
      int b,c;
      cin >> b >> c;
      b--; c--;
      int ret = 0;
      for(int i = 0; i < 26; i++){
        if(v.at(i)(b, c+1) > 0) ret++;
      }
      cout << ret << endl;
    }
  }
}


Measured memory_bytes: 214148
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int l, r; cin >> l >> r;
  if(r - l + 1 >= 2019){
    cout << 0 << endl;
    return;
  }
  unsigned long long int minx = 2018;
  for(unsigned long long int i = l; i <= r - 1; i++){
    for(unsigned long long int j = i + 1; j <= r; j++){
      //cout << i << " " << j << " " << (i * j) << endl;
      minx = min((i * j) % 2019, minx);
    }
  }
  cout << minx << endl;
  return;
}

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int K = 100 + 10;
char str[K][K];

struct Edge {
  int v, c;
  Edge* nxt;
};

const int N = 210;
const int M = 21000;
Edge* a[N];
Edge pool[M], *last;

int pre[N];
Edge* idx[N];

inline Edge* new_edge(int v, int c, Edge* nxt) {
  Edge* p = last++;
  p->v = v;
  p->c = c;
  p->nxt = nxt;
  return p;
}

inline void add_edge(int u, int v, int c) {
  a[u] = new_edge(v, c, a[u]);
  a[v] = new_edge(u, c, a[v]);
}

inline Edge* dual(Edge* p) {
  return pool + ((p - pool) ^ 1);
}

int augment(int s, int t) {
  int aug = INF;
  for (int i = t; i != s; i = pre[i]) {
    aug = min(aug, idx[i]->c);
  }
  for (int i = t; i != s; i = pre[i]) {
    idx[i]->c -= aug;
    dual(idx[i])->c += aug;
  }
  return aug;
}

int maxflow(int s, int t, int n) {
  int ret = 0;
  while (true) {
    queue<int> Q;
    Q.push(s);
    fill(pre, pre + n, -1);
    while (!Q.empty()) {
      int i = Q.front();
      Q.pop();
      for (Edge* it = a[i]; it; it = it->nxt) {
        if (pre[it->v] < 0 && it->c) {
          Q.push(it->v);
          idx[it->v] = it;
          pre[it->v] = i;
        }
      }
    }
    if (pre[t] < 0) break;
    int aug = augment(s, t);
    if (aug == 0) break;
    ret += aug;
  }
  return ret;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", str[i]);
  }
  int s = n + m, t = s + 1;
  last = pool;
  fill(a, a + t + 1, nullptr);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (str[i][j] == 'S') {
        add_edge(s, i, INF);
        add_edge(s, j + n, INF);
      } else if (str[i][j] == 'T') {
        add_edge(i, t, INF);
        add_edge(j + n, t, INF);
      } else if (str[i][j] == 'o') {
        add_edge(i, n + j, 1);
      }
    }
  }
  int ret = maxflow(s, t, t + 1);
  if (ret >= INF) ret = -1;
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 200005

const int INF = 1e9+7;


int main(){

    ll n;
    cin >> n;
    vector<ll> a(ARRAY_MAX,0);
    for(int i = 0;i < n;i++){
        cin >> a[i+1];
    }
    for(int i = 0;i < n;i++){//累積和
        a[i+1] += a[i];
    }

    map<ll,ll> mp;
    for(int i = 0;i <= n;i++){
        mp[a[i]]++;
    }
    ll ans = 0;

    for(auto itr:mp){
        ans += (itr.second)*(itr.second-1)/2;
    }
    cout << ans << endl;





    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (A == 5 && B == 5 && C == 7) {
		cout << "YES" << endl;
	}
	else if (A == 5 && B == 7 && C == 5) {
		cout << "YES" << endl;
	}
	else if (A == 7 && B == 5 && C == 5) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	
}


Measured memory_bytes: 3632
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(n)]
for r in l:
  p,s=int(r[0])-1,r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)

Measured memory_bytes: 84824
import math

a,b,h,m = list(map(int,input().split()))

lon = m * 360/60
tan = (h*60+m) * 360 / (12*60)
kaku = tan - lon

print(math.sqrt(a**2 + b**2 - (2*a*b) * math.cos(math.radians(kaku))))


Measured memory_bytes: 9500
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B=[]
for i in range(K):
    if i!=(K-1):B.append(A[i+1]-A[i])
    else: B.append(A[0] + N-A[i])
print(sum(B)-max(B))

Measured memory_bytes: 24908
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

p_index = 0
q_index = 0
for i, perm in enumerate(permutations(range(1, n+1))):
    if perm == p:
        p_index = i
    if perm == q:
        q_index = i
print(abs(p_index - q_index))

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

const long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new DirectedGraph(N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        G.add_edge(s[0], s[1]);
    }

    auto scc = new StronglyConnectedComponent(G);

    auto Q = readln.chomp.to!int;
    while (Q--) {
        s = readln.split.map!(to!int);
        auto u = s[0];
        auto v = s[1];
        writeln( scc.index[u] == scc.index[v] ? 1 : 0 );
    }
}


class DirectedGraph {
    int n;
    int[][] adj;
    int[][] inv;

    this(int n) {
        this.n = n;
        adj = new int[][](n);
        inv = new int[][](n);
    }

    void add_edge(int u, int v) {
        adj[u] ~= v;
        inv[v] ~= u;
    }
}


class StronglyConnectedComponent : DirectedGraph {
    int[] index;
    int[][] scc;

    this(DirectedGraph g) {
        int cnt = 0;
        auto ord = new int[](g.n);
        auto used = new bool[](g.n);
        index = new int[](g.n);

        void dfs1(int n) {
            if (used[n]) return;
            used[n] = true;
            foreach (m; g.adj[n]) if (!used[m]) dfs1(m);
            ord[cnt++] = n;
        }

        void dfs2(int n) {
            if (used[n]) return;
            used[n] = true;
            index[n] = cnt;
            scc.back ~= n;
            foreach (m; g.inv[n]) if (!used[m]) dfs2(m);
        }

        foreach (i; 0..g.n) if (!used[i]) dfs1(i);

        cnt = 0;
        fill(used, false);

        foreach_reverse (i; 0..g.n) {
            if (used[ord[i]]) continue;
            scc.length += 1;
            dfs2(ord[i]);
            cnt += 1;
        }

        super(cnt);
        auto edge = new bool[int][](cnt);

        foreach (i; 0..g.n)
            foreach (j; g.adj[i])
                if (index[i] != index[j])
                    edge[index[i]][index[j]] = true;

        foreach (i; 0..cnt)
            foreach (j; edge[i].keys)
                add_edge(i, j);
    }
}



Measured memory_bytes: 11376
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n>>k;


    cin>>str;

    vector<pll>v;

    v.eb(0,0);

    for(i=0; i<n; i++)
    {
        if(str[i]=='0')
        {
            a=i+1;

            while(i<n && str[i]=='0')i++;

            b=i;

            v.eb(a,b);


        }
    }



    v.eb(n+1,n+1);



    if( (v.size()-2)==0 || (v.size()-2)<=k)
        ans=n;

    n=v.size();

    m=n;




    /*for(auto x : v)
        cout<<x<<" ";

    cout<<endl;*/


   for(i=k+1; i<n ; i++)
    {
        sum=v[i].F-v[i-(k+1)].S-1;

       // cout<<sum<<endl;

        ans=max(sum,ans);
    }




  /*  n=str.size();

    for(i=0; i<n && k==0; i++)
    {
        cnt=0;

        while(i<n && str[i]=='1')
        {
            i++;
            cnt++;
        }

       // cout<<i<<" "<<cnt<<endl;

        ans=max(cnt,ans);

    }
*/


    cout<<ans<<endl;


}



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

using namespace std;
typedef long long ll;

struct Point {
  ll x;
  ll y;
};

int main() {
  ll H; cin >> H;
  ll W; cin >> W;
  vector<string> A(H);
  for (ll j=0; j < H; ++j) cin >> A[j];
  queue<Point> openq;
  queue<Point> procq;
  for (ll j=0; j < H; ++j) {
    for (ll k=0; k < W; ++k) {
      if (A[j][k] == '#') openq.push(Point{k, j});
    }
  }
  ll ans = 0;
  while (!openq.empty()) {
    procq = move(openq);
    while (!procq.empty()) {
      Point p = procq.front(); procq.pop();
      if (p.x-1 >= 0 && A[p.y][p.x-1] == '.') {
        A[p.y][p.x-1] = '#';
        openq.push(Point{p.x-1, p.y});
      }
      if (p.x+1 < W && A[p.y][p.x+1] == '.') {
        A[p.y][p.x+1] = '#';
        openq.push(Point{p.x+1, p.y});
      }
      if (p.y-1 >= 0 && A[p.y-1][p.x] == '.') {
        A[p.y-1][p.x] = '#';
        openq.push(Point{p.x, p.y-1});
      }
      if (p.y+1 < H && A[p.y+1][p.x] == '.') {
        A[p.y+1][p.x] = '#';
        openq.push(Point{p.x, p.y+1});
      }
    }
    ans += 1;
  }
  cout << ans-1 << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> s(n), t(n); // 累積和
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
    if(i) s.at(i) += s.at(i - 1);
  }
  for(int i = 0; i < n; i++){
    cin >> t.at(i);
  }
  for(int i = n - 2; i >= 0; i--){
    t.at(i) += t.at(i + 1);
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = max(ans, s.at(i) + t.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import Text.Printf

func :: Int -> Int -> Int -> Int
func k' k total = func' total
  where
  func' t
    | t == 0 = 0
    | otherwise = q + func' p
      where
      x = k * k * k * (11 - t `mod` 10) `mod` 10
      (p, q) = quotRem (t + k' * x) 10

main :: IO ()
main = do
  kk <- fmap read getLine
  let k' = if kk `mod` 7 == 0 then kk `div` 7 else kk
      k = k' `mod` 10
      t = (k * k * k `mod` 10) * k' `div` 10
  printf "%d\n" $ if k `mod` 2 == 0 || k == 5 then -1 else 1 + func k' k t


Measured memory_bytes: 20492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define PI (acos(-1))
typedef long double ld;
typedef long long ll;

int main() {
  int a,b;
  cin >> a>>b;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 3592