akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;

int main(void){
    // Your code here!
    long long n;
    vector<long long> a;
    deque<long long> b;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        a.push_back(temp);
    }
    
    for(int i = 0; i < n; i++){
        if(i % 2 == 0)
            b.push_back(a[i]);
        else
            b.push_front(a[i]);
    }
    if(n % 2 == 0){
        for(int i = 0; i < n; i++)
            cout << b[i] << ' ';
    }
    else{
        for(int i = 0; i < n; i++)
            cout << b[n-i-1] << ' ';
    }
    cout << endl;
    
    return 0;
    
}

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

using namespace std;
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int inf = 1000000007;
const int N = 5000 + 7;
const int multipleTest = 0;

int n;
vi adj[N];
int x[N];

ii res[N];
int dp[2][N];

void dfs(int u, int d) {
    for (int v : adj[u]) {
        dfs(v, d + 1);
    }
    dp[0][0] = 0;
    for (int j = 1; j < N; ++j) dp[0][j] = inf;
    int cur = 0;
    for (int v : adj[u]) {
        int pre = cur;
        cur ^= 1;
        ii x = res[v];
        for (int j = 0; j < N; ++j) dp[cur][j] = inf;
        for (int j = 0; j < N; ++j) {
            if (dp[pre][j] < inf) {
                if (j + x.first < N) dp[cur][j + x.first] = min(dp[cur][j + x.first], dp[pre][j] + x.second);
                if (j + x.second < N) dp[cur][j + x.second] = min(dp[cur][j + x.second], dp[pre][j] + x.first);
            }
        }
    }
    int mn = N - 1;
    bool found = false;
    for (int j = 0; j <= x[u]; ++j) if (dp[cur][j] < inf) {
            found = true;
            mn = min(mn, dp[cur][j]);
        }
    if (!found) {
        puts("IMPOSSIBLE");
        exit(0);
    }
    res[u] = mk(x[u], mn);
}

void solve() {
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        int u; scanf("%d", &u);
        adj[u].push_back(i);
    }
    for (int i = 1; i <= n; ++i) scanf("%d", x + i);
    dfs(1, 0);
    puts("POSSIBLE");
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        solve();
    }
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin >> n;
    vector<long long>a(n);
    vector<long long>num(1000000);
    long long ans=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ans+=a[i];
        num[a[i]]++;
    }
    long long k;
    cin >> k;
    for(int i=0;i<k;i++){
        long long b,c;
        cin >> b >> c;
        long long oboe=num[b];
        num[b]=0;
        num[c]+=oboe;
        ans-=oboe*b;
        ans+=oboe*c;
        cout << ans << endl;

    }
}

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

