akhauriyash/Code-Regression huggingface dataset:
h,w = list(map(int, input().split()))
h1 = h//2
h2 = h//2 + h%2
w1 = w//2
w2 = w//2 + w%2

ans = (h1*w1 + h2*w2)

if h == 1 or w == 1:
    print(1)
else:
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <queue>
using namespace std;


queue<char> q;
int m, h;
string s;
char ch;



int main(){
	while (cin >> s && s != "-") {
		q = queue<char>();
		for (int i = 0; i < s.size(); i++) {
			q.push(s[i]);
		}
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			while (h != 0) {
				ch = q.front(); q.pop();
				q.push(ch);
				h--;
			}
		}
		while (!q.empty()) {
			cout << q.front();
			q.pop();
		}
		cout << endl;
	}

	return 0;
}

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

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

  int max = 0;
  int remain = K;

  if (K >= A){
    max += A;
    remain -= A;
  }
  else
  {
    max += K;
    remain = 0;
  }

  if (K >= A + B){
    remain -= B;
  }
  else
  {
    remain = 0;
  }
  

  if (K >= A + B + C){
    max -= C;
  }
  else
  {
    if (remain > 0)  max -= remain;
  }
  
  cout << max << endl;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	map<string,int>ans;
	ans["AC"]={0};
	ans["WA"]={0};
	ans["TLE"]={0};
	ans["RE"]={0};
	string temp;
	for(int i=0;i<n;i++){
		cin>>temp;
		ans[temp]++;
	}
	cout<<"AC x "<<ans["AC"]<<"\n";
	cout<<"WA x "<<ans["WA"]<<"\n";
	cout<<"TLE x "<<ans["TLE"]<<"\n";
	cout<<"RE x "<<ans["RE"]<<"\n";
	return 0;
}

Measured memory_bytes: 3628
# 再帰関数を利用して全ての組み合わせを求める
def loop(n_cnt, my_list):
    if n_cnt==n:     # 再帰の終了条件
        bool_list = [i>=x for i in my_list[1:]]
        if all(bool_list):
            ans.append(my_list[0])
    else:
        # 要素同士を足す
        add_list = [my_list[i] + CA[n_cnt][i] for i in range(m+1)]
        loop(n_cnt+1, my_list)
        loop(n_cnt+1, add_list)
        

n,m,x = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(n)]

ans = []

loop(0,[0]*(m+1))
print(min(ans) if len(ans)!=0 else '-1')


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n;
    cin >> n;

    double x, sum = 0.0;
    string u;
    rep(0, n) {
        cin >> x >> u;
        if (u == "JPY") {
            sum += x;
        } else if (u == "BTC") {
            sum += (x * 380000.0);
        }
    }
    printf("%lf\n", sum);
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#coding: utf-8

x = list(map(str, input().split()))
y = list()

def getOp():
    b = y.pop()
    a = y.pop()
    return [a, b]

for i in x:
    if i == '+':
        op = getOp()
        y.append(op[0] + op[1])
    elif i == '-':
        op = getOp()
        y.append(op[0] - op[1])
    elif i == '*':
        op = getOp()
        y.append(op[0] * op[1])
    else:
        y.append(int(i))

print(y.pop())


Measured memory_bytes: 5604
n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        ss[i+1] = 1

sss = [0] * (n+1)
cnt = 0
for i in range(n+1):
    cnt += ss[i]
    sss[i] = cnt


for i in range(q):
    l, r = map(int, input().split())
    print(sss[r-1] - sss[l-1])



Measured memory_bytes: 8436
#include <iostream>
#include <string.h>
#include <map>
using namespace std;

