akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Curtain
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');

        var longer = int.Parse(input[0]);
        var curtain = int.Parse(input[1]);

        var ans = 0;

        if(longer - curtain * 2 > 0)
        {
            ans = longer - curtain * 2;
        }
        else
        {
            ans = 0;
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
N = int(input())
S = input()
ans = ""

for i in range(len(S)):
    if ord(S[i]) + N > ord("Z"):
        ans += chr(ord(S[i]) + N - (ord("Z") - ord("A") + 1))
    else:
        ans += chr(ord(S[i]) + N)
print(ans)


Measured memory_bytes: 3060
import math
def gcd3(a,b,c):
    return math.gcd(math.gcd(a,b),c)
def main():
    K=int(input())
    ans=0
    for i in range(1,K+1):
        for j in range(1,i+1):
            for k in range(1,j+1):
                if i==j and j==k:
                    ans+=i
                elif i!=j and j!=k and k!=i:
                    ans+=gcd3(i,j,k)*6
                else:
                    ans+=gcd3(i,j,k)*3
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    if(n<k){
        long long ans = n%k;
        long long ans1 = k-ans;
        n = min(ans,ans1);
    }
    else{
        long long ans = n%k;
        while(ans>k){
            ans = ans%k;
        }
        long long ans2 = n%k;
        long long ans3 = k-ans2;
        n = min(ans2,ans3);
    }
    cout << n <<endl;
    return 0;
}


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

using namespace std;

using ll = long long;

inline ll cnt(ll x, ll y) { return (x < 0 ? 0ll : x / y + 1); }

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

    ll a, b, x;
    cin >> a >> b >> x;
    cout << cnt(b, x) - cnt(a - 1, x) << endl;

    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  ll n; cin >> n;
  ll a[n];
  ll sum = 0;
  bool even = true;
  bool odd = true;
  for(ll i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if(a[i]%2 ==1) even = false;
    if(a[i]%2 ==0) odd = false;
  }
  if(even) {
    cout << "second" << endl;
  } else {
    if(n % 2 == 0) {
      if(sum == n) cout << "first" << endl;
      else if(odd) cout << "first" << endl;
      else if(sum % 2 == 0) cout << "second" << endl;
      else cout << "first" << endl;
    } else {
      cout << "first" << endl;
    }
  }

  return 0;
}




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

#define ll long long int 
#define pii pair<int, int>
#define INF 0x3f3f3f3f
#define fi first
#define se second
#define f(n) for(int i = 0; i < n; i++)
#define f2(n) for(int i = 1; i <= n; i++)
#define debug(x) if(on)cout << x << endl
#define on true
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back

int gcd(int a, int b){
	if(a%b == 0)
		return b;

	return gcd(b, a%b);
}


int main(){
	
	int n, aux;

	vector<int> v, l, r;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> aux;
		v.pb(aux);
	}

	aux = v[0];
	l.pb(0);
	l.pb(aux);
	for(int i = 1; i < n; i++){
		l.pb(gcd(aux, v[i]));
		aux = gcd(aux, v[i]);
	}

	aux = v[n-1];
	r.pb(0);
	r.pb(aux);
	for(int i = n-2; i >= 0; i--){
		r.pb(gcd(aux, v[i]));
		aux = gcd(aux, v[i]);
	}
	r.pb(0);
	reverse(r.begin(), r.end());

	
	l[0] = r[1];
	r[n+1] = l[n];
	
	int mx = -1;
	for(int i = 2; i < n; i++){	
		if(gcd(l[i-1], r[i+1]) > mx)
			mx = gcd(l[i-1], r[i+1]);
	}
	
	mx = max(mx, r[2]);
	mx = max(mx, l[n-1]);
	mx = max(mx, l[0]);

	cout <<  mx << endl;

return 0;
}






