akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    a = [A, B, C]
    a = sorted(a, reverse=True)
    print(a[0]*10 + a[1] + a[2])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B < C + D){
    cout << "Right" << endl;
  }else if (A + B > C + D){
    cout << "Left" << endl;
  }else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pb push_back
#define SQ(a) (a)*(a)
 
using namespace std;
  
// Return the number of moves with a given direction 

int main()
{
    std::ios::sync_with_stdio(false);
    int T = 1;
    //cin>>T;
    for(int t = 1;t<=T;t++)
    {
        int n,k;
        cin>>n>>k;
        
        vector<bool> dp(k+1);
        vector<int> a(n);

        for(int i = 0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a.begin(),a.end());
        for(int i=1;i<=k;i++)
        {
            for(int j = 0;j<n;j++)
            {
                if(i >= a[j])
                {
                    dp[i] = dp[i] || !dp[i-a[j]];
                }
            }
        }
        if(dp[k])
            cout<<"First"<<endl;
        else
            cout<<"Second"<<endl;
        

        
    }

    return 0;
}





        

Measured memory_bytes: 3640
_, *A = map(int, open(0).read().split())
lc = 10**6 + 1
C = [0] * lc
for a in A: C[a] += 1
import functools, math
t = any(sum(C[i::i]) > 1 for i in range(2, lc))
t += functools.reduce(math.gcd, A) > 1
print(['pairwise','setwise','not'][t], 'coprime')


Measured memory_bytes: 121492
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int m = sc.nextInt();
        int p[] = new int[m];
        String s[] = new String[m];
        for(int i = 0; i < m; i++){
        	p[i] = sc.nextInt();
            s[i] = sc.next();
        }
        boolean ac[] = new boolean[n];
        int wa[] = new int[n];
        int ac_count = 0;
        int wa_count = 0;
        for(int i = 0; i < m; i++){
            int count = 0;
            if(ac[p[i] - 1]){
            	continue;
            }
            if(s[i].equals("WA")){
            	wa[p[i] - 1]++;
            }else{
            	ac_count++;
                wa_count += wa[p[i] - 1];
                ac[p[i] - 1] = true;
            }
        }
        System.out.println(ac_count + " " + wa_count);
    }
} 

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

using namespace std;

double table[] = {0, 48, 51, 54, 57, 60, 64, 69, 75, 81, 91};
const char *cls[] = {"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"};

int main() {
    double w;
    while(cin >> w) {
        double *pos = lower_bound(table, table+sizeof(table)/sizeof(double), w);
        cout << cls[pos-table-1] << endl;
    }
    return 0;
}

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


