akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int x,a,b;
  cin >> x >> a >> b;
  a=abs(x-a);
  b=abs(x-b);
  if(a<b) pr('A');
  else pr("B");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import re

tmp = raw_input()

length = len(tmp)


tmp1 = tmp.replace("0", "")
tmp2 = tmp.replace("1", "")

if len(tmp1) > len(tmp2):
    tmp3 = len(tmp1) - len(tmp2)

else:
    tmp3 = len(tmp2) - len(tmp1)


division = length - tmp3

print(division)

Measured memory_bytes: 2820
#include<iostream>

using namespace std;
#define GRAY 1
#define BLACK 2
#define WHITE 0
#define INF  2000000
int n, mincost, u;
int M[100][100];

//プリム法
void prim(){
 int d[100],p[100],color[100];
 for(int i=0;i<n;i++){
   d[i]=INF;
   p[i]=-1;
   color[i]=WHITE;
 }
 d[0]=0;

 while(1){
   mincost = INF;
   u=-1;
   for(int i=0;i<n;i++){
     if(color[i]!= BLACK && d[i]< mincost){
       mincost = d[i];
       u = i;
     }
   }
   if(u== -1){
     break;
   }
   color[u] = BLACK;

   for(int v=0;v<n;v++){
     if(color[v]!=BLACK &&  M[u][v]!=INF){
       if(d[v]>M[u][v]){
         d[v]=M[u][v];
         p[v]=u;
         color[v]=GRAY;
       }
     }
   }
 }
 int sum=0;
 for(int i=0;i<n;i++){
   if(p[i]!=-1) sum+=M[i][p[i]];
 }
 cout<<sum<<endl;
}


int main(){
  cin>>n;
  for(int i=0;i< n ; i++){
   for(int j=0;j<n;j++){
      int in;
      cin >> in ;
      if(in == -1){
        M[i][j]= INF;
      }
      else M[i][j] = in;
   }
  }
prim();

  return 0;
}



Measured memory_bytes: 3128
import java.util.*;