Measured memory_bytes: 1784
// B - 754
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s; cin>>s;
	int mini = INT_MAX;
	for(int i=0; i<s.size()-2; ++i){
		int diff = abs(753 - stoi(s.substr(i,3)));
		if(mini > diff) mini = diff;
	}
	cout<< mini <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,K,Q;
	cin >> N >> K >> Q;
	vector<int> vec(Q);
	for(int i = 0;i < Q;i++) {
		cin >> vec.at(i);
	}
	vector<int> cnt(N);
	for(int i = 0;i < N;i++) {
		cnt.at(i) = K;
	}
	for(int i = 0;i < Q;i++) {
		cnt.at(vec.at(i) - 1)++;
	}
	for(int i = 0;i < N;i++) {
		if(cnt.at(i) - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if(X < A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include<iostream>


int main(){
    char a;
    while(1){
        scanf("%c", &a);
        if(isalpha(a)){
            if(isupper(a)) printf("%c", tolower(a));
            else printf("%c", toupper(a));
        }
        else printf("%c", a);
        if(a == '\n')break;
    }
    return 0;
}



Measured memory_bytes: 3152
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	int num[100] = {};
	for (int i = 0; i < N; i++)cin >> num[i];
	sort(num, num + N);
	reverse(num, num + N);
	for (int i = 0; i < M; i++)ans += num[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
VALUES = [10000, 5000, 1000]

(bills, money) = (int(tok) for tok in input().split())
res = (-1, -1, -1)

for i in range(bills + 1):
  for j in range(bills - i + 1):
    k = bills - i - j
    curr_money = i * VALUES[0] + j * VALUES[1] + k * VALUES[2]
    
    if curr_money == money:
      res = (i, j, k)

print(res[0], res[1], res[2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
int a[300];
bool f()
{
	bool f=true;
	for(int i=0;i<n;i++)
		if(a[i]%2==1)
			f=false;
	return f;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0;
	while(f())
	{
		ans++;
		for(int i=0;i<n;i++)
			a[i]/=2;
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int N,i,ans=1;
  char S[100000];
  cin >> N;
  for(i=0;i<N;i++)cin >> S[i];
  for(i=0;i<N-1;i++) {
    if(S[i] != S[i+1])ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
/**    epsileer 10 August 2019  17:34:06  **/    
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> PII;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define TEST int t = 1; while(t--) solve()

void solve(){
    int k,n; cin>>k>>n;
    int temp = k;
    vector<int> a; a.PB(n);
    for(int i=1;i<k;i++){
        if(n-i >= -1000000)
            a.PB(n-i);
    }
    for(int i=1;i<k;i++){
        if(n+i <= 1000000)
            a.PB(n+i);
    }
    sort(a.begin(), a.end());
    for(int i=0;i<a.size();i++)
        cout<<a[i]<<" ";
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int h,w,n;
    cin>>h>>w>>n;
    vector<int> a;
    REP(i,0,n){
        int tmp;
        cin>>tmp;
        REP(j,0,tmp) a.push_back(i+1);
    }
    
    vector< vector<int> > ans = vector< vector<int> > (h,vector<int>(w,0));
    
    int nextx=0,nexty=0;
    REP(i,0,a.size()){
        ans[nexty][nextx] = a[i];
        if(nextx+1<w && ans[nexty][nextx+1]==0) nextx++;
        else if(nexty+1<h && ans[nexty+1][nextx]==0) nexty++;
        else if(nextx-1>=0 && ans[nexty][nextx-1]==0) nextx--;
        else if(nexty-1>=0 && ans[nexty-1][nextx]==0) nexty--;
    }
    REP(i,0,h){
        REP(j,0,w) cout<<ans[i][j]<<" ";
        cout<<ENT;
    }
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
ll x[1000000];
int main()
{
  ll a,b,c=0,d,e,i,j,k;
  char s[1000];
  in>>a;
  for(i=0;i<a;i++)
  {
      in>>x[i];
  }
  sort(x,x+a);
  for(i=0;i<a;i++)
  {
      for(j=i+1;j<a;j++)
      {
          for(k=j+1;k<a;k++)
          {
              if(x[i]!=x[j]&&x[j]!=x[k])
              {
                  if(x[i]+x[j]>x[k])
                  {
                      c++;
                  }
              }
          }
      }
  }
  out<<c<<nl;

}


Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			
			if(H==0&&W==0) {
				break;
			}
				
			for(int i=0; i<H; i++) {
				for(int j=0; j<W; j++) {
					System.out.printf("#");
				}
				System.out.printf("%n");
			}
			
			System.out.printf("%n");
		}
	}

}



Measured memory_bytes: 81744
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        char c = input.charAt(0);
        
        switch(c) {
        case 'A':
            System.out.println('T');
            break;
        case 'C':
            System.out.println('G');
            break;
        case 'G':
            System.out.println('C');
            break;
        case 'T':
            System.out.println('A');
            break;
        default:
            break;
        }
        
        
    }
}


Measured memory_bytes: 20820
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a = Integer.parseInt(s.substring(s.length()-1));

        System.out.println(a == 3 ? "bon" : (a == 0 || a == 1 || a == 6 || a == 8) ? "pon" : "hon");
        sc.close();

    }

}


Measured memory_bytes: 35620
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
before = 30
for i in range(N):
    ate = A[i]-1
    ans += B[ate]
    if before+1==ate:
        ans += C[ate-1]
    before = ate
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int gcd(int a, int b) {
		if (b == 0) return a;
		gcd(b, a % b);
}

int main() {
		int N;
		cin >> N;
		int A[N];
		for (int i = 0; i < N; i++) cin >> A[i];

		int L[N];
		L[0] = A[0];
		for (int i = 1; i < N; i++) {
				L[i] = gcd(L[i-1], A[i]);
		}

		int R[N];
		R[0] = A[N-1];
		for (int i = 1; i < N; i++) {
				R[i] = gcd(R[i-1], A[N-1-i]);
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
				if (i==0) ans = max(ans, R[N-2]);
				else if (i==N-1) ans = max(ans, L[N-2]);
				else ans = max(ans, gcd(L[i-1], R[N-i-2]));
		}

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


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

#define maxn 1005
#define N 100000
#define inf (int) 2e9
#define mode (int) 1000000007
#define ll long long
#define ii pair <int, int>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

int m, n;
char a[maxn][maxn];
int f[maxn][maxn];

int main() {
    //freopen("main.inp", "r", stdin);
    cin >> m >> n;
    FOR(i, 1, m)
       FOR(j, 1, n)
           cin >> a[i][j];
    FOR(i, 1, m)
       if(a[i][1] == '.')
          f[i][1] = 1;
       else break;
    FOR(j, 1, n)
       if(a[1][j] == '.')
          f[1][j] = 1;
       else break;
    FOR(i, 2, m)
       FOR(j, 2, n) {
           if(a[i][j] == '.')
              f[i][j] += f[i - 1][j] + f[i][j - 1];
              f[i][j] %= mode;
       }
    cout << f[m][n];
}


Measured memory_bytes: 8444
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();

        // 主処理
        List<String> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            String head = s.substring(i, s.length());
            String foot = s.substring(0, i);
            String word = head + foot;
            list.add(word);
        }
        boolean judge = list.contains(t);
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22740
#!/bin/sh                                                                                                                             
read n x
m=$n

b=$(( ( n | x ) & -( n | x ) ))
n=$((n/b))
x=$((x/b))

while [ $x -ne 0 ]
do
    x=$(( x / ( x & -x ) ))
    [ $n -gt $x ] && n=$(( ( x ^= ( n^= x ) ) ^ n ))
    x=$(( x - n ))
done
echo $(( (m - n * b) * 3 ))

Measured memory_bytes: 376
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5;

int n;

vector<int> adj[MAXN + 5];

int type[MAXN + 5];

inline char safe_getchar()
{
	register char ch(getchar());
	while(!isdigit(ch)) ch = getchar();
	return ch;
}

inline void input()
{
	n = read<int>();
	for(int i = 1; i < n; ++i)
	{
		int u = read<int>(), v = read<int>();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i = 1; i <= n; ++i) type[i] = safe_getchar() - '0';
}

const int INF = (int) 1e9;

int f[MAXN + 5], g[MAXN + 5], anc[MAXN + 5];

inline void dfs_f(int u, int fa)
{
	anc[u] = fa;

	f[u] = 0;
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_f(v, u);
		chkmax(f[u], f[v] + 1);
	}
}

inline void dfs_g(int u, int fa)
{
	int deg = SZ(adj[u]) - 1;

	static int pre[MAXN + 5], suf[MAXN + 5];

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		pre[i] = suf[i] = v == fa ? 0 : f[v] + 1;
	}
	for(int i = 1; i <= deg; ++i) chkmax(pre[i], pre[i - 1]);
	for(int i = deg - 1; i >= 0; --i) chkmax(suf[i], suf[i + 1]);

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		if(v != fa)
		{
			int res = g[u];
			if(i > 0) chkmax(res, pre[i - 1]);
			if(i < deg) chkmax(res, suf[i + 1]);
			chkmax(g[v], res + 1);
		}
	}

	for(auto v : adj[u]) if(v != fa)
		dfs_g(v, u);
}

