akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double angle_a = (H + M / 60.0) * 2 * M_PI / 12.0;
    double angle_b = M * 2 * M_PI / 60.0;
    double angle;
    if (angle_a > angle_b) angle = angle_a - angle_b;
    else angle = angle_b - angle_a;

    // cout << angle_a << endl << angle_b << endl << angle << endl;
    cout << setprecision(15) << sqrt(A * A + B * B - 2 * A * B * cos(angle)) << endl;
    // cout << cos(PI) << endl;
}





Measured memory_bytes: 4192
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int count = 0;
	for (int i = 0; i < n - 2; i++) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;

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

map<string, int> mp = {{"yotta",24},{"zetta",21},{"exa",18},{"peta",15},{"tera",12},{"giga",9},{"mega",6},{"kilo",3},{"hecto",2},{"deca",1},{"deci",-1},{"centi",-2},{"milli",-3},{"micro",-6},{"nano",-9},{"pico",-12},{"femto",-15},{"ato",-18},{"zepto",-21},{"yocto",-24}};

int Tc;

int main() {
  
  cin >> Tc;
  rep(_, Tc) {
    string s, SI, ti;
    cin >> s >> SI;
    if(mp.find(SI) == mp.end()) {
      ti = SI;
      SI.clear();
    } else {
      cin >> ti;
    }
    
    
    int b = 0;
    if(s.size() > 2 && s.substr(0, 2) == "0.") {
      int pos = 2;
      while(s[pos] == '0')
	pos++;

      b = 1 - pos + mp[SI];
    }
    else {
      int pos = find(s.begin(), s.end(), '.') - s.begin();
      b = pos - 1 + mp[SI];
    }
    
    int N = s.size();
    
    if(s.size() > 2 && s.substr(0, 2) == "0.") {
      int pos = 2;
      while(s[pos] == '0')
	pos ++;
      cout << s[pos++];
      if(pos < N) {
	cout << ".";
	while(pos < N) cout << s[pos++];
      }
    }
    else {
      rep(i, N) {
	if(i == 1) cout << ".";
	if(s[i] == '.') continue;
	cout << s[i];
      }
    }
    cout << " * 10^" << b << " " << ti << endl;
  }
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  string s;
  cin >> s;

  int ans = 0;
  rep(i, s.size()) {
    if (i % 2 == 0) {   // g を出す
      if (s[i] == 'p') ans--;
    } else {  // p を出す
      if (s[i] == 'g') ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3764
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Measured memory_bytes: 9052
X , Y  =  map ( int , input().strip().split(" ") ) ;

r = -1 ;
for a in range ( 0, X + 1 ) :
	b = X -a ;
	if a * 2 + b * 4 == Y :
		r = 1 ;
		break ;
if r == -1 : 
	print ( "No") ;
else :
	print ("Yes" ) ;


Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
#include <functional>	
using namespace std;

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




	return 0;
}

Measured memory_bytes: 256
#include <iostream> // std::cout
#include <string>   // std::string
#include <queue>    // std::queue
#define NMAX 100000
using namespace std;

void solve(int n, int q, queue<string> name, queue<int> time) {
    int jikoku = 0;
    while ( !name.empty() || !time.empty() ) {
        string name_val = name.front();
        int time_val = time.front();
        if (time_val <= q) {
            name.pop();
            time.pop();
            jikoku += time_val;

            // output
            cout << name_val << " " << jikoku << endl;
        } else {
            time_val -= q;
            name.pop();
            time.pop();
            name.push(name_val);
            time.push(time_val);
            jikoku += q;
        }
    }
}

int main() {
    // input
    int n, q;
    cin >> n >> q;

    queue<string> name;
    queue<int> time;
    for (int i=0; i<n; i++) {
        string name_val;
        int time_val;
        cin >> name_val;
        cin >> time_val;
        name.push(name_val);
        time.push(time_val);
    }

    // solve and output
    solve(n, q, name, time);
}


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

int main(){
  int X, N;
  cin >> N >> X;
  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L.at(i);
  int count = 0;
  int Dn = 0;
  for(int i = 0; Dn < X + 1; i++){
    count++;
    Dn += L.at(i);
    if(i == N - 1){
      if(Dn < X + 1) count++;
      break;
    }
  }
  cout << count << endl;
}

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

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

using namespace std;

map<string,int> atoms;

tuple<int, int> num(const string& s, int i) {
  int v = 0;
  int n = s.size();
  for(;i<n;++i) {
    if (s[i] < '0' || '9' < s[i]) break;
    v *= 10;
    v += s[i] - '0';
  }
  return make_tuple(v, i);
}

tuple<int,int> atom(const string& s, int i) {
  string name;
  if ('a' <= s[i+1] && s[i+1] <= 'z') name = s.substr(i, 2);
  else name = s.substr(i,1);
  //cout<<name<<endl;
  if (atoms.find(name) == end(atoms)) return make_tuple(-1, i + name.size());
  return make_tuple(atoms[name], i + name.size());
}

tuple<int,int> atomss(const string& s, int i) {
  int w, e;
  tie(w, e) = atom(s, i);
  if ('0' <= s[e] && s[e] <= '9') {
    int t, te;
    tie(t, te) = num(s, e);
    if (w == -1) return make_tuple(-1, te);
    return make_tuple(w * t, te);
  }
  return make_tuple(w, e);
}

tuple<int,int> calc(const string& s, int i = 0) {
  int w, e;
  if (s[i] == '(') {
    int iw, ni;
    tie(iw, ni) = calc(s, i+1);
    int tm;
    tie(tm, e) = num(s, ni+1);
    if (iw == -1) w = -1;
    w = iw * tm;
  } else {
    tie(w, e) = atomss(s, i);
  }
  if (e != s.size() && s[e] != ')') {
    int tailw, taile;
    tie(tailw, taile) = calc(s, e);
    if (w == -1 || tailw == -1) return make_tuple(-1, taile);
    return make_tuple(tailw + w, taile);
  }
  if (w == -1) return make_tuple(-1, e);
  return make_tuple(w, e);
}

int main() {
  while(1){
    string atm;
    cin>>atm;
    if(atm == "END_OF_FIRST_PART") break;
    int w;
    cin>>w;
    atoms[atm] = w;
  }
  while(1) {
    string mol;
    cin>>mol;
    if(mol == "0") break;
    auto p = calc(mol);
    if (get<0>(p) != -1)
      cout<<get<0>(p)<<endl;
    else
      cout<<"UNKNOWN"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#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);
  double ans = 0;
  ans = (double)(1.0*(a[0]+a[1]))/2;
  for(int i = 2; i<n; i++){
  	ans = (double)(ans+a[i])/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,b,c:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(a);
    Read(b);
    Readln(c);

    if ((a=5)and(b=5)and(c=7)) or ((a=5)and(b=7)and(c=5)) or ((a=7)and(b=5)and(c=5)) then
      Writeln('YES')
    else
      Writeln('NO');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  vector<int> a_kind(100001, 0);
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    int inp;
    cin >> inp;
    ++a_kind[inp];
    sum += inp;
  }
  int q;
  cin >> q;
  vector<ll> ans(q);
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    sum += (ll)(-1 * (ll)a_kind[b] *(ll)b) + (ll)((ll)a_kind[b] * (ll)c);
    a_kind[c] += a_kind[b];
    a_kind[b] = 0;
    ans[i] = sum;
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 3860
N = int(input())
a,b = [], []
for i in range(N):
  x,y = map(int, input().split())
  a.append(x+y)
  b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1] - a[0], b[-1] - b[0])
print(ans)

Measured memory_bytes: 25712
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[101010],b[101010];
int c[202020];
int main()
{
	int n,cn,now;
	long long suma=0,sumb=0,sum=0,ans,k;
	scanf("%d",&n);
	cn=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		suma+=a[i];
		sumb+=b[i];
		c[++cn]=a[i];
		c[++cn]=b[i];
	}
	ans=min(suma,sumb);
	sort(c+1,c+1+cn);
	for(int i=1;i<=n;i++)
		sum+=c[i];
	for(int i=1;i<=n;i++)
	{
		now=n;
		k=sum;
		if(max(a[i],b[i])>c[now])
		{
			k+=max(a[i],b[i]);
			k-=c[now];
			now--;
		}
		if(min(a[i],b[i])>c[now])
		{
			k+=min(a[i],b[i]);
			k-=c[now];
			now--;
		}
		ans=min(ans,k);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,j,l,i;
    cin>>k>>a>>b;
    j=0;
    for(i=1;i>0;i++)
    {
        l=k*i;
        if(l>=a&&l<=b)
        {
            j=1;
        }
        if(l>b)
            break;
    }
    if(j==1)
        cout<<"OK\n";
    else
        cout<<"NG\n";

}

Measured memory_bytes: 3632
#include <cstdio>

int main()
{
    int r,c;
    scanf("%d %d", &r, &c);

    int matrix[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            scanf("%d", &matrix[i][j]);
        }
    }

    int sum_matrix[r + 1][c + 1];
    for(int i = 0; i < r + 1; i++){
        for(int j = 0; j < c + 1; j++){
            sum_matrix[i][j] = 0;
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            sum_matrix[i][j] = matrix[i][j];
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            sum_matrix[i][c] += matrix[i][j];
        }
    }
    for(int i = 0; i < c; i++){
        for(int j = 0; j < r; j++){
            sum_matrix[r][i] += matrix[j][i];
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            sum_matrix[r][c] += matrix[i][j];
        }
    }
    for(int i = 0; i < r + 1; i++){
        for(int j = 0; j < c + 1; j++){
            if (j == 0) printf("%d", sum_matrix[i][j]);
            else printf(" %d", sum_matrix[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1108
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()


int main(){
    int N;cin>>N;
    int a,b;
    int target;
    int ans=0;
    for(int c=1;c<N;c++){
        target=N-c;
        for(int a=1;a*a<=target;a++){
            if(target%a==0 && a*a!=target){
                ans+=2;
            }else if(target%a==0 && a*a==target){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3636
/*
 * Author : anaksoleh
 * 1 sept 2019
 */

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

char S[5];
char T[5];

int main()
{
	for(int i = 1 ; i <= 3 ; i++){
		cin >> S[i];
	}

	for(int i = 1 ; i <= 3 ; i++){
		cin >> T[i];
	}

	int cnt = 0;
	for(int i = 1 ; i <= 3 ; i++){
		if(S[i] == T[i]){
			++cnt;
		}
	}

	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define cases int t;cin>>t;while(t--)
int main()
{
    iso;
   /*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
   int n;cin>>n;
   int ans=0;
    int ar[n];
     f(i,0,n)cin>>ar[i];
     for(int i=0;i<n;i++)
     {
     	 for(int j=i+1;j<n;j++)
     	 {
            ans+=ar[i]*ar[j];
     	 }
     }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
string a;
int is,i1;
int main()
{
	cin>>a;
	int len=a.size();
	for(int i=0;i<len;i++)
	{
		if(a[i]=='C')
		{
			for(int j=i+1;j<len;j++)
			{
				if(a[j]=='F'){cout<<"Yes";return 0;}
			}
		}
	}
	cout<<"No";
	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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int PT[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int QT[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int RT[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if(A + B >= C)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 764
n = gets(chomp:true).to_i
a = gets.split.map(&:to_i)
gets
m = gets.split.map(&:to_i)

def solve(i, n, a, m)

  # 返り値処理
  # 組み合わせてmから引いた答えが0ならばtrue
  if m == 0
    return true
  end

  # 再帰回数がa配列のサイズn以上になったらfalse
  if i >= n
    return false
  end
  # 返り値処理

  # dig処理
  # 左値を引かなかった場合、右値を引いた場合
  # orになっているので1回でもtrueが返ればtrue
  res = solve(i + 1, n, a, m) || solve(i + 1, n, a, m-a[i])
  return res
  # dig処理
end

m.each{|value| puts solve(0, n, a, value) ? "yes" : "no"}


Measured memory_bytes: 8892
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int check(long p){
  int c = 0;
  int s[3] = {};

  while(p  > 0){
    c = p % 10;
    p = (p - c)/10;
    if(c == 3){
      s[0]++;
    } else if(c == 5){
      s[1]++;
    } else if(c == 7){
      s[2]++;
    }
  }
  if(s[0] > 0 && s[1] > 0 && s[2] > 0){
    return 0;
  } else {
    return 1;
  }
}

int dfs(long k, int p, int s[3]){
  int i, ret;
  if(k <= p){
    if(check(k) == 0){;
      ret = 1;
      //printf("%ld\n", k);
    } else {
      ret = 0;
    }
    for(i = 0; i < 3; i++){
      ret += dfs(10*k + s[i], p, s);
    }
    return ret;
  } else {
    return 0;
  }
}

int main(){
  int c;
  long p;
  int s[3] = {3, 5, 7};
  scanf("%ld", &p);
  c = dfs(0, p, s);
  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

//TETORIS
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			boolean[][] m = new boolean[5000][5];
			while(n--!=0){
				int d = sc.nextInt();
				int p = sc.nextInt();
				int q = sc.nextInt()-1;
				if(d==2){
					int k = 4999;
					while(k>=0&&!m[k][q])k--;
					k++;
					for(int i=k;i<k+p;i++)m[i][q]=true;
				}
				else{
					int k = 4999;
					while(true){
						boolean f = true;
						if(k>=0){
							for(int j=q;j<q+p;j++){
								if(m[k][j])f = false;
							}
						}
						if(!f||k==-1){
							k++;
							for(int j=q;j<q+p;j++)m[k][j]=true;
							break;
						}
						k--;
					}
				}
				boolean con = true;
				int k = 0;
				while(k<5000&&con){
					con = false;
					boolean t = true;
					for(int j=0;j<5;j++){
						if(m[k][j])con = true;
						else t = false;
					}
					if(t){
						boolean f = true;
						int i = k;
						while(i<5000&&f){
							f = false;
							for(int j=0;j<5;j++){
								if(m[i][j])f = true;
							}
							if(f){
								for(int j=0;j<5;j++){
									m[i][j] = m[i+1][j];
								}
							}
							i++;
						}
					}
					else k++;
				}
			}
			int s = 0;
			for(int i=0;i<5000;i++)for(int j=0;j<5;j++)s+=m[i][j]?1:0;
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 43416
#include <cstdio>
#include <iostream>
#include <unordered_map>

using namespace std;

int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  scanf("%d", &N);

  unordered_map<int, int> um;
  for (size_t index=0; index<N; index++) {
    int i;
    scanf("%d", &i);
    if (um.count(i) == 0) {
      um[i] = 1;
    } else {
      um[i]++;
    }
  }

  int ans = 0;
  for(auto it = um.begin(); it!=um.end(); it++) {
    if (it->second % 2 == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1e9;
    rep(i,n-k+1){
        int left = x[i];
        int right = x[i+k-1];
        if(left < 0 && right < 0) chmin(ans, -left);
        else if(left < 0 && right >= 0){
            if(-left < right) chmin(ans, right-2*left);
            else chmin(ans, 2*right-left);
        }
        else if(left >= 0 && right >= 0) chmin(ans, right);
    }
    cout << ans << endl;
	return 0;
}

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

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

using namespace std;

vector<vector<int>> x(10,vector<int>(10));

int check(char s[]){
  int a=0;
  rep(j,4){
    a=x[a][s[j]-'0'];
  }
  return a;
}

signed main()
{
  rep(i,10)rep(j,10)cin>>x[i][j];
  set<int> set;
  rep(i,10000){
    char s[10]={};
    sprintf(s,"%04d",i);
    s[4]=check(s)+'0';
    rep(j,5){
      rep(k,10){
	char t[10]={};
	rep(l,5)t[l]=s[l];
	t[j]=k+'0';
	if(atoi(s)==atoi(t))continue;
	//	cout<<atoi(s)<<" "<<atoi(t)<<endl;
	char ss[10]={},tt[10]={};
	rep(l,4)ss[l]=s[l],tt[l]=t[l];
	int y=0;
	rep(l,4)y=x[y][ss[l]-'0'];
	int z=0;
	rep(l,4)z=x[z][tt[l]-'0'];
	if(x[y][s[4]-'0']==x[z][t[4]-'0']){
	  set.insert(atoi(ss));set.insert(atoi(tt));
	  //cout<<ss<<" "<<tt<<endl;
	}
      }
    }
    rep(j,4){
      char t[10];
      rep(k,5)t[k]=s[k];
      swap(t[j],t[j+1]);
      if(atoi(s)==atoi(t))continue;
      char ss[10]={},tt[10]={};
      rep(l,4)ss[l]=s[l],tt[l]=t[l];
      int y=0;
      rep(l,4)y=x[y][ss[l]-'0'];
      int z=0;
      rep(l,4)z=x[z][tt[l]-'0'];
      if(x[y][s[4]-'0']==x[z][t[4]-'0']){
	set.insert(atoi(ss));set.insert(atoi(tt));
	//	cout<<ss<<" "<<tt<<endl;
      }

    }
  }
  cout<<set.size()<<endl;
  return 0;
}



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

bool fight(int& a, int& b){
    a -= b;
    if(a <= 0)
        return false;
    return true;
}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(fight(c,b) && fight(a,d));
    if(a > 0) cout << "Yes";
    else      cout << "No";
    
    return 0;
}

Measured memory_bytes: 3624
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[1000001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


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

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k,m;
lld x,y,n1,b=0,a,n2,h,z,c;
lld p=1000000000;
double pi=3.1415926535;

void solve()
{
    cin>>n ;
    vector<lld> v,w(n);
    for(i=0;i<n;i++)
    {
        cin>>l;
        v.pb(l);
    }
    w[0]=0;
    w[1]=abs(v[1]-v[0]);
    for(i=2;i<n;i++)
    {
        w[i] = min(abs(v[i]-v[i-2])+w[i-2],abs(v[i]-v[i-1])+w[i-1] );  
    }
    cout<<w[n-1];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
   //  cin>>t;
    //cout<<t;
     //getfac(p1);
    //check the value by which modulo is to be taken

    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 2168
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

for i in range(N):
    A[i] -= i

A.sort()

if N%2==0:
    A = list(map(lambda x: x-A[N//2], A))
else:
    A = list(map(lambda x: x-A[(N-1)//2], A))


A = list(map(abs,A))

print(sum(A))

Measured memory_bytes: 91764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 4000007
#define mod 1000000007
ll a[55],b[55];
ll cost[100],n;
vector<int>v[1000];
void Set()
{
    for(ll j=0; j<=n; j++)
    {
        cost[j]=-1;
    }
}
void bfs(ll x)
{
    cost[x]=1;
    queue<int>q;
    q.push(x);
    while(!q.empty())
    {
        ll f=q.front();
        q.pop();
        ll sz=v[f].size();
        for(ll i=0;i<sz;i++)
        {
            ll adj=v[f][i];
            if(cost[adj]==-1)
            {
                q.push(adj);
                cost[adj]=1;
            }
        }
    }
}
int main()
{
    ll i,j,k,l,m,c;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>a[i]>>b[i];
    }
    i=0;
    c=0;
    while(i<m)
    {
        Set();
        for(j=0;j<=m+1;j++)
        {
            v[j].clear();
        }
        for(j=0; j<m; j++)
        {
            if(j!=i)
            {
                v[a[j]].push_back(b[j]);
                v[b[j]].push_back(a[j]);
            }
        }
        bfs(1);
        for(j=1;j<=n;j++)
        {
            if(cost[j]==-1)
            {
                c++;
                break;
            }
        }
        i++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const char B = '#';
    const char W = '.';
    
    int n; cin >> n;
    string s; cin >> s;
    int b = 0, w = 0, lb = 0, rw = 0;
    REP(i,n) {
        if (s[i] == B) b++;
        else w++;
    }

    int ans = min(b,w);
    rw = w;
    REP(i,n) {
        if (s[i] == B) lb++;
        else rw--;
        ans = min(ans,rw+lb);
    }

    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string itoa(int x) {
    string ret = "", rev="";
    while (x) {
        rev += (x%10) + '0';
        x /= 10;
    }
    for (int i=rev.size()-1; i>=0; --i) {
        ret += rev[i];
    }
    return ret;
}

void solve() {
    string s;
    string ans = "";
    cin >> s;
    ans += s[0];
    ans += itoa(s.size()-2);
    ans += s[s.size()-1];
    cout<< ans;

}

int main() {

	solve();
    return 0;
}


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

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

    int N;
    cin >> N;
    map<string, int> mp;
    while (N--) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int M;
    cin >> M;
    while (M--) {
        string t;
        cin >> t;
        mp[t]--;
    }

    int ans = 0;
    for (auto &p : mp) {
        ans = max(ans, p.second);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> L(n);
  rep(i,n){
    cin>>L[i];
  }
  sort(all(L),greater<int>());
  int ans=0;
  rep(i,n-2){
    fori(j,i+1,n-1){
      int l,r;
      l=j;r=n;
      int k;
      while(l+1<r){
        k=(l+r)/2;
        if(L[i]-L[j]<L[k]){
          l=k;
        }else{
          r=k;
        }
      }
      ans+=(l-j);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
def ceil(a, b):
    return -(-a//b)

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 0, 0
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
        elif t < scr_t and a >= scr_a:
            scr_t = t * ceil(scr_t, t)
            scr_a = scr_t * a // t
        elif a < scr_a and t >= scr_t:
            scr_a = a * ceil(scr_a, a)
            scr_t = scr_a * t // a
        else:
            if t / a >= scr_t / scr_a:
                scr_a = a * ceil(scr_a, a)
                scr_t = scr_a * t // a
            else:
                scr_t = t * ceil(scr_t, t)
                scr_a = scr_t * a // t

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <fstream>
#define rep(i,a,b) for (long long i = a; i < b; i++)
using namespace std;
long long n;
vector <long long> dp;
long long bf(long long p, long long pp , long long sum, vector <long long>& fec){
    
    if(dp[p]!=-1){
        return dp[p];
    }
    if (pp==n-1){
        //cout << sum  << endl;
        return sum;
    } else if(pp>=n){
        return 1000000000;
    }
    //cout << abs(fec[pp]-fec[p]) << "  " << p << "   " << pp << endl;
    return dp[p]= min(bf(p+1, p, sum + abs(fec[pp]-fec[p]), fec) , bf(p+2, p, sum + abs(fec[pp]-fec[p]), fec));
}

int main(){
    int k;
    cin >> n >> k;
    dp.assign(n+k+k,10000000000000);
    
    vector <long long> fector(n+k, 0);
    rep(i,0,n){
        cin >> fector[i];
    }
    dp[0]=0;
    rep(i,0,n-1){

        
            rep(j,1,k+1){
                dp[i+j] = min(dp[i+j], dp[i]+abs(fector[i]-fector[i+j]));
            }
          
    }
    cout << dp[n-1] << "\n";
    //cout << bf(0, 0, 0, fector) << endl;

}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Get Lost
public class Main{
	Scanner sc=new Scanner(System.in);

	int w, h, gx, gy, n;
	int[] xs, ys;
	String run;

	void run(){
		w=sc.nextInt();
		h=sc.nextInt();
		gx=sc.nextInt()-1;
		gy=sc.nextInt()-1;
		n=sc.nextInt();
		xs=new int[n];
		ys=new int[n];
		for(int i=0; i<n; i++){
			xs[i]=sc.nextInt()-1;
			ys[i]=sc.nextInt()-1;
		}
		run=sc.next()+"$";
		solve();
	}

	void solve(){
		long sum=0;
		for(int d=0; d<4; d++){
			sum+=solve1();
			int ngx=h-1-gy, ngy=gx;
			gx=ngx;
			gy=ngy;
			for(int i=0; i<n; i++){
				int nx=h-1-ys[i], ny=xs[i];
				xs[i]=nx;
				ys[i]=ny;
			}
			int t=w;
			w=h;
			h=t;
		}
		println(sum+"");
	}

	TreeSet<Integer>[] sets1, sets2;

	@SuppressWarnings("unchecked")
	long solve1(){
		sets1=new TreeSet[w];
		for(int i=0; i<w; i++){
			sets1[i]=new TreeSet<Integer>();
			sets1[i].add(-1);
			sets1[i].add(h);
		}
		sets2=new TreeSet[h];
		for(int i=0; i<h; i++){
			sets2[i]=new TreeSet<Integer>();
			sets2[i].add(-1);
			sets2[i].add(w);
		}

		for(int i=0; i<n; i++){
			sets1[xs[i]].add(ys[i]);
			sets2[ys[i]].add(xs[i]);
		}
		sets1[gx].add(gy);
		sets2[gy].add(gx);

		long sum=1;
		for(int x=0; x<w; x++){
			int py=-2;
			for(int y : sets1[x]){
				int sy=y-1;
				if(sy!=py){
					if(ok(x, sy, 0)){
						// [py+1, y-1]
						sum+=y-py-1;
					}
				}
				py=y;
			}
		}
		return sum;
	}

	boolean ok(int x, int y, int d){
		for(int k=0; k<run.length(); k++){
			int wx, wy; // wall or goal
			int nx, ny; // next point
			if(d==0){
				wx=nx=x;
				wy=sets1[x].higher(y);
				ny=wy-1;
			}else if(d==1){
				wy=ny=y;
				wx=sets2[y].lower(x);
				nx=wx+1;
			}else if(d==2){
				wx=nx=x;
				wy=sets1[x].lower(y);
				ny=wy+1;
			}else{
				assert d==3;
				wy=ny=y;
				wx=sets2[y].higher(x);
				nx=wx-1;
			}
			if(wx==gx&&wy==gy){
				return true;
			}
			x=nx;
			y=ny;
			if(run.charAt(k)=='L'){
				d=(d+3)%4;
			}else if(run.charAt(k)=='R'){
				d=(d+1)%4;
			}
		}
		return false;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

typedef long long ll;
typedef vector<int, int> vi;
typedef pair<int, int> pi;
#define F first;
#define S second;
#define PB push_back;
#define MP make_pair;
#define REP(i, a, b) for(int i = a; i <= b; i++)
ll itr(int *arr, int curr, int size, int value) {
	if(size==curr){
		return value%360;
	}
	ll add = itr(arr, curr+1, size, value + arr[curr]);
	ll sub = itr(arr,curr+1, size, value-arr[curr]);
	if(add == 0){
		return add;
	}
	return sub;
}
int main(){
	int n,k;
	cin >> n >> k;
	int arr[k];
	REP(i,0,k-1) {
		cin >> arr[i];
	}
	int dist[k];
	REP(i,0,k-1) {
		if(i==0) {
			dist[i] = n - arr[k-1] + arr[i];
		} else{
			dist[i] = arr[i] - arr[i-1];
		}
	}
	int max = INT_MIN, pos = -1;
	REP(i, 0, k-1) {
		if(max < dist[i]) {
			max = dist[i];
			pos = i;
		}
	}
	ll sum = 0;
	REP(i,0,k-1) {
		if(i==pos)continue;
		sum+=dist[i];
	}
	cout << sum;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
    	Scanner i = new Scanner(System.in);
      	int[] res = new int[] {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};
    	int K = i.nextInt();
      	System.out.println(res[K - 1]);
    }
}


Measured memory_bytes: 21076
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
 
typedef struct{
  char suit;
  int value;
} Card;
 
Card L[MAX/2 + 2],R[MAX/2 +2];
 
void merge(Card *A,int n,int left,int mid,int right){
  int i,j,k,n1,n2;
  n1 = mid-left;
  n2 = right-mid;
  for(i=0;i<n1;i++) L[i] = A[left+i];
  for(i=0;i<n2;i++) R[i] = A[mid +i];
  L[n1].value = SENTINEL;
  R[n2].value = SENTINEL;
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    if(L[i].value <= R[j].value) A[k] = L[i++];
    else A[k] = R[j++];
  }
}
 
void mergeSort(Card *A,int n,int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}
 
int partition(Card *A,int n,int p,int r){
  int i,j;
  Card t,x;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}
 
void quickSort(Card *A,int n,int p,int r){
  int q;
  if(p < r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
 
int main(){
  int n,i,v;
  Card A[MAX],B[MAX];
  char S[10];
  int stable=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);
  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit) stable=0;
  }
  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) printf("%c %d\n",B[i].suit,B[i].value);
  return 0;
}

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

int main(){
	long long n, p, temp, o = 0, e = 0, ans = 0;
	cin >> n >> p;
	while(n--){
		cin >> temp;
		if(temp % 2)
			o++;
		else e++;
	}
	if(p && o == 0)
		ans = 0;
	else ans = 1;
	for(int i = 1; i < o; i++){
		ans *= 2ll;
	}
	for(int i = 0; i < e; i++){
		ans *= 2ll;
	}
	cout << ans << endl;
	return 0;
}

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

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

    int n, wmax;
    cin >> n >> wmax;

    vector<int> v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];

    vector<vector<int>> dp(n, vector<int>(wmax+1, 0));
    rep(i, wmax+1) {
        if(i >= w[0]) dp[0][i] = v[0];
    }

    rep1(i, n) rep(j, wmax+1){
        if(j < w[i]) dp[i][j] = dp[i-1][j];
        else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
    }

    cout << dp[n-1][wmax] << endl;


    return 0;
}


Measured memory_bytes: 6836
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }else{
        rep(i,n/2){
            if(s[i]!=s[i+n/2]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

const int MAX_N = (int)1e5 + 5;
int A[MAX_N], B[MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    for(int i=0;i<N;i++) cin >> A[i], B[i] = A[i];
    
    sort(B, B+N);
    
    int ans = 0;
    for(int i=0;i<N;i++){
        int idx = distance(B, lower_bound(B, B+N, A[i]));
        if(i%2!=idx%2) ans++;
    }
    
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int>b(m);
    REP(i,m)IN(b[i]);
    int cnt=0;
    REP(i,n){
        int sum=0;
        REP(j,m){
            int a;
            cin>>a;
            sum+=a*b[j];
        }
        if(sum+c>0)cnt++;
    }
    OUT(cnt);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

int main() {
	int N;
	cin >> N;
	LL T = 1, A = 1;
	rep(i, N) {
		LL t, a;
		cin >> t >> a;
		LL k = max((T + t - 1) / t, (A + a - 1) / a);
		T = k*t;
		A = k*a;
	}
	cout << T + A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#define ld long double
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define endl "\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
int n;
inline void solve()
{
    cin>>n;
    int a[n+2];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    a[0]=0;
    a[n+1]=0;
    ll sum=0;
    for(int i=1;i<n+2;i++)
    {
        sum+=abs(a[i]-a[i-1]);
    }
    //cout<<sum<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+ abs(a[i+1]-a[i-1])<<endl;
    }
    
}
int main()
{
    Imposter
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        cout<<fixed<<setprecision(10);
       solve();
        
    }
    return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const long long MOD = 1000000007;

ll N, M;
ll A[100001];
ll B[100001];

ll cnt;
ll ans[100001];

int par[100001];
ll num[100001];

int root(int x) {
    if (x == par[x]) {
        return x;
    } else {
        return par[x] = root(par[x]);
    }
}
bool isSame(int x, int y) {
    return root(x) == root(y);
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);

    if (x != y) {
        ll newNum = num[x] + num[y];
        cnt += num[x] * (num[x] - 1) / 2;
        cnt += num[y] * (num[y] - 1) / 2;
        cnt -= newNum * (newNum - 1) / 2;
        
        par[y] = x;
        num[x] = newNum;
    }
}



int main() {
    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        cin >> A[i] >> B[i];
    }

    for (int i = 1; i <= N; i++) {
        par[i] = i;
        num[i] = 1;
    }
    cnt = N * (N - 1) / 2;

    for (int i = M; i >= 1; i--) {
        ans[i] = cnt;
        marge(A[i], B[i]);
    }
    for (int i = 1; i <= M; i++) {
        cout << ans[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 4864
S = raw_input()
n = int(raw_input())

for i in range(n):
    command = (raw_input()).split(" ")
    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])
        print S[a:b+1]
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])
        T = S[a:b+1]
        S = S[0:a] + T[::-1] + S[b+1:]
    else:
        a = int(command[1])
        b = int(command[2])
        S = S[0:a] + command[3] + S[b+1:]

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  long long ans=0;
  for(int i=0;i<N-1;i++){
    ans+=A.at(i)/2;
    A.at(i)%=2;
    long long x=min(A.at(i),A.at(i+1));
    A.at(i+1)-=x;
    ans+=x;
  }
  ans+=A.at(N-1)/2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long n, vector<long long> p) {
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])) {
            ans++;
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long n;
  cin >> n;
  vector<long long> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  solve(n, move(p));
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  int INF = INT_MAX;
  ll mod = 1e9+7;
  // lld PI = 3.141592653;



  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     
    int n;
    cin>>n;
    vector<pair<ll,ll>> a(n);
    for (int i = 0;i<n;i++) cin>>a[i].first >> a[i].second;
    ll ans = 0;
    for (int i = n-1; i>=0; i--){
      a[i].first += ans;
      ll need = (a[i].second - a[i].first % a[i].second) % a[i].second;
      ans += need;
    }
    cout<<ans<<"\n";







}
  

Measured memory_bytes: 4404
import sys
input = sys.stdin.readline

n=int(input())
jobs=sorted(list(list(map(int,input().split())) for _ in range(n)), key=lambda x: x[1])
time = 0
for job in jobs:
    time+= job[0]
    if time > job[1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 56144
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main implements Runnable {

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long[] h = new long[n];

		for(int i = 0 ; i < n ; i++) {
			h[i] = sc.nextLong();
		}

		int cnt = 0;
		int max = 0;
		for(int i = 0 ; i < n - 1 ; i++) {
			if(h[i] >= h[i + 1]) {
				cnt++;
			} else {
				if(cnt > max) {
					max = cnt;
				}
				cnt = 0;
			}
		}
		if(cnt > max) {
			max = cnt;
		}

		System.out.println(max);

	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 24148
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    int tar = S[K-1];
    for(auto &c:S){
        if(c != tar)c = '*';
    }
    cout << S << endl;
}

Measured memory_bytes: 256