public class Main {
		public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String num = sc.nextLine();
		String[] numArray = num.split("");
		int count = 0;
		for(int i = 0;i<numArray.length;i++) {
			int[] numInt = new int[numArray.length];
			numInt[i] = Integer.parseInt(numArray[i]);

			if(numInt[i] == 1) {
				count++;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 35416
#include <bits/stdc++.h>
using namespace std;
int seg[262156], d;
void update(int i, int x) {
	i |= 1 << d; seg[i] = x;
	while(i > 1) {
		i >>= 1;
		seg[i] = min(seg[i * 2], seg[i * 2 + 1]);
	}
}
int query(int a, int b, int k, int l, int r) {
	if(a <= l && r <= b) return seg[k];
	if(r <= a || b <= l) return 2147483647;
	int lc = query(a, b, k * 2, l, (l + r) >> 1);
	int rc = query(a, b, k * 2 + 1, (l + r) >> 1, r);
	return min(lc, rc);
}
int n, q, tp, x, y;
int main() {
	scanf("%d%d", &n, &q);
	d = 32 - __builtin_clz(n);
	fill(seg, seg + (1 << (d + 1)), 2147483647);
	while(q--) {
		scanf("%d%d%d", &tp, &x, &y);
		if(tp == 0) update(x, y);
		else {
			int ret = query(x, y + 1, 1, 0, 1 << d);
			printf("%d\n", ret);
		}
	}
	return 0;
}

Measured memory_bytes: 4204
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  int n;  cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i=0; i<n-2; i++){
    string ss = s.substr(i, 3);
    if(ss == "ABC")  {
      ans++;
      i+=2;
    }
  }
  cout << ans << endl;
  return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  REP(i,n - 1){
    if(s[i] != s[i + 1]){
      ans ++;
    }
  }
  cout << ans << endl;
} 

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct RangeAddQuery {
	int n;
	vector<int>d;
	RangeAddQuery(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2*n, 0);
	}
	void add(int a, int b, int x=-1, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;

		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			if (x >= 0)d[k] += (r - l)*x;
			return;
		}
		else {
			if (d[k] != 0) {
				d[2 * k] += d[k] / 2;
				d[2 * k + 1] += d[k] / 2;
				d[k] = 0;
			}
			add(a, b, x, 2 * k, l, (l + r) / 2);
			add(a, b, x, 2 * k + 1, (l + r) / 2, r);
		}
	}
	int get(int i) {
		add(i, i + 1);
		return d[n + i];
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeAddQuery raq(n);
	rep(x, 0, q) {
		int com; cin >> com;
		if (com) {
			int i; cin >> i;
			cout << raq.get(i-1) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			raq.add(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4952
card_dict = {'S':[],'H':[],'C':[],'D':[]}
s_key = ['S','H','C','D']
number = input()
for i in range(int(number)):
    card = input()
    card = card.split()
    s, n = card
    card_dict[s].append(int(n))
else:
    ori = set(list(range(1,14)))
    for key in s_key:
        c = set(card_dict[key])
        d = list(ori - c)
        d.sort()
        for i in d:
            print('{} {}'.format(key,i))



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

class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[self.parent[x]] = self.parent[x] = self.root(self.parent[self.parent[x]]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





Measured memory_bytes: 27192
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,x;
  cin >> n >> x;
  vector<LL> b(n),l(n),u(n);
  REP(i,n) cin >> b[i] >> l[i] >> u[i];
  LL ao = 0;
  REP(i,n) ao += b[i] * l[i];
  if(ao == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<LL,LL> > gain;
  REP(i,n) gain.emplace_back(x*u[i]-b[i]*u[i]+b[i]*l[i], i);
  sort(gain.rbegin(),gain.rend());
  LL tmp = ao;
  LL subs = 0;
  while(tmp>0) {
    tmp -= gain[subs].first;
    ++subs;
  }
  LL lst = x;
  REP(j, subs) {
    LL i = gain[j].second;
    LL tmpb = tmp + gain[j].first - b[i] * l[i];
    if(tmpb <= 0) {
      lst = min(lst, b[i] - (-tmpb)/l[i]);
    } else {
      lst = min(lst, b[i] + (tmpb-1)/u[i]+1);
    }
  }
  --subs;
  tmp += gain[subs].first;
  FOR(j, subs, n) {
    LL i = gain[j].second;
    LL tmpb = tmp - b[i] * l[i];
    if(tmpb < 0) {
      lst = min(lst, b[i] - (-tmpb)/l[i]);
    } else {
      lst = min(lst, b[i] + (tmpb-1)/u[i]+1);
    }
  }
  cout << subs*x+lst << endl;
  return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  long long n,x,d;
  cin>>n>>x>>d;
  
  if(d == 0){
    if(x == 0){
      cout<<1<<endl;
    }else{
      cout<<n+1<<endl;
    }
    return 0;
  }
  
  map<long long, vector<pair<long long, long long>>> mp;
  for(long long k = 0; k<=n; k++){
    long long c = k*x;
    long long l = (k-1)*k/2;
    long long r = l + (n-k)*k;
    c += l*d;
    long long s = r - l;
    //c ~ c + D(R-L) の値をDごとに取る。
    long long modulo = (c%abs(d) + abs(d))%abs(d);
    c = (c- modulo)/d;
    //(c - modulo)/d ~ (c - modulo)/d + (R-L) の値を取る。
    mp[modulo].emplace_back(c,s);
  }
  
  long long ans = 0;
  for(auto p:mp){
    long long modulo = p.first;
    vector<pair<long long, long long>> vec = p.second;
    int m = vec.size();
    if(m == 0)continue;
    vector<pair<long long, int>> events;
    REP(i,m){
      long long c = vec[i].first;
      long long s = vec[i].second;
      if(s >= 0){
        events.emplace_back(c, 1);
        events.emplace_back(c + s + 1LL, -1);
      }else{
        events.emplace_back(c + s, 1);
        events.emplace_back(c + 1LL, -1);
      }
        
    }
    sort(ALL(events));
    int cnt = 0;
    long long now = -INF;
    for(auto event:events){
      if(cnt > 0){
        ans += event.first - now;
      }
      cnt += event.second;
      now = event.first;
    }
  }
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 22144
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      mut x: i64,
      mut k: usize,
      d: i64,
   }
   if k % 2 == 1 {
      x = x.abs() - d;
      k -= 1;
   }
   x = x.abs();
   let m = (x / 2 / d) as usize;
   let ans = if k / 2 >= m + 1 {
      x %= 2 * d;
      min(x, 2 * d - x)
   } else {
      x - k as i64 * d
   };
   println!("{}", ans);
}


Measured memory_bytes: 2148
n,m = gets.chomp.split(" ").map(&:to_i)

min = 1
max = n

m.times do |i|
  l,r = gets.chomp.split(" ").map(&:to_i)
  min = l if l > min
  max = r if r < max
end

puts [max - min + 1, 0].max



Measured memory_bytes: 14376
/*
  Ashraful Islam
  University of Asia Pacific
  Date:06th March 2020
  Category:Number Theory
  Todo--
  11957 - Checkers
  https://codeforces.com/problemset/problem/584/D
*/
#include<bits/stdc++.h>
#define all(o) (o).begin(),(o).end()
using namespace std;
typedef long long ll;
const int N=1e5+5;
long long n,m,len,k,cs=1,tc;
void scan(int &x)
{
  scanf("%d",&x);
}

int A[N],B[N],fuck[4][N];
void Solve()
{
 int x,y,p;
 cin>>x>>y>>p;

 for(int i=1;i<=x;++i)cin>>A[i];
 for(int j=1;j<=y;++j)cin>>B[j];

  int mn_a=1e9+5,mn_b=1e9+5;

  for(int i=1;i<=x;++i)mn_a=min(mn_a,A[i]);
  for(int i=1;i<=y;++i)mn_b=min(mn_b,B[i]);

  int ans=mn_a+mn_b;
  int a,b,c;
  for(int i=1;i<=p;++i)
  {
    cin>>a>>b>>c;
    ans=min(ans,A[a]+B[b]-c);
  }

  cout<<ans<<endl;
}
int main()
{
  Solve();
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int n,m,i,j;
    scanf("%d %d\n",&n,&m);
    int a[n][m];
    int b[m];
    int c[n];
    //n*m??????A???????????????
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d ",&a[i][j]);
            //printf("%d ",a[i][j]);?¢????
        }
    }
    //m*1??????b???????????????
    for(i=0;i<m;i++){
        scanf("%d\n",&b[i]);
    }
    //n*1??????c????±???????
    for(i=0;i<n;i++){
        c[i]=0;
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
            }
    }
    ///n*1???????????¨???
    for(i=0;i<n;i++){
        printf("%d\n",c[i]);
    }
    return 0; /*0?????????*/
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int sum=0;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        sum+=a;
    }
    if(sum>n){
        cout << -1;
    }else{
        cout <<n-sum;
    }
    cout << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int euclid(int small, int big){
    int amari = 0,tmp = 0;
    
    if(small > big){
        tmp = small;
        small = big;
        big = tmp;
    }
    while(true){
        if((amari = big % small) == 0)
            return small;
        big = small;
        small = amari;
    }
    return 0;
}

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> vec(n);
    rep(i,n){ 
        cin >> vec[i];
        vec[i] = abs(x-vec[i]);
    }
    sort(vec.begin(),vec.end());
    
    int ans = vec[0];
    if(n>1){
        reps(i,1,n){
            if((ans = euclid(ans,vec[i])) == 1){
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		String s=in.next();
		int ans=0;
		for(int i=0;i<s.length();i++)
		{
			if(i==s.length()-2) {
				if(s.charAt(i)==s.charAt(i+1)) {
					i++;
				}
			}else if(i!=s.length()-1){
				if(s.charAt(i)==s.charAt(i+1)) {
					i++;
					ans++;
					i++;
				}
			}
			ans++;
		}

		System.out.println(ans);
			
	}
}
	


Measured memory_bytes: 40368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

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

	static int INF = 1 << 30;
	static int modP = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = new long[n+1];
			for (int i = 0; i <= n; i++) {
				a[i] = i;
			}

			long[] sum = new long[n+1];
			sum[0] = a[0];
			TreeSet<Long> set = new TreeSet<>();
			for (int i = 1; i <= n; i++) {
				sum[i] = sum[i-1] + a[i];

				if (sum[i] >= n) {
					long sa = sum[i]-n;
					for (long j = 1; j <= i; j++) {
						if (j == sa) {
							continue;
						}
						set.add(j);
					}
					break;
				}
			}

			for (Long l : set) {
				out.println(l);
			}
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 180160
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<long long> a(n+1,0);
	for(int i=1;i<=n;i++){
		cin >> a[i];
		a[i]+=a[i-1];
	}
	long long ans=1LL<<50;
	for(int k=-1;k<=1;k+=2){
		int sign=k;
		long long plus=0,minus=0;
		for(int i=1;i<=n;i++){
			if(a[i]+plus-minus>0){
				if(sign==-1) minus+=a[i]+plus-minus+1;
			}else if(a[i]+plus-minus<0){
				if(sign==1)	plus+=-(a[i]+plus-minus)+1;
			}else{
				if(sign==-1) minus+=1;
				else if(sign==1) plus+=1;
			}
			sign*=-1;
		}
		if(ans>plus+minus) ans=plus+minus;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
 
  // 1の数を表す変数
  const string vowel = "aeiou";

  bool checkC = false;
  
  for (int i = 0; i < 5; i++) {
      if (vowel.at(i) == c) {
        checkC = true; 
      }
  }
  
  if(checkC){
      cout << "vowel" << endl;
  } else {
     cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;

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


Measured memory_bytes: 3612
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

vector<vector<int> > g(200010);
ll score[200010];
bool done[200010];

void walk(int p) {
  if (done[p]) return;
  done[p] = true;
  for (int next : g[p]) {
    if (done[next]) continue;
    score[next] += score[p];
    walk(next);
  }
}


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q; cin >> N >> Q;
  FOR(i,0,N-1) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  FOR(i,0,Q) {
    int p, x; cin >> p >> x;
    score[p] += x;
  }
  walk(1);
  FOR(i,1,N+1) {
    cout << score[i] << endl;
  }
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  if (a * b <= 0) cout << "Zero" << endl;
  else if (a + b > 0) cout << "Positive" << endl;
  else if ((b - a) % 2 == 0) cout << "Negative" << endl;
  else cout << "Positive" << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
 
int length();
 
char X[1000+1], Y[1000+1];
int c[1000+1][1000+1];
 
int LCS() {
    int i,j,m,n;
    m = strlen(X);
    n = strlen(Y);
     
    for (i=1;i<=m;i++) {
        c[i][0] = 0;
    }
    for (j=0;j<=n;j++) {
        c[0][j] = 0;
    }
    for ( i = 1; i <= m; i++) {
        for ( j = 1; j <= n; j++) {
            if ( X[i - 1] == Y[j - 1]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else if (c[i - 1][j] >= c[i][j -1]) {
                c[i][j] = c[i - 1][j];
            } else {
                c[i][j] = c[i][j - 1];
            }
        }
    }
    return c[m][n];
}
 
int main() {
    int i, n;
     
    scanf("%d", &n);

    for( i = 0; i < n; i++) {
        scanf("%s %s", &X, &Y);

        printf("%d\n" ,LCS());
    }
    return 0;
}


Measured memory_bytes: 5640
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    if N>=30:
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()


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

LL sum_a[100010] = {}, sum_b[100010] = {};
LL c[100010] = {};
priority_queue<LL, vector<LL>, greater<LL>> a;
priority_queue<LL> b;

int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i ++) {
    LL t; cin >> t;
    sum_a[0] += t;
    a.push(t);
  }
  for (int i = 1; i <= n; i ++) cin >> c[i];
  for (int i = 0; i < n; i ++) {
    LL t; cin >> t;
    sum_b[n + 1] += t;
    b.push(t);
  }

  for (int i = 1; i <= n; i ++) {
    LL t = a.top();
    sum_a[i] = sum_a[i - 1];
    if (c[i] > t) {
      sum_a[i] += c[i];
      sum_a[i] -= t;
      a.push(c[i]);
      a.pop();
    }
  }
  for (int i = n; i >= 1; i --) {
    LL t = b.top();
    sum_b[i] = sum_b[i + 1];
    if (c[i] < t) {
      sum_b[i] += c[i];
      sum_b[i] -= t;
      b.push(c[i]);
      b.pop();
    }
  }

  LL ans = -1e18;
  for (int i = 0; i <= n; i ++) {
    ans = max(ans, sum_a[i] - sum_b[i + 1]);
  }
  cout << ans << endl;
}

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

using namespace std;

int n;
int A, B, C;
int D[100];
int main() {
    cin >> n;
    cin >> A >> B;
    cin >> C;
    for (int i = 0; i < n; i++) {
        cin >> D[i];
    }

    int ans = 0;
    int sum = 0;
    // テゥツ卍催ゥツ??10,9,8,...)テ」ツ?ォテ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ?
    sort(D, D + n);
    reverse(D, D + n);
    for (int i = 0; i < n; i++) {
        // テ」ツδ暗」ツδε」ツδ氾」ツδウテ」ツつーテ」ツ?ョテ」ツつォテ」ツδュテ」ツδェテ」ツδシテ」ツ?ョテ・ツ青暗ィツィツ?
        sum += D[i];
        ans = max(ans, (sum + C) / (A + B * (i + 1)));
    }
    cout << ans << endl;

    return 0;
}

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

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);
    for (int& x : A) cin >> x, x--;
    for (int& x : B) cin >> x;
    for (int& x : C) cin >> x;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += B[A[i]];
        if (i && A[i] - 1 == A[i - 1]) {
            ans += C[A[i - 1]];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000010;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN], f[MAXM], g[MAXM];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i];
        f[a[i]]++;
    }
    FOR(i,1,1000000) g[i] = 1;
    FOR(i,1,1000000) {
        if (!f[i]) continue;
        for (int j = i+i; j <= 1000000; j += i) {
            g[j] = 0;
        }
    }
    int res = 0;
    FOR(i,1,1000000)
        if (f[i] == 1 && g[i]) res++;
    cout << res;
    return 0;
}


