akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ELogs {
public:
    int N, K;
    vector<int> A;

    bool check(int x) {
        int cnt = 0;
        REP(i, N) {
            cnt += (A[i] - 1) / x;
        }
        return cnt <= K;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N >> K;
        A.resize(N);
        REP(i, N) cin >> A[i];

        int l = 0;
        int r = INF;
        while (r - l > 1) {
            int mid = (r + l) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        cout << r << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ELogs solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4680
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int b = sc.nextInt();
			if(b == 0){
				//System.out.println("break");
				break;
			}
			int[] a = new int[b];
			int left,right,searchvalue;
			for(int i=0; i < a.length; i++){
				a[i] = sc.nextInt();
			}
			searchvalue = sc.nextInt();
			left = 0; right = a.length-1;
			System.out.println(solve(left, right, searchvalue, a));
		}
	}

	int solve(int left, int right,int sv,int[] a){
		int index = (left + right) / 2;
		if(a[index] == sv){
			return 1;
		}else if(left > right){
			return 0;
		}else if(a[index] < sv){
			return 1 + solve(++index, right, sv, a);
		}else if(a[index] > sv){
			return 1 + solve(left, --index, sv, a);			
		}
		return 0;
	}
}

Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
int main()
{	int f=1;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i=i+2)
	{
		if(s[i]=='R'||s[i]=='U'||s[i]=='D') continue;
		else
		{
			f=0;break;
		}
	}
	for(int i=1;i<s.size();i=i+2)
	{
		if(s[i]=='L'||s[i]=='U'||s[i]=='D') continue;
		else
		{
			f=0;break;
		}
	}
	if(f==1)
	{
		cout<<"Yes";
	}
	else cout<<"No";
	
}


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

int main() 
{
	int n , ans = 0;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		int temp; cin >> temp; ans^=temp;
	}
	cout << ((!ans)? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
const double eps = 1e-8;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}
template<typename T> inline void chmin(T& t, T f){if(t > f)t = f;}

int h, w;
vector<string> bldg;
vector<vector<bool> > vis;

