akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define ll long long
#define y1 caibictq
#define P pair<int, int>
#define fi first
#define se second

using namespace std;

const int MAXN = 6010;
const int MAXM = 100010;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int n, m, k;
ll tot, cnt, ans;

int read() {
	int f = 1, s = 0;
	char ch = getchar();
	while ('0' > ch || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while ('0' <= ch && ch <= '9') {s = (s << 1) + (s << 3) + ((int)ch ^ 48); ch = getchar();}
	return s * f;
}

ll a[MAXN][MAXN];

ll f[MAXN][MAXN][4];

int main() {
	int T;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1, x, y, v; i <= k; i++) {
		scanf("%d%d%d", &x, &y, &v);
		a[x][y] = v;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			for (int k = 1; k <= 3; k++) {
				f[i][j][k] = max(f[i - 1][j][3], f[i][j - 1][k - 1]) + a[i][j];
				f[i][j][k] = max(f[i][j][k], f[i][j - 1][k]);
				ans = max(ans, f[i][j][k]);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 377052
# A - Security
# https://atcoder.jp/contests/abc131/tasks/abc131_a

s = input()

result = 'Good'
i = 0
j = 1
while j < len(s):
    if s[i] == s[j]:
        result = 'Bad'
        break

    i += 1
    j += 1

print(result)


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author toshif
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyReader in = new MyReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, MyReader in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < W + 2; i++) {
                sb.append("#");
            }
            sb.append("\n");

            for (int i = 0; i < H; i++) {
                sb.append("#" + in.next() + "#\n");
            }

            for (int i = 0; i < W + 2; i++) {
                sb.append("#");
            }
            sb.append("\n");

            out.println(sb);
        }

    }

    static class MyReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public MyReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N, X, M;
	cin >> N >> X >> M;

	map<Int, Int> mp;
	Int cnt = 1;
	Int A = X;
	vector<Int> sum(1000000, 0);
	Int ans = 0;
	while (cnt <= N) {
		sum[cnt] += sum[cnt - 1];
		if (mp.count(A) == 0) {
			mp[A] = cnt;
			sum[cnt++] += A;
			A = A * A % M;
			continue;
		}

		Int idx = mp[A];
		sum[cnt] += A;
		A = A * A % M;
		
		Int S = sum[cnt] - sum[idx];
		Int n = cnt - idx;
		ans = sum[idx] + (N - idx) / n * S;
		for (Int i = 0; i < (N - idx) % n; ++i) {
			ans += A;
			A = A * A % M;
		}
		break;
	}
	if (cnt > N) { ans = sum[N]; }
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 14028
#include<stdio.h>

int main()
{
	int i,n;
	int x =100000;
	scanf("%d",&n);
	for(i=1;i<n+1;i++){
		x=x*1.05;
		if(x%1000!=0)
		    x=(x/1000+1)*1000;
	}
	printf("%d\n",x);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    string S;
    int w;
    cin >> S >> w;
    for(int i=0;i<S.length();i+=w){
        cout << S[i];
    }
    cout << endl;
    
    return 0;
}

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

const int nax = 1e5 + 5;

vector<int> adj[nax];
bool visited[nax];
int indegree[nax];
int dist[nax];