Measured memory_bytes: 12208
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map(int, input().split())
    A = deque([int(input()) for i in range(M)])
    if N == 1:
        print(1)
    else:
        dp = [0]*N
        # 一段目と二段目への行き方
        if len(A) != 0:
            out = A.popleft() 
        else:
            out = 0

        if out != 1:
            dp[0] = 1
        else:
            dp[0] = 0
            if len(A) != 0:
                out = A.popleft()
        if out != 2:
            dp[1] = 1+dp[0]
        else:
            dp[1] = 0
            if len(A) != 0:
                out = A.popleft()

        for i in range(2,N):
            if i+1 == out:
                dp[i] = 0
                if len(A) != 0:
                    out = A.popleft()
            else:
                if dp[i-2] != 0 or dp[i-1] != 0:
                    dp[i] = dp[i-2] + dp[i-1]

        if dp[N-1] != 0:
            print(dp[N-1]%(10**9 + 7))
        else:
            print(0)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 460380
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    ll n;
    cin >> n;
    ll a[n];
    ll backet[1000000] = {0};
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        backet[a[i]]++;
        backet[a[i] + 1]++;
        if(a[i] >= 1){
            backet[a[i] - 1]++;
        }
    }
    
    ll ans = 0;
    
    for(ll i = 0; i < 1000000; i++){
        if(backet[i] > ans)ans = backet[i];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 8832
from itertools import permutations
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
li=[i for i in range(1,n+1)]
perm = list(permutations(li))
for i in perm:
  if p == list(i):
    a=perm.index(i)+1
  if q == list(i):
    b=perm.index(i)+1
print(abs(a-b))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll cu = 1000;
    ll stock = 0;
    //cout << cu << endl;
    for(int i=0;i<n-1;i++){
        if(a[i] < a[i+1]){
            stock = cu / a[i];
            cu += (a[i+1] - a[i]) * stock;
        }
        //cout << cu << endl;
    }
    cout << cu << endl;
}