int size[MAXN + 5], p[MAXN + 5], q[MAXN + 5];

inline void dfs_pq(int u, int fa, int tot)
{
	p[u] = type[u] ? 0 : INF;

	size[u] = type[u];
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_pq(v, u, tot);
		if(size[v]) chkmin(p[u], f[v] + 1);
		size[u] += size[v];
	}

	q[u] = size[u] == tot ? INF : g[u];
}

inline void solve()
{
	dfs_f(1, 0);
	dfs_g(1, 0);

	int tot = 0;
	for(int i = 1; i <= n; ++i) tot += type[i];
	dfs_pq(1, 0, tot);

	LL ans = 1;
	for(int u = 1; u <= n; ++u)
	{
		int l = type[u] ? 0 : min(p[u], q[u]), r = max(f[u], g[u]) - 1;
		for(auto v : adj[u])
		{
			if(v == anc[u]) chkmin(r, f[u] + 1);
			else chkmin(r, g[v]);
		}
		ans += max(0, r - l + 1);
	}
	printf("%lld\n", ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h_list(n);
  for(int i = 0; i < n; i++) {
    cin >> h_list[i];
  }

  sort(h_list.begin(), h_list.end());

  if (n > k) {
    for(int i = 0; i < k; i++) {
      h_list.pop_back();
    }
  }
  else {
    cout << 0 << endl;
    return 0;
  }
  int64_t ans = 0;
  for(int i = 0; i < h_list.size(); i++) { 
    ans += h_list[i];
  }

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

Measured memory_bytes: 1024
H, W, M = map(int, input().split())

objects = set()
sum_h = [0] * W
sum_w = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    objects.add((h, w))
    sum_h[w] += 1
    sum_w[h] += 1

max_sum_h = max(sum_h)
max_sum_w = max(sum_w)

ans = max_sum_h + max_sum_w - 1

arg_max_h = [h for h in range(H) if sum_w[h] == max_sum_w]
arg_max_w = [w for w in range(W) if sum_h[w] == max_sum_h]
for h in arg_max_h:
    for w in arg_max_w:
        if (h, w) not in objects:
            ans = max_sum_h + max_sum_w
            break
    else:
        continue
    break

print(ans)


Measured memory_bytes: 83464
#include<cstdio>
#include<algorithm> 
#include<cstring>
using namespace std;
int n,m,a,b;
bool g[200010],f[200010],flag;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		a=read();b=read();
		if(flag)continue;
		if(a>b)swap(a,b);
		if(a==1)
		{
			if(f[b]){flag=true;continue;}
			g[b]=true;
		}
		if(b==n)
		{
			if(g[a]){flag=true;continue;}
			f[a]=true;
		}
	}
	if(flag)printf("POSSIBLE");
	else printf("IMPOSSIBLE");
	return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int K,T;
    cin >> K >> T;

    vector<int> a(T);
    REP(i,T) cin >> a[i];
    sort(all(a),greater<>());

    pl(max((a[0]-1)-(K-a[0]),0))

    return 0;
}

