akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   stack<int> S1;
   stack<pair<int, int> > S2;
   char ch;

   int sum = 0;
   for (int i=0; cin >> ch; i++){
      if (ch == '\\') S1.push(i);
      else if (ch=='/' && S1.size()>0){
         int j = S1.top(); S1.pop();
         sum += i - j;
         int a = i - j;
         while (S2.size() > 0 && S2.top().first > j){
            a += S2.top().second; S2.pop();
         }
         S2.push(make_pair(j, a));
      }
   }
   vector<int> ans;
   while (S2.size() > 0) {ans.push_back(S2.top().second); S2.pop();}
   reverse(ans.begin(), ans.end());
   cout << sum << endl;
   cout << ans.size();
   for(int i=0; i<ans.size(); i++){
      cout << " ";
      cout << ans[i];
   }
   cout << endl;

   return 0;
}



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

int main(){
  int n;

  while(cin >> n, n){
    string pre;
    cin >> pre;

    int cnt = 0;

    for(int i = 0; i < n - 1; i++){
      string s;
      cin >> s;

      if(pre == "lu" && s == "ru" ||
         pre == "ru" && s == "lu" ||
         pre == "ld" && s == "rd" ||
         pre == "rd" && s == "ld"){
        cnt++;
      }

      pre = s;
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll A, B, C, D;

int main(void) {
  cin >> A >> B >> C >> D;
  cout << max(min(B, D) - max(A, C), 0LL) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define MAX ((ll)(1e17+100))
#define MX ((ll)(1e5+100))
#define ARRS ((ll)(1e6+100))
#define ARS ((ll)(1e3+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;

ll n;
string s;
map<pair<string,string> ,ll> mp;

int main(){
	ll n;
	cin>>n;
	cin>>s;
	for(int t=0; t<(1<<n); t++){
		string f,e;
		f=e="";
		for(int i=0; i<n; i++){
			if((t>>i)&1)f+=s[i];
			else e+=s[i];
		}
		//reverse(e.begin(),e.end());
		//f+=e;
		mp[{f,e}]++;
	}
	ll pas=0;
	for(int t=0; t<(1<<n); t++){
		string f,e;
		f=e="";
		for(int i=0; i<n; i++){
			if((t>>i)&1)f+=s[2*n-i-1];
			else e+=s[2*n-i-1];
		}
		//reverse(e.begin(),e.end());
		//f+=e;
		pas+=mp[{f,e}];
	}
	cout<<pas;
}


Measured memory_bytes: 91904
#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 << "Right" << endl;
  }
  
  else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  
  else {
    cout << "Left" << endl;
  }
}

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

int divide_cnt(int n) {
  int ret = 0;
  while (true) {
    if (n % 2 != 0) break;
    ret++;
    n /= 2;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  int max = -10000000;
  int ret;
  for (int i = 1; i <= n; i++) {
    int cnt = divide_cnt(i);
    if (max < cnt) {
      max = cnt;
      ret = i;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n;
	string s;
	cin>>n>>s;
	ll x,y,z,ans=0;
	char xx,yy,zz;
	ll arr[n+1],brr[n+1],crr[n+1];
	for(int a=0;a<=n;a++)
	{
		arr[a]=brr[a]=crr[a]=0;
	}
	for(int a=n-1;a>=0;a--)
	{
		if(s[a]=='R')
		arr[a]=arr[a+1]+1;
		else
		arr[a]=arr[a+1];
		if(s[a]=='G')
		brr[a]=brr[a+1]+1;
		else
		brr[a]=brr[a+1];
		if(s[a]=='B')
		crr[a]=crr[a+1]+1;
		else
		crr[a]=crr[a+1];
	}
	for(int a=0;a<n;a++)
	{
		for(int b=a+1;b<n-1;b++)
		{
			if(s[a]==s[b])
			continue;
			else 
			{
				xx=s[a];
				yy=s[b];
				if(xx=='R'&&yy=='G')
				zz='B';
				else if(xx=='G'&&yy=='R')
				zz='B';
				if(xx=='R'&&yy=='B')
				zz='G';
				else if(xx=='B'&&yy=='R')
				zz='G';
				if(xx=='B'&&yy=='G')
				zz='R';
				else if(xx=='G'&&yy=='B')
				zz='R';
				if(zz=='R')
				{
					ans+=arr[b+1];
					if(b+b-a<n)
					{
						if(s[b+b-a]=='R')
						ans--;
					}
				}
				if(zz=='G')
				{
					ans+=brr[b+1];
					if(b+b-a<n)
					{
						if(s[b+b-a]=='G')
						ans--;
					}
				}
				if(zz=='B')
				{
					ans+=crr[b+1];
					if(b+b-a<n)
					{
						if(s[b+b-a]=='B')
						ans--;
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3684
N=int(input())
A=[]
B=[]
for i in range(N):
    Ai,Bi=map(int,input().split())
    A.append(Ai)
    B.append(Bi)
ans=0
for i in reversed(range(N)):
    ans+=(-(A[i]+ans))%B[i]
print(ans)

Measured memory_bytes: 11048
import java.util.Scanner;

// 8
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ab = Integer.valueOf(String.format("%d%d", a, b));
		
		int x = 1;
		String ans = "No";
		while (ab >= x*x) {
			if(ab == x*x) { 
				ans = "Yes";
				break;
			}
			++x;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35752
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
    int n,m,wa=0,ac=0;
    cin>>n>>m;
    vector<int> a(n,0),w(n,0);
    while(m--)
    {
        int que; string s;
        cin>>que>>s;
        if(s=="WA" && a[que-1]==0)
            w[que-1]++;
        else if(s=="AC" &&a[que-1]==0)
            a[que-1]++;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==1)
            ac++;
        if(w[i]>0 && a[i]!=0)
           wa+=w[i];
    }
    cout<<ac<<" "<<wa<<endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

N,Q = II()
A = III()
X = Line(Q,1)

if N==2:
    for _ in range(Q):
        print(A[-1])
    exit()

sum_list = [0]*N
now_odd = 0
now_even = 0
for i in range(N):
    if i%2==0:
        now_even += A[i]
        sum_list[i] = now_even
    else:
        now_odd += A[i]
        sum_list[i] = now_odd        

left_sum = [0]*N
now = 0
for i in range(N)[::-1]:
    now += A[i]
    left_sum[i] = now

for x in X:
    left = 0
    right = N//2
    while (right-left>1):
        mid = left + (right-left)//2
        if abs(A[N-mid-2]-x)<abs(A[N-2*mid-2]-x):
            right = mid
        else:
            left = mid
    right1 = right

    left = 0
    right = N//2 + 1
    while (right-left>1):
        mid = left + (right-left)//2
        if abs(A[N-mid-1]-x)<abs(A[N-2*mid-1]-x):
            right = mid
        else:
            left = mid
    right2 = right

    flag = False
    if right1 != right2:
        flag = True

    ans = left_sum[N-right2]

    if flag:
        if N-right1-right2-2>=0:
            ans += sum_list[N-right1-right2-2]
    else:
        if N-right1-right2-1>=0:
            ans += sum_list[N-right1-right2-1]
    print(ans)

Measured memory_bytes: 71848
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
tmp = 0
for i in range(N):
    tmp_mon = max(A[i] - tmp, 0)
    killed_mon = min(A[i], tmp)
    cnt += min(B[i], tmp_mon) + killed_mon

    if B[i] > tmp_mon:
        tmp = B[i] - tmp_mon
    elif B[i] <= tmp_mon:
        tmp = 0

cnt += min(A[-1], tmp)

print(cnt)

Measured memory_bytes: 18624
#include <utility>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int n;
int r[111111], c[111111];

struct uni {
  int a[111111];
  uni() { memset(a, -1, sizeof(a)); }
  int root(int p) {
    return a[p] < 0 ? p : (a[p] = root(a[p]));
  }
  bool find(int p, int q) {
    return root(p) == root(q);
  }
  void merge(int p, int q) {
    p = root(p);
    q = root(q);
    if (p == q) return;
    a[p] += a[q];
    a[q] = p;
  }
  int sz(int p) {return -a[root(p)];}
};

uni u1, u2;
bool used[111111];

int calc(uni& u) {
  int res = 0;
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++) {
    // printf("%d: %d %d\n", i, u.sz(i), u.root(i));
    if (!used[u.root(i)]) {
      res += u.sz(i) - 1;
      used[u.root(i)] = true;
    }
  }
  return res;
}

int rr[111111], cc[111111];
pair<int, int> aa[111111], bb[111111];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", r+i, c+i);
    aa[i] = {r[i], c[i]};
    bb[i] = {c[i], r[i]};
  }

  sort(aa, aa + n);
  sort(bb, bb + n);
  for (int i = 0; i < n; i++) {
    u1.merge(i, bb[i].second - 1);
    u2.merge(i, aa[i].second - 1);
    rr[r[i]] += 1;
    cc[c[i]] += 1;
  }

  for (int i = 1; i <= n; i++) {
    if (rr[i] != 1 || cc[i] != 1) {
      puts("-1");
      return 0;
    }
  }

  int res1 = calc(u1);
  int res2 = calc(u2);
  printf("%d\n", min(res1, res2));
  return 0;
}



Measured memory_bytes: 7624
// 8/2 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    queue<int> white, red;

    // cout << N << endl;
    // cout << c << endl;

    rep(i, N) {
        if (c[i] == 'W') {
            // cout << "here?1" << endl;
            white.push(i);
        }
    }
    for (int i = N-1; i >= 0; i--) {
        if (c[i] == 'R') {
            // cout << "here?2" << endl;
            red.push(i);
        }
    }

    int ans = 0;

    while (!white.empty() && !red.empty()) {
        // cout << "here?" << endl;
        int w = white.front();
        int r = red.front();
        // printf("w, r = %d, %d\n", w, r);
        white.pop();
        red.pop();
        if (w < r) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4388
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()

	// dp[i][j] は i個の数列で状態jである個数
	// j == 0 0も9も含まない

	dp := make([][]mint, N+10)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]mint, 4)
	}
	dp[0][0] = 1
	n10 := mint(10)
	n9 := mint(9)
	n8 := mint(8)

	for i := 1; i <= N; i++ {
		dp[i][0] = dp[i-1][0].mul(n8)
		dp[i][1] = dp[i-1][1].mul(n9).add(dp[i-1][0])
		dp[i][2] = dp[i-1][2].mul(n9).add(dp[i-1][0])
		dp[i][3] = dp[i-1][3].mul(n10).add(dp[i-1][1]).add(dp[i-1][2])
	}

	fmt.Println(dp[N][3])
}

type mint int64

var mod = mint(1e9 + 7)

// add は a + bを返します
func (a mint) add(b mint) mint {
	return (a + b) % mod
}

// sub は a - bを返します
func (a mint) sub(b mint) mint {
	return (a - b + mod) % mod
}

// mul は a * bを返します
func (a mint) mul(b mint) mint {
	return (a * (b % mod)) % mod
}

// div は a/bを返します
func (a mint) div(b mint) mint {
	return a.mul(b.inv())
}

// inv は aの逆元を返します
func (a mint) inv() mint {
	// 拡張ユークリッドの互除法
	b := mod
	u := mint(1)
	v := mint(0)
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	return (u + mod) % mod
}

// pow は a ^ bを返します
func (a mint) pow(b mint) mint {
	ans := mint(1)

	for b != 0 {
		if b&1 == 1 {
			ans = ans.mul(a)
		}
		a = a.mul(a)
		b = b >> 1
	}
	return ans
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args...)
}


Measured memory_bytes: 59168
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

long calc(long x, long y) {
    if (x % y == 0) return -1;
    for (int i = 2; ; i++) {
        if (y % i != 0)
            return x * i;
    }
}

void main() {
    auto xy = readints;
    int x = xy[0], y = xy[1];
    writeln(calc(x, y));
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
 
public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
    } 
    public static void main (String[] args) 
	{
        //code by sushant kumar
        FastReader in=new FastReader();
        int n=in.nextInt();
        int m=in.nextInt();
        long k=in.nextLong();
        long a[]=new long[n+1];
        long b[]=new long[m+1];

        for(int i=1;i<n+1;i++)
        {
            
            a[i]=in.nextLong()+a[i-1];
        }
        for(int i=1;i<m+1;i++)
        {
            
            b[i]=in.nextLong()+b[i-1];
        }
        long ans=0; int j=m;
        for(int i=0;i<n+1;i++)
        {
            if(a[i]>k)
                break;
            while(a[i]+b[j]>k)
                j--;
            ans=Math.max(ans,i+j);
        }
        System.out.println(ans);

    

       
    }
}

Measured memory_bytes: 67944
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include <iomanip>

using namespace std;

int factorial(int n)
{
    if(n==1)return 1;
    return factorial(n-1)*n;
}

int main()
{
    int n;
    cin>>n;
    vector< vector<int> > array(n,vector<int>(2,0));
    vector<int> index(n,0);
    for (int i = 0; i < n; i++)
    {
        index[i]=i;
    }
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin>>array[i][j];
        }
    }

    
    double sum=0;
    do
    {
        for (int i = 0; i < n-1; i++)
        {
            int x=abs(array[index[i]][0]-array[index[i+1]][0]);
            int y=abs(array[index[i]][1]-array[index[i+1]][1]);
            sum+=sqrt(pow(x,2)+pow(y,2));
        } 
    }while(next_permutation(index.begin(),index.end()));
    
    cout << std::fixed << std::setprecision(10) <<sum/factorial(n);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

vector<pair<ll, ll>> fac_v;
ll fac_size = 0;
ll ans = 1;
ll M, N;
auto check = [&](ll n) {
	//std::cerr << "checking: " << n << std::endl;
	if (M / n >= N && M % n == 0) {
		ans = max(ans, n);
	}
};
void dfs(ll n_bef, ll depth) {
	if (depth == fac_size) {
		check(n_bef);
	} else {
		auto fac_e = fac_v[depth];
		ll tmp = 1;
		for (ll i = 0; i <= fac_e.second; ++i) {
			dfs(n_bef * tmp, depth + 1);
			//std::cerr << "[" << depth << "]" << n_bef << " * " << tmp << endl;
			tmp *= fac_e.first;
		}
	}
}
int main() {
	cin >> N >> M;
	ll M2 = M;
	map<ll, ll> fac;
	for (ll n = 2; n*n <= M2;) {
		if (M2%n == 0) {
			++fac[n];
			M2 /= n;
		}
		else ++n;
	}
	if(M2 != 1)
		++fac[M2];
	fac_v.reserve(fac.size());
	for (const auto& f : fac) {
		fac_v.push_back(f);
		//std::cerr << "push_back: " << f.first << " ^ " << f.second << endl;
	}
	fac_size = fac_v.size();
	dfs(1, 0);
	check(M);
	/*auto check = [&](ll n) {
		auto M_n = M/n;
		if (M % n == 0 && M_n >= N) {
			if (max < M_n)
				max = M_n;
		}
	};*/
	/*ll ans = 1;
	auto check = [&](ll n) {
		if (M / n >= N && M % n == 0) {
			ans = max(ans, n);
		}
	};
	for (ll n = 1; n*n <= M; ++n) {
		check(n);
	}
	check(M);*/
	out(ans);

	return 0;
}


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


int main() {
    int i, j, d[7], d_next[7], num, top, front;

    cin >> d[1] >> d[2] >> d[3] >> d[4] >> d[5] >> d[6];
    cin >> num;

    for(i=0;i<num;i++){
        cin >> top >> front;
        if (top == d[1]){
            if(front == d[2]){
                cout << d[3] << endl;
            }else if(front == d[3]){
                cout << d[5] << endl;
            }else if(front == d[5]){
                cout << d[4] << endl;
            }else if(front == d[4]){
                cout << d[2] << endl;
            }
        }else if(top == d[2]){
            if(front == d[6]){
                cout << d[3] << endl;
            }else if(front == d[3]){
                cout << d[1] << endl;
            }else if(front == d[1]){
                cout << d[4] << endl;
            }else if(front == d[4]){
                cout << d[6] << endl;
            }
        }else if(top == d[3]){
            if(front == d[1]){
                cout << d[2] << endl;
            }else if(front == d[2]){
                cout << d[6] << endl;
            }else if(front == d[6]){
                cout << d[5] << endl;
            }else if(front == d[5]){
                cout << d[1] << endl;
            }
        }else if(top == d[4]){
            if(front == d[2]){
                cout << d[1] << endl;
            }else if(front == d[1]){
                cout << d[5] << endl;
            }else if(front == d[5]){
                cout << d[6] << endl;
            }else if(front == d[6]){
                cout << d[2] << endl;
            }
        }else if(top == d[5]){
            if(front == d[1]){
                cout << d[3] << endl;
            }else if(front == d[3]){
                cout << d[6] << endl;
            }else if(front == d[6]){
                cout << d[4] << endl;
            }else if(front == d[4]){
                cout << d[1] << endl;
            }
        }else if(top == d[6]){
            if(front == d[3]){
                cout << d[2] << endl;
            }else if(front == d[2]){
                cout << d[4] << endl;
            }else if(front == d[4]){
                cout << d[5] << endl;
            }else if(front == d[5]){
                cout << d[3] << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3052
#include <stdio.h>

int main(void)
{
    int i, p, m, s;
    
    scanf("%d", &m);
    for (i = 0; i < 2; i++) {
        scanf("%d", &p);
        if (p < m)
            m = p;
    }
    
    s = m;
    
    scanf("%d", &m);
    for (i = 0; i < 1; i++) {
        scanf("%d", &p);
        if (p < m)
            m = p;
    }
    
    s += m - 50;
    
    printf("%d\n", s);
    
    return 0;
}

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

#define esp 1e-9

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	long long int nn=n;
	long long int ans=0;
	while(nn--){
		long long int x;
		cin>>x;
		ans+=x;
	}
	cout<<ans-n;
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
char hantei(char);

int n;
char chana[1000],chanb[1000];


int main(){
  int i,j,m;
  char w;

  while(1){
    scanf("%d",&n);
    if(n==0)break;

    for(i=0;i<n;i++){
      scanf(" %c %c",&chana[i],&chanb[i]);
    }


    scanf("%d",&m);
    for(j=0;j<m;j++){
      scanf(" %c",&w);
      printf("%c",hantei(w));
    }
    printf("\n");
    
  }
  return 0;
}

char hantei(char w){
  int i;                        
  for(i=0;i<n;i++){
    if(w==chana[i])return chanb[i];
  }
  return w;
}

Measured memory_bytes: 0
#B
S = input()
n = len(S)
a = list(S)
reva = a[n::-1]
sub1 = a[0:(int((n-1)/2))]
sub2 = a[int((n+3)/2-1):]
if a == reva and sub1 == sub1[len(sub1)::-1] and sub2 == sub2[len(sub2)::-1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M, X;
    cin >> N >> M >> X;

    vi C(N), A[N];
    REP(i, N) {
        cin >> C[i];
        REP(j, M) {
            int a; cin >> a;
            A[i].pb(a);
        }
    }

    ll c_min = INF;
    REP(b, 1 << N) {
        vi v(M, 0);

        ll c = 0;
        REP(j, N) {
            if (b >> j & 1) {
                REP(k, M) {
                    v[k] += A[j][k];
                }

                c += C[j];
            }
        }

        bool f = true;
        REP(j, M) {
            if (v[j] < X) f = false;
        }

        if (f) c_min = min(c_min, c);
    }

    if (c_min == INF) print(-1);
    else print(c_min);
}


Measured memory_bytes: 3664
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		Set<Integer> paintCans = new HashSet<Integer>();
		paintCans.add(scan.nextInt());
		paintCans.add(scan.nextInt());
		paintCans.add(scan.nextInt());

		System.out.println(paintCans.size());
	}

}

Measured memory_bytes: 22612
#include<iostream>
#include<vector>
#include<algorithm>
#define inf 1000000009
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> dp(n,inf);
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		if(i+1<n){
			dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
		}
		if(i+2<n){
			dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
		}
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using lint = long long;

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

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.begin(), xs.end());

    int ok = n - 1, ng = -1;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;

        lint sz = std::accumulate(xs.begin(), xs.begin() + mid + 1, 0LL);
        bool judge = true;
        for (int i = mid + 1; i < n; ++i) {
            if (xs[i] > sz * 2) {
                judge = false;
                break;
            }
            sz += xs[i];
        }

        (judge ? ok : ng) = mid;
    }

    std::cout << n - ok << std::endl;
    return 0;
}


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

struct RollingHash {
    const int base = 10007;
    static const int M = 2;
    const vector<int> mod = {999999937, 1000000007};
    vector<long long> hash[M], power[M];
    RollingHash(const string &s, int base = 9973) : base(base) {
        int n = s.size();
        for (int iter = 0; iter < M; iter++) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            for (int i = 0; i < n; ++i) {
                hash[iter][i + 1] = (hash[iter][i] * base + s[i]) % mod[iter];
                power[iter][i + 1] = power[iter][i] * base % mod[iter];
            }
        }
    }
    long long get(int l, int r, int id = 0) {   // [l, r)
        long long ret = hash[id][r] - hash[id][l] * power[id][r - l] % mod[id];
        return ret < 0 ? ret + mod[id] : ret;
    }
};
bool match(RollingHash &rh1, int s1, RollingHash &rh2, int s2, int len) {
    for (int iter = 0; iter < RollingHash::M; iter++)
        if (rh1.get(s1, s1 + len, iter) != rh2.get(s2, s2 + len, iter))
            return false;
    return true;
}