void dfs(int v)
{
    if(visited[v]==true)
       return;

    visited[v] = true;
    for (int k : adj[v])
    {
        dist[k] = max(dist[k], dist[v] + 1);
        indegree[k]--;

        if (indegree[k] == 0)
        {
            dfs(k);
        }
    }
}
#undef int
int main()
{
#define int long long
    int n, m;
    cin >> n >> m;
    int u, v;

    for (int i = 0; i < m; i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        ++indegree[v];
    }

    for (int i = 1; i <= n; i++)
    {
        if (!visited[i] && indegree[i] == 0)
        {
            dfs(i);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = max(ans, dist[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 10496
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*約数の個数(x含む)*/ll divi(ll x){ll i,ans=0;rep(i,2,x+1){if(x%i==0){ans++;}}return ans;}
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll k,n;
 sc(n);sc(k);
 ll a[n+1];
 ll b;
 rep(i,0,n){sc(a[i]);}
 rep(i,0,n){rep(j,i+1,n){if(a[i]>a[j]){b=a[i];a[i]=a[j];a[j]=b;}}}
 rep(i,0,k){ans+=a[i];}
 pr(ans);
return 0;}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[100001];
ll inv[201];

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

void mod_add(ll &a, ll b){
	a +=b; a%= MOD;
}

int main(){
	REP(i, 201)inv[i] = mod_div(1, i);

	ll n, x;scanf("%d %d",&n, &x);
	vector<ll> v(n);
	REP(i, n)scanf("%d", &v[i]);
	sort(ALL(v));

	dp[x] = 1;
	REV(i, 100001){
		if(dp[i] == 0)continue;
		int cou = 0;
		while(cou < n && v[cou] <= i)cou++;
		if(cou == 0)continue;
		ll rate = inv[cou];
		REP(j, cou){
			mod_add(dp[i % v[j]], dp[i] * rate);
		}
		dp[i] = 0;
	}

	ll ans = 0;
	REP(i, 100001){
		mod_add(ans, dp[i] * i % MOD);
	}
	REP(i, n)ans = (ans * (i + 1)) % MOD;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<int>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,int b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int main()
{
    FIO;
    ll n,t,x,y;
    string s;
    cin>>s;x=0,y=0;
    rep(i,0,3){
        if(s[i]=='S'){y=max(y,x);x=0;}
        else x++;
    }
    y=max(y,x);
    cout<<y;
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int bb[1234][1234], cc[123][123][123];
int res[123456], uio[1234][1234];
signed main() {
	int n, m, a, b, x = INF, mae = 0, ans = 0; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (h > 0 && (a + mae) >= m) { x = h; }
		mae = a;
	}
	if (x == INF) { cout << "Impossible" << endl; return 0; }
	cout << "Possible" << endl;
	for (int h = 1; h < x; h++) {
		cout << h << endl;
	}
	for (int h = n - 1; h > x; h--) {
		cout << h << endl;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#define LEN 1000
int main(void){
    // Your code here!
    int n;
    double s[LEN];
    double ans,mid;
    scanf("%d",&n);
    
    while(n != 0){
        mid = 0.0;
        ans = 0.0;
        for(int i=0; i<n; i++){
            scanf("%lf",&s[i]);
            mid += s[i];
        }
        mid /= n;
        for(int i=0; i<n; i++){
            ans += (s[i] - mid)*(s[i] - mid);
        }
        
        printf("%0.8f\n",sqrt(ans/n));
        
        scanf("%d",&n);
        
    }
}



Measured memory_bytes: 2104
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b && a>c)
    {
        if(b>c)
        {
            printf("%d %d %d\n",c,b,a);
        }
        else{
             printf("%d %d %d\n",b,c,a);
        }
    }
     else if(b>a && b>c)
    {
        if(a>c)
        {
            printf("%d %d %d\n",c,a,b);
        }
        else{
             printf("%d %d %d\n",a,c,b);
        }
    }
     else if(c>a && c>b)
    {
        if(b>a)
        {
            printf("%d %d %d\n",a,b,c);
        }
        else{
             printf("%d %d %d\n",b,a,c);
        }
    }
    return 0;
}



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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<int> edges(N);
    for(int i = 0;i < N; i++)
    {
        cin >> edges.at(i);
    }
    sort(edges.begin(), edges.end());
    int longestEdge = edges.at(N - 1);
    int sumEdge = 0;
    for(int i = 0; i < N - 1; i++)
    {
        sumEdge += edges.at(i);
    }
    if(sumEdge > longestEdge)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;



int dp[100][2][100];//dp[keta][未満である][0でない数の個数]

int main(){
  string N;cin >> N;
  int K;cin >> K;
  int l = N.size();
  vi n;

  for(auto a : N){
    n.push_back(a - '0');
  }
  dp[0][0][0] = 1;
  for(int i = 0;i < l;++i){
    for(int smaller = 0;smaller < 2;++smaller){
      for(int j = 0;j < l;++j){
        for(int x = 0;x <= (smaller ? 9 : n[i]);++x){
          dp[i + 1][smaller || x < n[i]][(x ? j+1 : j)] += dp[i][smaller][j];
        }
      }
    }
  }
  cout << dp[l][0][K]+dp[l][1][K];
}


Measured memory_bytes: 764
import java.util.*;


public class Main {
  public static void main(String[] args) {

  Scanner vd = new Scanner(System.in);
  int n = vd.nextInt();
  
  if(n<1200) System.out.println("ABC");
  else if(n<2800) System.out.println("ARC");
  else System.out.println("AGC");
 }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ret return
using namespace std;
int main() {
	int n;cin>>n;
	ll seq[n];
	memset(seq,0ll, sizeof(seq));
	ll num;
	for(int i=0;i<n;i++){
		cin>>num;
		if(num==0ll) {
			cout<<0<<endl;
			ret 0;
		}
		seq[i]=num;
		
	}
	ll product=seq[0];
	for(int i=1;i<n;i++){
		if(1000000000000000000ll / product < seq[i]){
			cout<<-1<<endl;
			ret 0;
		}
		product*=seq[i];
	}
	cout<<product<<endl;
	ret 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,A; cin >> N >> A;
    vector<int> x(N);
    REP(i,N){
        int a; cin >> a;
        x[i] = a-A;
    }
    vector<vector<ll>> dp(N+1, vector<ll>(3000,0));
    int geta = 1500;

    dp[0][geta] = 1;
    REP(i,N){
        REP(j,3000){
            if(0<=j+x[i] && j+x[i]<3000){
                dp[i+1][j+x[i]] += dp[i][j];
            }
            dp[i+1][j] += dp[i][j];
        }
    }

    cout << dp[N][geta]-1 << endl;


    return 0;
}

Measured memory_bytes: 4564
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  int n,l;
  cin>>n>>l;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  int p=0,q,r;
  for(int i=0;i<n-1;i++){
    if(vec[i]+vec[i+1]>=l){
      p++;
      q=i;
      r=i+1;
      break;
    }
  }
  if(p==0){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  for(int i=1;i<r;i++){
    cout<<i<<endl;
  }
  for(int i=n-1;i>r;i--){
    cout<<i<<endl;
  }
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
string a,b,c;
	int ans=0;
	cin >>a>>b>>c;
	cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 3548
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){

    int N,K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }

    //解答のsum
    /*
    vector<ll> sum_a;
    for (int l = 0; l < N; l++) {
        ll sm = 0;
        for (int r = l+1; r <= N; r++) {
            sm += a[r-1];
            sum_a.push_back(sm);
        }
    }
    */
 

    //int sum_a[N * (N+1) / 2] = {0};
    //vector<int> sum_a(N * (N+1) /2);
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        for (int k = i; k < N; k++){
            ll t_sum = 0;
            for (int p = i; p <= k; p++){
                t_sum += a[p];
            }
            sum_a.push_back(t_sum);
        }
    }
    /*
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        ll sum = 0;
        for (int k = i; k < N; k++){
            sum += a[k];
            sum_a.push_back(sum);
        }
    }
    */

    /*
    int x = 0;
    int t = 40;
    while(t != 0){
        int cnt = 0;
        ll prov = x + pow(2,t-1);
        for (int i = 0; i < sum_a.size(); i++){
            if ((prov & sum_a[i]) == prov){
                cnt++;
            }
        }
        if (cnt >= K){
            x += prov -x;
        }
        t--;
    }

    cout << x << endl;
    */
    ll ans = 0;
    for (int lg = 50; lg >= 0; lg--) {
        ll nans = ans | (1LL << lg);
        int cnt = 0;
        for (ll d: sum_a) {
            if ((nans & d) == nans) cnt++;
        }
        if (cnt >= K) ans = nans;
    }
    cout << ans << endl;



}



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

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

    vector<int> v(n,0);
    for(auto&& x: v){
        cin >> x;
    }

    int ans = v[1] - v[0];

    int minv = v[0];

    for(int i=1; i<n; ++i){
        ans = max(ans, v[i] - minv);
        minv = min(minv, v[i]);
    }

    cout << ans <<endl;

    return 0;

}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

signed main() {
  int n;
  cin >> n;
  vec<int> h(n);
  rep (i, n) {
    cin >> h[i];
  }
  if (count(all(h), 0LL) == n) {
    cout << 0 << endl;
    return 0;
  }
  h.push_back(0);


  int ans = 0;
  int H = h.size();
  while (1) {
    bool flg = false;
    int idx = 0;
    repp (i, 0, H) {
      if (h[i] == 0) {
        if (flg == true) {
          idx = i;
          break;
        }
      } else {
        flg = true;
      }
    }

    rep (i, idx) {
      h[i] = max(0LL, h[i] - 1);
    }

    ans++;

    // print1(all(h));
    if (count(all(h), 0LL) == H) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n;
    int array[n];
    int counter = 0;

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

    while (1)
    {
        for (int i=0;i<n;i++){
            if(array[i]%2==0){
                array[i] = array[i]/2;
                }
            else{
                goto LABEL;
            }
        }
        counter++;
    }
    LABEL:printf("%d", counter);
    return 0;
    
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    REP(i,n){
      cin >> x[i] >> y[i];
    }

    llong dp[20][20] = {};
    dp[1][1] = 1;
    for(int i = 1; i <= 16; ++i){
      for(int j = 1; j <= 16; ++j){
        bool is_const = false;
        for(int k = 0; k < n; ++k){
          if(i+1 == x[k] && j == y[k]){
            is_const = true;
            break;
          }
        }
        if(!is_const)
          dp[i+1][j] += dp[i][j];

        is_const = false;
         for(int k = 0; k < n; ++k){
          if(i == x[k] && j+1 == y[k]){
            is_const = true;
            break;
          }
        }
        if(!is_const)
          dp[i][j+1] += dp[i][j];
      }
    }

    cout << dp[a][b] << endl;
  }

  return 0;
}




Measured memory_bytes: 3012
N = int(input())
list1 = []
list2 = []
p = 0
k = 0
for i in range(N):
    a, b = map(int, input().split())
    list1.append(a)
    list2.append(b)
for j in range(N):
    if list1[j] == list2[j]:
        p += 1
    else:
        p = 0
    if p == 3:
        k += 1

if k >= 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int C[100];
int P[100];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d,g;cin>>d>>g;
    for(int i=1;i<=d;i++){
        cin>>P[i]>>C[i];
    }
    int ans = 1e9;
    // 1問で完結する場合
    // for(int i=1; i<=d; i++){
    //     int t = (g + (100*i -1)) / (100*i);
    //     if(C[i]>t) chmin(ans, t);
    // }

    for(int bit = 0; bit<(1<<d); bit++){
        int t_score = 0;
        int p_count = 0;
        int chosen[100] = {0};
        for(int i=0; i<d; i++){
            if(bit & (1<<i)){ // 完答するやつ
                int index = i+1;
                chosen[index]=1;
                t_score += ((index*100 * P[index]) + C[index]);
                p_count += P[index];
            }
        }
        // 超えていなかった部分の帳尻合わせ
        if(t_score < g){
            int rem = g-t_score;
            for(int i=1; i<=d;i++){
                if(chosen[i] || P[i]==1) continue;
                int t = (rem + (100*i -1)) / (100*i);
                if(P[i]>t) chmin(ans, p_count+t);
            }
        } else {
            chmin(ans, p_count);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
long long a,b[2003],ans;
int main()
{
	cin>>a;
	for(int i=0;i<a;i++)
	{
		cin>>b[i];
	}
	sort(b,b+a);
	for(int i=0;i<a;i++)
	{
		for(int j=i+1;j<a;j++)
		{
			for(int k=j+1;b[k]<b[i]+b[j]&&k<a;k++)
			{
//				cout<<"b[i]:"<<b[i]<<"b[j]:"<<b[j]<<"b[k]:"<<b[k]<<"b[i]+b[j]:"<<b[i]+b[j]<<endl;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << max(a+b,max(a*b,a-b)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

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

using namespace std;

int main()
{
    int H, W;
    scanf("%d %d\n", &H, &W);

    string data[H];
    string ans[H];
    REP(i, H)
    {
        cin >> data[i];
        ans[i] = data[i];
    }

    REP(i, H)
    {
        int j;
        for (j = 0; j < W; j++)
        {
            if (data[i][j] == '#')
            {
                break;
            }
        }

        //j == H なら１度もbreakしてない <=> 全て'.'
        if (j == W)
        {
            REP(k, W)
            {
                ans[i][k] = 'n';
            }
        }
    }

    REP(i, W)
    {
        int j;
        for (j = 0; j < H; j++)
        {
            if (data[j][i] == '#')
                break;
        }
        if (j == H)
        {
            REP(k, H)
            {
                ans[k][i] = 'n';
            }
        }
    }

    REP(i, H)
    {
        bool check = true;
        REP(j, W)
        {
            if (ans[i][j] != 'n')
            {
                cout << ans[i][j];
                check = false;
            }
        }
        if (!(check))
            cout << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int hako[111111];
int main(void){
  int n,x;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x;
    hako[x]++;
  }
  int res=0;
  for(int i=0;i<111111-2;i++){
    res=max(res,hako[i]+hako[i+1]+hako[i+2]);
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int X,N;
  cin >> X >> N;
  if(N == 0){
    cout << X << endl;
  }else{
    vector<int> suuretu(N);
    for(int i = 0;i < N;i++){
      cin >> suuretu.at(i);
    }
    int x;
    int judge = 0,now = 1000000,nowi = 0;
    for(int i = 0;i < X + 100;i++){
      for(int j = 0;j < N;j++){
        if(suuretu.at(j) == i){
          judge = 1;
        }
      }
      if(judge == 0){
        x = abs(i - X);
        if(x <= now){
          if(now == x){
            nowi = min(nowi,i);
          }else{
            now = x;
            nowi = max(nowi,i);
          }
        }
      }
      judge = 0;
    }
    cout << nowi << endl;
  }
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=5)
	{
		cout<<"0"<<endl;
		return 0;
	}
	if(a>=6&&a<=12) 
	{
		cout<<b/2<<endl;
	}
	else cout<<b<<endl;
	return 0;
}

 







Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> a(n);
    ll sum = 0;
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    sum += a[0];
    repf(i,1,n/2) sum += a[i]*2;
    if (n%2==1) {
        sum += a[n/2];
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  cout << fixed << setprecision(10);

  double a, b, v;
  cin >> a >> b >> v;
  double s = v / a;
  if (s > a * b / 2.0) {
    double theta = atan((a * b - s) / (a * a / 2.0));
    // cout << theta << endl;
    cout << theta / M_PI * 180.0 << endl;
  } else {
    double phi = atan(s / (b * b / 2.0));
    double theta = M_PI_2 - phi;
    cout << theta / M_PI * 180.0 << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int n, C, fir, L[7];

long long F[257][311];

int A1[257], A2[257], B[33][33], tim = -1, Fac[6] = {1, 1, 2, 6, 24, 120};

int main() {
    scanf("%d%d", &n, &C);
    for(int i = 0; i < n; i++) scanf("%d", &L[i]);
    for(int i = 0; i < (1 << (n - 1)); i++)
        for(int j = 0; j < (1 << (n - 1)); j++)
            if(__builtin_popcount(i) == __builtin_popcount(j)) {
                A1[++tim] = i;
                A2[tim] = j;
                B[i][j] = tim;
            }
    sort(L, L + n);
    fir = L[n - 1];
    memset(F, 0, sizeof F);
    F[0][fir * n] = 1;
    for(int i = 0; i <= C * n; i++) if(i % n)
        for(int S = 0; S < tim; S++) {
            int s1 = A1[S], s2 = A2[S], tmp;
            if((s2 >> (i % n - 1)) & 1) continue;
            tmp = s2 + (1 << (i % n - 1));
            for(int j = i; j <= C * n; j++) if(F[S][j])
                for(int nxt1 = 0; nxt1 < n - 1; nxt1++) if(!((s1 >> nxt1) & 1))
                    F[B[s1 + (1 << nxt1)][tmp]][min(C * n, max(j, i + L[nxt1] * n))] += F[S][j];
        }
    printf("%.15lf\n", F[tim][C * n] / pow(C, n - 1) / Fac[n - 1]);
    return 0;
}


Measured memory_bytes: 768
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
ts = []
for _ in range(Q):
    ts.append(tuple(map(int, input().split())))

scores = []
for A in combinations_with_replacement(range(1, M + 1), N):
    score = 0
    for t in ts:
        a, b, c, d = t
        if A[b - 1] - A[a - 1] == c:
            score += d
    scores.append(score)

print(max(scores))


Measured memory_bytes: 12636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[200000],b[200000];
    REP(i,n){
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b,b+n);
    reverse(b,b+n);
    REP(i,n)cout << (a[i]==b[0]?b[1]:b[0]) << endl;
}

Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9+7
#define LINF (long long)4e18

int sums(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N; cin >> N;
    int S = sums(N);
    if(N % S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}
   

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int r, D, x2000, i = 1;
	scanf("%d %d %d", &r, &D, &x2000);
	while (i <= 10) {
		x2000 = r * x2000 - D;
		printf("%d\n", x2000);
		i++;
	}


	return 0;
}

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

int main(){
    int res[4][13],n,c;
    char m;
    
    for(int i = 0 ; i < 4 ; i++)
        for(int j = 0 ; j < 13 ; j++)
            res[i][j] = 0;
    
    
    cin >> n;
    while(n--){
        cin >> m >> c;
        if(m == 'S') res[0][c-1] = 1;
        else if(m == 'H') res[1][c-1] = 1;
        else if(m == 'C') res[2][c-1] = 1;
        else res[3][c-1] = 1;
    }
    
    for(int i = 0 ; i < 4 ; i++){
        for(int j = 0 ; j < 13 ; j++){
            if(!res[i][j]){
                if(i == 0) cout << 'S' << ' ' << j+1 << endl;
                else if(i == 1) cout << 'H' << ' ' << j+1 << endl;
                else if(i == 2) cout << 'C' << ' ' << j+1 << endl;
                else cout << 'D' << ' ' << j+1 << endl;
            }
            
        }
    }
  
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ninf 0xc0c0c0c0
#define de(x) cout<<#x<<"="<<x<<endl;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define fi first
#define se second
#define pb push_back
#define pdi pair<double,int>
#define mp(a,b) make_pair(a,b)
#define mt(a,b) memset(a,b,sizeof(a))
#define ll long long
using namespace std;
int main()
{
	int ans=0;
	int n,l,r;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l>>r;
		ans+=(r-l+1); 
	}
	cout<<ans<<endl;
	return 0; 
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e7+1;
int A[Max];

int32_t main()
{
	c_p_p();
	int n;
	cin>>n;
	
	rep(i,2,n+1)
	{
		for(int j=i;j<=n;j+=i)A[j]+=1;
	}
 	int ans=0;
	rep(i,1,n+1)
	{
		ans+=(A[i]+1)*i;
		//deb(A[i]);
	}
	cout<<ans;
	return 0;
}
	

Measured memory_bytes: 81736
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn enum_patterns(h: usize, nt: usize, cur: &mut Vec<usize>) -> Vec<Vec<usize>>{
    if nt == h{
        return vec![cur.clone()];
    }


    let mut ans: Vec<Vec<usize>> = enum_patterns(h, nt+1, cur);
    cur.push(nt);
    let mut tmp = enum_patterns(h, nt+1, cur);
    cur.pop();

    ans.append(&mut tmp);

    return ans;
}

fn main(){
    let line = read_as_vec::<usize>();
    let (h, w, k) = (line[0], line[1], line[2]);

    let mut s = vec![];

    for _ in 0..h{
        let line = read_as_string().chars().collect::<Vec<char>>();
        s.push(line);
    }
    let mut cur = vec![];
    let patterns = enum_patterns(h, 1, &mut cur);

    let mut ans = std::usize::MAX;
    'cand: for pat in &patterns{
        let mut cur_ans = pat.len();
        //decide blongs
        let mut belongs = vec![0;h];
        if pat.len() == 0{
            for i in 0..belongs.len(){
                belongs[i] = 0;
            }
        }else{
            let mut cur_label = 0;
            for i in 0..belongs.len(){
                if cur_label >= pat.len(){
                    belongs[i] = cur_label;
                    continue;
                }
                if i  >= pat[cur_label]{
                    cur_label += 1;
                }
                belongs[i] = cur_label;
            }
        }
        // eprintln!("pat = {:?}", pat);
        // eprintln!("belongs = {:?}", belongs);
        let mut blocks: Vec<usize>= vec![0;pat.len()+1];
        for j in 0..w{
            for i in 0..h{
                if s[i][j] == '1'{
                    blocks[belongs[i]] += 1;
                }
            }

            //split here
            if blocks.iter().any(|x| *x > k){
                blocks = vec![0;pat.len()+1];
                cur_ans += 1;
                for i in 0..h{
                    if s[i][j] == '1'{
                        blocks[belongs[i]] += 1;
                    }
                }
                //this is not answer
                if blocks.iter().any(|x| *x > k){
                    continue 'cand;
                }
            }
        }
        //eprintln!("this pattern cost = {}", cur_ans);
        ans = cmp::min(ans, cur_ans);
        //eprintln!("----\n\n");
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N=gets.to_i
a_array=gets.chomp.split(" ").map(&:to_i)
b_array=gets.chomp.split(" ").map(&:to_i)

d_array=[]
(0..(N-1)).each do |n|
    d_array.push(a_array[n] - b_array[n])
end
d_array = d_array.sort

minus_sum = 0
minus_count = 0
while d_array[minus_count] < 0 do
    minus_sum += d_array[minus_count]
    minus_count+=1
end

plus_count=0
while minus_sum < 0 do
    plus_count += 1
    break if d_array[-1 * plus_count] <= 0
    minus_sum += d_array[-1 * plus_count]
end

if minus_sum >= 0
    puts minus_count + plus_count
else
    puts "-1"
end


Measured memory_bytes: 28924
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[300005];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n*3;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n*3);long long ans=0;
	for(int i=n*3-1;i>n;i-=2) ans+=(long long)a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string s;
    cin >> s;

    for(int i = 0; i < s.size() -2; ++i)
    {
        if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2])
        {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    for(int i = 0; i < s.size() -1; ++i)
    {
        if(s[i] == s[i+1])
        {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    


    cout << -1 << " " << -1 << endl;


    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 301
int n,m;
int a[N][N];
int num[N];
bool v[N];
int ans;
int main(){
	scanf("%d%d",&n,&m);
	int s;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
		int b=a[i][1];
		if(++num[b]>ans){
			ans=num[b];
			s=b;
		}
	}
	for(int i=1;i<m;++i){
		memset(num,0,sizeof num);
		v[s]=1;
		int tans=0;
		bool find;
		for(int j=1;j<=n;++j){
			find=false;
			for(int k=1;k<=m;++k){
				int b=a[j][k];
				if(!v[b]){
					if(++num[b]>tans){
						tans=num[b];
						s=b;
					}
					find=true;
					break;
				}
			}
			if(!find)break;
		}
		if(find)
			ans=min(ans,tans);
	}
	printf("%d",ans);
	return 0;
}


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

using namespace std ;
#define int long long int

const int maxn = 1e5 + 5;
const int inf = 1e10 ;
vector< vector<int> > dp(maxn, vector<int>(3,inf));
vector <int> a(maxn), b(maxn), c(maxn);
int n;



int32_t main(){
    //#ifndef ONLINE_JUDGE
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
    //#endif
    cin >> n ;
    for(int i = 0 ; i < n ; i++ ){
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
    for(int i = 1 ; i < n ; i++ ){
        dp[i][0] = a[i] + max(dp[i-1][1] , dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0] , dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0] , dp[i-1][1]);
        // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }

    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
    return 0;
}

Measured memory_bytes: 8064
def main():
    h, w, *ca = map(int, open(0).read().split())
    it = zip(*[iter(ca[:100])] * 10)
    *c, = map(lambda i: list(i), it)
    a = ca[100:]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    ans = 0
    cost = {i: c[i][1] for i in [0, 2, 3, 4, 5, 6, 7, 8, 9]}
    cost.update({-1: 0, 1: 0})

    for i in a:
        ans += cost[i]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5896
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1e16
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 2e3 + 2;
ll i,n,m,ans;
ll a[N], b[N];
ll dp[N][N];
ll solve(ll i,ll j)
{
    ll &res = dp[i][j];
    if(res != -1) return res;

    if(i == 0 || j == 0) return res = 1;

    res = (solve(i, j - 1) + solve(i - 1,j) - solve(i - 1,j - 1) + mod) % mod;
    if(a[i] == b[j])
        res = (res + solve(i - 1,j - 1)) % mod;

    return res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    memset(dp, -1, sizeof(dp));
    rep(i,1,n + 1) cin>>a[i];
    rep(i,1,m + 1) cin>>b[i];
    ans = solve(n, m);
    cout<<ans;
    return 0;
}

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

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    if (a[0] == a[1]) {
        cout << a[2] << endl;
    } else if (a[1] == a[2]) {
        cout << a[0] << endl;
    } else {
        cout << a[1] << endl;
    }
}


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

char s1[3000+9], s2[3000+9];
int dp[3000][3000], nex[3000][3000], len1, len2;

int solve(int a=0, int b=0){
    if(a == len1 || b == len2) return 0;

    int &ret=dp[a][b];
    if(ret != -1) return ret;

    if(s1[a] == s2[b]){
        ret=1+solve(a+1, b+1);
        nex[a][b]=1;
        return ret;
    }


    ret = solve(a+1, b);
    nex[a][b]=2;

    if(solve(a, b+1) > ret)
        ret=solve(a, b+1), nex[a][b]=3;

    return ret;
}

int main(){
    scanf("%s %s", s1, s2);
    len1=strlen(s1), len2=strlen(s2);
    memset(dp, -1, sizeof(dp));
    int s=solve();

    int x=0, y=0;
    while(s){
        if(s1[x] == s2[y]) printf("%c", s1[x]), s--;
        if(nex[x][y] == 1) x++, y++;
        else if(nex[x][y] == 2) x++;
        else if(nex[x][y] == 3) y++;
    }

    return 0;
}


Measured memory_bytes: 70784