akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
 

signed main(){

  int p,r,t;
  cin>>p>>r>>t;
  
  vector<int> LL(r);
  for(int i=0;i<r;i++) cin>>LL[i];

  vector<vector<int> > n(p,vector<int> (r));
  for(int i=0;i<p;i++)
    for(int j=0;j<r;j++) cin>>n[i][j];


  vector<int> P(t),R(t);
  for(int i=0;i<t;i++) cin>>P[i]>>R[i], P[i]--,R[i]--;
  
  
  auto deadLock=[&](int x){
    vector<int> L = LL;
    vector<queue <int> > Q(r);
    vector<vector<int> > cnt(p,vector<int> (r,0));
    
    auto ok = [&](int p){
      for(int i=0;i<r;i++) if(n[p][i] != cnt[p][i]) return 0;
      return 1;
    };

    auto freeL = [&](int p){
      for(int i=0;i<r;i++) L[i] += cnt[p][i], cnt[p][i] = 0;
    };

    //cout<<"L ";
    //for(int i=0;i<r;i++) cout<<L[i]<<" ";cout<<endl;
    
    auto use =[&](){
      int res = 0;
      for(int i=0;i<r;i++){
	if(Q[i].empty()) continue;
	if(L[i] == 0) continue;
	int process = Q[i].front(); Q[i].pop();
	L[i]--, cnt[process][i]++;
	if(!ok(process)) continue;
	freeL(process);
	res = 1;
      }
      return res;
    };
    
    for(int i=0;i<x;i++){
      int pi = P[i];
      int ri = R[i];
      Q[ri].push(pi);
      while(use());
    }
    // simulation owari

    //for(int i=0;i<r;i++) cout<<Q[i].size()<<endl;

    auto sum=[&](int p){
      int res = 0;
      for(int i=0;i<r;i++) res += cnt[p][i];
      return res;
    };

    auto canFree=[&](int p){
      for(int i=0;i<r;i++) if(n[p][i] - cnt[p][i] > L[i]) return 0;
      return 1;
    };

    //cout<<"L: ";
    //for(int i=0;i<r;i++) cout<<L[i]<<" ";cout<<endl;
    /*for(int i=0;i<p;i++){
      cout<<"i="<<i<<": ";
      for(int j=0;j<r;j++) cout<<cnt[i][j]<<" ";
      cout<<endl;
    }
    */

    int update = 1;
    while(update){
      update = 0;
      for(int i=0;i<p;i++){ //process
	if(sum(i) == 0) {continue;}
	if(!canFree(i)) continue;
	update = 1;
	freeL(i);
	while(use());
      }
    }

    for(int i=0;i<p;i++) if(sum(i)) return 1;   
    for(int i=0;i<r;i++) if(!Q[i].empty()) return 1;
    return 0;
  };

  
  int ans = -1;
  {
    int L = 1, R = t+1;
    while(L+1<R){
      int M = (L+R)/2;
      if(deadLock(M)) R = M;
      else L = M;
    }
    ans = R;
    if(R == t+1) ans = -1;
  }

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




Measured memory_bytes: 7732
from collections import Counter

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

def nC2(n):
  return n*(n-1)//2

cum=[A[0]%M]
for i in range(1,N):
  cum.append((cum[-1]+A[i])%M)

c = Counter(cum)

ans=c[0]
for k in c.keys():
  ans += nC2(c[k])

print(ans)

Measured memory_bytes: 21200
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-4;
const int N=200000+10,maxn=500+100,inf=0x3f3f3f;

ll a[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++)a[i]+=a[i-1];
    ll ans=1e15;
    for(int i=0;i<n-1;i++)
    {
        ans=min(ans,abs(a[n-1]-2*a[i]));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N; string S;
  cin >> N >> S;

  int ans = 0;
  rep(i,1,N-1) {
    set<char> a, b;
    rep(j,0,N-1) {
      if (j < i) a.insert(S[j]);
      else b.insert(S[j]);
    }

    vector<char> v;
    set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(v));

    ans = max(ans, int(v.size()));
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<cmath>
using namespace std;
#define int long long
#define doauble long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int a, b;
signed main(){
	cin >> a >> b;
	cout << 6 - (a + b) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int l = 0;
    int r = N-1;
    int res = 0;
    while (1) {
        while (1) {
            if (l >= r) break;
            if (s[l] == 'W') break;
            else ++l;
        }
        while (r) { 
            if (l >= r) break;
            if (s[r] == 'R') break;
            else --r;
        }
        if (l >= r) break;
        swap(s[l], s[r]);
        ++l, --r;
        ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N,K,X,Y;cin>>N>>K>>X>>Y;
    if(N<=K)cout<<N*X<<endl;
    else cout<<X*K+(N-K)*Y<<endl;
}

Measured memory_bytes: 256
N = int(input())
sum_B = 0
min_B = 10**9 + 1
diff = False
for i in range(N):
  A, B = list(map(int, input().split()))
  if A != B:
    diff = True
  sum_B += B
  if A > B:
    min_B = min(B, min_B)
print((sum_B - min_B) if diff else 0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll d, g;
  cin >> d >> g;
  vector<ll> p, c;
  REP(i, d) {
    ll P, C;
    cin >> P >> C;
    p.pb(P);
    c.pb(C);
  }
  ll ret = INF;
  REP(bit, 1 << d) {
    ll maisuu = 0, cnt = 0;
    for (ll i = d - 1; i >= 0; i--) {
      if ((bit >> i) & 1) {
        maisuu += p[i];
        cnt += (i + 1) * p[i] * 100;
        cnt += c[i];
      }
    }
    for (ll i = d - 1; i >= 0; i--) {
      if (cnt >= g) {
        break;
      }
      if (!((bit >> i) & 1)) {
        REP(j, p[i]) {
          cnt += (i + 1) * 100;
          maisuu++;
          if (cnt >= g) {
            break;
          }
        }
      }
    }
    if (cnt >= g) {
      ret = min(ret, maisuu);
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T1,T2;
    cin >> T1 >> T2;
    ll A1,A2,B1,B2;
    cin >> A1 >> A2 >> B1 >> B2;
    ll v1 = T1 * (A1 - B1);
    ll v2 = T2 * (A2 - B2);
    if(v1 + v2 == 0){
        print("infinity");
        return 0;
    }
    if((v1 > 0 && v2 > 0) || (v1 < 0 && v2 < 0)){
        print(0);
        return 0;
    }
    if(v1 < 0){
        v1 *= -1;
        v2 *= -1;
    }
    if(abs(v1) > abs(v2)){
        print(0);
        return 0;
    }
    ll diff = abs(v2) - v1;
    ll tt = (v1 + diff - 1) / diff;
    if(v1 % diff == 0) tt++;
    tt *= 2;
    tt--;
    if(v1 % diff == 0) tt--;
    print(tt);
    

}

Measured memory_bytes: 256
n,m=gets.split.map &:to_i
p=[];y=[]
m.times{|i|p[i],y[i]=gets.split.map &:to_i}
ans=p.zip(y,(0..m).to_a).sort_by{|x|[x[0],x[1]]}
z=1
for i in 0...m
  (ans[i][3]=z;next) if i==0
  if ans[i-1][0]==ans[i][0]
    z+=1
    ans[i][3]=z
  else
    z=1
    ans[i][3]=z
  end
end
m.times{|i|
    x=(1000000+ans[i][0]).to_s.chars
    y=(1000000+ans[i][3]).to_s.chars
    x.shift;y.shift
    ans[i][4]=(x+y).join
}
ans=ans.sort_by{|x|x[2]}
ans.each{|y|puts y[4]}


Measured memory_bytes: 52080
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, k[100005];
	long long int ans = 0;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
	}
	if (a == 1) {
		if(k[0]>b) ans = k[0] - b;
		else ans = 0;
	}
	else {
		for (int i = 1; i < a; ++i) {
			if (k[i] + k[i - 1] > b) {
				ans += k[i] + k[i - 1] - b;
				k[i] -= k[i] + k[i - 1] - b;
				k[i] = max(0, k[i]);
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,r; cin>>n>>r;
	if (n<10) cout<<(100*(10-n)+r)<<endl;
	else cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vpll path;
//***********//
int main() { 
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vl P(1000001);
	for (i = 0; i < N; i++) {
		if (!P[A[i]]) {
			ans++;
			if (i != N - 1) {
				if (A[i] == A[i + 1]) {
					ans--;
				}
			}
			ll now = A[i];
			while (now <= 1000000) {
				P[now] = 1;
				now += A[i];
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 12756
n,k=[int(i) for i in input().split()]
s=input()
 
ope=s[0]
cnt=1
l=[];
if s[0]=='0':
	l.append(0)
for i in range(1,len(s)):
	if s[i]==ope:
		cnt+=1
	else:
		l.append(cnt)
		ope=s[i]
		cnt=1
l.append(cnt)
 
if s[len(s)-1]=='0':
	l.append(0)
	
start=0
end=2*k
 
max_sum=sum(l[start:end+1])
cur_sum=max_sum
start+=2
end+=2
while end<len(l):
    cur_sum=cur_sum-l[start-2]-l[start-1]+l[end-1]+l[end]
    max_sum=max([max_sum,cur_sum])
    start+=2
    end+=2
print(max_sum)

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

const int maxn = 300005;
int a[maxn], top, n, K;

int main() {
	scanf("%d%d", &K, &n);
	if (!(K&1)) {
		printf("%d ", K / 2);
		rep (i, 2, n) printf("%d ", K);
		return 0;
	}
	rep (i, 1, n) a[i] = (K + 1) / 2;
	top = n;
	rep (i, 1, n / 2)
		if (a[top] == 1) top--;
		else {
			a[top]--;
			while (top < n) a[++top] = K;
		}
	rep (i, 1, top) printf("%d ", a[i]);
	
	return 0;
}


Measured memory_bytes: 3456
import java.util.*;
import java.io.*;
public class Main {
	
	public static boolean[] vis;
	public static ArrayList<Integer>[] adj;
	public static int[] lis;
	public static int[] val;
	public static ArrayList<Integer> ls;
	
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		//Scanner in = new Scanner(System.in);
		//int n = in.nextInt();
		int n = Integer.parseInt(f.readLine());
		adj = new ArrayList[n];
		val = new int[n];
		StringTokenizer st = new StringTokenizer(f.readLine());
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<Integer>();
			val[i] = Integer.parseInt(st.nextToken());//in.nextInt();
		}
		for (int i = 0; i < n-1; i++) {
			//int u = in.nextInt()-1, v = in.nextInt()-1;
			st = new StringTokenizer(f.readLine());
			int u = Integer.parseInt(st.nextToken())-1, v = Integer.parseInt(st.nextToken())-1;
			adj[u].add(v);
			adj[v].add(u);
		}
		//for (int i = 0; i < n; i++) System.out.println(i + ": " + adj[i]);
		
		ls = new ArrayList<Integer>();
		ls.add(val[0]);
		vis = new boolean[n];
		vis[0] = true;
		lis = new int[n];
		lis[0] = 1;
		for (int i = 0; i < adj[0].size(); i++) {
			dfs(adj[0].get(i));
		}
		for (int i = 0; i < n; i++) System.out.println(lis[i]);
	}
	
	public static void dfs(int i) {
		if (vis[i]) return;
		vis[i] = true;
		if (val[i] > ls.get(ls.size()-1)) {
			ls.add(val[i]);
			lis[i] = ls.size();
			for (int j = 0; j < adj[i].size(); j++) {
				dfs(adj[i].get(j));
			}
			ls.remove(ls.size()-1);
		} else {
			int low = 0, high = ls.size()-1;
			while (low < high) {
				int mid = (low+high)/2;
				if (val[i] > ls.get(mid)) low = mid+1;
				else high = mid;
			}
			int rep = ls.set(high, val[i]);
			lis[i] = ls.size();
			for (int j = 0; j < adj[i].size(); j++) {
				dfs(adj[i].get(j));
			}
			ls.set(high, rep);
		}
	}
}

Measured memory_bytes: 109060
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
    char s[101],p[101],m[201];
    scanf("%s %s", s, p);
    strcat(m, s);
    strcat(m, s);
    if (strstr(m, p) != NULL) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll a,b,c,d;
  string s;
  cin>>a;
  //cin>>a>>b;
  //cin>>a>>b>>c;
  //cin>>a>>b>>c>>d;
  //cin>>s;
  cout<<a*a<<endl;
  return 0;
}

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

using namespace std;
using P = pair<int,int>;

#define rep(i,n) for(int i=0; i<(int)n; i++)

bool isBigger(P a, P b){
    // return a > b
    return (a.first > b.first) && (a.second > b.second);
}

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

    vector<P> A(N);
    vector<P> B(N);

    rep(i,N){
        cin >> A.at(i).first;
        cin >> A.at(i).second;
    }
    rep(i,N){
        cin >> B.at(i).first;
        cin >> B.at(i).second;
    }

    sort(A.begin(), A.end(), [](P left, P right)->bool{if(left.second == right.second)return left.first > right.first;
                                                        else return left.second > right.second;});
    sort(B.begin(), B.end(), [](P left, P right)->bool{if(left.first == right.first)return left.second < right.second;
                                                        else return left.first < right.first;});

    // cout << "A:" << endl;
    // for(P p : A)cout << p.first << " " << p.second << endl;

    // cout << "B:" << endl;
    // for(P p : B)cout << p.first << " " << p.second << endl;

    int res = 0;
    vector<bool> usedA(N,false);
    rep(i,N){
        P b = B.at(i);
        rep(j,N){
            if(usedA.at(j))continue;
            P a = A.at(j);
            if(isBigger(b,a)){
                // printf("make pair: a(%d, %d)\tb(%d, %d)\n", a.first, a.second, b.first, b.second);
                usedA.at(j) = true;
                res++;
                break;
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 3616
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  int ans = 0;
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= n / r; i++)
  {
    for (int j = 0; j <= (n - i * r) / g; j++)
    {
      int k = (n - i * r - j * g) / b;
      if (n == i * r + j * g + b * k)
      {
        ans++;
      }
    }
  }
  cout << ans << "\n";
}

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

int gcd(int x, int y, int z) {
    int n = min(min(x, y), z);
    for (int d = n; d > 0; d--) {
        if (x % d == 0 && y % d == 0 && z % d == 0) {
            return d;
        }
    }
}

int sum(int k) {
    int sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                sum += gcd(i, j, l);
            }
        }
    }

    return sum;
}

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

    cout << sum(k) << endl;
}

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

using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        string s = to_string(i);
        if (s.length() % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>

int	main(void)
{
	int	N, first;

	scanf("%d", &N);
	first = N % 10;
	if (first == 3)
		printf("bon\n");
	else if (first == 0 || first == 1 || first == 6 || first == 8)
		printf("pon\n");
	else
		printf("hon\n");
	return (0);
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import product
from collections import deque
def resolve():
    h,w,k=map(int,input().split())
    G=[list(input()) for _ in range(h)]
    D=[(1,0),(-1,0),(0,1),(0,-1)]
    for i,j in product(range(h),range(w)):
        if(G[i][j]=='S'):
            i0,j0=i,j
            break

    dist=[[INF]*w for _ in range(h)]
    dist[i0][j0]=0
    # BFS
    Q=deque([(i0,j0)])
    while(Q):
        i,j=Q.popleft()
        for di,dj in D:
            ni=i+di; nj=j+dj
            if(not (0<=ni<h and 0<=nj<w)): continue
            if(dist[ni][nj]!=INF or G[ni][nj]=='#'): continue
            dist[ni][nj]=dist[i][j]+1
            Q.append((ni,nj))

    # 後は距離が k 以下の点から一直線に外に向かえばよい
    ans=INF
    for i,j in product(range(h),range(w)):
        if(dist[i][j]<=k):
            d=min(i,j,h-i-1,w-j-1)
            if(d==0):
                print(1)
                return
            else:
                ans=min(ans,2+(d-1)//k)
    print(ans)
resolve()

Measured memory_bytes: 105436
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

void func()
{
	int K;
	int64_t ans = 0;
	cin >> K;
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			int tmp = gcd(a, b);
			for (int c = 1; c <= K; c++) {
				ans += gcd(tmp, c);
			}
		}
	}
	cout << ans << endl;
}

int main() {

//	while (1)
		func();
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<int,P> PP;

int p[10001],r[10001];
void init(){rep(i,10001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    init();
    PP a[m];
    rep(i,m) cin >> a[i].S.F >> a[i].S.S >> a[i].F;
    sort(a,a+m);
    int c=n/2;
    rep(i,m) {
      if(same(a[i].S.F,a[i].S.S)) continue;
      unite(a[i].S.F,a[i].S.S);
      c--;
      if(!c) {
        pr(a[i].F);
        break;
      }
    }
  }
}

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


Measured memory_bytes: 1396
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
const int maxi=2000000000;
const int maxq=1000000000;
const ll mod=1000000007LL;
#define f(i,a,b) for(ll  i=(a); i<(b);++i)
/*
unsigned int countSetBits(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
*/

/*
const int maxx=9000000;
void SieveOfEratosthenes(vector<int> &primes){
    bool IsPrime[maxx+1];
    memset(IsPrime, true, sizeof(IsPrime));
    for(int p=2;p*p<=maxx ;p++){
        if(IsPrime[p]){
            for(int i=p*p;i<maxx ;i+=p) IsPrime[i]=false;
        }
    }
    f(p,2,maxx +1){
        if(IsPrime[p]) primes.push_back(p);
    }
    }
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,res=0;
    cin>>n;
    while(res<n) res+=1000;

    cout<<res-n<<endl;

    return 0;
}




Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#define LL long long
LL N, A, B, C, D;
int main() {
	std::cin >> N >> A >> B >> C >> D;
	for (LL i = 0; i < N; i++) {
		LL M = D*(N - i - 1) - C*i;
		LL m = C*(N - i - 1) - D*i;
		if (m <= A - B&&A - B <= M) {
			std::cout << "YES" << std::endl;
			return 0;
		}
	}
	std::cout << "NO" << std::endl;
	return 0;
}

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

#define lli long long int
#define pb push_back

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

  string s, r;
  cin >> s;
  r = s;

  reverse(r.begin(), r.end());

  bool can = true;

  if (s != r)
  {
    can = false;
  }

  int i = (s.size() - 1) / 2, f;

  string s2 = s.substr(0, i);
  string r2 = s2;
  reverse(r2.begin(), r2.end());

  if (s2 != r2)
  {
    can = false;
  }

  i = (s.size() + 3) / 2;
  f = s.size() - i;

  s2 = s.substr(i - 1, f + 1);
  r2 = s2;
  reverse(r2.begin(), r2.end());

  if (s2 != r2)
  {
    can = false;
  }

  (can) ? cout << "Yes\n" : cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100000 + 5
#define H 1000000000000000000
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++i)
const double eps = 1e-6;
int n, ans, a[N];
signed main(){
    scanf("%lld", &n), ans = 1;
    rep(i, 1, n) scanf("%lld", &a[i]);
    rep(i, 1, n) if(a[i] == 0){ puts("0"); return 0;}
    rep(i, 1, n){
        long double x = (long double)H / a[i], y = (long double)ans;
        if(x < y){ puts("-1"); return 0;}
        ans = ans * a[i];
    } 
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4536
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	vi dp(21);
	int a;
	cin>>a;
	dp[a]++;
	rep(i,n-2){
		cin>>a;
		vi t(21);
		rep(j,21)if(dp[j]){
			if(j+a<21)t[j+a]+=dp[j];
			if(0<=j-a)t[j-a]+=dp[j];
		}
		dp=t;
	}
	cin>>a;
	cout<<dp[a]<<endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int mod=1e9+7;
int dp[5001][5001]={};

int main()
{
    int n,L;
    scanf(" %d %d", &n, &L);
    vector<int> x(n), a(n);
    rep(i,n) scanf(" %d", &x[i]);
    rep(i,n) scanf(" %d", &a[i]);

    if(a[0]==0) dp[0][x[0]]=1;
    else for(int i=x[0]; i<L; i+=a[0]) dp[0][i]=1;

    for(int i=1; i<n; ++i)
    {
        int sum=0;
        if(a[i]==0)
        {
            rep(j,x[i]) (sum+=dp[i-1][j])%=mod;
            dp[i][x[i]]=sum;
        }
        else
        {
            rep(j,L)
            {
                if(j-x[i]>=0 && (j-x[i])%a[i]==0) dp[i][j]=sum;
                (sum+=dp[i-1][j])%=mod;
            }
        }
    }

    int ans=0;
    rep(i,L) (ans+=dp[n-1][i])%=mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 69848
#include "bits/stdc++.h"
using namespace std;

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

    int n;
    cin >> n;

    int a[n];
    for(int& i : a)cin >> i;

    map<int,int>c1,c2;

    for(int i=0;i<n;i+=2)c1[a[i]]++;
    for(int i=1;i<n;i+=2)c2[a[i]]++;

    int mx=0 ,sum=0;
    int num;
    for(auto [x,y] : c1){
        if(y>mx){
            num=x;
            mx=y;
        }
    }

    sum+=mx; mx=0;

    for(auto [x,y] : c2){
        if(y>mx && x!=num){
            mx=y;
        }
    }

    sum+=mx;
    int sum2=0;
    mx=-1;

    for(auto [x,y] : c2){
        if(y>mx){
            num=x;
            mx=y;
        }
    }
    sum2+=mx; mx=0;

    for(auto [x,y] : c1){
        if(y>mx && x!=num){
            mx=y;
        }
    }

    sum2+=mx;
    cout<<min(n-sum,n-sum2)<<endl;
}




Measured memory_bytes: 8560
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

readline = sys.stdin.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 18908
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = readLine()!.characters.split(" ").map{Int(String($0))!}
var sum = [0]
(0..<N).forEach{sum+=[sum[$0]+L[$0]]}
print(sum.reduce(0){$0+($1>X ?0:1)})

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int H, W, N;
    cin >> H >> W >> N;

    map<PII, ll> cnt;
    rep(i, N) {
        int X, Y;
        cin >> Y >> X;
        X--, Y--;

        for (int y=Y-2; y<=Y; y++) {
            for (int x=X-2; x<=X; x++) {
                if (in_range(x, y, W-2, H-2)) {
                    cnt[PII(x, y)]++;
                }
            }
        }
    }

    map<int, ll> ans;
    ll tmp = 0;
    for (auto &p : cnt) {
        // cerr << p.first.first << " " << p.first.second << " " << p.second << endl;
        ans[p.second]++;
        tmp++;
    }

    ans[0] = (ll)(H-2) * (W-2) - tmp;
    for (int i=0; i<=9; i++) {
        cout << ans[i] << endl;
    }
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, m, h, k;
    cin >> n >> m >> h >> k;
    if(!n)
        return false;
    vector<int> a(m), b(m), money(m), time(m), company(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i] >> money[i] >> time[i] >> company[i];
        --a[i], --b[i], --company[i];
    }
    int st, en, p;
    cin >> st >> en >> p;
    --st, --en;
    vector<int> flag(p, 0);
    vector<int> flag_money(p);
    for(int i = 0; i < p; ++i){
        int l;
        cin >> l >> flag_money[i];
        for(int j = 0; j < l; ++j){
            int kk;
            cin >> kk;
            --kk;
            flag[i] |= (1 << kk);
        }
    }
    vector<int> money_dp(1 << k, MOD);
    money_dp[0] = 0;
    for(int i = 0; i < (1 << k); ++i)
        for(int j = 0; j < p; ++j)
            chmin(money_dp[i | flag[j]], money_dp[i] + flag_money[j]);

    struct Edge{
        int to, time, money, company;
        Edge(int a, int b, int c, int d) : to(a), time(b), money(c), company(d){}
    };
    vector<vector<Edge>> edges(n);
    for(int i = 0; i < m; ++i){
        edges[a[i]].emplace_back(b[i], time[i], money[i], company[i]);
        edges[b[i]].emplace_back(a[i], time[i], money[i], company[i]);
    }

    int ans = MOD;

    for(int fl = 0; fl < (1 << k); ++fl){
        if(money_dp[fl] == MOD)
            continue;
        vector<vector<int>> dp(n, vector<int>(h + 1, MOD));
        dp[st][0] = money_dp[fl];
        priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> que;
        que.emplace(money_dp[fl], st, 0);
        while(!que.empty()){
            int cost, pos, tim;
            tie(cost, pos, tim) = que.top();
            que.pop();
            if(dp[pos][tim] != cost)
                continue;
            for(auto& ed : edges[pos]){
                if(tim + ed.time > h)
                    continue;
                int add = (fl & (1 << ed.company)) ? 0 : ed.money;
                if(chmin(dp[ed.to][tim + ed.time], dp[pos][tim] + add)){
                    que.emplace(dp[ed.to][tim + ed.time], ed.to, tim + ed.time);
                }
            }
        }
        chmin(ans, *min_element(dp[en].begin(), dp[en].end()));
    }

    cout << (ans == MOD ? -1 : ans) << endl;

    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3312
package main

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

const MAX_QUEUE_SIZE = 2000000

type PriorityQueue struct {
	content [MAX_QUEUE_SIZE]int
	size int
}

func (q *PriorityQueue) reset() {
	for i := 0; i < MAX_QUEUE_SIZE; i++ {
		q.content[i] = -1
	}
}

func (q *PriorityQueue) insert(x int) {
	pos := q.size + 1
	q.content[pos-1] = x
	q.size = q.size + 1
	for {
		if pos <= 1 {
			break
		}
		prev := pos / 2
		if q.content[prev-1] < q.content[pos-1] {
			q.content[pos-1], q.content[prev-1] = q.content[prev-1], q.content[pos-1]
			pos = prev
		} else {
			break
		}
	}
}

func (q *PriorityQueue) extract() int {
	// Assume that the queue is not empty
	extracted := q.content[0]
	q.content[0] = -1
	q.content[0], q.content[q.size-1] = q.content[q.size-1], q.content[0]
	q.size = q.size - 1

	pos := 1
	for {
		left := pos * 2
		right := pos * 2 + 1
		if left > q.size {
			break
		}
		largest := pos
		if q.content[left-1] < q.content[right-1] {
			if q.content[largest-1] < q.content[right-1] {
				largest = right
			}
		} else {
			if q.content[largest-1] < q.content[left-1] {
				largest = left
			}
		}
		if largest == pos {
			break
		}
		q.content[pos-1], q.content[largest-1] = q.content[largest-1], q.content[pos-1]
		pos = largest
	}
	return extracted
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	q := PriorityQueue{}
	q.reset()

	for {
		// fmt.Println(q.content[0:10])
		command := nextText(sc)
		switch(command) {
		case "insert":
			v, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			q.insert(v)
		case "extract":
			fmt.Println(q.extract())
		case "end":
			os.Exit(0)
		default:
			panic(fmt.Errorf("unknown command: %s", command))
		}
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


Measured memory_bytes: 29760
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<int> num(4);
void a(int x){
    for(int i=0; i<4; i++){
        num[3-i]=x%10;
        x/=10;
    }
}

int main(){
    int n;
    cin >> n;
    a(n);
    if(num[0]+num[1]+num[2]+num[3]==7)cout <<num[0]<<'+'<<num[1]<<'+'<<num[2]<<'+'<<num[3]<<"=7" << endl;
    else if(num[0]+num[1]+num[2]-num[3]==7)cout <<num[0]<<'+'<<num[1]<<'+'<<num[2]<<'-'<<num[3]<<"=7" << endl;
    else if(num[0]+num[1]-num[2]+num[3]==7)cout <<num[0]<<'+'<<num[1]<<'-'<<num[2]<<'+'<<num[3]<<"=7" << endl;
    else if(num[0]-num[1]+num[2]+num[3]==7)cout <<num[0]<<'-'<<num[1]<<'+'<<num[2]<<'+'<<num[3]<<"=7" << endl;
    else if(num[0]+num[1]-num[2]-num[3]==7)cout <<num[0]<<'+'<<num[1]<<'-'<<num[2]<<'-'<<num[3]<<"=7" << endl;
    else if(num[0]-num[1]-num[2]+num[3]==7)cout <<num[0]<<'-'<<num[1]<<'-'<<num[2]<<'+'<<num[3]<<"=7" << endl;
    else if(num[0]-num[1]+num[2]-num[3]==7)cout <<num[0]<<'-'<<num[1]<<'+'<<num[2]<<'-'<<num[3]<<"=7" << endl;
    else cout <<num[0]<<'-'<<num[1]<<'-'<<num[2]<<'-'<<num[3]<<"=7" << endl;
}

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

typedef long long ll;
ll mod = 1000000007;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n;
    string str;
    map<string, int> map1;
    for(int i=0; i<n; i++){
        cin >> str;
        map1[str]++;
    }
    cin >> m;
    map<string, int> map2;
    for(int j=0; j<m; j++){
        cin >> str;
        map2[str]++;
    }
    int mx = -1;
    for(auto i:map1){
        int k = i.second - map2[i.first];
        mx = max(mx, k);
    }
    cout << max(mx, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int a[3000];
int dp[3000][3000];//x～yが残っているとき操作する方の勝ち点
int saiki(int x, int y) {
	if (x == y)return a[x];
	if (dp[x][y] != -1)return dp[x][y];
	int S = max(a[x] - saiki(x + 1, y), a[y] - saiki(x, y - 1));
	return dp[x][y] = S;
}
signed main() {
	memset(dp, -1, sizeof(dp));
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << saiki(0, n - 1) << endl;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,l=1,r,a[maxn],flg[maxn];
long long ans=-1e18,f[maxn],g[maxn];
int main()
{
	read(n);
	flg[1]=1;
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
		if(i<n)
		{
			char cc;
			scanf("%s",&cc);
			if(cc=='-')
				flg[i+1]=-1;
			else
				flg[i+1]=1;
		}
	}
	for(int i=1;i<=n;i++)
		f[i]=f[i-1]+flg[i]*a[i];
	for(int i=n;i>=1;i--)
		g[i]=g[i+1]+a[i];
	while(l<=n&&flg[l]==1)
		l+=1;
	for(;l<=n;l=r+1)
	{
		long long s=a[l];
		r=l;
		while(r<n&&flg[r+1]==1)
		{
			r+=1;
			s+=a[r];
		}
		ans=max(ans,f[l-1]+g[r+1]-s);
	}
	printf("%lld\n",max(ans,f[n]));
    return 0;
}


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

int main() {
  char c;
  
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	for i := 3; i <= n; i++ {
		if i%3 == 0 {
			fmt.Print(" ")
			fmt.Print(i)
			continue
		}

		num := i
		for {
			if num%10 == 3 {
				fmt.Print(" ")
				fmt.Print(i)
				break
			}

			if num/10 == 0 {
				break
			}

			num = num / 10
		}
	}
	fmt.Println()
}



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

using namespace std;

using int64 = __int128_t;
const int64 INF = 1LL << 61;

template< class T >
struct CumulativeSum {
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  void add(int k, int x) {
    data[k] += x;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int k) {
    if(k < 0) return (0);
    return (data[min(k, (int) data.size() - 1)]);
  }
};


int main() {
  int N, X;
  int P[200001];
  cin >> N >> X;
  P[0] = 0;
  for(int i = 1; i <= N; i++) {
    cin >> P[i];
  }
  CumulativeSum< int64 > Q(N + 1);
  for(int i = 0; i <= N; i++) Q.add(i, P[i]);
  Q.build();

  int64 ret = INF;
  for(int i = 1; i <= N; i++) {
    int64 add = 0;
    add += 1LL * i * X;

    if(N % i > 0) {
      vector< pair< int, int > > arr;
      arr.emplace_back(0, 1);
      for(int j = 1; j <= N; j += i) arr.emplace_back(j, j + N % i);
      reverse(begin(arr), end(arr));
      add += Q.query(arr[0].second - 1) - Q.query(arr[0].first - 1);
      for(int j = 1; j < arr.size(); j++) {
        int64 sum = 0;
        sum += Q.query(arr[j - 1].second - 1) - Q.query(arr[j - 1].first - 1);
        sum -= Q.query(arr[j - 1].second - i - 1) - Q.query(arr[j - 1].first - i - 1);
        sum *= j + 1;
        sum *= j + 1;
        add += sum;
      }
    }
    {
      vector< pair< int, int > > arr;
      arr.emplace_back(0, 1);
      for(int j = 1; j <= N; j += i) {
        arr.emplace_back(j + N % i, min(N + 1, j + i));
        if(arr.back().first >= arr.back().second) arr.pop_back();
      }
      reverse(begin(arr), end(arr));
      add += Q.query(arr[0].second - 1) - Q.query(arr[0].first - 1);
      for(int j = 1; j < arr.size(); j++) {
        int64 sum = 0;
        sum += Q.query(arr[j - 1].second - 1) - Q.query(arr[j - 1].first - 1);
        sum -= Q.query(arr[j - 1].second - i - 1) - Q.query(arr[j - 1].first - i - 1);
        sum *= j + 1;
        sum *= j + 1;
        add += sum;
      }
    }


    ret = min(ret, add);
  }
  cout << (long long) (ret + 1LL * X * N) << endl;
}

Measured memory_bytes: 6388
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi v(n);
    rep(i, n) {
        cin >> v[i];
    }

    vi lsum(n+1), rsum(n+1);
    rep(i, n) {
        lsum[i+1] = lsum[i] + v[i];
        rsum[n-i-1] = rsum[n-i] + v[n-i-1];
    }

    int ans = 0;
    set<int> se;
    rep(i, min(n+1, k+1)) {
        rep(j, i) {
            if(v[j] < 0) se.insert(v[j]);
        }
        rep(j, min(k+1-i, n-i+1)) {
            if(j and v[n-j] < 0) se.insert(v[n-j]); 
            int num = lsum[i] + rsum[n-j];
            int x = k-i-j;
            for(int ne:se) {
                if(x--) {
                    num -= ne;
                } else break;
            }
            ans = max(ans, num);
        }
        se.clear();
    }

    cout << ans << endl;
}

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

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

    vector<vector<bool>> dp(N + 1, vector<bool>(1 << 24, false));
    dp[0][1] = true;

    int D;
    for (int i = 1; i <= N; i++)
    {
        cin >> D;
        if (D == 0)
        {
            continue;
        }
        for (int j = 0; j < (1 << 24); j++)
        {
            if (dp[i - 1][j])
            {
                assert(bitset<24>(j).count() == i);
                if (j != (j | (1 << D)))
                {
                    dp[i][(j | (1 << D))] = true;
                }
                if (j != (j | (1 << (24 - D))))
                {
                    dp[i][(j | (1 << (24 - D)))] = true;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << 24); i++)
    {
        if (dp[N][i])
        {
            int s = INT_MAX;
            bitset<24> b(i);
            for (int j = 0; j < 24; j++)
            {
                for (int k = 0; k < j; k++)
                {
                    if (b[j] && b[k])
                    {
                        s = min(s, min((j - k), 24 - (j - k)));
                    }
                }
            }
            if (s != INT_MAX)
            {
                ans = max(ans, s);
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int64_t hw_day = 0;
    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        hw_day += a;
    }
    cout << ((n - hw_day >= 0) ? n - hw_day : -1) << endl;
    return 0;
}

Measured memory_bytes: 3672
from collections import Counter
mod = 10**9+7
n = int(input())

li = []
def prime_factor(n):
    L = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            L.append(i)
            n = n//i
    if n != 1:
        L.append(n)
    return L

for i in range(2,n+1):
    li.extend(prime_factor(i))

L = Counter(li)
ans = 1
for k,v in L.items():
    ans *=(v+1)%mod
print(ans%mod)

Measured memory_bytes: 3444
N = int(input())
a = list(map(int,input().split()))

s1 = a[0]
s2 = 0
for i in range(1,N):
    s2 = s2 + a[i]
MIN = abs(a[0]-s2) 
for i in range(1,N):
    MIN = min(MIN,abs(s1-s2))
    s1 = s1+ a[i]
    s2 = s2 - a[i]
    
print(MIN)

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

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    pair<int, int> p1 = make_pair(W, H), p2 = make_pair(0, 0);
    for (int i=0; i<N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) p2.first = max(x, p2.first);
        else if (a == 2) p1.first = min(x, p1.first);
        else if (a == 3) p2.second = max(y, p2.second);
        else if (a == 4) p1.second = min(y, p1.second);
    }
    int area = (p1.first-p2.first) * (p1.second-p2.second);
    if (p1.first<p2.first || p1.second<p2.second) cout << 0 << endl;
    else cout << area << endl;
}

Measured memory_bytes: 256
//幹線道路
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int h, w, A[26][26], disa = 0, disb = 99999999;

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) cin >> A[i][j];
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {//上からi番目,左からj番目を幹線道路
			disa = 0;
			for (int k = 0; k < h; k++) {
				for (int l = 0; l < w; l++) {//上からk番目,左からl番目
					disa += ((min(abs(k - i), abs(l - j))*A[k][l]));
				}
			}
			if (disa < disb)disb = disa;
		}
	}

	cout << disb << endl;


	return 0;
}



Measured memory_bytes: 3136