vector<vector<int>> divisors_table(int n) {     // except for n
    vector<vector<int>> divisors(n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = i + i; j <= n; j += i) divisors[j].emplace_back(i);;
    }
    return divisors;
}

int main() {
    string s; cin >> s;
    int n = s.length();
    if (s == string(n, s[0])) return !(cout << n << endl << 1 << endl);
    RollingHash rh(s);
    auto ds = divisors_table(n);
    auto check = [&](int l, int r) {
        int len = r - l;
        for (int d: ds[len]) if (match(rh, l, rh, l + d, len - d)) return false;
        return true;
    };
    if (check(0, n)) return !(cout << 1 << endl << 1 << endl);
    int cnt = 0;
    for (int i = 1; i < n; i++) cnt += check(0, i) && check(i, n);
    cout << 2 << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 74008
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

vector <vector <int>> g, ids;

void dfs(int nod, int par, int e) {
	ids[e].push_back(nod);
	for(auto it : g[nod]) {
		if(it != par) {
			dfs(it, nod, e ^ 1);
		}
	}
}

int main() {
#ifdef HOME
	ifstream cin("C.in");
	ofstream cout("C.out");
#endif
	int i, n;
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	g.resize(n + 1);
	for(i = 1; i < n; i++) {
		int x, y; cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	ids.resize(2);
	dfs(1, 0, 0);
	if(ids[0].size() > ids[1].size()) {
		swap(ids[0], ids[1]);
	}

	vector <int> cnt(3), sol(n + 1);
	for(i = 1; i <= n; i++) {
		cnt[i % 3]++;
	}

	if(ids[0].size() <= cnt[0]) {
		for(i = 0; i < ids[0].size(); i++) {
			sol[ids[0][i]] = 3 * cnt[0];
			cnt[0]--;
		}
		
	}
	else {
		for(i = 0; i < ids[0].size(); i++) {
			if(cnt[2] > 0) {
				cnt[2]--;
				sol[ids[0][i]] = 3 * cnt[2] + 2;
			}
			else {
				sol[ids[0][i]] = 3 * cnt[0];
				cnt[0]--;
			}
		}
	}
	for(i = 1; i <= n; i++) {
		if(sol[i]) continue;
		for(int j = 0; j < 3; j++) {
			if(cnt[j]) {
				sol[i] = j + (cnt[j] - (j > 0)) * 3;
				cnt[j]--;
				break;
			}
		}
	}

	for(i = 1; i <= n; i++) {
		cout << sol[i] << " ";
	}

	return 0;
}



Measured memory_bytes: 20596
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1] * W[l] % p)
        
        for i in range(1 << k - l):
            for j in range(d):
                s = i * 2 * d + j
                f[s], f[s+d] = (f[s] + f[s+d]) % p, U[j] * (f[s] - f[s+d]) % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1] * iW[l] % p)
        
        for i in range(1 << k - l):
            for j in range(d):
                s = i * 2 * d + j
                f[s+d] *= U[j]
                f[s], f[s+d] = (f[s] + f[s+d]) % p, (f[s] - f[s+d]) % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print(*convolve(A, B))