Measured memory_bytes: 256
program x
    integer(8)A,B;
    read*,A,B;A=A-1;
    write(*,'(i0)')xor(xor0to(A),xor0to(B))
contains
function xor0to(x) result(y)
    integer(8) x,y;
    if(mod(x,4)==0)then;y=x;
    else if(mod(x,4)==2)then;y=x+1;
    else if(mod(x,4)==1)then;y=1;
    else if(mod(x,4)==3)then;y=0;
    else if(mod(x,4)==-1)then;y=0;endif;
endfunction xor0to
end program x

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define ll long long  
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
 
#define md          1000000007
#define fmd         998244353 
#define M           2011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll F[M],IV[M];

ll dp[M][M];

vector<pair<ll,ll> > v;
ll f(ll i,ll j){
	ll index=(v.size()-1-(j-i));
	if(i==j){
		return v[index].F*abs(v[index].S-i);
	}
	if(dp[i][j]!=-1)return dp[i][j];
	return dp[i][j]=max(f(i,j-1)+v[index].F*abs(v[index].S-j),f(i+1,j)+v[index].F*abs(v[index].S-i));
}
ll chose(ll n,ll k){
	if(k>n)return 0;
	ll r=F[n];r=r*IV[k];r%=md;r=r*IV[n-k]%md;return r%md;
}
int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n;
    for(i=0;i<n;++i){
    	cin>>x;
    	v.pb({x,i});
    }
    memset(dp,-1,sizeof(dp));
    sort(all(v));
    reverse(all(v));

    ll p=f(0,n-1);
    cout<<p<<"\n";



    
 
 
 
 
 
    // trace(f(2,2));
 
 
 
	die();
 
}
void prec(){
	F[0]=IV[0]=1;
} 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
    int t;
    t=1;;
    prec();
    // cin>>t;
 
    while(t--){
 
        solve();
    }
 
 
 
 
 
 