int main() {
  long long num;
  long long a,b;
  long long sa;
  long long kekka = 0;
  bool nearL = true;
  
  cin >> num >> a >> b;
  
  sa = (b - a) % 2;
  
  if(a - 1 <= num - b) nearL = true;
  else nearL = false;
  
  if(sa == 0){
    kekka = (b - a) / 2;
  }else if(nearL == true){
    kekka = a - 1 + 1 + (b - a -1) / 2;
  }else{
    kekka = num - b + 1 + (b - a -1) / 2;
  }
  
  cout << kekka;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN=1e5;

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll s1=a*c;
    ll s2=a*d;
    ll s3=b*c;
    ll s4=b*d;
    cout << max(s1,max(s2,max(s3,s4)));
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int a = sc.nextInt();
    int b = sc.nextInt();

    String ans = "No";
    for (int c = 1; c <= 3; c++) {
      int total = a*b*c;
      if (total%2==1){
        ans = "Yes";
        break;
      }
    }
    out.println(ans);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

    long nextLong() {
      return Long.parseLong(next());
    }

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

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	i64 a, b; scanf("%lld%lld", &a, &b); b++;
	
	i64 ans = 0, latte = 2;
	if((a & 1) == 1 and ((b - a) / 2) % 2 == 1) ans = b % 2;
	else if((a & 1) == 1 and ((b - a) / 2) % 2 == 0) ans = 1 - b % 2;
	else if((a & 1) == 0 and ((b - (a + 1)) / 2) % 2 == 1) ans = b % 2;
	else if((a & 1) == 0 and ((b - (a + 1)) / 2) % 2 == 0) ans = 1 - b % 2;
	for(int i = 1; i < 50; i++) {
		i64 bit = (1LL << latte) - 1;
		i64 A = a & bit;
		
		if(A > (1LL << (latte - 1))) {
			i64 X = A - (1LL << (latte - 1));
			if(X % 2 == 1) ans ^= (1LL << (latte - 1));
		}
		
		i64 B = b & bit;
		if(B > (1LL << (latte - 1))) {
			i64 X = B - (1LL << (latte - 1));
			if(X % 2 == 1) ans ^= (1LL << (latte - 1));
		}
		latte++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    int n;
    int data[10] = {0, 111, 222, 333, 444, 555, 666, 777, 888, 999};

    while(scanf("%d",&n)==1){
        for(int i=0; i<10; i++){
            if(n<=data[i]){
                printf("%d\n",data[i]);
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())

ac, wa, tle, re = 0, 0, 0, 0


for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1
    else:
        pass

print("AC x "+ str(ac))
print("WA x "+ str(wa))
print("TLE x "+ str(tle))
print("RE x "+ str(re))

Measured memory_bytes: 9208
class Dice:
    def __init__(self, labels):
        self.surface = {x: labels[x-1] for x in range(1, 6+1)}
    def move_towards(self, direction):
        if direction == 'N':
            self._move(1, 2, 6, 5)
        elif direction == 'S':
            self._move(1, 5, 6, 2)
        elif direction == 'E':
            self._move(1, 4, 6, 3)
        elif direction == 'W':
            self._move(1, 3, 6, 4)
    def get_upper(self):
        return self.surface[1]
    def _move(self, i, j, k, l):
        temp_label = self.surface[i]
        self.surface[i] = self.surface[j]
        self.surface[j] = self.surface[k]
        self.surface[k] = self.surface[l]
        self.surface[l] = temp_label

labels = list(map(int, input().split()))
dice = Dice(labels)
moves = input()
for move in moves:
    dice.move_towards(move)
print(dice.get_upper())


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A)
{
  // 終了条件は+1
  if (A.size() == n + 1)
  {
    int now = 0;
    rep(i, q)
    {
      if (A[b[i]] - A[a[i]] == c[i])
        now += d[i];
    }
    ans = max(ans, now);
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m)
  {
    dfs(A);
    A.back()++;
  }
}

int main()
{
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int n, p[20020];

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++)scanf("%d", p+i);
	int a[20020] = {}, b[20020] = {};
	for(int i=1;i<=n;i++)a[i] = i, b[i] = n+1-i;
	for(int i=1;i<=n;i++){
		int u = p[i], ad = n - i;
		for(int j=u+1;j<=n;j++)a[j] += ad;
		for(int j=1;j<u;j++)b[j] += ad;
	}
	for(int i=1;i<=n;i++)printf("%d ", a[i]); puts("");
	for(int i=1;i<=n;i++)printf("%d ", b[i]); puts("");
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 896
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    double n;
    cin>>n;
    cout<<2.0*n*M_PI<<"\n";
}

Measured memory_bytes: 3768
f=lambda:map(int,input().split())
n,m=f()
d=[[]for _ in range(n+1)]
c=[]
for _ in range(m):
    a,b=f()
    d[a]+=[b]
    d[b]+=[a]
    c+=[[a,b]]
ans=0
for i,j in c:
    a=[0]*(n+1)
    b=list(d[i])
    b.remove(j)
    now=0
    while b:
        now=b.pop(0)
        if a[now]==0:
            a[now]+=1
            for k in d[now]:
                if a[k]==0 and k!=i:
                    b+=[k]
    if a[j]==0:
        ans+=1
print(ans)

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

int main()
{
  int n;
  cin >> n;
  int ans=1;
  bool samemochi=0;
  vector<int> d(n);
  for(int i=0;i<n;++i){
    cin >> d.at(i);
    if(i>0){
      for(int j=i-1;j>=0&&samemochi==0;--j){
        if(d.at(i)==d.at(j)){
          samemochi=1;
        }
      }
      if(samemochi==0){
        ++ans;
      }
      samemochi=0;
    }
  }
  
  cout << ans;
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;


const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;


ll mm = 1e18+1;
void solve() {
	ld a,b;cin>>a>>b;
	cout<<(ll)(a*b)<<"\n";
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


Measured memory_bytes: 3748
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(int i(s); i < int(n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

signed main()
{
  int N, M;
  cin >> N >> M;

  int low = 0;
  int hi = INF;
  rep(i, 0, M) {
    int l, r;
    cin >> l >> r;
    chmax(low, l);
    chmin(hi, r);
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (low <= i && i <= hi) ++ans;
  }

  cout << ans << endl;
  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 repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

lint table[15][10];

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

    rep(i, 10) table[1][i] = 1;
    for(int d = 2; d <= 11; d++){
        rep(i, 10){
            if(i == 0){
                table[d][0] = table[d-1][0] + table[d-1][1]; continue;
            }
            if(i == 9){
                table[d][9] = table[d-1][8] + table[d-1][9]; continue;
            }
            table[d][i] = table[d-1][i-1]+table[d-1][i]+table[d-1][i+1];
        }
    }

    int s, t; bool ok = false;
    repn(d, 10){
        repn(i, 9){
            if(k <= table[d][i]){
                s = d; t = i; ok = true; break;
            }
            k -= table[d][i];
        }
        if(ok) break;
    }

    lint ans = 0;
    for( ; s >= 1; s--){
        ans += t * (lint)pow(10, s-1);

        if(s == 1) break;
        rep(c, 3){
            if(c == 0 && t == 0) continue;
            int p;
            if(c == 0){
                p = table[s-1][t-1];
                if(k <= p){
                    t--; break;
                }else k -= p;
            }
            if(c == 1){
                p = table[s-1][t];
                if(k <= p){
                    break;
                }else k -= p;
            }
            if(c == 2){
                t++;
            }
        }
    }

    out(ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,w;
    cin>>n>>w;
    ll a[n][2];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    ll dp[n][w+1];
    for(int i=0;i<n;i++){
        dp[i][0]=0;
    }
    for(int j=0;j<=w;j++){
        if(a[0][0] <= j) dp[0][j]=a[0][1];
        else dp[0][j]=0;
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=w;j++){
            if(a[i][0]<=j){
                dp[i][j]=max(dp[i-1][j-a[i][0]]+a[i][1],dp[i-1][j]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n-1][w];
}

Measured memory_bytes: 78336
data=[]
while(True):
  a,b=map(int,input().split(' '))
  data.append((a,b))
  if a==0 and b==0:
    break
  

for a,b in data:
  if a==0 and b==0:
    break
  else:
    line='#'*b
    for i in range(a):
      print(line)
    print('')



Measured memory_bytes: 5632
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int finded = 0;
		int lineSamount = scan.nextInt();
		int[] lineSnum = new int[lineSamount];
		for(int i=0; i<lineSamount; i++){
			lineSnum[i] = scan.nextInt();
		}
		int lineTamount = scan.nextInt();
		int[] lineTnum = new int[lineTamount+1];
		int notfound =0;
		for(int i=0; i<lineTamount; i++){
			lineTnum[i] = scan.nextInt();
		}

		for(int i=0; i<lineSamount; i++){
			int j = 0;
			lineTnum[lineTamount] = lineSnum[i];
			while(lineTnum[j] != lineSnum[i]){
				j++;
			}
			if(j == lineTnum.length-1 ){
//				????????????????????£??????
				notfound++;
			}
			else {
				finded++;
				lineTnum[j] = -1;
			}
		}
		System.out.println(finded);
	}
}

Measured memory_bytes: 40472
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final String LINE_SPR = System.getProperty("line.separator");
    final int BIG_MOD = 1000000007;

    void run() throws Exception {
        String line;
        while((line = br.readLine()) != null) {
            String[] nums = line.split(" ");
            int a = Integer.parseInt(nums[0]);
            int b = Integer.parseInt(nums[1]);
            int sum = a + b;
            int c = 0;
            while(sum > 0) {
                sum /= 10;
                c++;
            }
            System.out.println(c);
        }
    }


    /*
     * Templates
     */
    void dumpObjArr(Object[] arr, int n) {
        for(int i = 0; i < n; i++) {
            System.out.print(arr[i]);
            if(i < n - 1)
                System.out.print(" ");
        }
        System.out.println("");
    }

    void dumpObjArr2(Object[][] arr, int m, int n) {
        for(int j = 0; j < m; j++) 
            dumpObjArr(arr[j], n);
    }

    int ni() throws Exception {
        return Integer.parseInt(br.readLine().trim());
    }

    long nl() throws Exception {
        return Long.parseLong(br.readLine().trim());
    }

    String ns() throws Exception {
        return br.readLine();
    }

    boolean isPrime(int n) {
        for(int i=2;i<n;i++) {
            if(n%i==0)
                return false;
        }
        return true;
    }

    int getPrime(int n) {
        List<Integer> primes = new ArrayList<Integer>();
        primes.add(2);
        int count = 1;

        int x = 1;
        while(primes.size() < n) {
            x+=2;
            int m = (int)Math.sqrt(x);
            for(int p : primes) {
                if(p > m) {
                    primes.add(x);
                    break;
                }

                if(x % p == 0) 
                    break;
            }
        }

        return primes.get(primes.size() - 1);
    }

    void gcjPrint(String str, int t) {
        System.out.println("Case #" + t + ": " + str);
    }

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

Measured memory_bytes: 17000
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;

int n, nq;
int a[2 * MAXN], b[2 * MAXN];

ll now;
bool same[2 * MAXN];
set<pair<int,int> > same2diff;
set<pair<int,int> > diff2same;

void change(set<pair<int, int> > &s, int idx, int oval, int nval) {
	s.erase(MP(oval, idx)); s.insert(MP(nval, idx));
}

void update() {
	while (true) {
		bool change = false;
		while (SZ(same2diff) >= 2) {
			auto a = same2diff.end(); --a; auto b = a; --b;
			if ((ll)a->first + b->first <= 0) break;
			now += (ll)a->first + b->first;
			same[a->second] = same[b->second] = false;
			diff2same.insert(MP(-a->first, a->second));
			diff2same.insert(MP(-b->first, b->second));
			same2diff.erase(a);
			same2diff.erase(b);
			change = true;
		}
		while (SZ(diff2same) >= 2) {
			auto a = diff2same.end(); --a; auto b = a; --b;
			if ((ll)a->first + b->first <= 0) break;
			now += (ll)a->first + b->first;
			same[a->second] = same[b->second] = true;
			same2diff.insert(MP(-a->first, a->second));
			same2diff.insert(MP(-b->first, b->second));
			diff2same.erase(a);
			diff2same.erase(b);
			change = true;
		}
		while (SZ(same2diff) >= 1 && SZ(diff2same) >= 1) {
			auto a = same2diff.end(); --a; auto b = diff2same.end(); --b;
			if ((ll)a->first + b->first <= 0) break;
			now += (ll)a->first + b->first;
			same[a->second] = false, same[b->second] = true;
			diff2same.insert(MP(-a->first, a->second));
			same2diff.insert(MP(-b->first, b->second));
			same2diff.erase(a);
			diff2same.erase(b);
			change = true;
		}
		if (!change) break;
	}
}

void run() {
	scanf("%d%d", &n, &nq); REP(i, 2 * n) scanf("%d", &a[i]); REP(i, 2 * n) scanf("%d", &b[i]);
	now = 0; same2diff.clear(); diff2same.clear();
	REP(i, 2 * n) {
		now += a[i]; same[i] = true;
		if (i != 0 && i != 2 * n - 1) same2diff.insert(MP(b[i] - a[i], i));
	}
	REP(qi, nq) {
		int idx, aval, bval; scanf("%d%d%d", &idx, &aval, &bval); --idx;
		if (same[idx]) now += aval - a[idx];
		else now += bval - b[idx];
		if (idx != 0 && idx != 2 * n - 1) {
			if (same[idx]) change(same2diff, idx, b[idx] - a[idx], bval - aval);
			else change(diff2same, idx, a[idx] - b[idx], aval - bval);
		}
		a[idx] = aval, b[idx] = bval;
		update();
		printf("%lld\n", now);
	}
}

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


Measured memory_bytes: 12800
import java.util.Scanner;

class Node {
	int i, id, left, right, parent = -1, sibling = -1, degree = 0, depth = 0, height = 0;

	public Node(int Id, int l, int r) {
		id = Id;
		left = l;
		right = r;
	}

	public void Show() {

		System.out.print("node " + id + ": parent = " + parent + ", sibling = " + sibling + ", degree = " + degree
				+ ", depth = " + depth + ", height = " + height + ", ");
		if (parent == -1) {
			System.out.println("root");
		} else if (degree == 0) {
			System.out.println("leaf");
		} else {
			System.out.println("internal node");
		}
	}
}

public class Main {
	static Node[] node = new Node[100000];

	public static void hight(int i) {
		if (node[i].parent != -1 && node[node[i].parent].height < node[i].height + 1) {
			node[node[i].parent].height = node[i].height + 1;
			hight(node[i].parent);
		}
	}

	public static void depth(int i) {
		if (node[i].left != -1) {
			node[node[i].left].depth=node[i].depth+1;
			depth(node[i].left);
		}
		if (node[i].right != -1) {
			node[node[i].right].depth=node[i].depth+1;
			depth(node[i].right);
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i, n, id, l, r;
		n = scan.nextInt();
		for (i = 0; i < n; i++) {
			id = scan.nextInt();
			l = scan.nextInt();
			r = scan.nextInt();
			node[id] = new Node(id, l, r);
		}
		for (i = 0; i < n; i++) {
			if (node[i].left != -1) {
				node[i].degree++;
				node[node[i].left].parent = node[i].id;
				node[node[i].left].sibling = node[i].right;
			}
			if (node[i].right != -1) {
				node[i].degree++;
				node[node[i].right].parent = node[i].id;
				node[node[i].right].sibling = node[i].left;
			}
		}
		for (i = 0; i < n; i++) {
			if (node[i].parent == -1) {
				depth(i);
			}
			if (node[i].degree == 0) {
				hight(i);
			}
		}
		for (i = 0; i < n; i++) {
			node[i].Show();
		}
		scan.close();
	}
}


Measured memory_bytes: 26844
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, M;
	cin >> N >> M;
	cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
void card(char,int);
int p=0;
int main(){
  char a[101],b[101],c[101];
  int i=0,j=0,k=0;
  scanf("%s%s%s",a,b,c);
  while(1){
    if(p==0){
      card(a[i],0);
      i++;
    }
    else if(p==1){
      card(b[j],1);
      j++;
    }
    else if(p==2){
      card(c[k],2);
      k++;
    }
    else break;
  }
  return 0;
}
void card(char a,int b){
  if(a=='a'){
    p=0;
    return;
  }
  else if(a=='b'){
    p=1;
    return;
  }
  else if(a=='c'){
    p=2;
    return;
  }
  else{
    if(b==0){
      cout << "A" << endl;
    }
    if(b==1){
      cout << "B" << endl;
    }
    if(b==2){
      cout << "C" << endl;
    }
    p=4;
    return;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int a, b, c;
  string r = "NO";
  cin >> a >> b >> c;
  rep(i, 1000) {
    if (((i + 1) * a % b) == c) r = "YES";
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(void){

    int n, min = 0, ans = 0;

    cin >> n;

    vector<int> h(n);

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

    for(int i = 0;i < n;i++){
        if(min <= h[i]){
            min = h[i];
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,i,j,srx[2000000]={0},sry,t,p;
int main()
{
   scanf("%d%d",&n,&k);
   for(i=1;i<=n;++i)
   {
    scanf("%d",&t);
    srx[t]++;
   }
   sort(srx+1,srx+n+1);
   for(i=n;i>n-k;--i)
   sry+=srx[i];
   printf("%d",n-sry);
   return 0;
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(c % gcd(a, b) == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 256
n = int(input())
blue = []
red = []
score_list = []
for i in range(n):
    blue.append(input())
m = int(input())
for j in range(m):
    red.append(input())
for value in blue:
    score = 0
    for s in blue:
        if value == s:
            score += 1
    for t in red:
        if value == t:
            score -= 1
    if score not in score_list:
        score_list.append(score)
if max(score_list) < 0:
    print(0)
else:
    print(max(score_list))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << max(a-b*2, 0) << endl;
  return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 1000000007
#define INFL 2000000000000000000LL
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;


class UnionFind {
public:
	vector<int> par, rank;

	void init(int n) {
		par = vector<int>(n);
		rank = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	// ??¨??????????±???????
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	// x??¨y????±??????????????????????
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}

	// x??¨y???????????????????±????????????????
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	UnionFind(int n) {
		init(n);
	}

	UnionFind() {}
};

int main() {
	int V, E;
	cin >> V >> E;
	UnionFind uf(V);
	priority_queue<pair<int, P>, vector<pair<int, P> >, greater<pair<int, P> > > edge;

	rep(i, E) {
		int s, t, w;
		cin >> s >> t >> w;
		edge.push(mp(w, mp(s, t)));
	}
	ll ans = 0;
	rep(i, V - 1) {
		pair<int, P> e;
		do {
			e = edge.top();
			edge.pop();
		} while (uf.same(e.second.first, e.second.second));
		ans += e.first;
		uf.unite(e.second.first, e.second.second);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4660
// abc131d.cpp : Megalomania
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

bool asc(const map<ll,ll> &a, const map<ll,ll> &b){
  return a < b;
}

int main(){
  int N; in(N);
  map<ll,ll> jb;

  ll a, b;
  rp(i,N){
    cin>>a>>b;
    jb[b] += a;
  }

  bool f = true;
  a = b = 0;
  for(auto e = jb.begin(); e!=jb.end(); e++){
    a += e->second;
    if(a>e->first){
      f = false;
      break;
    }
  }
  ote((f?"Yes":"No"));

}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
vector<pair<long long,long long>> pf(long long N){
    vector<pair<long long,long long>> v;
    for(long long i = 2; i*i <= N; i++){
        if(N%i != 0) continue;
        long long counter = 0;
        while(N%i == 0){
            counter ++;
            N /= i;
        }
        v.push_back(make_pair(i,counter));
    }
    if(N!= 1) v.push_back(make_pair(N,1));
    return v;
}
 
long long find(long long n){
    // long long ans;
    // long long sum = 0;
    long long l = 1;
    long long r = n;
    while(r - l >1){
        long long c = (l + r)/2;
        if(c*(c+1)/2 <= n) l = c;
        else r = c;
    }
    return l;
    // for(int i =1; i <= n + 1000; i++){
    //     sum += i;
    //     if(sum > n) {
    //         ans = i - 1;
    //         break;
    //     }
    // }
}
 
int main(){
    long long N;
    cin >> N;
    // cout << find(N) << endl;
    vector<pair<long long,long long>> v = pf(N);
    long long  ans = 0;
    for(int i =0; i < v.size(); i++){
        ans += find(v.at(i).second);
    }
    cout << ans << endl;
}

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

int main() {
  bool line, n;
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i = 0; i < H; i++)
    cin >> a.at(i);
  for (int i = 0; i < H; i++) {
    line = true;
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') {
        line = false;
        break;
      }
    }
    if (line) {
      for (int j = 0; j < W; j++) {
        a.at(i).at(j) = 'n';
      }
    }
  }
  for (int i = 0; i < W; i++) {
    line = true;
    for (int j = 0; j < H; j++) {
      if (a.at(j).at(i) == '#') {
        line = false;
        break;
      }
    }
    if (line) {
      for (int j = 0; j < H; j++) {
        a.at(j).at(i) = 'n';
      }
    }
  }
  for (int i = 0; i < H; i++) {
    n = false;
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) != 'n'){
        cout << a.at(i).at(j);
        n = true;
      }
    }
    if (n)
      cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;



int main() {
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;

	return 0;
}

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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for(int c = 0; c <= C; c++){
                if( a*500+b*100+c*50 == X ){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = 1000000007;
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}
#define level 22

ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
  
    ll x;
    cin>>x;
    ll ans=0;
    ans=(x/500)*1000;
    x=x-(x/500)*500;
    ans=ans+(x/5)*5;
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

void dfs(const Graph &g, size_t v, int &t, vector<int> &d, vector<int> &f) {
    d[v] = t;
    for (const Edge &e: g[v])
        if (!d[e.dst])
            dfs(g, e.dst, ++t, d, f);

    f[v] = ++t;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t k;
        scanf("%*d %zu", &k);
        for (size_t j=0; j<k; ++j) {
            size_t v;
            scanf("%zu", &v);
            --v;

            connect(g, i, v);
        }
    }

    vector<int> d(n), f(n);
    int t=0;
    for (size_t v=0; v<n; ++v)
        if (!d[v])
            dfs(g, v, ++t, d, f);

    for (size_t i=0; i<n; ++i)
        printf("%zu %d %d\n", i+1, d[i], f[i]);

    return 0;
}

Measured memory_bytes: 2740
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int h, a;
  cin >> h >> a;

  int ans = h / a;
  if (h % a != 0) ans++;
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   
   if((A+B)>(C+D)){
       cout<<"Left"<<endl;
   }
   
   else if((A+B)==(C+D)){
       cout<<"Balanced"<<endl;
   }
   
   else if((A+B)<(C+D)){
       cout<<"Right"<<endl;
   }
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
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;
}

int main() {
    ll h, w, x, y;
    cin >> w >> h >> x >> y;
    double ret = (h * w) / 2.0;
    cout << fixed << setprecision(10) << ret << " ";
    if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
k = input()

if k == "RRR":
    print(3)
elif k == "RRS":
    print(2)
elif k == "SRR":
    print(2)
elif k == "RSS":
    print(1)
elif k == "RSR":
    print(1)
elif k == "SSR":
    print(1)
elif k == "SRS":
    print(1)
else:
    print(0)

Measured memory_bytes: 61624
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize;n],
    }

    let mut b: Vec<usize> = vec![0;3];
    for i in 0..n {
        if a[i]%2!=0 {
            b[0] += 1;
        } else {
            if a[i]%4==0 {
                b[2] += 1;
            } else {
                b[1] += 1;
            }
        }
    }
    let mut odd = b[0];
    if b[1]%2!=0 {
        odd += 1;
    }

    if odd<=b[2]+1 {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

double a[105];
signed main(){
	int n; cin>>n;
	double sum=0.0;
	for(int i=0; i<n; i++){ 
		cin>>a[i];
		sum+=a[i];
	}
	
	double d=sum/n;
	pair<double, int> ans; ans.first=101.0;
	for(int i=0; i<n; i++){
		double b=(a[i]-d<0) ? d-a[i]:a[i]-d;
		if(ans.first>b){
			ans.first=b;
			ans.second=i;
		}
	}
	cout<<ans.second<<en;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 20
#define Q 200

int n,A[N];

int solve(int i,int m){

  int res;

  if(m==0)return 1;
  if(i>=n)return 0;

  res=solve(i+1,m)||solve(i+1,m-A[i]);
  
  return res;
}

int main(){

  int i,j,q,B;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d",&q);

  for(j=0;j<q;j++){

    scanf("%d",&B);
      if(solve(0,B)==1)printf("yes\n");
      else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2104
n = gets.chomp.to_i
s = gets.chomp
countb = 0
countw = 0
countm = 0
abs = 0
pos = n - 1

while pos >= 0
  if s[pos] == '.' then
    break
  end
  pos -= 1
end

while pos >= 0
  if s[pos] == '.' then
    countm += 1
    countw += 1
  else
    countb += 1
  end

  if countm < countb then
    abs += countw
    countb = 0
    countw = 0
    countm = 0
  end
  pos -= 1
end

puts abs + [countw, countb].min


Measured memory_bytes: 2172
import java.io.*;
import java.util.Scanner;



public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = 0;
        int b = 0;
        String op = "null";
        int S = 0;
        int i = 0;
        while(i == 0){
            a = scan.nextInt();
            op = scan.next();
            b = scan.nextInt();
            
            
            if(op.equals("+")){
                S = a + b;
                System.out.println(S);
            }else  if(op.equals("-")){
                S = a - b;
                System.out.println(S);
            }else  if(op.equals("*")){
                S = a * b;
                System.out.println(S);
            }else  if(op.equals("/")){
                S = a / b;
                System.out.println(S);
            }else if(op.equals("?")){
                i = 1;
            }
        }
     }
    
}



Measured memory_bytes: 26420
import java.io.*;

public class Main {
	 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String s;
        while ((s = br.readLine()) != null) {
            String[] lc = s.split(" ");
            double x1 = Double.parseDouble(lc[0]);
            double y1 = Double.parseDouble(lc[1]);
            double x2 = Double.parseDouble(lc[2]);
            double y2 = Double.parseDouble(lc[3]);
            double x3 = Double.parseDouble(lc[4]);
            double y3 = Double.parseDouble(lc[5]);
            double xp = Double.parseDouble(lc[6]);
            double yp = Double.parseDouble(lc[7]);
            
            x1 -= xp;
            y1 -= yp;
            x2 -= xp;
            y2 -= yp;
            x3 -= xp;
            y3 -= yp;
            
            double a = x2*y3 - x3*y2;
            double b = x3*y1 - x1*y3;
            double c = x1*y2 - x2*y1;
            
            System.out.println(a*b>0 && a*c>0 ? "YES" : "NO");
        }
 
    }
}

Measured memory_bytes: 25140
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int n,m;
    cin>>n>>m;
    vector<priority_queue<ll>> vecque(8,priority_queue<ll>());
    rep(i,n){
        ll tmp[3];
        cin>>tmp[0]>>tmp[1]>>tmp[2];
        rep(j,8){
            bitset<(1<<4)> s(j);
            ll hoge=0;
            rep(k,3){
                if(s[k]){
                    hoge+=tmp[k]*-1;
                }else{
                    hoge+=tmp[k];
                }
            }
            vecque[j].push(hoge);
        }
    }
    ll ans=-INF*100000;
    rep(i,8){
        ll tmp=0;
        rep(j,m){
            ll hoge=vecque[i].top();
            vecque[i].pop();
            tmp+=hoge;
        }
        ans=max(ans,tmp);
    }
    O(ans);
    
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N;
    cin>>N;
    vector<double> p(N+1);
    for(int i=0;i<N;i++)cin>>p[i+1];

    vector< vector<double> > dp(N+1, vector<double>(N+1, 0));
    for(int i=1;i<=N;i++)dp[i][0]=1;
    double ans = 0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=dp[i][j-1]*p[j]+dp[i-1][j-1]*(1-p[j]);
            //cout<<dp[i][j]<<" ";
        }
    }
    printf("%.10lf\n",dp[1+N/2][N]);

    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX (int)1e+5

int N;
map<string, ll> a;

int main() {
    cin >> N;
    char s[15];

    for (int i=0; i<N; i++) {
        cin >> s;
        sort(s, s+10);
        if (a.find(s)==a.end()) a[s]=1;
        else a[s]++;
    }

    ll ans = 0;

    for (const auto x : a) {
        ans += (ll)x.second*(x.second-1)/2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 11136
// ===========================================
// 20.03.12
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=1; i<=n; i++)
#define rez(i,n) for(int i = 0; i<n; i++)
#define ET "\n"
#define CLR(arr) memset(&arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;
const int mini = 10e5+5;



int main(){
    
    int n; cin >> n;
    int maxWght; cin >> maxWght;
    
    
    int w[n+1];
    int v[n+1];
    rep(i,n) cin >> w[i] >> v[i];
    
    ll dp[maxWght+1]; CLR(dp);
    for(int i=1; i<=n; i++){
        for(int j=maxWght; j-w[i]>=0; j--){
            if(j-w[i] >= 0)
                dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
        }
    }
    cout << dp[maxWght];
}



Measured memory_bytes: 1024