Measured memory_bytes: 204560
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long h = sc.nextLong();
        long w = sc.nextLong();

        if (h == 1 || w == 1) {
            System.out.println(1);
            System.exit(0);
        }

        long ans = h * (w / 2);
        if (w % 2 == 1) {
            if (h % 2 == 0)
                ans += h / 2;
            else
                ans += h / 2 + 1;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] str = stdR.readLine().split(" ");
        long K = Long.parseLong(str[0]);
        long A = Long.parseLong(str[1]);
        long B = Long.parseLong(str[2]);
        if(A + 1 < B) {
            if(K <= A) {
                System.out.println(K + 1);
            }else {
                K = K - A + 1;
                System.out.println(A + (B - A) * (K / 2) + K % 2);
            }
        }else {
            System.out.println(1 + K);
        }
    }
}


Measured memory_bytes: 22612
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

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;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;

void solve(){
		int n,m;
		cin>>n>>m;
		if(n>0)n--;
		if(m>0)m--;
		int sum=0;
		while(n!=0){
			sum+=n;
			n--;
		}
		while(m!=0){
			sum+=m;
			m--;
		}
		cout<<sum;
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    string s; cin>>s;

    ll ans = 1;
    ll rcnt = 0, gcnt = 0, bcnt = 0;
    ll premin = 1, premid = 1, premax = 1;
    for(int i=0; i<3*n; i++){
        rcnt += (s[i] == 'R');
        gcnt += (s[i] == 'G');
        bcnt += (s[i] == 'B');

        vector<ll> cnt;
        cnt.emplace_back(rcnt);
        cnt.emplace_back(gcnt);
        cnt.emplace_back(bcnt);
        sort(cnt.begin(), cnt.end());

        ll cntmin = cnt[0], cntmid = cnt[1], cntmax = cnt[2];
        
        if(premin < cntmin){
            ans *= (cntmid - cntmin + 1);
            ans %= MOD;
        }

        if(premid < cntmid){
            ans *= (cntmax - cntmid + 1);
            ans %= MOD;
        }

        if(0 < cntmin){
            rcnt--, bcnt--, gcnt--;
            cntmin--, cntmid--, cntmax--;
        }

        premin = cntmin;
        premid = cntmid;
        premax = cntmax;
    }

    for(ll i=1; i<=n; i++){
        ans *= i;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
A = input()
import collections
a_frq_dict = collections.Counter(A)

n_all = len(A) * (len(A)-1) * 0.5 + 1
n_duplication = 0
for frq in a_frq_dict.values():
    n_duplication += frq * (frq-1) * 0.5

print(int(n_all - n_duplication))
# print(n_all, n_duplication)



Measured memory_bytes: 40176
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

ll dp[11][11];
ll dq[11];

void f(int i, int k, int p)
{
    //cout << i _ k << endl;
    if (i == 0)
        return;

    int sum = 0;
    if (p == -1)
    {
        for (int j = 1; j < 10; ++j)
        {
            if (sum + dp[i][j] >= k)
            {
                cout << j;
                f(i - 1, k - sum, j);
                return;
            }
            sum += dp[i][j];
        }
    }
    else
    {
        for (int j = max(0, p - 1); j <= min(9, p + 1); ++j)
        {
            if (sum + dp[i][j] >= k)
            {
                cout << j;
                f(i - 1, k - sum, j);
                return;
            }
            sum += dp[i][j];
        }
    }
}

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

    for (int i = 0; i < 10; ++i)
        dp[1][i] = 1;

    dq[1] = 9;
    for (int i = 2; i <= 10; ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            dp[i][j] = (j == 0 ? 0 : dp[i - 1][j - 1]) + dp[i - 1][j] + dp[i - 1][j + 1];
            if (j) dq[i] += dp[i][j];
        }
    }


    int sum = 0;
    for (int i = 1; i <= 10; ++i)
    {
        if (sum + dq[i] >= k)
        {
            f(i, k - sum, -1);
            return 0;
        }
        sum += dq[i];
    }
}


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