#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 35384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mi 1000000007
int state[200005];
int dp[5000][1005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int cost[m+1];
	for(int i=0;i<5000;i++){
		for(int j=0;j<1005;j++){
			dp[i][j]=mi;
		}
	}
	for(int i=1;i<=m;i++){
		int q;
		cin>>cost[i]>>q;
		while(q--){
			int x;
			cin>>x;
			state[i]|=(1<<(x-1));
		}
	}
	dp[0][0]=0;
	for(int i=0;i<(1<<n);i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=min(dp[i][j],dp[i][j-1]);
			dp[i|state[j]][j]=min(dp[i|state[j]][j],dp[i][j-1]+cost[j]);
		}
	}
	int ans=dp[(1<<n)-1][m];
	if(ans==mi) cout<<"-1\n";
	else cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    vector<int> a(100);
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.begin()+N,greater<>());
    int Alice=0;
    int Bob=0;
    for (int i = 0; i < N; i++)
    {
        if(i%2==0){
            Alice+=a[i];
        }
        else{
            Bob+=a[i];
        }
    }
    int res=Alice-Bob;
    cout << res << endl;
    return 0;

    
}

Measured memory_bytes: 256
#include  <stdio.h>
#include  <stdlib.h>
int main()
{
	int p;
	int a[101];
	scanf("%d",&p);
	int i = 0,flag = 1;
	for(i=0;i<p;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
		{
			if(a[i]%3==0 ||a[i]%5==0)
			;
			else
				flag = 0;
		}
	}
	if(flag)
		printf("APPROVED");
	else
		printf("DENIED");
	return 0;
}

Measured memory_bytes: 128
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [n] <- readInt
  a <- readInt
  print $ solve a

solve a = maximum $ map length $ group $ sort $ concatMap (\x -> [x - 1, x, x + 1]) a


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

using namespace std;
typedef long long ll;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
const ll mod = 1e9 + 7;
#define REP(i, o, n) for (ll i = o; i < n; i++)
#define rep(i, n) REP(i, 0, n)

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

ll lcm(ll a, ll b) { return a / gcd(b, a % b) * b; }