int main () {
  long long n;
  cin >> n;
  string h;
  map<char, long long> march;
  for (long long i = 0; i < n; i++) {
    cin >> h;
    march[h[0]]++;  
  }
  long long MARCH[5];
  MARCH[0] = march['M'];
  MARCH[1] = march['A'];
  MARCH[2] = march['C'];
  MARCH[3] = march['R'];
  MARCH[4] = march['H'];
  long long ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      for (int l = 0; l < 5; l++) {
        if (i == j || j == l || l == i) {
          // 何もしない  
        }  
        else {
          ans = ans + MARCH[i] * MARCH[j] * MARCH[l];    
        }
      } 
    }  
  }
  cout << ans/6 << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  int a[k];
  for (int i = 0; i < k; i++) cin >> a[i];
  long long rl = 2, ru = 2;
  if (a[k - 1] != 2) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = k - 1; i; i--) {
    rl = ((rl - 1) / a[i - 1] + 1) * a[i - 1];
    ru = (ru + a[i] - 1) / a[i - 1] * a[i - 1];
    if (rl >= ru + a[i] || ru < rl) {
      cout << -1 << "\n";
      return 0;
    }
  }
  ru += a[0] - 1;
  cout << rl << " " << ru << "\n";
  return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Sumitrust_2019
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] md1 = ReadInts();
            int[] md2 = ReadInts();
            if (md1[0] == md2[0])
            {
                WriteLine(0);
            }
            else
            {
                WriteLine(1);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;
ll a, b;
int main(void)
{
	cin >> a >> b;
	if (a <= 0 && b >= 0)cout << "Zero" << endl;
	else {
		if (b < 0) {
			if ((b - a + 1) % 2)cout << "Negative" << endl;
			else cout << "Positive" << endl;
		}
		else cout << "Positive" << endl;

	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int f(std::string s,char m,int n){if(!n)return std::cout<<s<<"\n",0;for(char c='a';c<=m;++c)f(s+c,m+(c==m),n-1);}main(){int n;std::cin>>n;f("a",'b',n-1);}

Measured memory_bytes: 1536
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  int n;
  set<string> strs;

  cin >> n;

  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;

    strs.insert(tmp);
  }

  cout << (int)strs.size() << endl;

  return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end(),greater<int>());
	int ans=0;
	for(int i=0;i<n;i+=2){
		ans+=a[i];
	}
	for(int i=1;i<n;i+=2){
		ans-=a[i];
	}
	cout<<ans<<endl;
}

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

int main(){
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    if(x*x+y*y <= d*d) ans++;
  }
  cout << ans << endl;




}


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

int main(){
  int p,q,r;
  cin>>p>>q>>r;
  cout<<p+q+r-max(p,max(q,r))<<endl;

  return 0;
}

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

long double pi = acosl(-1.0L);

int main() {
  long double a, b, x;
  scanf("%Lf %Lf %Lf", &a, &b, &x);

  long double h = x / a / a;
  long double theta;
  if (x == a*a*b) {
    theta = 0.0;
  } else if (x*2 >= a*a*b) {
    long double y = std::max(0.0L, 2*(b-h));
    // theta = std::acos(a / std::hypot(a, y));
    theta = std::atan2(y, a);
  } else {
    long double y = 2*a*h / b;
    // theta = std::acos(y / std::hypot(b, y));
    theta = std::atan2(b, y);
  }

  theta *= 180.0L / pi;
  printf("%.20Lf\n", theta);
}