static const int N = 100;
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;

int nt[N];

int next(int u) {
  for (int v = nt[u]; v < n; v++) {
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
};

void dfs_visit(int r) {
  for (int i = 0; i < n; i++) {
    nt[i] = 0;
  }
  stack<int> S;
  S.push(r);
  color[r] = gray;
  d[r] = ++tt;

  while(!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == white) {
        color[v] = gray;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = black;
      f[u] = ++tt;
    }
  }
};

void dfs() {
  for (int i = 0; i < n; i++) {
    color[i] = white;
    nt[i] = 0;
  }
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == white) dfs_visit(u);
  }
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }
};

int main() {
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
};



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

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

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

int main(void)
{
  ll n;
  cin >> n;
  vector<ll> P(n);
  rep(i, n) cin >> P[i];
  ll ans = 0;
  ll m = 2 * n;
  rep(i, n)
  {
    auto x = P[i];
    if (m > x)
    {
      ans++;
      m = x;
    }
  }

  cout << ans << endl;

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

Measured memory_bytes: 1792
#include <stdio.h>
char st[100010];
int main()
{
  int n,k;scanf("%d%d",&n,&k);
  scanf("%s",st+1);
  int tmp=0;st[0]='R';st[n+1]='L';
  for (int i=1;i<=n;++i)
  {
    if (st[i]=='L' && st[i-1]=='L') ++tmp;
    if (st[i]=='R' && st[i+1]=='R') ++tmp;
  }
  tmp+=k*2;
  if (tmp>n-1) tmp=n-1;
  printf("%d\n",tmp);
}

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

using namespace std;

typedef long long ll;
int n;
int arr[100100];
int ord[100100];
ll tim[100100];
bool cmp(int a, int b) {return arr[a]>arr[b]||(arr[a]==arr[b]&&a<b);}

int main() {
    int i, mdx;
    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%d",&arr[i]);
    for (i=0;i<n;i++) ord[i] = i;
    sort(ord,ord+n,cmp);
    ord[n] = n;
    mdx = ord[i];
    for (i=0;i<n;i++) {
        mdx = min(mdx,ord[i]);
        tim[mdx] += 1LL*(arr[ord[i]]-arr[ord[i+1]])*(i+1);
    }
    for (i=0;i<n;i++) printf("%lld\n",tim[i]);

    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string N;cin >> N;
    bool ok = false;
    if(N[0] == '7')ok = true;
    if(N[1] == '7')ok = true;
    if(N[2] == '7')ok = true;
    if(ok)cout << "Yes" << endl;
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int[][] sheet = new int[n][n];
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					sheet[i][j] = scan.nextInt();
				}
			}
			int[] row = new int[n];
			int[] col = new int[n];
			int sum = 0;
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					sum += sheet[i][j];
					row[i] += sheet[i][j];
					col[j] += sheet[i][j];
				}
			}
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					System.out.printf("%5d",sheet[i][j]);
				}
				System.out.printf("%5d\n",row[i]);
			}
			for(int i = 0;i < n;i++){
				System.out.printf("%5d",col[i]);
			}
			System.out.printf("%5d\n",sum);
		}
	}
}