Measured memory_bytes: 3616
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	TLong n;
	TLong x,y;
	cin >> n;
	x = sqrt(n);
	while(n % x != 0)	--x;
	
	y = n / x;
	// cout << x << ' ' << y << endl;
	OUT((x - 1) + (y - 1)) BR;
	RET;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
static const int MAX = 51;
static const int INFTY = 101;
class edge {
public:
    int source, target, cost;
    edge(int source, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
};
int V;

class DisjointSet {
public:
    vector<int> rank, p;
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

    bool same (int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }

    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

bool compare(const edge& a, const edge& b) {
    return a.cost < b.cost;
}

int main(){

    int s, d, cost, ans;
    for (; ;) {
        scanf("%d %d", &s, &d);
        if (s == 0 && d == 0) break;
        V = s + d;
        vector<edge> G;
        for (int i = 0; i < s; i++) {
            for (int j = s; j < V; j++) {
                std::scanf("%d", &cost);
                cost = (cost == 0) ? INFTY : cost;
                if (cost != 0) G.push_back(edge(0, j, cost));
            }
        }

        for (int i = s; i < V-1; i++) {
            for (int j = i+1; j < V; j++) {
                std::scanf("%d", &cost);
                cost = (cost == 0) ? INFTY : cost;
                if (cost != 0) G.push_back(edge(i, j, cost));
            }
        }

        std::sort(G.begin(), G.end(), compare);
        DisjointSet ds(V+1);
        ans = 0;
        int p;
        for (int i = 0; i < G.size(); i++) {
            if (!ds.same(G[i].source, G[i].target)) {
                ds.unite(G[i].source, G[i].target);
                ans+= G[i].cost;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define N 100011

using namespace std;

int n, m, ans, dp[N];
vector<int> adj[N];

int dfs(int v) {
	if(dp[v] != -1) return dp[v];
	dp[v] = 0;
	for(int u : adj[v]) {
		dp[v] = max(dp[v], dfs(u));
	}
	dp[v]++;
	return dp[v];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u].push_back(v);
	}
	for(int i=0; i<n; i++) {
		if(dp[i] == -1) ans = max(ans, dfs(i));
	}
	cout << ans-1 << endl;
	return 0;
}


Measured memory_bytes: 7552
#include <stdio.h>
int main(void){
	int people;
	people = 0;
	while(1){
		int m,f,r;
		scanf("%d %d %d\n",&m,&f,&r);
			if(m==-1 && f==-1 && r==-1){
				break;
			}else{
				int a[people],b[people],c[people];
				a[people] = m;
				b[people] = f;
				c[people] = r;
				int sum;
				sum = a[people] + b[people];
				if(a[people]==-1 || b[people]==-1){
					printf("F");
				}else if(sum>=80){
					printf("A");
				}else if(sum<80 && sum>=65){
					printf("B");
				}else if(sum<65 && sum>=50){
					printf("C");
				}else if(sum<50 && sum>=30){
					if(c[people]>=50){
						printf("C");
					}else{
						printf("D");
					}
				}
				else{
					printf("F");
				}
				printf("\n");

				people = people + 1;
			}
		}
	return 0;
}

Measured memory_bytes: 576
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
}

const int INF = 1e9, MAXN = 1e5 + 10;                 	

void solve() {                         
	int n;
	cin >> n;

	cout << n * (n - 1) / 2 << endl;
}	


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

int main(int argc, char *argv[])
{
  int N, V[100], C[100];
  cin >> N;

  for (int i = 0; i < N; i++) cin >> V[i];
  for (int i = 0; i < N; i++) cin >> C[i];

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (V[i] > C[i]) {
      ans += V[i]-C[i];
    }
  }

  cout << ans << endl;

  return 0;
}


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

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