Measured memory_bytes: 128
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main {

		  public static void main(String[] args) {
			     java.util.Scanner scanner = new java.util.Scanner(System.in);
			     String passcode = scanner.next();
			     String keyword = scanner.next();
				  int length = passcode.length() - keyword.length() + 1;
				  
				  boolean[] result = new boolean[length];
				  for (int i = 0; i < length; i++) {
					  for (int j = 0; j < keyword.length(); j++ ) {
						if (!charMatch(keyword.charAt(j), passcode.charAt(i + j))) {
							result[i] = true;
							break;
						}
					  }
				  }
				  List<String> results = new ArrayList<>();
				  
				  for (int i = 0; i < length; i++) {
					  if (result[i] == false) {
						  int start = i;
						  int end = i + keyword.length();
						  String tmp = passcode.substring(0, i) + keyword + passcode.substring(end, passcode.length());
						  results.add(tmp.replaceAll("\\?", "a"));
					  }
				  }
				  if (results.size() == 0) {
					  System.out.println("UNRESTORABLE");
				  } else {
					  Collections.sort(results);
					  System.out.println(results.get(0));
				  }
			  }
	  
		  
		  private static boolean charMatch(char keyword, char passcode) {
			  return (keyword == passcode || passcode == '?');
		  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define ST first
#define ND second
using namespace std;

double dist(double x1, double x2, double y1, double y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main(){

	int n;
	cin >> n;
	int s[n];
	vector<pair<double, double>> v;

	for(int i=0;i<n;i++){
		s[i] = i;
		double x, y;
		cin >> x >> y;
		v.push_back({x, y});
	}
	int qtd = 0;
	double tot = .0;
	do{
		for(int i=0;i<n-1;i++){
			pair<double, double> a = v[s[i]];
			pair<double, double> b = v[s[i+1]];
			tot+=dist(a.ST, b.ST, a.ND, b.ND);
			//cout << dist(a.ST, b.ST, a.ND, b.ND) << endl;
		}
		qtd++;
	}while(next_permutation(s, s+n));

	printf("%lf\n", tot/qtd);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

int b[50],r[50],t[50];
int y;

double motori(int i){
    if(t[i]==1){
        return (double)y*r[i]/100 + 1;
    }else{
        return pow(1+(double)r[i]/100, y);
    }
}
int main(){
    int n;
    while(cin >> n, n){
        cin >> y;
        for(int i=0;i<n;i++){
            cin >> b[i] >> r[i] >> t[i];
        }

        int max_i = 0;
        double max_m = motori(0);
        for(int i=1;i<n;i++){
            double m = motori(i);
            if(m>max_m){
                max_i = i;
                max_m = m;
            }
        }
        cout << b[max_i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	int A,B;
	cin >> A >> B ;
	cout << (A+B)%24 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int i, ans = 0;
    int N, num;

    scanf("%d", &N);

    for(i=0; i < N; i++) {
        scanf("%d", &num);
        if((num % 2) != 0 && (i % 2) == 0) ans++;
    }

    printf("%d\n", ans);
    return 0;
}

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

void solve() {
    int N, K;
    cin >> N >> K;
    int k = 0;
    queue<double> e_q;
    double e_sum = 0;
    double e_max = 0;
    for (int i = 0; i < N; ++i) {
        double p;
        cin >> p;
        double e = (1 + p) / 2.0;
        e_q.push(e);
        e_sum += e;
        if (e_q.size() == K) {
            if (e_max < e_sum) e_max = e_sum;
        } else if (K < e_q.size()) {
            double e_p = e_q.front();
            e_q.pop();
            e_sum -= e_p;
            if (e_max < e_sum) e_max = e_sum;
        }
    }
    cout << fixed << setprecision(10) << e_max << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1920
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
vector<int> seen;
int d[110],f[110],z=1;
int dfs(vector<vector<int> > g,int v){
  int i;
  seen[v]=1;
  d[v]=z;
  z++;
  for(i=0;i<g[v].size();i++){
    if(seen[g[v][i]]==0){
      dfs(g,g[v][i]);
    }
  }
  f[v]=z;
  z++;
};
int main(){
  vector<vector<int> > g(110);
  int x,i,j,u,k,n,v;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      g[u].push_back(v);
    }
  }
  seen.assign(n,0);
  for(i=0;i<n;i++){
    if(seen[i]==0){
      dfs(g,i);
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int A = N /1000;
  int B = (N /100) % 10;
  int C = (N / 10 ) % 10;
  int D = N % 10;
 
  
  int s[8] = {0,B+C+D,B+C,C+D,D+B,B,C,D};
  
  int answer;
  for (int i=0;i<8;i++){
    if(A+B+C+D == 7 + s[i]*2){
      answer=i;goto Exit;}
  }
  
  Exit:;
  
  switch(answer){
    case 0 : cout << A << "+" << B  << "+" << C << "+"<< D << "=7";break;
    case 1 : cout << A << "-" << B  << "-" << C << "-"<< D << "=7";break;
    case 2 : cout << A << "-" << B  << "-" << C << "+"<< D << "=7";break;
    case 3 : cout << A << "+" << B  << "-" << C << "-"<< D << "=7";break;
    case 4 : cout << A << "-" << B  << "+" << C << "-"<< D << "=7";break;
    case 5 : cout << A << "-" << B  << "+" << C << "+"<< D << "=7";break;
    case 6 : cout << A << "+" << B  << "-" << C << "+"<< D << "=7";break;
    case 7 : cout << A << "+" << B  << "+" << C << "-"<< D << "=7";break;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    reverse(all(A));

    int k = 0;
    int d = A[0];
    rep(i, 1, N) {
        int d_ = A[0] / 2 - min(A[i], A[0] - A[i]);
        if (chmin(d, d_)) k = A[i];
    }

    cout << A[0] << " " << k << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[90];
	int i, j;
	
	while (fgets(s, 90, stdin) != NULL){
		
		while (1){
			if (strstr(s, "the") != '\0' || strstr(s, "this") != '\0' || strstr(s, "that") != '\0'){
				break;
			}
			for (i = 0; s[i] != '\0'; i++){
				if ('a' <= s[i] && s[i] <= 'y'){
					s[i]++;
				}
				else if ('z' == s[i]){
					s[i] = 'a';
				}
			}
			j++;
		}
		printf("%s", s);
	}
	
	return (0);
}

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

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

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

    vector<int> dp(n, 0);
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h [i - 2]));
    }
    cout << dp[n - 1] << endl;
}

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

#define ll long long

string s,s1,s2;
ll q,n,m;
char c;
bool f;

int main()
{
//    freopen("a.in","r",stdin);
    cin>>s>>q;
    for(ll i=0;i<q;i++)
    {
        cin>>n;
        if(n==1)
        {
            f=!f;
        }
        else
        {
            cin>>m>>c;
            if(m==1)
            {
                if(f)
                    s2+=c;
                else
                    s1+=c;
            }
            else
            {
                if(f)
                    s1+=c;
                else
                    s2+=c;
            }
        }
    }
    if(f)
    {
        reverse(s2.begin(),s2.end());
        reverse(s.begin(),s.end());
        cout<<s2<<s<<s1;

    }
    else
    {
        reverse(s1.begin(),s1.end());
        cout<<s1<<s<<s2;
    }

}




Measured memory_bytes: 1088
#include<iostream>
using namespace std;
int main () {
  int K, A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; i ++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

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

int main()
{
    int n, m, l;
    long long t;
    cin >> n >> m >> l;
    long long a[n][m], b[m][l], c[n][l];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> t;
            a[i][j] = t;
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> t;
            b[i][j] = t;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            long long sum = 0;
            for (int k = 0; k < m; k++) {
                sum += a[i][k] * b[k][j];
            }
            c[i][j] = sum;
            cout << c[i][j];
            if (j == l - 1) cout << endl;
            else cout << ' ';
        }
    }
}



Measured memory_bytes: 3324
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

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

	int N, M, K;
	cin >> N >> M >> K;
	if (K % N == 0 || K % M == 0) {
		puts("Yes");
	}
	else{
		int ok = 0;
		for (int x = 0; x <= M; x++) {
			for (int y = 0; y <= N; y++) {
				if (M*y + N*x - 2*x*y == K)ok = 1;
			}
		}
		if (ok)puts("Yes");
		else puts("No");
	}

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
c = gets.split(" ").map(&:to_i)

ans = 0
a.each.with_index do |n, i|
  ans += b[n-1]
  if i > 0 && a[i] - a[i-1] == 1
    ans += c[a[i]-2]
  end
end
p ans

Measured memory_bytes: 1788
// https://atcoder.jp/contests/abc120/tasks/abc120_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) { data.assign(sz, -1); }

    // 集合xとyを併合する. 併合済のときfalse, 未併合のときtrueが返される
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    // 要素kが属する集合を求める
    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    // 要素kが属する集合の要素の数を求める
    int size(int k) { return (-data[find(k)]); }
};

void solve() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v(M);
    for (auto &x : v) {
        cin >> x.first >> x.second;
        x.first--, x.second--;
    }
    UnionFind uf(N);
    // 不便さの逆の連結数を求める
    vector<int> ans;
    ans.emplace_back(0);
    // UnionFindは連結のみ可能なので、逆順で連結する
    for (int i = M - 1; i > 0; i--) {
        int sz1 = uf.size(v[i].first);
        int sz2 = uf.size(v[i].second);
        // 新たに併合した場合
        if (uf.unite(v[i].first, v[i].second)) {
            // 連結数が(sz1 * sz2)増える
            ans.emplace_back(ans.back() + sz1 * sz2);
        } else {
            ans.emplace_back(ans.back());
        }
    }
    reverse(ALL(ans));
    const int sum = N * (N - 1) / 2;
    for (auto &x : ans) {
        cout << sum - x << "\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 6588
#include <iostream>
#include <algorithm>
using namespace std;
bool sor(int a,int b){
        return a>b;
};
int main(){
        int n;
        cin >> n;
        int a[n];
        int al=0;
        int bo=0;
        for(int i=0; i<n; i++) {
                cin >> a[i];
        }
        sort(a,a+n,sor);
        for(int i=0; i<n; i++) {
                if(i%2==0) al+=a[i];
                else bo+=a[i];
        }
        cout <<al-bo << endl;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 15.09.2018 15:38:24       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    b[i] = min(x, a[i]);
    x -= b[i];
  }
  b.back() += x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (a[i] == b[i]);
  }
  cout << ans << '\n';
  return 0;
}


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

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

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

  int c = 0;
  for(int i = 1; i < n - 1 ; i++) {
    int r = max(p[i-1], max(p[i], p[i+1]));
    int l = min(p[i-1], min(p[i], p[i+1]));
    if(p[i] != r && p[i] != l) c++;
  }

  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        output(3);
        return 0;
    }
    if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
        output(2);
        return 0;
    }
    if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        output(1);
        return 0;
    }
    output(0);
    
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
     
    void merge(int a[], int b[], int p, int n);
    void msort(int a[], int b[], int p, int n);
     
    int main(){

    	int N, K;
    	int *h;
    	int *work;
    	int difference = 1000000000;
     
    	scanf("%d", &N);
    	scanf("%d", &K);
    	h = (int*)malloc(sizeof(int)*N);
     
    	for (int i = 0; i < N; i++){
    		scanf("%d", h+i);
    	}
     
    	work = (int*)malloc(sizeof(int)*N);
    	memset(work, 0, N);
        

    	msort(h, work, 0, N);
        

    	for (int i = 0; i <= N-K; i++){
    		if (h[i+K-1]-h[i] < difference){
    			difference = h[i+K-1] - h[i];
    		}  
    	}
        
        printf("%d\n", difference);
    }
     
    void merge(int a[], int b[], int p, int n){
    	int i, j, k, h;
    	h = n/2;
    	i = p;
    	j = p+h;
        
        for (k = p; k < p+n; k++){
        	if (j == p+n || i < p+h && a[i] <= a[j]){
        		b[k] = a[i++];
        	}else{
        		b[k] = a[j++];
        	}
        }
     
        for (k = p; k < p+n; k++){
        	a[k] = b[k];
        }
    }
     
    void msort(int a[], int b[], int p, int n){
    	int h;
     
    	if (n > 1){
    		h = n/2;
    		msort(a, b, p, h);
    		msort(a, b, p+h, n-h);
    		merge(a, b, p, n);
    	}
    	
    }

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        int i = 1;
        while (true) {
            int width = y * i + z * (i + 1);
            if (x < width) {
                break;
            }
            i++;

        }
        System.out.println(i - 1);
    }

}