Measured memory_bytes: 24248
#include<stdio.h> 
#include<stdlib.h> 
#include<math.h> 
int main() 
 { 
    long long a,b,c,k,sum=0;        scanf("%lld%lld%lld%lld",&a,&b,&c,&k); 
    if(a>=k)
    printf("%lld",k);
    else if(a+b>=k)
    printf("%lld",a);
     else 
    { k=k-(a+b); 
        sum=a-k; 
        printf("%lld",sum); 
        } 
    return 0;
  } 




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

using namespace std;

const int vy[] = {0, 1, 0, -1}, vx[] = {-1, 0, 1, 0};

int W, H, S;
string M[50], MS[10][50];
int bit[50][50], v[2][50][50][1 << 10];
int mov[50][50];

int Solve()
{
  memset(v, -1, sizeof(v));
  for(int k = 0; k < S; k++) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(MS[k][i][j] == '*') bit[j][i] |= 1 << k;
      }
    }
  }
  queue< tuple< int, int, int, int > > que;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      switch(M[i][j]) {
        case '|':
          mov[j][i] = 3;
          break;
        case '_':
          mov[j][i] = 1;
          break;
        case '^':
          mov[j][i] = 2;
          break;
        case 'a' ... 'j':
          mov[j][i] = 1;
          M[i][j] -= 'a';
          break;
        case 'A' ... 'J':
          mov[j][i] = 2;
          M[i][j] -= 'A';
          break;
        case '%':
          que.emplace(0, j, i, 0);
          v[0][j][i][0] = 0;
          mov[j][i] = 1;
          break;
        case '&':
          mov[j][i] = 1;
          break;
        default:
          mov[j][i] = 0;
          break;
      }
    }
  }

  while(!que.empty()) {
    int f, x, y, button;
    tie(f, x, y, button) = que.front();
    que.pop();
    if(M[y][x] == '&') {
      return (v[f][x][y][button]);
    } else if(M[y][x] == '|') {
      int nf = f ^ 1;
      if(v[nf][x][y][button] == -1) {
        v[nf][x][y][button] = v[f][x][y][button] + 1;
        que.emplace(nf, x, y, button);
      }
    } else if(M[y][x] < 10) {
      int nbutton = button ^ (1 << M[y][x]);
      int nf = (f + (MS[M[y][x]][y][x] == '*')) & 1;
      if(v[nf][x][y][nbutton] == -1) {
        v[nf][x][y][nbutton] = v[f][x][y][button] + 1;
        que.emplace(nf, x, y, nbutton);
      }
    }
    for(int i = 0; i < 4; i++) {
      int nx = x + vx[i], ny = y + vy[i];
      int isgo = (f + __builtin_popcount(bit[nx][ny] & button)) & 1;
      if(v[f][nx][ny][button] == -1 && (mov[nx][ny] & ++isgo)) {
        v[f][nx][ny][button] = v[f][x][y][button] + 1;
        que.emplace(f, nx, ny, button);
      }
    }
  }
  return (-1);
}

int main()
{
  cin >> W >> H;
  for(int i = 0; i < H; ++i) {
    cin >> M[i];
  }
  cin >> S;
  for(int i = 0; i < S; i++) {
    for(int j = 0; j < H; j++) {
      cin >> MS[i][j];
    }
  }
  cout << Solve() << endl;
}

Measured memory_bytes: 23708
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int N, M, C;
    std::cin >> N >> M >> C;

    std::vector<int> B(M);
    for (int i = 0; i < M; ++i) {
        std::cin >> B[i];
    }

    int ret = 0;
    for (int i = 0; i < N; ++i) {
        std::vector<int> A(M);
        for (int j = 0; j < M; ++j) {
            std::cin >> A[j];
        }

        const auto val = std::inner_product(
            A.cbegin(), A.cend(), B.cbegin(), 0
        );

        if (val + C > 0) { ++ret; }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256