    int n;
    cin >> n;
    vector<int> h(n) ,v(n);
    for(auto &it : h) cin >> it;
    
    v[0] = 0;
    v[1] = abs(h[1] - h[0]);

    for(int i = 2 ; i < n ; ++i){
        v[i] = min(abs(h[i] - h[i-1])+v[i-1],abs(h[i] - h[i-2])+v[i-2]);
    }
    cout << v[n-1] ;
    return 0;
}

Measured memory_bytes: 1024
#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 ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int K, X;
    cin >> K >> X;
    if (500 * K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define Y first
#define X second
#define INF 1 << 30
#define EPS 1e-10

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

int n;

int main(){
  while(scanf("%d", &n) && n){
    vector<pi>v;
    map<pi, int>m;
    int x, y;
    rep(i, n){
      scanf("%d%d", &x, &y);
      v.PB(MP(y, x));
      m[MP(y, x)] = 1;
    }

    int res = 0;
    rep(i, n) REP(j, i+1, n){
      pi a = v[i], b = v[j];
      int y = a.Y - b.Y, x = a.X - b.X;
      //      printf("a %d %d b %d %d x %d y %d\n", a.Y, a.X, b.Y, b.X, x, y);
      if(!((m.count(MP(a.Y + x, a.X - y)) && m.count(MP(b.Y + x, b.X - y)))
	   || (m.count(MP(a.Y - x, a.X + y)) && m.count(MP(b.Y - x, b.X + y))))) continue;
      res = max(res, y*y + x*x);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1436
N=int(input())

DP=[[0 for i in range(3)] for j in range(N)]
DP[0]=list(map(int,input().split()))
for i in range(1,N):
    lis=list(map(int,input().split()))
    for j in range(3):
        DP[i][j]=lis[j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[N-1]))

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

#define int long long
#define inf 1000000007LL
#define INF 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

class Dinic {
public:
  vector<vector<pair<int, int>>> v;
  vector<int> e;

  vector<int> k;
  vector<int> j;

  Dinic(int n) {
    v.resize(n);
    k.resize(n);
    j.resize(n);
  }
  void add_edge(int a, int b, int atob, int btoa = 0) {
    v[a].push_back(make_pair(b, e.size()));
    e.push_back(atob);
    v[b].push_back(make_pair(a, e.size()));
    e.push_back(btoa);
  }
  void dyk(int s) {
    for(auto& i : k) {
      i = inf;
    }
    queue<pair<int, int>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()) {
      int w = pq.front().first;
      int b = pq.front().second;
      pq.pop();
      if(k[b] > w) {
        k[b] = w;
        for(auto i : v[b]) {
          if(e[i.second] > 0) {
            pq.push(make_pair(w + 1, i.first));
          }
        }
      }
    }
  }
  int dfs(int s, int t, int p, int c) {
    if(p == t) {
      return c;
    }
    int all = 0;
    while(c > all && j[p] < v[p].size()) {
      if(k[v[p][j[p]].first] == k[p] + 1) {
        int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second]));
        e[v[p][j[p]].second] -= r;
        e[v[p][j[p]].second ^ 1] += r;
        if(r < c - all) {
          j[p]++;
        }
        all += r;
      }
      else {
        j[p]++;
      }
    }
    return all;
  }
  int solve(int s, int t) {
    int all = 0;
    while(1) {
      dyk(s);
      for(auto& i : j) {
        i = 0;
      }
      int r = dfs(s, t, s, inf);
      if(r == 0) {
        return all;
      }
      all += r;
    }
  }
};