void actual() {
  ll a, b, m=-101;

  cin >> a >> b;
  m = max(a+b, m);
  m = max(a-b, m);
  m = max(a*b, m);

  cout << m << endl;
}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    actual();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };


int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	k %= 2;
	if (k == 0)return !printf("%lld", a - b);
	printf("%lld", b - a);
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll n;
vector<ll> adj[MAXN];
ll dp[MAXN][2];

void dfs(ll v,ll par){
    for (auto u:adj[v]){
        if (u == par)
            continue;
        dfs(u,v);
    }
    for (auto u:adj[v]){
        if (u == par)
            continue;
        dp[v][0] *= (dp[u][1] % MOD + dp[u][0] % MOD ) % MOD + 1;
        dp[v][1] *=  dp[u][0] % MOD + 1;
        dp[v][0] %= MOD;
        dp[v][1] %= MOD;
    }
    dp[v][0] += MOD;
    dp[v][0] --;
    dp[v][0] %= MOD;
}

int main()
{
    fast_io;
    cin >> n;
    ll a,b;
    for (int i = 1; i <= n;i++){
        dp[i][0] = dp[i][1] = 1;
    }
    for (int i = 1;i < n;i++){
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs(1,0);
    ll ans = (dp[1][0] + dp[1][1] + 1) % MOD;
    cout << ans  << endl;
}


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

using namespace std;


const int N = 1e5 + 5;

int n;
int h[N];
int mem[N];

int jump(int i){
    if(i == n-1) return 0;

    if(mem[i] != -1) return mem[i];

    int x = abs(h[i] - h[i + 1]) + jump(i + 1);
    int y = x;

    if(i + 2 < n) y = abs(h[i] - h[i + 2]) + jump(i + 2);

    mem[i] = min(x , y);
    return mem[i];
}

main(){
    scanf("%d" , &n);

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

    memset(mem , -1 , sizeof mem);
    printf("%d\n" , jump(0));

    return 0;
}


Measured memory_bytes: 4096
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m):
        a = sorted([S() for _ in range(n)])
        ak = collections.Counter(''.join(a))
        al = sum(ak.values())
        t = ''.join([S() for _ in range(m)])
        if len(t) < al:
            return 0

        fm = {}
        def ff(s, a):
            if len(a) == 1:
                return s == a[0]
            key = (s, tuple(a))
            if key in fm:
                return fm[key]
            for i in range(len(a)):
                if s[:len(a[i])] != a[i]:
                    continue
                if ff(s[len(a[i]):], a[:i] + a[i+1:]):
                    fm[key] = True
                    return True
            fm[key] = False
            return False

        r = 0
        for i in range(len(t) - al + 1):
            ts = t[i:i+al]
            if collections.Counter(ts) != ak:
                continue
            if ff(ts, a):
                r += 1

        return r

    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 23024
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("faild to read line");
    let mut sum: u64 = 0;
    for elem in line.split_whitespace() {
        sum += elem.trim().parse::<u64>().unwrap();
    }
    println!("{}", sum%24);
}


Measured memory_bytes: 4352
#!/usr/bin/env python3

import sys
from math import gcd
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

dup = False
dup_key = None
counter = Counter(A)
for key, val in counter.items():
    if val > 1:
        dup = True
        if dup_key is None:
            dup_key = key
        else:
            dup_key = max(dup_key, key)


def max_gcd_pair(S):
    # Assumption 1: S is the list of numbers
    # Assumption 2: There are no duplicates in S
    s = set(S)
    m = max(S)
    res = 1
    i = m
    while i > 0:
        a = i
        cnt = 0
        while a <= m: # a maxed at max of the list
            if a in s:
                cnt += 1
            a += i
        if cnt >= 2:  # we have found the result
            res = i
            break
        i = i - 1
    return res


pair = max_gcd_pair(A)
if dup:
    pair *= dup_key

if pair == 1:
    print('pairwise coprime')
    sys.exit()


setw = A[0]
for j in range(N):
    setw = gcd(setw, A[j])