Measured memory_bytes: 22996
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a,&b)
	
	ans := 0
	if b == 1 {
		ans = 0
	} else {
		for i := 1;; i++{
          plgCnt :=(a - 1) * (i - 1)  + a
			if plgCnt >= b{
				ans = i
				break
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
N,M=map(int,input().split())
ship=[list(map(int,input().split())) for _ in range(M)]
port1=[]
port2=[]
for i in range(M):
    if ship[i][0]==1:
        port1.append(ship[i][1])
    if ship[i][1]==N:
        port2.append(ship[i][0])

port1=set(port1)
port2=set(port2)
if len(port1&port2)>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 103640
using Yorukatsu057.Questions;
using Yorukatsu057.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu057.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc106/tasks/abc106_c
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            var k = inputStream.ReadLong();
            var oneCount = s.TakeWhile(c => c == '1').Count();

            if (oneCount >= k)
            {
                yield return '1';
            }
            else
            {
                yield return s.SkipWhile(c => c == '1').First();
            }
        }
    }
}

namespace Yorukatsu057
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu057.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu057.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int main(){
  int N,n,d;
  int x[222],y[222];
  const int dy[] = {0,1,0,-1}, dx[] = {-1,0,1,0};

  while(cin >> N, N){
    x[0] = 0; y[0] = 0;
    int minx = 0, miny = 0;
    int maxx = 0, maxy = 0;

    for(int i=1;i<N;i++){
      cin >> n >> d;
      x[i] = x[n]+dx[d]; y[i] = y[n]+dy[d];
      minx = min(minx, x[i]); maxx = max(maxx, x[i]);
      miny = min(miny, y[i]); maxy = max(maxy, y[i]);
    }
    cout << maxx-minx+1 << " " << maxy-miny+1 << endl;
  }
}