signed main() {
  int h, w;
  cin >> h >> w;
  Dinic f(h * w * 2 + 2);
  rep(i, h) {
    rep(j, w - 1) {
      f.add_edge((i * w + j) * 2, (i * w + j + 1) * 2, inf, inf);
    }
  }
  rep(i, h - 1) {
    rep(j, w) {
      f.add_edge((i * w + j) * 2 + 1, ((i + 1) * w + j) * 2 + 1, inf, inf);
    }
  }
  int s, t;
  rep(i, h) {
    string ss;
    cin >> ss;
    rep(j, w) {
      if(ss[j] == 'o') {
        f.add_edge((i * w + j) * 2, (i * w + j) * 2 + 1, 1, 1);
      }
      if(ss[j] == 'S') {
        s = i * w + j;
      }
      if(ss[j] == 'T') {
        t = i * w + j;
      }
    }
  }
  f.add_edge(h * w * 2, s * 2, inf);
  f.add_edge(h * w * 2, s * 2 + 1, inf);
  f.add_edge(t * 2, h * w * 2 + 1, inf);
  f.add_edge(t * 2 + 1, h * w * 2 + 1, inf);
  int ans = f.solve(h * w * 2, h * w * 2 + 1);
  if(ans >= inf) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll MOD=1e9+7;
const int INF = 0x3f3f3f3f;

int main(){
    int h,a;
    cin>>h>>a;
    int ans=h/a;
    if(a>=h) ans=1;
    else if(h%a!=0) ans++;
    cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long  A,B,N;
	cin>>N>>A>>B;
	long long  s;
	s=N/(A+B);
	//cout<<s<<endl;
	 long long sy=N-s*(A+B);
	long long  ans=s*A;
	if(sy<=A)
	ans+=sy;
	else
	ans+=A;
	cout<<ans;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000

using namespace std;
typedef long long ll;

int hist[220000];
int main()
{
  int N, K; cin >> N >> K;
  REP(i, N) {
    int A; cin >> A;
    hist[A]++;
  }
  vector<int> v;
  REP(i, 220000) {
    if (hist[i] > 0) v.PB(hist[i]);
  }
  sort(ALL(v));
  int ans = 0;
  REP(i, (int)v.size() - K) {
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b;
  cin>>a>>b;

  if(a>0){
    cout<<"Positive"<<endl;
  }else{
    if(b>=0){
      cout<<"Zero"<<endl;
    }else{
      if((b-a+1)%2){
        cout<<"Negative"<<endl;
      }else{
        cout<<"Positive"<<endl;
      }
    }
  }
	return 0;
}

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

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  int winCount[N]={0};
  
  int winner;
  for(int i=1; i<=Q; i++) {
    cin >> winner;
    winCount[winner-1]+=1;
  }
  for(int i=1; i<=N; i++){
    if(K - (Q - winCount[i-1]) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N;
    cin >> N;
    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    if (N == 4) {
        cout << "2 5 20 63" << endl;
        return 0;
    }
    if (N == 5) {
        cout << "2 3 4 6 9" << endl;
        return 0;
    }
    set<int> ans;
    auto temp = [](int now) {
        int m = now / 4;
        int d = now % 4;
        if (d == 0) return m * 6;
        else if (d == 1) return m * 6 + 2;
        else if (d == 2) return m * 6 + 3;
        else if (d == 3) return m * 6 + 4;
    };
    for (int i = 1; i <= N; i++) {
        ans.insert(temp(i));
    }
    int num = accumulate(ans.begin(), ans.end(), 0LL);
    int six = (N + 1) / 4 + 1;
    if (num % 6 == 2) {
        ans.erase(8);
        ans.insert(six * 6);
    } else if (num % 6 == 3) {
        ans.erase(9);
        ans.insert(six * 6);
    } else if (num % 6 == 5) {
        ans.erase(9);
        if ((N + 1) % 4 != 3) --six;
        ans.insert(6 * six + 4);
    }
    auto itr = ans.begin();
    for (int i = 0; i < N; i++) cout << (*itr++) << (i == N - 1 ? '\n' : ' ');
}


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

const int MAX = 55556;
int main() {
	int N;
	cin >> N;
	static bitset<MAX> sieve(0);
	sieve.flip();
	for (int i = 2;i < MAX;++ i) if (sieve[i]) for (int j = i << 1;j < MAX;j += i) sieve.reset(j);
	for (int i = 0, j = 3;i < N;j += 10) {
		if (sieve[j]) {
			cout << j << endl;
			++ i;
		}
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

どの5個を選んでも合成数になるのに各値が素数なところがミソ
考えられるのは、全て5で割った余りが等しいということ
この場合、全て足すと必ず5の倍数になるので……
*/

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	}
}


Measured memory_bytes: 24020
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n)	for(int i=0;i<n;i++)
int main(){
	int a,b;
	cin>>a>>b;
	if(a<=0&&b>=0){
		cout<<"Zero"<<endl;
	}
	else if(a>0&&b>0){
		cout<<"Positive"<<endl;
	}
	else{
		if((abs(a-b)+1)%2==0){
			cout<<"Positive"<<endl;
		}
		else{
			cout<<"Negative"<<endl;
		}
	}
	
}

Measured memory_bytes: 256
//
//  main.cpp
//  ATcode131
//
//  Created by didi on 2020/1/16.
//  Copyright © 2020年 didi. All rights reserved.
//

#include <iostream>
#include <map>
#include <vector>
#include <set>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int N, L;
    cin >> N >> L;
    int MAX = 1e9;
    int a = MAX, b = -MAX;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int k = L + i;
        sum += k;
        if (k >= 0) a = min(a, k);
        if (k <= 0) b = max(b, k);
    }
    if (b == -MAX || a < -b) {
        sum -= a;
    } else {
        sum -= b;
    }
    cout << sum;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
 int a[100]={0};
 for(int i=0;i<5;i++)
 a[i]=rr;
 int k=rr;
 int flag=0;
 rep(i,0,4)
 rep(j,i+1,5)
 if(a[j]-a[i]>k)
 flag=1;
 if(flag)
 printf(":(\n");
 else
 printf("Yay!\n"); 
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int i,j,n,m;
  while(1){
    scanf("%d%d",&n,&m);
    if(n==0&&m==0){
      break;
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++){
	if((i+j)%2==0) printf("#");
	else  printf(".");
      }
      printf("\n");
    }
    printf("\n");


  }


  return 0;
}



Measured memory_bytes: 2104