int main(){
  int n;
  cin >>n;
  vector <int> a(n);
  rep(i,n)cin>>a.at(i);

  int point =0;
  int number =0;

  bool endflag =1;
  rep(i,n){
    if(a.at(i)==1){
      endflag =0;
      point =i;
      break;
    }
  }

  if(endflag){
    cout <<-1<<endl;
    return 0;
  }

  endflag =1;
  while(1){
    endflag = 1;
    for (int i =point;i<n;i++){
      //cout<<"i = "<<i<<endl;
      if(a.at(i)==(number+1)){
        //cout<< "get number ="<<a.at(i)<<endl;
        endflag =0;
        point =i;
        break;
      }
    }
    if(endflag){
      cout<<n-number<<endl;
      return 0;
    }
    ++number;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x) {return power(x, MOD - 2);}
const int MAXN = 1e5 + 5;
//const bool is_in = container.find(element) != container.end();
int main()
{
	zapp;
	string s;
	cin >> s;
	int mod = 2019;
	map <int, int> mp;
	++mp[0];
	int curr = 0, pw = 1, i;
	ll ans = 0;
	for (i = s.size() - 1; i >= 0; i--)
	{
		curr = (((s[i] - '0') * pw + curr)) % mod;
		ans += mp[curr];
		++mp[curr];
		pw = (pw * 10) % mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	char c;
	cin>>c;
	if('A'<=c&&c<='Z'){
		cout<<"A";
	}else{
		cout<<"a";
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
 
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	long long int n,count=0,i;
	cin>>n;
	int res=abs((-1+sqrt(abs((1-(4*1*2*n)))))/2);
	cout <<res+1;
	
}

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

int main(){
  int a, b, c;
  cin>>a>>b>>c;
  int k;
  cin>>k;
  int count=0;
  while (a>=b){
    b*=2;
    count++;
  }
  while (b>=c){
    c*=2;
    count++;
  }
  if (count<=k) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
def xor_sum(a)
  (0..40).map{|i| include1_num(a,i)}
end

def include1_num(a,i)
  (((a + 1) / 2 ** (i + 1)) * (2 ** i) + [(a + 1) % (2 ** (i + 1)) - 2 ** i,0].max) % 2
end
a,b = gets.chomp.split(' ').map(&:to_i)
num = 0
(0..40).each do |i|
  num += 2 ** i if xor_sum(a - 1)[i] != xor_sum(b)[i] 
end
puts num

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

using namespace std;

const int inf = 0x3f3f3f3f;

string s, l;
int pd[3030][3030];

int solve(int x, int y){
  if(pd[x][y] != -1) return pd[x][y];
  if(x == s.size() || y == l.size()) return 0;

  pd[x][y] = 0;

  if(s[x] == l[y]) pd[x][y] = solve(x+1, y+1) + 1;

  pd[x][y] = max(pd[x][y], solve(x, y+1));
  pd[x][y] = max(pd[x][y], solve(x+1, y+1));
  pd[x][y] = max(pd[x][y], solve(x+1, y));

  return pd[x][y];
}

int loop[3030][3030];
void rebuild(int x, int y, string& ans){
  if(pd[x][y] < pd[0][0] - ans.size()) return ;
  if(loop[x][y]) return ;
  if(x == s.size() || y == l.size()) return ;

  //cout << ans << " " << x << " " << y << " = " << pd[x][y] << endl;

  loop[x][y] = 1;

  if(s[x] == l[y]){
    if(pd[x][y] == pd[0][0] - ans.size()){
      ans = ans + s[x];
    }
    rebuild(x+1, y+1, ans);
  }

  rebuild(x, y+1, ans);
  rebuild(x+1, y, ans);
  rebuild(x+1, y+1, ans);
}

int main(){
  cin>>s>>l;

  memset(pd, -1, sizeof pd);

  //cout << solve(0,0) << endl;
  solve(0,0);

  string saida = "";
  memset(loop, 0, sizeof loop);
  rebuild(0, 0, saida);
  cout << saida << endl;

  /*for(int i=0 ; i<s.size() ; i++){
    for(int j=0 ; j<l.size() ; j++)
      cout<<pd[i][j];
    cout<<endl;;
  }*/
}

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

int main() {

    int K, X;
    cin >> K >> X;

    for (int i = X - K + 1; i < X + K; ++i) {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

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

int main()
{
    map<string, int> s;

    int n; cin>>n;
    for(string x; n--; ++s[x]) cin>>x;

    int m; cin>>m;
    for(string x; m--; --s[x]) cin>>x;

    int res=0;
    for(auto& e: s) res=max(res, e.second);
    cout<<res<<endl;
}

Measured memory_bytes: 256
def mod2(n):
    return n%2

def f(L): #L=[A,B,C]
    L2 = list(map(mod2, L))
    num0 = L2.count(0)
    if num0 == 0 or num0 == 3:
        L.sort()
        L.reverse()
        return (L[0] * 2 -L[2] - L[1]) //2
    else:
        d = 0 if num0 == 1 else 1
        m = {0, 1, 2} - {L2.index(d)}
        Lnext = [L[n] + 1 if n in m else L[n] for n in range(3)]
        return 1 + f(Lnext)
        
print(f(list(map(int, input().split()))))

Measured memory_bytes: 3064
N=int(input())
S=list(input())

count=0
LR=[0,0]
for i in range(N):
    if S[i]=="(":
        count+=1
    else:
        if count==0:
            LR[0]+=1
            continue
        count-=1

LR[1]=count
for i in range(2):
    for j in range(LR[i]):
        if i==0:
            S.insert(0,"(")
        else:
            S.append(")")

print("".join(S))

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

int main() {
  string s;
  cin >> s;
  char prev = s[0];
  int ans = 0;
  for(int i = 1; i < s.size(); ++i) {
    if(prev != s[i]) {
      ans++;
    }
    prev = s[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = list(input())
b = [0]*n
for i in range(m):
    b[i] = list(input())
ans = 0
for i in range(0,n-m+1):
    if ans == 1:
        break
    for j in range(0,n-m+1):
        sw = 1
        for x in range(m):
            for y in range(m):
                if a[i+x][j+y] == b[x][y]:
                    pass
                else:
                    sw = 0
        if sw == 1:
            ans = 1
            break
print(["No","Yes"][ans])

Measured memory_bytes: 9072
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt(),w=sc.nextInt(),n=0,a[][]=new int[h][w],t[][]=new int[h][w];
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                a[i][j]=sc.nextInt();
                t[i][j]=a[i][j];
            }
        }
        sc.close();
        for(int i=0;i<h-1;++i){
            for(int j=0;j<w;++j){
                if(t[i][j]%2!=0){
                    --t[i][j];
                    ++t[i+1][j];
                    ++n;
                }
            }
        }
        for(int i=0;i<w-1;++i){
            if(t[h-1][i]%2!=0){
                --t[h-1][i];
                ++t[h-1][i+1];
                ++n;
            }
        }
        System.out.println(n);
        for(int i=0;i<h-1;++i){
            for(int j=0;j<w;++j){
                if(a[i][j]%2!=0){
                    --a[i][j];
                    ++a[i+1][j];
                    System.out.println((i+1)+" "+(j+1)+" "+(i+2)+" "+(j+1));
                }
            }
        }
        for(int i=0;i<w-1;++i){
            if(a[h-1][i]%2!=0){
                --a[h-1][i];
                ++a[h-1][i+1];
                System.out.println(h+" "+(i+1)+" "+h+" "+(i+2));
            }
        }
    }
}

Measured memory_bytes: 96468
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){

int N;
cin >> N;
vector<vector<int>> seat(N, vector<int>(2));
for (int i = 0; i < N; i++){
     for (int j = 0; j < 2; j++){
          cin >> seat.at(i).at(j);
     }
}

int people = 0;

for (int i = 0; i < N; i++){
     people += seat.at(i).at(1) - seat.at(i).at(0) + 1;
}

cout << people << endl;

return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		double a=sc.nextInt();
		double b=sc.nextInt();
		double h=sc.nextInt();
		double m=sc.nextInt();



		double angle = Math.toRadians( (h * 30 + m * 0.5) - m * 6 );
		double ans = Math.sqrt( a * a + b * b - 2 * a * b * Math.cos(angle) );

		System.out.printf("%.20f %n", ans);





		sc.close();

	}

}


Measured memory_bytes: 36000
#include <iostream>
#include <cstdint>

using namespace std;

int main()
{
    int r, d, x2000;

    cin >> r >> d >> x2000;

    int64_t x = x2000;
    for (int i = 1; i <= 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,M,ans=1;
  cin >> N >> M;
  for(int i=1;i<=sqrt(M);i++){
    if(M%i==0){
      int x=M/i,y=i;
      if(y>ans && x>=N) ans=y;
      if(x>ans && y>=N) ans=x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;


int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	 // int t ;
	 // cin>>t;
	 // whln(t){

    ll n ;
    cin>>n;
    cout<<(n+1)/2;

		
}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

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

int main() {
  int x;
  cin >> x;
  int coin500 = x/500, coin5 = (x%500)/5;
  cout << coin500*1000+coin5*5 << endl;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}

signed main() {
	int a;
	cin >> a;
	int b = a / 1000, c = a / 100 % 10, d = a / 10 % 10, e = a % 10;
	//cout << b << " "<<c <<" "<< d <<" "<< e << endl;
	if (b == c || c == d || d == e) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

long long arr[55];
long long stu[55];
long long ans = 0;
int n;
long long x;
void f(int d){
    if(x==arr[d]){
        ans += stu[d];
        return ;
    }else if(x){
        x--;
        if(x>=arr[d-1]){
            x-=arr[d-1];
            ans += stu[d-1];
            if(x==0){
                return ;
            }else {
                x--;
                ans++;
                if(x)f(d-1);
            }

        } else f(d-1);
    }
}
int main(){
    arr[0] = 1;
    arr[1] = 5;
    arr[2] = 13;
    stu[0] = 1;
    stu[1] = 3;
    stu[2] = 7;
    for(int i=3;i<51;i++){
        //arr[i] = 1+arr[i-1]+1+arr[i-1]+1;
        arr[i] = arr[i-1]*2+3;
        stu[i] = stu[i-1]*2+1;
    }


    scanf("%d%lld",&n,&x);
    f(n);
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const ll inf = 1e18 + 7;
const int N = 3e5 + 17;

int n, m;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	n = sz(s);
	vi a(n + 1);
	vi cur(n + 1);
	for (int k = 0; k < 26; k++) {
		for (int i = 0; i < n; i++) {
			a[i + 1] = s[i] - 'a' == k ? 1 : 0;	
			cur[i + 1] = a[i + 1] + cur[i];
		}
		set<ii> w;
		ii last = {0, 0};
		for (int i = 1; i <= n; i++) {
			if (sz(w)) {
				auto f = *w.begin();
				if (2 * cur[i] - i > f.fi) { cout << f.se + 1 << " " << i << endl; re 0; }
			}
			w.insert(last);
			last = mp(2 * cur[i] - i, i);
		}
	}
	cout << -1 << " " << -1;	
}


Measured memory_bytes: 8748
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	string str;
	cin>>str;
	vi rl(N),wr(N);
	if(str[0]=='W')
		rl[0]=1;
	F0R(x,N-1)
	{
		rl[x+1]=rl[x];
		if(str[x+1]=='W')
			rl[x+1]++;
		 // bug(rl[x+1]);
	}
	if(str.back()=='R')
		wr.back()=1;
	F0Rd(x,N-1)
	{
		wr[x]=wr[x+1];
		if(str[x]=='R')
			wr[x]++;
		// bug(wr[x]);
	}
	int ans=min(wr[0],rl.back());
	F0R(x,N-1)
	{
		int val=min(wr[x+1],rl[x])+abs(wr[x+1]-rl[x]);
		ckmin(ans,val);
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 5160
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long n, x;
    readlnTo(n, x);
    auto a = readLongs();

    long ans;
    foreach(i; iota(n-1)) {
        auto d = a[i] + a[i+1] - x;
        if(d > 0) {
            a[i+1] -= min(a[i+1], d);
            ans += d;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 4220
N = int(input())
s = []
for i in range(N):
    s.append(int(input()))
s.sort()
ssum = sum(s)
dp = [[-(10**5) for i in range(ssum+1)] for j in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    for j in range(ssum+1):
        if j-s[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-s[i-1]]+s[i-1])
        else:
            dp[i][j] = dp[i-1][j]

maxa = 0
for j in range(N+1):
    for i in range(ssum+1):
        if (dp[j][i])%10 == 0:
            continue
        else:
            now = dp[j][i]
            maxa = max(maxa,now)

print(maxa)

Measured memory_bytes: 27252
// Problem : D - String Equivalence
// Contest : AtCoder - Panasonic Programming Contest 2020
// URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

int n;

void dfs(string cur, char limit){
    if(sz(cur) == n){
        cout<<cur<<endl;
        return;
    }
    for(char c='a';c<=limit;c++) dfs(cur+c,(c == limit ? limit+1 : limit));
}

void solve(){
    cin>>n;
    dfs("",'a');
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k,x,y;
  cin >> n >> k >> x >> y;

  cout << min(n,k) * x + max(0,n-k) * y << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define test ll t;cin>>t;while(t--)
#define rep(i,k,n) for(ll i=k;i<n;i++)
#define MOD 998244353
#define fast  ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define pb push_back
#define mod 1000000007
#define MAX 100000
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
ll power(ll x, ll y, ll p)  { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
ll max(ll a, ll b) {if (a > b)return a; return b;}
ll min(ll a, ll b) {if (a < b)return a; return b;}
ll ssum(ll n) {return (n * (n + 1)) / 2;}
ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}


// void mult(ll a[][2] , ll b[][2]) {
// 	ll c[2][2];
// 	rep(i, 0, 2) {
// 		rep(j, 0, 2) {
// 			c[i][j] = 0;
// 			rep(k, 0, 2)
// 			c[i][j] = (c[i][j] % mod + ( a[i][k] * b[k][j]) % mod) % mod;
// 		}
// 	}
// 	rep(i, 0, 2)
// 	rep(j, 0, 2)
// 	a[i][j] = c[i][j];
// }

// ll fib(ll n, ll a, ll b) {
// 	ll I[2][2] = {{1, 0}, {0, 1}};
// 	ll A[2][2] = {{0, 0}, {1, (b / a)}};
// 	while (n) {
// 		if (n % 2)
// 			mult(I, A);
// 		mult(A, A);
// 		n /= 2;
// 	}
// 	return a * I[0][0] + b * I[1][0];
// }



int main() {


	ll n;
	cin >> n;
	ll dp[n], a[n];
	rep(i, 0, n) {
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	rep(i, 2, n) {
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 1792
using System;

class Program
{
    static void Main(string[] args)
    {
      string s = Console.ReadLine();
      string t = Console.ReadLine();
      
      int ans = 0;
      for(int i=0;i<3;i++)
      {
        if(s[i] == t[i])
          ans++;
      }
      Console.WriteLine(ans );
    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll a = 2;
  ll b = 1;
  REP(i, 0, n) {
    ll c = a + b;
    a = b;
    b = c;
  }
  cout << a << endl;
}


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

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

    vector<string> w(n);
    for(int i=0; i<n; i++){
        cin >> w[i];
    }

    for(int i=1; i<n; i++){
        if(w[i-1][w[i-1].length()-1] != w[i][0]){
            cout << "No" << endl;
            return 0;
        }
    }

    sort(w.begin(), w.end());
    for(int i=1; i<n; i++){
        if(w[i-1] == w[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();

            var a = cin.ArrayInt(2);
            var aa = new string[2];
            for (int i = 0; i < a[1]; i++)
            {
                aa[0] += a[0];
            }

            for (int i = 0; i < a[0]; i++)
            {
                aa[1] += a[1];
            }
            
            Array.Sort(aa);

            Console.WriteLine(aa[0]);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11360
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  ll h, n;
  cin >> h >> n;
  vl a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vvl data(h + 1, vl(n, 0));
  rep(i, h + 1) {
    if (i > 0) {
      ll tmp = i / a[0];
      if (i % a[0]) tmp++;
      tmp *= b[0];
      data[i][0] = tmp;
    }
  }
  REP(j, 1, n) {
    REP(i, 1, h + 1) {
      if (i - a[j] >= 0) {
        data[i][j] = min(data[i][j - 1], data[i - a[j]][j] + b[j]);
      } else {
        data[i][j] = min(data[i][j - 1], b[j]);
      }
    }
  }
  // cerr << "!" << endl;
  cout << data[h][n - 1] << endl;
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int h, w, m;
	cin >> h >> w >> m;

	unordered_map<int, unordered_set<int>> mpx, mpy;

	int inx, iny;

	for (int i = 0; i < m; i++) {
		cin >> inx >> iny;
		mpx[inx].insert(iny);
		mpy[iny].insert(inx);
	}

	vector<int> vx, vy;

	int mx = 0, my = 0;

	for (auto x: mpx)
		mx = max((int)x.second.size(), mx);

	for (auto y: mpy)
		my = max((int)y.second.size(), my);

	// deb(mx);
	// deb(my);

	for (auto x: mpx)
		if (x.second.size() == mx)
			vx.push_back(x.first);

	for (auto y: mpy)
		if (y.second.size() == my)
			vy.push_back(y.first);

	// for (int x: vx) cout << x << " ";
	// cout << endl;

	// for (int y: vy) cout << y << " ";
	// cout << endl;

	int res = mx + my - 1;
	bool end = false;

	for (int i = 0; i < vx.size() && !end; i++) {
		for (int j = 0; j < vy.size(); j++) {
			if (mpx[vx[i]].find(vy[j]) == mpx[vx[i]].end()) {
				end = true;
				res++;
				break;
			}
		}
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 100140
n = int(input())
tlist=list(map(int, input().split()))
m=int(input())
total=sum(tlist)
ans = []
for i in range(m):
    p,x=map(int,input().split())
    ans.append(total-tlist[p-1]+x)

for t in range(m):
    print(ans[t])

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;


signed main()
{
	int N, K;
	cin >> N >> K;

	if (K == 0)
	{
		cout << N * N << endl;
		return 0;
	}

	int sum = 0;
	for (int i = 1; i <= N; i++)
	{
		int l = K - 1;
		int ll = K % i;
		if (ll > 0)
		{
			l += (i - ll);
			sum += MAX(0, (i - MAX(ll, K)));
		}

		int r = N + 1;
		int rr = N % i;
		if (rr < i - 1)
		{
			r -= (rr + 1);
			sum += MAX(0, rr - K + 1);
		}

		int a = MAX(0, i - K);
		int s = ((r - l - 1) / i) * a;
		sum += s;
	}

	cout << sum << endl;
}







Measured memory_bytes: 256
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = ii()
    B = ii()
    C = ii()
    X = ii()
    print(len([1 for a in range(A+1) for b in range(B+1) for c in range(C+1) if 500*a+100*b+50*c == X]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> u(n+1);
	for (int i = 0; i < n;i++){
		cin >> v[i];
	}
	v.push_back(0);
	u[0] = v[0];
	for (int i = 0; i < n+1;i++){
		if (0 < i) u[i] = v[i]-v[i-1];
	}
	int ans = 0;
	for (int i = 0; i < n+1;i++){
		if (u[i] > 0) ans+=u[i];
	}
	//for (int i = 0; i < n;i++){
	//	cout << u[i] << " ";
	//}
	//cout << endl;
	cout << ans << endl;
	
	
	return 0; 
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a%2;
  d = b%2;
  a = a+c;
  b = b+d;
  cout << ((a+b)/2)-((c+d)/2) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;
#define def 0

int main() {
  //
  ll n;
  cin >> n;
  ll odd = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a & 1) odd++;
  }
  if (odd & 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 632
#include<stdio.h>
#include<math.h>
 
int main(void){
    int n, x[100], y[100];
    double tmp;
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &x[i]);
    for(int i=0; i<n; i++) scanf("%d", &y[i]);
    tmp=0;
    for(int i=0; i<n; i++) tmp+=abs(x[i]-y[i]);
    printf("%lf\n", tmp);
    tmp=0;
    for(int i=0; i<n; i++) tmp+=abs(x[i]-y[i])*abs(x[i]-y[i]);
    printf("%lf\n", sqrt(tmp));
    tmp=0;
    for(int i=0; i<n; i++) tmp+=abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i]);
    printf("%lf\n", cbrt(tmp));
    tmp=0;
    for(int i=0; i<n; i++) if(tmp<abs(x[i]-y[i])) tmp=abs(x[i]-y[i]);
    printf("%lf\n", tmp);
    return 0;
}


Measured memory_bytes: 2112
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
const int INF = 1e9;
struct Edge{
    int dst, cap, rev;
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;
struct Dinic{
    Graph G;
    vector<int> level;
    vector<int> iter;
    
    Dinic(int N) : G(N), level(N), iter(N) {}

    void bfs(int s){
        level.assign(G.size(), -1);
        queue<int> que;
        que.push(s);
        level[s] = 0;
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(const auto& e : G[v]){
                if(e.cap > 0 && level[e.dst] < 0){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
            }
        }
    }

    int dfs(int v, int t, int f){
        if(v == t) return f;
        for(int& i = iter[v]; i < G[v].size(); i++){
            Edge& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.dst]){
                int d = dfs(e.dst, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.dst][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    void add_edge(int src, int dst, int cap){
        G[src].push_back({dst, cap, (int)G[dst].size()});
        G[dst].push_back({src, 0, (int)G[src].size() - 1});
    }

    int max_flow(int src, int dst){
        int flow = 0;
        while(true){
            bfs(src);
            if(level[dst] < 0) break;
            iter.assign(G.size(), 0);
            while(true){
                int f = dfs(src, dst, INF);
                if(f <= 0) break;
                flow += f;
            }
        }
        return flow;
    }
};
int main(){
    iostream_init();
    int H, W;
    while(cin >> H >> W) {
        string grid[100];
        REP(y, H) cin >> grid[y];
        vector<pair<int, int>> ps;
        REP(y, H) REP(x, W) if(grid[y][x] == 'S') ps.push_back(make_pair(x, y));
        REP(y, H) REP(x, W) if(grid[y][x] == 'T') ps.push_back(make_pair(x, y));
        REP(y, H) REP(x, W) if(grid[y][x] == 'o') ps.push_back(make_pair(x, y));

        Dinic dinic(ps.size() + ps.size() + W + H);
        REP(i, ps.size()) {
            int w = ps[i].first + ps.size() + ps.size();
            int h = ps[i].second + W + ps.size() + ps.size();
            dinic.add_edge(i, i + ps.size(), 1);
            dinic.add_edge(i + ps.size(), w, INF);
            dinic.add_edge(w, i, INF);
            dinic.add_edge(i + ps.size(), h, INF);
            dinic.add_edge(h, i, INF);
        }
        int ans = dinic.max_flow(0 + ps.size(), 1);
        if(ps[0].first == ps[1].first) ans = -1;
        if(ps[0].second == ps[1].second) ans = -1;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 2944
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();

		int K = scanner.nextInt();

		String S = scanner.next();

		String[] scannerArray = new String[N];

		scannerArray = S.split("");

		long ans = 0;

		for(int index = 1; index < N; index++) {
			if(scannerArray[index - 1].equals(scannerArray[index])) {
				ans++;
			}
		}

		ans += 2*K;

		log(Math.min(ans, N-1));

	}

	private static void dfs(int[] treeArray,int parrent, int children) {
		Vector<Vector> aa = new Vector<>();
		Vector<Integer> bb = new Vector<>();
		bb.add(1);
		aa.add(bb);
	}


	/**
	 * バブルソートの交換数を算出
	 * ※転倒数
	 * @param array
	 * @return
	 */
	private static long countSwapBabbleSort(int[] array, int N) {
		long ans = 0;
		int[] binary = new int[N + 1];

		for (int index = 0; index < array.length; index++) {
			ans = ans + (index - sum(binary, array[index]));
			add(binary, array[index], 1);
		}
		return ans;
	}

    //add value at idx on bit O(logN)
	private static void add(int[] bit,int idx,int value) {
        for(int i=idx;i<bit.length;i=i+(i&-i)) {
        	bit[i] += value;
        }
    }

    //return sum [1,idx] O(logN)
	private static long sum(int[] bit,int idx) {
        long ret = 0;
        for(int i=idx;i>0;i-=(i&-i)) {
        	ret += bit[i];
        }
        return ret;
    }

	private static void log(String str) {
		System.out.println(str);
	}

	private static void log(int str) {
		System.out.println(str);
	}

	private static void log(long str) {
		System.out.println(str);
	}

	private static void log(double str) {
		System.out.println(str);
	}

	private static void log(BigInteger str) {
		System.out.println(str);
	}

}



Measured memory_bytes: 34248
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b>> c;
  int answer;
  if(a==b){
    answer=c;
  }else if(b==c){
    answer = a;
  }else{
    answer=b;
  }
  cout << answer << endl;
  return 0;
}

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

ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		boolean f = true;
		if(a > x) {
			f = false;
		}
		else {
			if(x - a > b) {
				f = false;
			}
		}

		if(f) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
import math
import sys
def cross(a, b):
	return a[0]*b[1]-a[1]*b[0]
def dot(a, b):
	return a[0]*b[0]+a[1]*b[1]
def counterclockwise(a, b):
	return cross(a, b)<0
def sub(a, b):
	return [a[0]-b[0], a[1]-b[1]]
n=input()
p=[map(int, raw_input().split()) for i in range(n)]
index={tuple(p[i]): i for i in range(n)}
p.sort()
hull=[p[0]]
min_size=1
for i in range(1, n):
	while len(hull)>min_size and not counterclockwise(sub(p[i], hull[-1]), sub(hull[-1], hull[-2])):
		del hull[-1]
	hull.append(p[i])
assert hull[-1]==p[-1]
min_size=len(hull)
for i in range(n-2, -1, -1):
	while len(hull)>min_size and not counterclockwise(sub(p[i], hull[-1]), sub(hull[-1], hull[-2])):
		del hull[-1]
	hull.append(p[i])
assert hull[0]==hull[-1]==p[0]
del hull[-1]
result=[0.0]*n
print>>sys.stderr, hull
for i in range(len(hull)):
	a=sub(hull[(i+1)%len(hull)], hull[i])
	b=sub(hull[i], hull[i-1])
	value=dot(a, b)/math.sqrt(dot(a, a))/math.sqrt(dot(b, b))
	value=min(max(value, -1.0), 1.0)
	angle=math.acos(value)
	result[index[tuple(hull[i])]]=angle
for i in range(n):
	print result[i]/math.pi/2, 
print


Measured memory_bytes: 2820
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 100000000000000

int main(){
  int n;
  cin >> n;
  long long d[n];
  for(int i=0;i<n;i++) cin >> d[i];
  long long ans;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define maxn 100005
#define mod 1000000007
int h,w,a,b,fact[maxn*2]={1},inv[maxn*2]={1},ans;
int powmod(int a,int n)
{
	int res=1;
	while(n)
	{
		if(n&1) res=1ll*res*a%mod;
		a=1ll*a*a%mod;
		n>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d%d",&h,&w,&a,&b);
	for(int i=1;i<=w+h;i++)
	{
		fact[i]=1ll*fact[i-1]*i%mod;
		inv[i]=powmod(fact[i],mod-2);
	}
	for(int i=b+1;i<=w;i++)
		ans=1ll*(ans+1ll*fact[i+h-a-2]*inv[i-1]%mod*inv[h-a-1]%mod*fact[a+w-i-1]%mod*inv[a-1]%mod*inv[w-i]%mod)%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

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

   ll h[n],b[n];
   for(ll i=0;i<n;i++)
    cin>>h[i];
  for(ll i=0;i<n;i++)
    cin>>b[i];

   set<pair<ll,ll> > s;

  for(ll i=0;i<n;i++)
  {
    ll ht=h[i],bt=b[i];

    if(i==0)
   s.insert(mp(ht,bt));

   else
   {
    auto it=s.lower_bound({ht,-inf});

    if(it!=s.begin())
    {
      it--;
      bt+=it->ss;
      it++;   
    }

    while( it!=s.end() and bt>= it->ss )
    {
        s.erase(it);
      it=s.lower_bound({ht,-inf});
    }  
    s.insert({ht,bt});
  }
}
  ll ans=*max_element(b,b+n);

  for(auto i:s)
    ans=max(ans,i.ss);
  cout<<ans<<endl;
 
  }

Measured memory_bytes: 15872