Measured memory_bytes: 1160
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Cube {
public:
	int f[6];
	int sum;
	Cube() {
		f[0] = 1; f[1] = 2; f[2] = 3; f[3] = 4; f[4] = 5; f[5] = 6;
		sum = 1;
	}
	void roll(int i, int j, int k, int l) {
		int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
	void roll_north() { roll(0, 1, 5, 4); sum += f[0]; }
	void roll_east() { roll(0, 3, 5, 2); sum += f[0]; }
	void roll_west() { roll(0, 2, 5, 3); sum += f[0];}
	void roll_south() { roll(0, 4, 5, 1); sum += f[0];}
	void roll_right() { roll(1, 2, 4, 3); sum += f[0];}
	void roll_left() { roll(2, 1, 3, 4); sum += f[0];}
};
int main() {
	int n;
	while (cin >> n&&n) {
		Cube c;
		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;
			if (s == "North")c.roll_north();
			else if (s == "East")c.roll_east();
			else if (s == "South")c.roll_south();
			else if (s == "West")c.roll_west();
			else if (s == "Right")c.roll_right();
			else if (s == "Left")c.roll_left();
		}
		cout << c.sum << endl;
	}
	return 0;
}

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

int main() {
  int N,M; cin >> N >> M;
  vector<int> K(N);
  vector<vector<int> > A(N, vector<int>());
  for (int i=0; i<N; ++i) {
    cin >> K[i];
    A[i].resize(K[i]);
    for (int j=0; j<K[i]; ++j) cin >> A[i][j];
  }

  vector<int> B(M,0);
  for (int i=0; i<N; ++i)
    for (int j=0; j<K[i]; ++j)
      B[A[i][j]-1]++;

  cout << count(B.begin(), B.end(), N) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;

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

  vector<long long> s(N + 1);
  map<long long, long long> nums;
  for (int i = 0; i < N; i++) s[i + 1] = s[i] + A[i];
  for (int i = 0; i < N + 1; i++) nums[s[i]]++; 

  long long ans = 0;
  for (auto it : nums) {
    long long num = it.second;
    ans += num * (num - 1) / 2;
  }

  cout << ans << endl;

}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T>
struct WeightedUnionFind{
  T d;
  vector<int> r,p;
  vector<T> ws;