if setw == 1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 292284
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {
    int n; cin >> n;
    vi A(10005, 0);
    for (int i = 1; i*i < n; i++){
        for (int j = 1;; j++){
            int y = i*i + j*j + i*j; 
            if (y > n) break;
            for (int k = 1;; k++){
                int x = i*i + j*j + k*k + i*j + j*k + k*i;
                if (x > n) break;
                A[x]++;
            }
        }
    }
    for (int i = 1; i <=n; i++) cout << A[i] << endl;


    return 0;
}

Measured memory_bytes: 3576
package main
  
import (
    "fmt"
    "strings"
)

func main() {
    var s []byte
    fmt.Scan(&s)
    ss := strings.Split(string(s), "/")
    switch ss[1] {
    case "01", "02", "03", "04":
        fmt.Println("Heisei")
    default:
        fmt.Println("TBD")
    }
}


Measured memory_bytes: 640
n, k = map(int, input().split())

tmp = [0]*n
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))

    for j in a:
        tmp[j-1] += 1

ans = 0
for j in range(n):
    if tmp[j] == 0:
        ans += 1

print(ans)





Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,l,t,x,w,ans[100001],p,s;
int main(){
	scanf("%lld%lld%lld",&n,&l,&t);
	for(long long i=1;i<=n;i++){
		scanf("%lld%lld",&x,&w);
        if(w==2)p=x-t;
        else p=x+t;
        if(p>0)s=(s+p/l)%n;
        if(p<0)s=(s+(p+1)/l-1)%n;
        ans[i]=(p%l+l)%l;
    }
    sort(ans+1,ans+n+1);
    if(s>=0)s=s%n;
    else{
    	p=(s+1)/n+1;
    	s=s+p*n;
	}
    for(long long i=s+1;i<=n;i++)printf("%lld\n",ans[i]);
    for(long long i=1;i<=s;i++)printf("%lld\n",ans[i]);
}

Measured memory_bytes: 1920
// 解説動画
#include <bits/stdc++.h>
using namespace std;

bool check(vector<pair<int,int>> &A) {
    int cur = 0;
    for(auto &p : A) {
        if(cur + p.first < 0) { return false; }
        cur += p.second;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    int Sum = 0;
    vector<pair<int,int>> Left, Right;
    vector<pair<int,int>> A(N);
    {
        string S;
        for(int i = 0; i < N; ++i) {
            cin >> S;
            int Lmin = 0, Last = 0;
            for(auto &ch : S) {
                if(ch == ')') --Last;
                else ++Last;
                Lmin = min(Lmin, Last);
            }
            if(Last > 0) Left.push_back(make_pair(Lmin, Last));
            else Right.push_back(make_pair(-Last + Lmin, -Last));
            Sum += Last;
        }
    }

    //auto cmp = [](const pair<int,int> &a, const pair<int,int> &b) -> bool { return ( a.first > b.first ) || (!(a.first > b.first) && a.second > b.second); };
    sort(Left.rbegin(), Left.rend());
    sort(Right.rbegin(), Right.rend());
    /*
    cout << "Left: " << endl;
    for(auto &p : Left) {
        cout << p.first << " " << p.second << endl;
    }
    cout << "Right: " << endl;
    for(auto &p : Right) {
        cout << p.first << " " << p.second << endl;
    }
    */

    // 左側と右側で貪欲に詰めていく。
    if(check(Left) && check(Right) && Sum == 0) { cout << "Yes" << endl; }
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）
map<pair<int, int>, int> mp;

vector<vector<vector<int> > > warshall_floyd(int n,vector<vector<vector<int> > > spath) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++){  // 終端
        //cout<<"compare:"<<i<<" "<<j<<" "<<d[j][k]<<" "<<d[j][i] + d[i][k]<<endl;
        if( d[j][k] > d[j][i] + d[i][k]){
            //cout<<"renew:"<<i<<" "<<j<<" "<<d[j][i] + d[i][k]<<endl;
            d[j][k] = d[j][i] + d[i][k];
            auto temp = spath[j][i];
            temp.insert(temp.end(), spath[i][k].begin(), spath[i][k].end());
            spath[j][k] = temp;
        }
      }
    return spath;
}

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

  d = Matrix(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++) d[i][i] = 0;
  
  cin >> m;
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    from--; to--;
    d[to][from] = cost;
    d[from][to] = cost;
  }
    
    vector<vector<vector<int> > > spath(n, vector<vector<int> >(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            spath[i][j].push_back(i);
            spath[i][j].push_back(j);
        }
    }
  
  spath = warshall_floyd(n, spath);
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j && d[i][j] != INF){
        int loop=0;  
        pair<int, int> p;
        for (auto x : spath[i][j]){
                if(loop%2 == 0) p.first = x;
                else {
                    p.second = x;
                    if(p.first > p.second ){
                        int temp = p.first;
                        p.first = p.second;
                        p.second = temp;
                    }
                    //cout<<p.first<<p.second<<endl;
                    mp[p]++;
                }
                loop++;
            }
      }
    }
  }
  cout<<m-mp.size()<<endl;
  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=300000000;