inline bool inrect(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

pair<double, int> dfs(int sx, int sy){
    vis[sx][sy] = true;
    vector<double> ys;
    vector<pair<int, int> > on;
    int ly = w, ry = 0;
    queue<pair<int, int> > q;
    for(q.emplace(sx, sy); !q.empty();){
        int x = q.front().first, y = q.front().second; q.pop();
        ys.emplace_back(y + .5);
        if(x && !vis[x-1][y] && bldg[x-1][y] != '.' && bldg[x-1][y] != bldg[sx][sy]){
            on.emplace_back(x-1, y);
        }
        if(x == h-1 || (bldg[x+1][y] != '.' && bldg[x+1][y] != bldg[sx][sy])){
            chmin(ly, y); chmax(ry, y+1);
        }
        rep(i, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if(!inrect(nx, ny) || vis[nx][ny] || bldg[nx][ny] != bldg[sx][sy])continue;
            vis[nx][ny] = true;
            q.emplace(nx, ny);
        }
    }
    double M = accumulate(all(ys), 0.);
    int n = (int)ys.size();
    for(auto p: on)if(!vis[p.first][p.second]){
        pair<double, int> t = dfs(p.first, p.second);
        if(t.second == -1)return mp(M, -1);
        M += t.first; n += t.second;
    }
    return ly < M/n - eps && M/n + eps < ry? mp(M, n): mp(M, -1);
}

const char* solve(){
    vis.assign(h, vector<bool>(w, false));
    int y = find_if_not(all(bldg[h-1]), [](const char& c){return c == '.';}) - bldg[h-1].begin();
    return dfs(h-1, y).second != -1? "STABLE": "UNSTABLE";
}

int main(){
    while(cin >> w >> h, w|h){
        bldg.assign(h, "");
        rep(i, h)cin >> bldg[i];
        cout << solve() << '\n';
    }
    return 0;
}

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

int main(){
    int N,K;cin>>N>>K;
    int info[N];
    rep(i,N)cin>>info[i];
    int ans=INF;
    rep(i,N-K+1){
        int now=min(abs(info[i])+info[i+K-1]-info[i],abs(info[i+K-1])+info[i+K-1]-info[i]);
        ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long
#define llu unsigned long long
#define ld long double
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
#define present(v,x) (v).find(x) != (v).end()
#define cpresent(v,x) (find(all(v),x) != (v).end())
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }

inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int addmod(int a, int val, int p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline int submod(int a, int val, int p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

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

	int n;
	cin >> n;
	vector<ld> p(n+1);
	for(int i=1; i<=n; i++)
		cin >> p[i];

	ld dp[n+1][n+1];
	mset(dp, 0);

	dp[0][0] = 1;
	for(int i=1; i<=n; i++)
		for(int j=0; j<=n; j++)
			if(j==0)
				dp[i][j] = dp[i-1][j]*(1-p[i]);
			else
				dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);

	ld res = 0;
	for(int i=(n+1)/2; i<=n; i++)
		res += dp[n][i];

	cout << setprecision(10) << res << endl;

	return 0;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int main()
{
    FAST
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll last=0;
    for(int i=0;i<k;i++)
        last+=arr[i];
       // cout<<last<<endl;
    for(int i=k;i<n;i++){
        ll temp=last-arr[i-k];
        //cout<<arr[i-k]<<endl;
        temp+=arr[i];
        //cout<<temp<<"       "<<last<<endl;
        if(temp>last){
            cout<<"Yes"<<endl;
        }else{
        cout<<"No"<<endl;
        }
        last=temp;
        //cout<<last<<endl;
    }

    return 0;
}


Measured memory_bytes: 5128
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) rep2(i,0,n)

using namespace std;

void print(int x,int y){
    cout<<x<<" "<<y<<endl;
}

main(){
    int n;
    cin>>n;
    long int a[60];
    a[59]=0;
    rep(i,n) cin>>a[i];
    pair<int,int> p(59,0);
    
    rep(i,n){
    if(abs(a[i])>abs(a[p.first])) {
        p.first=i;
        if(a[i]>0) p.second=1;
        else p.second=-1;
    }
    }
    if(p.second==0) {
        cout<<0;
        return 0;
    }
    cout<<2*n-2<<endl;
    rep(i,p.first) print(p.first+1,i+1);
    rep2(i,p.first+1,n) print(p.first+1,i+1);
    if(p.second==1){
        rep(i,n-1) print(i+1,i+2);
    }
    else 
    {for(int i=n;i>1;i--)
    print(i,i-1);}
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
MOD = 1000000007

s = input()[:-1]

for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break
    
for i in range(len(s)-1,-1,-1):
    if s[i] == 'Z':
        z = i
        break

print(z-a+1)

Measured memory_bytes: 3512
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int age = stdIn.nextInt();
        
        //int c = stdIn.nextInt();
        //int k = stdIn.nextInt();
        //String s = stdIn.next();
        //char c[] = s.toCharArray();
        //boolean heisei = true;
        
        if(age == 1){
            System.out.println("Hello World");
        }else{
            int a = stdIn.nextInt();
            int b = stdIn.nextInt();
            System.out.println(a + b);
        }
        
        
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <set>

using namespace std;
int main(){
	typedef set<string> set_t;
	set_t Dic;
	int n;
	cin >> n;
	string cmd, word;
	for(int i = 0; i < n; i++){
		cin >> cmd;
		if(cmd == "insert"){
			cin >> word;
			Dic.insert(word);
		}
		if(cmd == "find"){
			cin >> word;
			if (Dic.count(word)){
				cout << "yes" << endl;
			}else{
				cout << "no" << endl;
			}
		}
	}
	return 0;
}


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

int M = 10000000;
int N,A,B,C;
vector<int> L;

int func(int i, int a, int b, int c) {
    if (i == N) {
        if (!a || !b || !c) return M;
        return abs(a - A) + abs(b - B) + abs(c - C); 
    }

    int res1 = func(i+1,a,b,c);
    int res2 = func(i+1,a+L[i],b,c) + (a?10:0);
    int res3 = func(i+1,a,b+L[i],c) + (b?10:0);
    int res4 = func(i+1,a,b,c+L[i]) + (c?10:0);
    
    return min(res1,min(res2,min(res3,res4)));
}
 
int main(){
    cin >> N >> A >> B >> C;
    rep(i,N){
        int l;
        cin >> l;
        L.emplace_back(l);
    }
    cout << func(0,0,0,0) << endl;

    return 0;
}

Measured memory_bytes: 256
public class Main {
  private static void solve() {
    int q = ni();

    for (int i = 0; i < q; i++) {
      long a = nl();
      long b = nl();
      if (a > b) {
        long tmp = a;
        a = b;
        b = tmp;
      }

      if (a == b || a + 1 == b) {
        System.out.println(2 * (a - 1));
      } else {
        long c = (long)Math.sqrt(a * b - 100);
        while ((c + 1) * (c + 1) < a * b) {
          c ++;
        }
        if (c * (c + 1) >= a * b) {
          System.out.println(2 * (c - 1));
        } else {
          System.out.println(2 * (c - 1) + 1);
        }
      }
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 22100
#include <iostream>
#include <cstdio>
using namespace std;
int main( void )
{
  int a,b,c,d,e,f;
  double x,y;
  while( 1 ){
    cin >> a >> b >> c >> d >> e >> f;
    if( cin.eof() ) break;
    x = (double)(c*e-b*f) / (a*e-b*d);
    y = (double)(a*f-c*d) / (a*e-b*d);
    printf( "%.3lf %.3lf\n", x+0.0, y+0.0 );
  }
  return 0;
}

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

int main(){
	int i=1,j,N,count;
	int a[100001];
	cin>>N;
	while(i<=N){cin>>a[i];i++;}

	for(i=1;i<=N;i++){
		j=a[i];
		if(i==a[j]){count++;}
	}
	cout<<count/2;

	return 0;
}

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

using namespace std;

vector<string> ans;
string s;
vector<bool> state(26,false);

int dfs(int idx, string sum){
	if(idx == s.size()){
		ans.emplace_back(sum);
		return 0;
	}
	char c = s[idx];
	if(state[c - 'a']){
		dfs(idx + 1, sum + c);
	}
	if(c + 1 <= 'z' && !state[c + 1 - 'a']){
		state[c + 1 - 'a'] = true;
		dfs(idx + 1, sum + (char)(c+1));
		state[c + 1 - 'a'] = false;
	}
	return 0;
}

int main(){
	while(cin >> s,s != "#"){
		ans.clear();
		state[0] = true;
		dfs(0, "");
		cout << ans.size() << endl;
		if(ans.size() < 10){
			for(auto it = ans.begin(); it != ans.end(); it++){
				cout << *it << endl;
			}
		} else {
			for(int i = 0;i < 5;i++) cout << ans[i] << endl;
			for(int i = 0;i < 5;i++) cout << ans[ans.size() - 5 + i] << endl;
		}
	}
}

Measured memory_bytes: 4344
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
  int n, m, i;
  cin >> n;
  vector<string> S(n);
  string s;
  rep(i, n){
    cin >> s;
    sort(s.begin(), s.end());
    S[i] = s;
  }
  sort(S.begin(), S.end());
  int64_t count = 1;
  int64_t sum = 0;
  for(i=0; i<n-1; i++){
    if(i==n-2&&S[i]==S[i+1]) {
      count++;
      int64_t ty = count*(count-1)/2;
      sum += ty;
      count = 1;
    }
    else if(S[i]==S[i+1]) count++;
    else {
      int64_t ty = count*(count-1)/2;
      sum += ty;
      count = 1;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 5760
#include<stdio.h>
int main()
{
    int n, i, flg = 0;
    char s[50][101] = {};
    int t[50] = {0};
    char x[101];
    int ans = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s%d",s[i],&t[i]);
    }
    scanf("%s",x);
    for(i = 0; i < n; i++){
        if(flg == 1) ans += t[i];
        if(strcmp(s[i], x) == 0) flg = 1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
using System;

public class ITP1_6_D
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int m = int.Parse(input[1]);
    int[,] A = new int[n, m];
    int[] b = new int[m];

    for (int i = 0; i < n; i++)
    {
      string[] data = Console.ReadLine().Split(' ');
      for (int j = 0; j < m; j++)
      {
        A[i, j] = int.Parse(data[j]);
      }
    }

    for (int i = 0; i < m; i++)
    {
      b[i] = int.Parse(Console.ReadLine());
    }

    for (int i = 0; i < n; i++)
    {
      int c = 0;
      for (int j = 0; j < m; j++)
      {
        c += A[i, j] * b[j];
      }
      Console.WriteLine(c);
    }
  }
}

Measured memory_bytes: 9388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    while(1) {
        string s;
        cin >> s;
        if (s == "-") break;
        int m;
        cin >> m;
        rep(i, 0, m) {
            int h;
            cin >> h;
            string tmp = s.substr(0, h);
            s.erase(0, h);
            s += tmp;
        }
        cout << s << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    ll n, k;
    cin >> n >> k;

    ll ans (1);
    rep(i, 0, n-1)
       ans *= k-1; 

    cout << ans * k << endl;

    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i = 0;i < s.size();i++){
    cout << (char)( ( (int)s[i]+n-(int)'A')%('Z'-'A'+1)+(int)'A') ;
  }
  cout << endl;
}

Measured memory_bytes: 3628
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 405;

signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    int ruisekiwa[n+1];
    ruisekiwa[0] = 0;
    REP(i,n) ruisekiwa[i+1] = ruisekiwa[i] + A[i];

    int dp[n_max][n_max];
    REP(i,n-1) dp[i][i+2] = A[i] + A[i+1];

    FOR(kukan,3,n + 1){
        REP(i,n){
            if(i + kukan > n) break;
            dp[i][i + kukan] = min(dp[i][i + kukan -1], dp[i+1][i + kukan]);
            FOR(j,i + 2,i + kukan){
                if(i + kukan - j == 1) break;
                chmin(dp[i][i + kukan ], dp[i][j] + dp[j][i+ kukan]);
            }
            dp[i][i + kukan] += ruisekiwa[i + kukan] - ruisekiwa[i];
        }
    }


    cout << dp[0][n] << endl;

}

Measured memory_bytes: 1536
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let s: Vec<u32> = read_vec();
    let q: usize = read();
    let t: Vec<u32> = read_vec();

    let mut cnt: u32 = 0;
    for i in 0..q {
        let tmp = t[i];
        let mut b = false;
        for j in 0..n {
            if s[j] == tmp {
                b = true;
                break;
            }
        }
        if b {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}



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

int main() {
    int i,j,k;
    int n,a;
    cin >> n >> a;
  if(n%500<=a)
  {
    cout <<  "Yes" << endl;
  }else
  {
    cout << "No" << endl;
  }
  
}


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

int main(){

    while(1){

	string s; cin >> s;

    if(s == "#") return 0;

    int cnt = 1;
    rep(i,s.size()){
        if(s[i] == '/') cnt ++;
    }

    vector<string> g(cnt, "");

    ll id = 0;

    rep(i,s.size()){

        if(s[i] == 'b'){
            g[id] = g[id] + "b";
            continue;
        }

        else if (s[i] != '/'){

            rep(j,(s[i] - '0')) g[id] = g[id] + ".";
            continue;

        }

        if(s[i] == '/'){
            id++;
            continue;
        }

    }

    //rep(i,cnt){
        //cout << g[i] << endl;
    //}

    int h1, w1, h2, w2; cin >> h1 >> w1 >> h2 >> w2;
    h1--; w1--; h2--; w2--;

    g[h1][w1] = '.'; g[h2][w2] = 'b';

    //rep(i,cnt){
        //cout << g[i] << endl;
    //}

    string ans = "";

    ll tmpi = 0;
    rep(i, cnt){
        rep(j, g[0].size()){

            if(g[i][j] == '.'){
                tmpi++;
                continue;
            }
            
            if(g[i][j] == 'b'){

                if(tmpi == 0){
                    ans = ans + "b";
                }

                else{
                    ans = ans + string(1,(tmpi + '0')) + "b";
                    tmpi = 0;
                }

            }
        }

        if(tmpi != 0) ans = ans + string(1,(tmpi + '0'));
        if(i != cnt -1) ans = ans + "/";

        tmpi = 0;

    }

    cout << ans << endl;

    }

}




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

int main() {
    int A, B, C;
    std::cin >> A >> B >> C;

    int max = std::max({A, B, C});
    if ((max * 3 - (A + B + C)) % 2 == 0) {
        std::cout << (max * 3 - (A + B + C)) / 2 << std::endl;
    } else {
        std::cout << ((max + 1) * 3 - (A + B + C)) / 2 << std::endl;
    }
}


Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts a[gets.to_i - 1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, n;
  string s;
  in(s);
  n = s.size();
  vector<ll> t(n, 0);
  a = 0;
  while(a < n){
    c = a;
    while(s[c + 1] == 'R')
      c++;
    b = c;
    while(s[b + 1] == 'L')
      b++;
    if((b - a + 1) % 2 == 0)
      t[c] = t[c + 1] = (b - a + 1) / 2;
    else{
      if((c - a) % 2 == 0){
        t[c] = (b - a + 1) / 2 + 1;
        t[c + 1] = t[c] - 1;
      }
      else{
        t[c] = (b - a + 1) / 2;
        t[c + 1] = t[c] + 1;
      }
    }
    a = b + 1;
  }
  rep(i, n){
    out(t[i]);
    hina;
  }
  memi;
}


Measured memory_bytes: 1408
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Integer
getInt = (\a -> read a :: Integer) <$> getLine

getIntArray :: IO [Integer]
getIntArray = ((map (\a -> read a :: Integer)) . words) <$> getLine

getStrArray :: Integer -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

main = do
    [a, b, c] <- getIntArray
    putStrLn (if c <= b && a <= b then "Yes" else "No")


Measured memory_bytes: 508
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

vector<int> edges[100005];
int depth[100005];
bool used[100005];
void dfs(int curr, int par=0) {
  for(int out: edges[curr]) {
    if(out == par) continue;
    depth[out] = depth[curr]+1;
    dfs(out, curr);
  }
}
void solve() {
  int n;
  cin >> n;
  for(int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  dfs(1);
  vector<pii> v;
  for(int i = 1; i <= n; i++) {
    v.emplace_back(depth[i], i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for(pii out: v) {
    int curr = out.second;
    if(used[curr]) continue;
    int found = -1;
    for(int out: edges[curr]) {
      if(depth[out] < depth[curr] && !used[out]) {
        found = out;
      }
    }
    if(found == -1) {
      cout << "First\n";
      return;
    }
    used[found] = true;
  }
  cout << "Second\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 7420
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

void solve() {
    cini(r);
    cout<<setprecision(12)<<fixed<<2*r*PI<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 3792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int digit_sum(int N) {
	int res = 0;
	while (N) {
		res += N % 10;
		N /= 10;
	}
	return res;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int sum = digit_sum(i);
		if (A <= sum && sum <= B) {
			ans += i;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# ２次元配列を１次元配列にする方法
a = sum([input().split() for i in range(3)], [])
# list文字列リストを数値リストに変換
a = [int(i) for i in a]
count = int(input())
if count < 3:
    print("No")
else:
    num = int(input())
    a = [-1 if int(i) == num else i for i in a]
    num = int(input())
    a = [-1 if int(i) == num else i for i in a]
    counter = 3
    d = False
    while (counter <= count):
        counter += 1
        num = int(input())
        a = [-1 if int(i) == num else i for i in a]
        point = sum(i == -1 for i in a)
        if point >= 3 and (sum(a[0:3]) == -3 or sum(a[3:6]) == -3 or sum(a[6:9]) == -3 or sum(a[0::3]) == -3 or sum(
                a[1::3]) == -3 or sum(a[2::3]) == -3 or sum(a[0::4]) == -3 or sum(a[2:7:2]) == -3):
            print("Yes")
            d = True
            break
    if not d:
        print("No")

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int X = (A); X <= (Y);++X)
#define _rep2(X, Y) for (int X = 0; X < (Y); ++X)
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int X = (Y-1); X >= 0; --X)
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll MAX = 1000000;
ll n, s;

ll digit_sum(ll n, ll b) {
  if (n == 0) return 0;
  else return digit_sum(n/b, b) + n%b;
}

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

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

  ll ans = -1;


  for (ll b = 2; b <= min(n+1, MAX); ++b) {
    ll sm = digit_sum(n, b);
    if (sm == s) {
      ans = b;
      break;
    }
  }

  if (ans > 0) {
    cout << ans << endl;
    return 0;
  }

  if ((n+1) <= MAX) {
    cout << -1 << endl;
    return 0;
  }


  for (ll p = MAX; p > 0; --p) {
    if ((n-s)%p != 0) continue;
    ll b = (n-s) / p + 1;
    if (b < 2) continue;
    ll sm = digit_sum(n, b);
    if (sm == s) {
      ans = b;
      break;
    }
  }

  if (ans > 0) {
    cout << ans << endl;
    return 0;
  }

  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }

  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  long long H,N;
    cin >> H>>N;
  int vec[N];
    int sum=0;
    REP(i,N){
        cin >> vec[i];
        sum+=vec[i];
     // cout << sum << endl;
    }
    if (sum >= H ){
        cout << "Yes"<< endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

int main() {
	int n, m, result = 0, i, a;

	cin >> n >> m;
	result = n;

	for (i = 0; i < m; i++) {
		cin >> a;
		result -= a;
	}
	if (result < 0) result = -1;

	cout << result<< endl;
	return 0;
}


Measured memory_bytes: 3636
require 'matrix'
require 'mathn'

class Land
	def initialize(*args)
		@cx, @cy, @points = args
	end

	def area
		s = 0
		(@points + [@points[0]]).each_cons(2) do |(x1, y1), (x2, y2)|
			s += x1 * y2 - y1 * x2
		end
		(s / 2.0).abs
	end

	def cut(a, b, c) #by line a*x+b*y+c=0
		s = a * @cx + b * @cy + c	
		@points.size.times do |i|
			(x1, y1), (x2, y2) = @points[i], @points[(i+1) % @points.size]
			if (a * x1 + b * y1 + c) * (a * x2 + b * y2 + c) < 0
				d, e = y2 - y1, x2 - x1
				m = Matrix[
					[a, b],
					[d, -e]
					]
				v = Vector[-c, d * x1 - e * y1]
				#p (m.inv * v).to_a
				@points[i] += (m.inv * v).to_a
			end
		end

		@points = @points.flatten.each_slice(2).to_a
		@points = @points.select{|x, y| s * (a * x + b * y + c) >= 0}
		
	end

	attr_reader :cx, :cy
end

loop do
	n, m = gets.split.map(&:to_i)
	break if n == 0
	points = (1..n).map { gets.split.map(&:to_i) }
	lands = (1..m).map do
		cx, cy = gets.split.map(&:to_i)
		l = Land.new(cx, cy, points.dup)
	end
	lands.combination(2) do |l1, l2|
		x1, y1, x2, y2 = l1.cx, l1.cy, l2.cx, l2.cy
		u, v = (x1 + x2) / 2, (y1 + y2) / 2

		a = x1 - x2
		b = y1 - y2
		c = -(a * u + b * v)
		
		l1.cut(a, b, c)
		l2.cut(a, b, c)
	end	
	lands.each {|l| p l.area.to_f}
end

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

using namespace std;

int a[100001];

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    long long mx1 = 0;
    long long mx2 = 0;
    for (int i = 0; i < n - 1; i++){
        if (a[i] == a[i + 1]){
            if (a[i] > mx1){
                mx2 = mx1;
                mx1 = a[i];
            } else if (a[i] > mx2){
                mx2 = a[i];
            }
            i++;
        }
    }
    cout << mx1 * mx2;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int x=0,max=0;
  for(int i=0;i<n;i++){
	if(s[i]=='I')x++;
	else if(s[i]=='D')x--;
	if(x>=max)max=x;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed compare(const void *a, const void *b){
	int sub = *(int *)b - *(int *)a;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

signed main(){
	int N, i, SB = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * N);
	int *sum = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &A[i], &B[i]);
		SB += B[i];
		sum[i] = A[i] + B[i];
	}
	qsort(sum, N, sizeof(int), compare);
	int ans = -SB;
	for(i = 0; i < N; i++){
		if(i % 2 == 0){
			ans += sum[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3324
#include <stdio.h>
#include <math.h>

int main(){
	int a[101]={};
	int i,n;
	int max;

	while(scanf("%d",&n)!=EOF){
		a[n]++;
	}
	max=0;
	for(i=1; i<=100; i++){
		if(max<a[i])max=a[i];
	}
	for(i=1; i<=100; i++){
		if(a[i]==max)printf("%d\n",i);
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }

  // 大きい順にソート
  sort(a,a+N,greater<int>());

  int dif=0;
  for(int i=0;i<N;i++){
    if(i==N-1){
      dif += a[i];
    }
    else{
      dif += a[i] - a[i+1];
    }
    i += 1;
  }

  cout << dif << endl;

  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.split.map(&:to_i)
q = gets.to_i
t = gets.split.map(&:to_i)
t.sort!
cnt = 0
idx = 0
for i in 0...q
  while t[i] > s[idx]
    idx += 1
  end
  if t[i] == s[idx]
    cnt += 1
  end
end
puts cnt

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

using namespace std;

int main() {
  int64_t K, N;
  cin >> K >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  A.push_back(K + A[0]);

  int64_t max_d = 0;
  for (int i = 0; i < N; i++) {
    max_d = max(max_d, A[i + 1] - A[i]);
  }
  cout << K - max_d << endl;
  return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <cmath>
using namespace std;
long long S[200005],rez=1LL<<62;
int N;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>S[i];
        S[i]+=S[i-1];
    }
    for(int i=1;i<N;i++)rez=min(rez,(long long)abs(S[i]-(S[N]-S[i])));
    cout<<rez;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
S = []


cnt_min = [50 for i in range(26)]

for i in range(n):
    cnt = [0 for i in range(26)]
    s = list(input())
    s.sort()
    for i in s:
        cnt[ord(i) - ord("a")] += 1

    for i in range(26):
        cnt_min[i] = min(cnt_min[i], cnt[i])


for i in range(26):
    for j in range(cnt_min[i]):
        print(chr(ord("a") + i), end = "")
print()

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

typedef long long ll;

int main()
{
    ll n, x;
    ll ans, c;
    cin >> n >> x;
    vector<int> a(n), b(n - 1);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ans = 0;
    if (a[0] > x)
    {
        ans = a[0] - x;
        a[0] = x;
    }
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] + a[i + 1] <= x)
            continue;
        c = a[i + 1] + a[i] - x;
        a[i + 1] -= c;
        ans += c;
    }
    cout << ans << endl;
}


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

const int maxn=2e5+3;
map<int,int> has;
int a[maxn];
int n,ans;

inline int Rd() {

	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	} return x;
}
inline int pd(int num) {
	
	int res=1;
	while(res<num) res<<=1;
	return res;
}

int main() {

	register int i;
	n=Rd();
	for(i=1;i<=n;++i)
	a[i]=Rd(),++has[a[i]];
	
	sort(a+1,a+1+n);
	int hi_num,alr,ano,minn;
	for(i=n;i>=1;--i) {
		
		alr=has[a[i]];
		if(!alr) continue;
		hi_num=pd(a[i]);
		if(hi_num==a[i]) {
			ans+=alr>>1;
		}
		else {
			ano=has[hi_num-a[i]];
			minn=min(ano,alr);
			ans+=minn;
			has[hi_num-a[i]]-=minn;
		} has[a[i]]=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19712
#include <iostream>
#include <cmath>

using namespace std;


int main() {

  int n;

  int prime[11000];
  int ans;

  prime[0]=prime[1]=0;

  for(int i=2;i<=10000;i++) prime[i]=1;

  for(int i=2;i<=sqrt(10000);i++) {

    if(prime[i]==1) {

      for(int j=2*i;j<=10000;j+=i) {

	prime[j]=0;

      }

    }

  }

  //for(int i=0;i<=10000;i++) if(prime[i]==1) cout << i << " ";

  while(cin >> n) {

    ans=0;

    for(int i=1;i<=n;i++) {

      if(prime[i]==1 && prime[n+1-i]==1) ans++;

    }

    cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

long long N;
long long dp[5001][5001];
vector<long long> H, P;
vector<pair<long long, long long> > HP;

const long long inf = 1e15;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        long long h, p;
        cin >> h >> p;
        H.push_back(h);
        P.push_back(p);
        HP.push_back(make_pair(h + p, i));
    }
    sort(HP.begin(), HP.end());
    for (int i = 0; i <= N;i++)
    {
        for (int j = 1; j <= N;j++)
        {
            dp[i][j] = inf;
        }
    }

    long long ans = 0;

    for (long long i = 1; i <= N;i++)
    {
        long long idx = HP[i - 1].second;
        for (long long j = 0; j <= i; j++)
        {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if (j - 1 >= 0 && dp[i - 1][j - 1] <= H[idx])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + P[idx]);
            }
            if(dp[i][j] < inf)
            {
                ans = max(ans, j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 195968
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector.Unboxed           as V
import           Text.Printf

main :: IO ()
main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  print . flip (-) b $ sum [1..(b - a)]



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

int ans[305][305];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h, w, k; cin >> h >> w >> k;
    int cur = 1;
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            char c; cin >> c;
            if(c == '.') ans[i][j] = 0;
            else ans[i][j] = cur++;
        }
    }
    for(int i=0; i<h; i++) {
        for(int j=1; j<w; j++) if(ans[i][j] == 0) ans[i][j] = ans[i][j-1];
        for(int j=w-2; j>=0; j--) if(ans[i][j] == 0) ans[i][j] = ans[i][j+1];
    }
    for(int i=1; i<h; i++) {
        for(int j=0; j<w; j++) if(ans[i][j] == 0) ans[i][j] = ans[i-1][j];
    }
    for(int i=h-2; i>=0; i--) {
        for(int j=0; j<w; j++) if(ans[i][j] == 0) ans[i][j] = ans[i+1][j];
    }
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            if(j) cout << ' ';
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    string s,t;
    cin>>s>>t;ll c=0;
    f(i,0,s.size())c+=(s[i]==t[i]);
    cout<<c;
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

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

    priority_queue<tuple<ll,ll>> que;
    vector<ll> iA,iB;
    REP(i,N) {
        ll A,B;
        cin >> A >> B;
        iA.push_back(A);
        iB.push_back(B);
        que.emplace(A + B, i);
    }

    ll A = 0, B = 0;
    REP(i,N) {
        ll val,idx;
        tie(val,idx) = que.top();
        que.pop();
        if (i % 2 == 0) A += iA[idx];
        if (i % 2 == 1) B += iB[idx];
    }

    cout << A - B << endl;

    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    cout << (n + 1) * n / 2 << endl;
}


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

int main(){
  int n; cin >> n;
  int a, b; cin >> a >> b;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  vector<int> c(3, 0);
  for (int i = 0; i < n; i++) {
    if (v[i] <= a) c[0]++;
    else if (v[i] <= b) c[1]++;
    else c[2]++;
  }
  cout << min({c[0], c[1], c[2]}) << endl;
  return 0;
}


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

typedef unsigned long long ui;

ui h[N], n, a, b;

bool chk(ui w) {
	ui s = 0;
	for (ui i = 0; i != n; ++i) {
		if (h[i] > b * w)
			s += (h[i] - 1 - b * w) / (a - b) + 1;
	}
	return s <= w;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0);
#ifdef _DEBUG
	ifstream cin("1.in");
#endif
	cin >> n >> a >> b;
	for (ui i = 0; i != n; ++i) cin >> h[i];
	ui l = 1, r = 1 << 30;
	while (l < r) {
		ui mid = (l + r) >> 1;
		if (chk(mid)) r = mid;
		else l = mid + 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256