  WeightedUnionFind(){}
  WeightedUnionFind(int n,T d):
    d(d),r(n,1),p(n),ws(n,d){iota(p.begin(),p.end(),0);}

  int find(int x){
    if(x==p[x]) return x;
    int t=find(p[x]);
    ws[x]+=ws[p[x]];
    return p[x]=t;
  }

  T weight(int x){
    find(x);
    return ws[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }

  T diff(int x,int y){
    return weight(y)-weight(x);
  }
};
//END CUT HERE

signed DSL_1_B(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,q;
  cin>>n>>q;
  WeightedUnionFind<int> wuf(n,0);

  for(int i=0;i<q;i++){
    int t,x,y,z;
    cin>>t>>x>>y;
    if(t){
      if(wuf.same(x,y)) cout<<wuf.diff(x,y)<<"\n";
      else cout<<"?\n";
    }else{
      cin>>z;
      wuf.unite(x,y,z);
    }
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/09/08
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_B&lang=jp
*/

signed main(){
  DSL_1_B();
  return 0;
}



Measured memory_bytes: 4128
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef long long LL;

int read()
{
    int x=0,flag=1;
    char c=getchar ();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    //freopen("input.txt","r",stdin);
    char s[5],t[5];
    scanf("%s %s",s,t);
    int ans=0;
    REP(i,0,2) if(s[i]==t[i]) ans++;
    cout<<ans;

	return 0;
}


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

int main()
{
    int x, y;
    cin >> x >> y;

    if (y > x) swap(x, y);

    for (; y > 0;) {
        int r = x % y;
        x = y;
        y = r;
    }

    cout << x << endl;

    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;

int n,m,num,e_n,e2_n,tep1,tep2,tep3;
struct zhk1{int to,la,ne,val;}e[2010];
struct zhk2{int to,la,ne,val;}e2[2010];
int h=1,t=0;
int q[10000010];
int b[1010],c[1010];
long long ans[1010];

int now,fh=1;char ch;
inline int get_num()
{
    now=0;fh=1;ch=getchar();
    while(ch<'0'||ch>'9')
	{
		if(ch=='-')fh=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9')
    {
        now=(now<<1)+(now<<3)+ch-'0';
        ch=getchar();
    }
    return now*fh;
}

inline void edge_add(int x,int y,int z)
{
    e_n++;
    e[e_n].to=y;
    e[e_n].val=z;
    e[e_n].ne=e[x].la;
    e[x].la=e_n;
}

inline void edge_add2(int x,int y,int z)
{
    e2_n++;
    e2[e2_n].to=y;
    e2[e2_n].val=z;
    e2[e2_n].ne=e2[x].la;
    e2[x].la=e2_n;
}

inline void solve1()
{
	h=1,t=0;
    q[++t]=n;
    c[n]=1;
    while(h<=t)
    {
        for(int i=e2[q[h]].la;i;i=e2[i].ne)
        {
            if(c[e2[i].to]==0)
            {
                q[++t]=e2[i].to;
                c[e2[i].to]=1;
            }
        }
        h++;
    }
}

inline void solve2()
{
	h=1,t=0;
    q[++t]=1;
    for(int i=1;i<=n;i++)ans[i]=-1000000000000000;
    ans[1]=0;
    while(h<=t)
    {
        for(int i=e[q[h]].la;i;i=e[i].ne)
        {
            if(ans[e[i].to]<ans[q[h]]+e[i].val)
            {
                ans[e[i].to]=ans[q[h]]+e[i].val;
                if(c[e[i].to]==1)q[++t]=e[i].to;
                if(e[i].to==n)
                {
                	num++;
                	if(num>n)
                	{
                		puts("inf");
						exit(0);
					}
				}
            }
        }
        h++;
    }
    printf("%lld\n",ans[n]);
}

int main()
{
	n=get_num();m=get_num();
	for(int i=1;i<=m;i++)
	{
		tep1=get_num();
		tep2=get_num();
		tep3=get_num();
		edge_add(tep1,tep2,tep3);
		edge_add2(tep2,tep1,tep3);
	}
	solve1();
	solve2();
	return 0;
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
	void main() {
		int h, w;
		int MOD = 1000000000 + 7;

		cin >> h >> w;
		char temp;
		vector<VI> grid(h + 5, VI(w + 5));
		vector<VI> paths(h + 5, VI(w + 5));
		paths[0][1] = 1;

		REP(i, 1, h + 1) {
			REP(j, 1, w + 1) {
				cin >> temp;
				if (temp == '#') {
					paths[i][j] = 0;
				}
				else {
					paths[i][j] = (paths[i - 1][j] + paths[i][j - 1]) % MOD;
				}
			}
		}


		cout << paths[h][w];


	}
}


signed main() {

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}


Measured memory_bytes: 8192
import numpy as np
from collections import deque
h,w = map(int,input().split())
s =["#"*(w+2)] + ["#" + str(input()) + "#" for i in range(h)] + ["#"*(w+2)]
s = np.array(s)
opt = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0

for i in range(h+2):
    for j in range(w+2):
        temp = [[0]*(w+2) for i in range(h+2)]
        temp[i][j] = 1
        dq = deque([(i,j)])
        
        while dq:
            x,y = dq.popleft()
            if s[x][y] == ".":
                for k in opt:
                    x1,y1 = x+k[0],y+k[1]
                    if s[x1][y1] == ".":
                        if temp[x1][y1] == 0:
                            temp[x1][y1] = temp[x][y] + 1
                            dq.append((x1,y1))
                        elif temp[x1][y1] > temp[x][y] + 1:
                            temp[x1][y1] = temp[x][y] + 1
                            dq.append((x1,y1))
        ans = max(ans,np.max(temp))
print(ans-1)



Measured memory_bytes: 12440
N = int(input())
A = sorted(list(map(int, input().split())))+[1e9+1]
B = sorted(list(map(int, input().split())))+[1e9+1]
C = sorted(list(map(int, input().split())))

i=0
j=0
k=0

NA=list(range(1,N+1))+[0]
NB=[0]*N+[0]
NC=[0]*N+[0]

while j<N:
  while A[i]<B[j]:
    i+=1
  NB[j]=NA[i-1]+NB[j-1]
  j+=1

j=0
while k<N:
  while B[j]<C[k]:
    j+=1
  NC[k]=NB[j-1]+NC[k-1]
  k+=1

#print(NA,NB,NC)
    
print(NC[-2])

Measured memory_bytes: 29728
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    int n;
    cin >> n;
    int a[n + 1], b[n];
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (b[i] >= a[i] + a[i + 1]) {
            ans += a[i] + a[i + 1];
            a[i] = a[i + 1] = 0;
        } else {
            if (b[i] < a[i]) {
                ans += b[i];
            } else {
                ans += b[i];
                a[i + 1] -= (b[i] - a[i]);
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int MAXN=1e5+9;
const ll INF=1e13;
ll arr[MAXN];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)
    {
        scanf("%lld",&arr[i]);
    }
    ll ans=INF;
    for(int i=0;i<=n-k;++i)
    {
        int left=i;
        int right=i+k-1;
        ll temp1=labs(arr[right]-arr[left])+labs(arr[left]-0LL);
        ll temp2=labs(arr[left]-arr[right])+labs(arr[right]-0LL);
        ans=min(ans,min(temp1,temp2));
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

vector<int> graf[200005];

int zliczanie[2], krawedzie, odwiedzony[200005];

void dfs(int x){
    zliczanie[odwiedzony[x] % 2]++;
    for (int i : graf[x]){
        if (!odwiedzony[i]){
            odwiedzony[i] = odwiedzony[x] + 1;
            dfs(i);
        }
        krawedzie++;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        graf[a].push_back(b + 100000);
        graf[b + 100000].push_back(a);
    }
    long long wynik = 0;
    for (int i = 1; i <= 200000; i++)
        if (!odwiedzony[i]){
            zliczanie[0] = 0;
            zliczanie[1] = 0;
            krawedzie = 0;
            odwiedzony[i] = 1;
            dfs(i);
            krawedzie /= 2;
            wynik += (long long)zliczanie[0] * zliczanie[1] - krawedzie;
        }
    cout << wynik << "\n";
    return 0;
}

Measured memory_bytes: 15136
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0 for _ in range(k + 1)]
for i in range(1, k + 1):
    for j in a:
        if i >= j:
            if dp[i - j] == 0:
                dp[i] = 1
        if dp[i] == 1:
            break
print("First" if dp[k] else "Second")

Measured memory_bytes: 44784
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  int x = 100000;
  rep(i, n) x = (x * 21 / 20 + 999) / 1000 * 1000;
  cout << x << endl;
}

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

int main(){
    long double n,total;
    cin>>n;
    total=0;
    rep(i,n){
        string s;
        long double a;
        cin>>a>>s;
        if(s=="JPY")total+=a;
        else total+=a*380000.0;

    }
    cout<<fixed<<setprecision(18)<<total<<endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	int low = p, high = n;
	while(low < high){
		int mid = (low + high + 1) >> 1;
		ll total = 0;
		rep(i, n){
			if(i < p-1 || i >= mid-1) total += m;
			else{
				if(a[i] > a[mid-1]+m){
					total = -1;
					break;
				}
				total += (a[mid-1] + m) - a[i];
			}
		}
		if(total >= (ll) m * v) low = mid;
		else high = mid - 1;
	}
	cout << low << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll n, d;
	cin >> n >> d;
	ll cnt = 0;
	rep(i, n) {
		ll x, y;
		cin >> x >> y;
		if (sqrt(x*x + y*y) <= d) cnt++;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3520