const LL MOD=1000000007;



int main(){
int a,b,c;
cin>>a>>b>>c;
if(b-a==c-b){
    cout<<"YES"<<endl;

}else{
    cout<<"NO"<<endl;
}
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < N; i++) {
          if (Math.sqrt(Math.pow(sc.nextInt(), 2) + Math.pow(sc.nextInt(), 2)) <= D) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 59128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a;
  string s;
  a=0;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> s;
      if(s == "Y") {
        a++;
        break;
      }
  }
  if(a == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
  return 0;
}
        

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

using namespace std;

using int64 = long long;

string S;
int dp[100][2][2][1 << 10];

int rec(int idx, bool zero, bool free, int bit) {
  if(idx == S.size()) return (__builtin_popcount(bit) == 3 && ((bit >> 3) & 1) && ((bit >> 5) & 1) && ((bit >> 7) & 1));
  if(~dp[idx][zero][free][bit]) return dp[idx][zero][free][bit];
  int ret = 0;
  for(int i = 0; i <= (free ? S[idx] - '0' : 9); i++) {
    if(zero && i == 0) {
      ret += rec(idx + 1, true, free & (S[idx] - '0' == i), 0);
    } else {
      ret += rec(idx + 1, false, free & (S[idx] - '0' == i), bit | (1 << i));
    }
  }
  return dp[idx][zero][free][bit] = ret;
}


int main() {
  memset(dp, -1, sizeof(dp));
  cin >> S;
  cout << rec(0, true, true, 0) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;
ll dp[100100][4];

//dp[][0],dp[][1],dp[][2],dp[][3]

int main(){
	string s; cin >> s;
	int n=s.size();
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		if(s[i]=='?'){
			for(int j=0;j<4;j++){
				(dp[i+1][j]+=dp[i][j]*3)%=mod;
				if(j<3)(dp[i+1][j+1]+=dp[i][j])%=mod;
			}
		}
		else{
			for(int j=0;j<4;j++){
				(dp[i+1][j]+=dp[i][j])%=mod;
			}
			if(s[i]=='A'){
				(dp[i+1][1]+=dp[i][0])%=mod;
			}
			if(s[i]=='B'){
				(dp[i+1][2]+=dp[i][1])%=mod;
			}
			if(s[i]=='C'){
				(dp[i+1][3]+=dp[i][2])%=mod;
			}
		}
	}
	cout << dp[n][3] << endl;
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int val = 0;
        int[] weights = new int[n];
        int[] value = new int[n];
        for (int i=0; i<n; i++) {
            weights[i] = sc.nextInt();
            value[i] = sc.nextInt();
            val += value[i];
        }
        long[][] dp = new long[n+1][val+1];
        for (int i=1; i<=val; i++) dp[0][i] = Integer.MAX_VALUE;
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=val; j++) {
                dp[i][j] = dp[i-1][j];
                if (j >= value[i-1]) {
                    dp[i][j] = Math.min(dp[i][j], weights[i-1] + dp[i-1][j-value[i-1]]);
                }
            }
        }
        for (int i=val; i>=1; i--) {
            if (dp[n][i] <= w) {
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 126416