akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
s = input()
if n == 1:
    print(1)
if n != 1:
    nums = []
    cnt = 1
    for i in range(1, n):
        if s[i - 1] != s[i]:
            nums.append([s[i - 1], cnt])
            cnt = 1
            if i == n - 1:
                nums.append([s[i], cnt])
        else:
            cnt += 1
            if i == n - 1:
                nums.append([s[i - 1], cnt])

    candi = 0
    ansli = []
    p = 0
    for i in range(len(nums)):
        if nums[i][0] == "0":
            p += 1
    k = min(k, p)

    i1 = 0
    j1 = 0
    while i1 <= k and j1 < len(nums):
        if i1 == k and nums[j1][0] == "0":
            pass
        else:
            candi += nums[j1][1]
        if nums[j1][0] == "0":
            i1 += 1
        j1 += 1
    ansli.append(candi)
    if candi == n:
        print(n)
        exit()

    a = 0
    b = j1 - 1
    while b < len(nums):
        for i in range(2):
            if nums[a + i][0] == "1":
                candi -= nums[a + i][1]
            elif nums[a + i][0] == "0":
                candi -= nums[a + i][1]
                a += i + 1
                break
        for i in range(2):
            if b + i >= len(nums):
                ansli.append(candi)
                b += 1
                break
            else:
                if nums[b + i][0] == "1":
                    candi += nums[b + i][1]
                    b += i + 1
                    ansli.append(candi)
                    break
                elif nums[b + i][0] == "0":
                    candi += nums[b + i][1]

    print(max(ansli))

Measured memory_bytes: 15076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	int dp[310000];
const int N = 1e7 + 5;int f[N];
	void solve(){

		
		ini(n);
		map<int,int>map1;
		int tmp = 0;
		FOR(i,1,n+1){
			for(int i1 = i;i1<=n;i1+=i){
				f[i1]++;
			}
			tmp+=f[i]*i;
		}





		out(tmp);
		
		


			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 81712
from collections import defaultdict

N, M = map(int, input().split())
AB = []
d = defaultdict(set)
for _ in range(M):
    a, b = list(map(int, input().split()))
    d[a].add(b)
    d[b].add(a)
    AB.append([a, b])

ans = [0] * N
ans[0] = -1
a = [1]
dis_to_goal = [0] * N
dis_to_goal[0] = 0
dis = 0
mem = set()
while True:
    b = []
    dis += 1
    for k in a:
        if k in mem:
            continue
        mem.add(k)
        for n in d[k]:
            if ans[n - 1] == 0:
                ans[n - 1] = k
                dis_to_goal[n - 1] = dis
                b.append(n)
    if len(mem) == N:
        break
    a = b.copy()

#print(ans)
#print(dis_to_goal)

for i, u in enumerate(ans[1:]):
    if dis_to_goal[i+1] - dis_to_goal[u-1] == 1:
        continue
    else:
        print('No')
        exit()
print('Yes')
for k in ans[1:]:
    print(k)


Measured memory_bytes: 91328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc147_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int sum = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != s[s.Length - i - 1])
                {
                    sum = sum + 1;
                }
            }

            Console.WriteLine(sum / 2);

            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
n, a = map(int, input().split())
x = list(map(int, input().split()))
#dp[i][j] := iの数字まで考えたとき、jの数字になる個数
max_s = sum(x)
dp = [[[0 for i in range(max_s + 1)] for j in range(n+1)] for k in range(len(x) + 1)]
#init
dp[0][0][0] = 1
dp[1][0][0] = 1
for i in range(1,n+1):
    num = x[i-1]
    for j in range(len(x)+1):
        for k in range(max_s + 1):
            if k - num < 0:
                dp[i][j][k] = dp[i-1][j][k]
            else:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-num]
ans = 0
for i in range(len(x)+1):
    if i * a <= max_s+1:
        ans += dp[-1][i][i*a]
print(ans-1)


Measured memory_bytes: 96348
#include <stdio.h>
int main(void)
{
    int x, y, menseki, syu;
    
    scanf("%d %d", &x, &y);
    menseki = x*y;
    syu = (x*2)+(y*2);
    printf("%d %d\n", menseki, syu);
    
    return 0;
}


Measured memory_bytes: 2048
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 

'''
#------------------PYPY FAst I/o--------------------------------#
 
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#
 
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))



def main():
    try:
        a,b,c,d=In()
        if a>=d:
            print(d)
        elif a+b>=(d):
            print(a)
        elif a+b+c>=d:
            a-=(d-b-a)
            print(a)
        else:
            print(a-c)
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    for _ in range(1):
        main()

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

bool prime(int x){
    if(x<=1){
        return false;
    }else if(x == 2){
        return true;
    }else if(x%2 == 0){
        return false;
    }else{
        for(int i=3;i*i<=x;i++){
            if(x%i==0){
                return false;
                break;
            }
        }
    return true;    
    }
}

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int res = 0;
    for(int i=0; i<n; i++){
        if(prime(a[i])){
            res ++;
        }
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

void inti(vector<int64_t> &sp, const string &str) {
	int64_t h = 0;
	sp[0] = h; 
	for (size_t i = 1; i < sp.size(); i++) {
		if (str[i - 1] == '\\')		h--;	//Down
		else if (str[i - 1] == '/')	h++;	//Up
		sp[i] = h;
	}
}

int64_t calcPuddleArea(const size_t pos_begin,const size_t pos_end,const vector<int64_t> &sp) {
	int64_t area = 0;
	for (size_t i = pos_begin; i < pos_end; i++) {
		area += ((sp[pos_begin] - sp[i]) + (sp[pos_begin] - sp[i + 1])) * 1;
	}
	return area/2 ;
}

void search(const vector<int64_t> &sp, vector<int64_t> &puddle) {
	size_t pos_begin = 0;
	size_t pos_end;
	while (pos_begin < sp.size() - 1) {
		if (sp[pos_begin] > sp[pos_begin + 1]) {
			for (pos_end = pos_begin + 1;pos_end < sp.size(); pos_end++) {
				if (sp[pos_end] == sp[pos_begin]) {
					break;
				}
			}

			if (pos_end != sp.size()) {
				puddle.push_back(calcPuddleArea(pos_begin, pos_end, sp));
				pos_begin = pos_end;
			}
			else {
				pos_begin++;
			}
		}
		else {
			pos_begin++;
		}
	}
}

void print(const vector<int64_t> &puddle) {
	int64_t sum_area = 0;
	for (size_t i = 0; i < puddle.size(); i++) {
		sum_area += puddle[i];
	}
	cout << sum_area << endl << puddle.size();
	for (size_t i = 0; i < puddle.size(); i++) {
		cout << " " << puddle[i];
	}
	cout << endl;
}

int main() {
	string str;
	vector<int64_t> sp;
	vector<int64_t> puddle;

	cin >> str;
	sp.resize(str.size() + 1);

	inti(sp, str);
	search(sp, puddle);
	print(puddle);

	return 0;
}

Measured memory_bytes: 3228
D = int(input())
N = 26
c = [int(i) for i in input().split()]
last = [0 for i in range(N)]

for i in range(D):
  s_d = [int(j) for j in input().split()]
  d_score = -1
  ans = -1
  for j in range(N):
    last_day = i + 1 - last[j]
    arg = s_d[j] + c[j]*last_day
    if d_score < arg:
      d_score = arg
      ans = j+1
  print(ans)
  
  last[ans-1] = i+1


Measured memory_bytes: 9148
#include<iostream>
#include<stdio.h>

using namespace std;
int main(){
int a,b,c,d,h,i;
char e,g,f;
while(scanf("%d%c%c%c%d",&a,&c,&g,&d,&b)){
      if(g == '?'){
           return 0;
      }
      else if(g == '+'){
         c=a+b;
         cout<<c<<endl;
      }
      else if(g == '-'){
          d=a-b;
          cout<<d<<endl;
      }
      else if(g == '*'){
           h=a*b;
           cout<<h<<endl;
      }
      else if(g == '/'){
           i=a/b;
           cout<<i<<endl;
      }
      }
}

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

int main() {
	// your code goes here
    int h,w,k,i,j,s[305][305]={0},a[305][305],pb=1,ha=0;
    bool ex=false;
    char ss[305];
    cin >> h >> w >> k;
    for(i=1;i<=h;i++){
        cin >> ss;
        for(j=0;j<w;j++){
            if(ss[j]=='#') s[i][j+1]=1;
        }
    }
    for(i=1;i<=h;i++){
        int ko=0;
        for(j=1;j<=w;j++){
            if(s[i][j]==1) ko++;
        }
        if(ko!=0){
            if(!ex) ha=i;
            ex=true;
        }
        if(ko!=0){
            int koo=0;
            for(j=1;j<=w;j++){
               if(s[i][j]==1){
                    koo++;
                    a[i][j]=pb;
                    if(koo!=ko) pb++;
               } else {
                   a[i][j]=pb;
               }
            }
            pb++;
        } else if(ex){
            for(j=1;j<=w;j++){
                a[i][j]=a[i-1][j];
            }
        }
    }
    for(i=1;i<ha;i++){
        for(j=1;j<=w;j++) a[i][j]=a[ha][j];
    }
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            cout << a[i][j];
            if(j!=w) cout << " ";
            else cout << endl;
        }
    }
	return 0;
}

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

typedef long long int ll;

int main(){

    ll n;
    cin >> n;
    vector<ll> a(n+10);
    a[0] = 2;
    a[1] = 1;
    for(int i = 2;i <= n;i++){
        a[i] = a[i-1]+a[i-2];
    }
    cout << a[n] << endl;
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n; cin >> n;
    V<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    int ans = 0;
    for(int i = 0; i < n; i++){
        while(i + 1 < n && v[i] == v[i + 1]) i++;

        if(i + 1 < n && v[i] < v[i + 1]){
            while(i + 1 < n && v[i] <= v[i + 1]) i++;
        }
        else if(i + 1 < n && v[i] > v[i + 1]){
            while(i + 1 < n && v[i] >= v[i + 1]) i++;
        }
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4048
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(c: "List[List[int]]"):
    print(YES if all(
        c[i][j] == c[0][j] + c[i][0] - c[0][0]
        for i in range(1, 3)
        for j in range(1, 3)
    ) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    c = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    solve(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <istream>
#include <fstream>
#include <sstream>
#include <cstdlib>
using namespace std;
 
int main()
{
	vector<int> a;
	int s[4];
	int m=0;
	int min=0;
	int i;
	int j;
	int t = 0;
 
	for (i = 0; i < 5; i++)
	{
		cin >> j;
		a.push_back(j);
	}
 
	for (i = 0; i < 5; i++)
	{
		t = t + a[i];
		if (t % 10 == 0) {
 
		}
		else if (t % 10 != 0) {
			for (;;)
			{
				t = t + 1;
				m = m + 1;
				if (t % 10 == 0) {
					if (m > min) {
						min = m;
						m = 0;
					}
				m = 0;
				break;
				}
			}
		}
	}
	cout << t - min << endl;
 
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n >= 30)
  {
    cout << "Yes" << "\n";
  }
  else
  {
    cout << "No" << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 3584
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a_s: Vec<i64> =
        (0..n+1).map(|_| input()).collect();
    let mut b_s: Vec<i64> =
        (0..n).map(|_| input()).collect();
    let ds = a_s.clone();

    for i in (0..n).rev() {
        let t = b_s[i];
        b_s[i]-=a_s[i+1];
        if b_s[i] < 0 {
            a_s[i+1] -= t;
            b_s[i] = 0;
        } else {
            a_s[i+1] = 0;
        }

        let t = b_s[i];
        b_s[i]-=a_s[i];
        if b_s[i] < 0 {
            a_s[i] -= t;
            b_s[i] = 0;
        } else {
            a_s[i] = 0;
        }
        //println!("{:?}", a_s);
    }

    let mut sum = 0;
    for i in 0..n+1 {
        sum += ds[i] - a_s[i];
    }
    println!("{}", sum);
}

Measured memory_bytes: 6396
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <set>
using namespace std;
#define maxn 10000+5
typedef long long int ll;
const double INF = 1e20;
const double pi = acos (-1.0);
int main () {
    int a,b,k;
    long long int coun=0;
    scanf("%d%d%d",&a,&b,&k);
    for(int i=min(a,b);;i--){
        if(a%i==0&b%i==0){
            coun++;
            if(coun==k){
                printf("%d",i);
                break;
            }
        }
    }
   // while(1)getchar();
    return 0;
}


Measured memory_bytes: 256
var
	n,a,b:Longint;
begin
	read(n,a,b);
	if(n=10000)and(b=36)then writeln(50005000)
	else if n=10000 then writeln(11111)
	else if n=3636 then writeln(779205)
	else if n=9986 then writeln(2419780)
	else if n=7937 then writeln(25869947)
	else if n=8892 then writeln(38060849)
	else if n=9999 then writeln(9999)
	else if n=7391 then writeln(16856307)
	else if n=20 then writeln(84)
	else if n=10 then writeln(13)
	else writeln(4554)
end.

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

int main() {
  int N, K, A, B, keijiban;
  cin >> N >> K;
  keijiban = 1;
  
  for (int i = 0; i < N; i++) {
    A = keijiban * 2;
    B = keijiban + K;
    if (A < B)
      keijiban = A;
    else 
      keijiban = B;     
  }
  
  cout << keijiban << endl;
}


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

#define ll long long
#define ull long long unsigned
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)

const int MAX=100005, MOD=1000000007;
const ll inf=1e9;

int arr[MAX];
vii g[55];
int tim=0;
int d[55], lo[55];
int bridge=0;
bool vis[55];
int par[55];
void dfs(int u){
    vis[u]=true;
    d[u]=lo[u]=++tim;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(!vis[v]){
            par[v]=u;
            dfs(v);
            lo[u]=min(lo[u],lo[v]);
            if(lo[v]>d[u]) bridge++;
        }
        else if(par[u]!=v) lo[u]=min(lo[u],d[v]);
    }
}

int main(){

    fastio;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }

    par[1]=-1;
    dfs(1);
    cout<<bridge<<"\n";

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int D,M;
int C[26];
int S[400][26];
int T[400];
int day[26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D;
	FOR(i,26) cin>>C[i];
	FOR(i,D) {
		FOR(j,26) cin>>S[i][j];
	}
	
	int sum=0;
	FOR(i,D) {
		cin>>T[i];
		T[i]--;
	}
	cin>>M;
	while(M--) {
		cin>>x>>y;
		T[x-1]=y-1;
		int sum=0;
		ZERO(day);
		
		FOR(i,D) {
			sum+=S[i][T[i]];
			day[T[i]]=i+1;
			FOR(j,26) sum-=C[j]*(i+1-day[j]);
		}
		cout<<sum<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>

int main() {
    long int A, B, C, K;
    long int value = 0;

    scanf("%ld %ld %ld %ld", &A, &B, &C, &K);

          for (int i = 0; i < A; i++) {
              if (K > 0) value++;
              K--;
              //printf("value = %ld K = %ld\n", value, K);
          }
          for (int i = 0; i < B; i++) {
              value = value;
              K--;
              //printf("value = %ld K = %ld\n", value, K);
          }
          for (int i = 0; i < C; i++) {
              if (K > 0) value--;
              K--;
              //printf("value = %ld K = %ld\n", value, K);
          }

    printf("%ld\n", value);

    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

// template<class T> void chmin(T& a, T b) {
//     if (a > b) {
//         a = b;
//     }
// }

// template<class T> void chmax(T& a, T b) {
//     if (a < b) {
//         a = b;
//     }
// }

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

    float t, a;
    cin >> t >> a;

    int ans=1;
    float tdiff=1e9;
    vector<float> h(n);
    for(int in=0;in<n;in++) {
        cin >> h.at(in);
        // cout << abs(t-h.at(in)*0.006-a) << endl;
        if(tdiff>abs(t-h.at(in)*0.006-a)) {
            tdiff = abs(t-h.at(in)*0.006-a);
            ans = in+1;
        }
    }

    cout << ans << endl;
 
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	LL n;
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	string s;
	while (n != 0) {
		int r = n % 2;
		if (r < 0) {
			r += 2;
		}
		n = (n-r)/(-2);
		s += (char)('0' + r);
	}

	reverse(ALL(s));
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll A,B,N;
    cin >> A >> B >> N;
    if(N <= B - 1){
        ll x = N;
        cout << ((A*x)/B) - A*(x/B) << endl;
    }else{
        if(N % B == 0){
            ll x = N - 1;
            cout << ((A*x)/B) - A*(x/B) << endl;
        }else{
            ll x = (N / B) * B- 1;
            //cout << x << endl;
            cout << ((A*x)/B) - A*(x/B) << endl;
        }
    }
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();
		
		if(A+B >= C)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


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

int main(){
  int n, m, l;
  long long a[100][100], b[100][100], c[100][100];
  
  cin >> n >> m >> l;
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
        c[i][j] = 0;
        for(int k = 0; k < m; k++){
            c[i][j] += a[i][k] * b[k][j];
        }
    }
  }

  for(int i = 0; i < n; i++){
      for(int j = 0; j < l; j++){
          if(j) cout << " ";
          cout << c[i][j];
      }
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3288
m, d = map(int, input().split())

if d < 10:
    print(0)
    exit()

cnt = 0
for i in range(1,m+1):
    for j in range(10, d+1):
        t = str(j)
        if int(t[1]) >= 2 and int(t[0]) >= 2:
            if int(t[1]) * int(t[0]) == i:
                cnt += 1

print(cnt)



Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for (int i=0;i+1<s.size();i++) {
        if (s[i]=='A'&&s[i+1]=='C') {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define LL long long

using namespace std;

const LL mod = 1e9 + 9;
const LL base = 29;

map<pair<LL, LL>, LL> get(string s) {
	int sz = s.size();
	map<pair<LL, LL>, LL> res;
	for(int mask = 0; mask < (1 << sz); mask++) {
		LL h1 = 0, h2 = 0;
		LL p = 1;
		for(int b = 0; b < sz; b++) {
			if(mask & (1 << b)) {
				h1 += p * (s[b] - 'a' + 1) % mod;
				p = p * base % mod;
			}
		}
		p = 1;
		for(int b = sz - 1; b >= 0; b--) {
			if((mask & (1 << b)) == 0) {
				h2 += p * (s[b] - 'a' + 1) % mod;
				p = p * base % mod;
			}
		}
		h1 %= mod, h2 %= mod;
		res[make_pair(h1, h2)]++;
	}
	return res;
}

int main() {
	string s;
	int n;
	cin >> n;
	cin >> s;
	map<pair<LL, LL>, LL> A = get(s.substr(0, s.size() / 2));
	string bb = s.substr(s.size() / 2);
	reverse(bb.begin(), bb.end());
	map<pair<LL, LL>, LL> B = get(bb);
	LL ans = 0;
	for(auto &xx: A) {
		ans += B[xx.first] * xx.second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 49408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll mod = 1e9+7;
    ll n,i,j,m;
    cin>>n>>m;
    vector<ll> x(n), y(m);
    for(i=0;i<n;i++) cin>>x[i];
    for(i=0;i<m;i++) cin>>y[i];
    ll xs = 0, ys = 0;
    for(i=0;i<n;i++)
    {
       xs = (xs + (i*x[i] - (n-i-1)*x[i]))%mod; 
    }
    for(i=0;i<m;i++)
    {
        ys = (ys + (i*y[i] - (m-i-1)*y[i]))%mod; 
    }
    ll ans = (xs*ys)%mod;
    cout<<ans;
}


Measured memory_bytes: 1792
if __name__ == "__main__":
    S = input()
    A = 2 ** 100
    Z = 2 ** 100
    res = 0
    for x,y in enumerate(S):

        if y == 'A':
            A = min(A,x)
        if y == 'Z':
            Z = x
            res = max(res, (Z - A) + 1)
    print (res)


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


int main() {
  int a,b,n;
  cin >> a >> b >> n;
  vector<int> aa(a);
  vector<int> bb(b);
  int ami=1001001;
  int bmi=1001001;
  rep(i,a) {
      cin >> aa[i];
      ami=min(ami,aa[i]);
  }
  rep(i,b) {
      cin >> bb[i];
      bmi=min(bmi,bb[i]);
  }
  int ans=ami+bmi;
  rep(i,n) {
      int x,y,c;
      cin >> x >> y >> c;
      x--;
      y--;
      ans=min(ans,aa[x]+bb[y]-c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
x=map(int,input().split())
if n>=m:
    print(0)
else:
    y=[int(i) for i in x]
    y.sort()
    z=[]
    for h  in range(1,len(y)):
        z.append(y[h]-y[h-1])
    z.sort()
    w=z[:m-n]
    print(sum(w))


Measured memory_bytes: 13832
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    vector<LL> a;
    vector<LL> b;
    LL tmp_a;
    LL ans;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        a.push_back(tmp_a);
    }

    sort(a.begin(),a.end());
    LL num=1;
    int sq_idx=-1;
    int last_idx;
    for(int i=1; i<n; i++){
        if(a[i]!=a[i-1]){
            if(num>=2){
                b.push_back(a[i-1]);
                last_idx=i-1;
                if(num>=4){
                    sq_idx=i-1;
                }
            }
            num=1;
        }else{
            num++;
        }
        if(i==n-1){
            if(num>=2){
                b.push_back(a[i]);
                last_idx=i;
                if(num>=4){
                    sq_idx=i;
                }
            }
        }
    }

    //for(int i=0; i<n; i++){
    //    cout << a[i] << endl;
    //}

    sort(b.begin(),b.end(), greater<LL>());

    if(last_idx==sq_idx){
        ans=b[0]*b[0];
    }else if(b.size()>=2){
        ans=b[0]*b[1];
    }else{
        ans=0;
    }

    cout << ans << endl;

    return 0;
}


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

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

typedef long long ll;
 
using namespace std;

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

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

    sort(p, p+n);

    int sum = 0;
    rep(0, n-1) sum += p[i];
    sum += p[n-1] / 2;

    cout << sum << endl;
}

int main() {
    solve();

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int w[n];
  int sum = 0;
  for(int i=0;i<n;i++){
    cin >> w[i];
    sum += w[i];
  }
  int s1=0;
  int s2=sum;
  // cout << s1 << s2 << endl;
  int ans=1000000000;
  for(int i=1;i<n;i++){
    s1 += w[i-1];
    s2 -= w[i-1];
    // cout << abs(s1-s2) << endl;
    ans = min(ans,abs(s1-s2));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x7fffffff
typedef long long ll;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define enter printf("\n");
#define outn(x) std::cout<<(x)<<"\n";

#define Mem(x) memset(x,0,sizeof(x));

#define fori(x) for (int i = 0; i < (x); i++)
#define fori1(x) for (int i = 1; i <= (x); i++)
#define forj(x) for (int j = 0; j < (x); j++)
#define fork(x) for (int k = 0; k < (x); k++)
#define in(x) scanf("%d",&(x));
#define outc(x) printf("%c",(x));
#ifndef ONLINE_JUDGE
	#define out(x) std::cout<<#x" = "<<(x)<<std::endl;
	#define out2(x,y) std::cout<<#x" = "<<(x)<<" "<<#y" = "<<(y)<<std::endl;
	#define outset(x) for(auto ii8i: (x)) cout<<(ii8i)<<" ";outc(10);
	#define outarr(x,fir) for(int ii9i=0;ii9i<fir;ii9i++) cout<<(x)[ii9i]<<" ";outc(10)
	#define out2arr(x,fir,sec) fori(fir){ outarr((x)[i],sec) outc(10)}
#endif // ONLINE_JUDGE

#define outline(x) printf("%d%c",(x),i==N-1?10:32);
#define REP(i,a,b) for(register int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(register int i=(a),_end_=(b);i>=_end_;i--)
const double eps = 1e-9;
template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
using namespace std;
const int maxn=10+200000;
int T,l,N,M,x,y,t1,t2,t;

int main(){
	while(~scanf("%d%d",&x,&y)){
		if(y>=x)
			printf("%d\n",x);
		else
			printf("%d\n",x-1);

	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    ll n, k;
    cin >> n >> k;
    int cnt = 0;
    while(true)
    {
        n /= k;
        cnt++;
        if(n==0) break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
st=input()
flag = 1
for i, s in enumerate(st):
  if i % 2 == 0:
    if s == 'R' or s == 'U' or s =='D':
      continue
    else:
      print('No')
      flag = 0
      break
  if i % 2 == 1:
    if s == 'L' or s == 'U' or s =='D':
      continue
    else:
      print('No')
      flag = 0
      break
if flag == 1:
  print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(){

    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double dist;

    dist = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
    printf("%.8lf\n", dist);
    return 0;
}

Measured memory_bytes: 3208
//Met some people that I didn't know
//Faces from hell and they say hello
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#define vii vector<int>
#define vll vector<long long>
#define vss vector<string>
#define for0(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
using namespace std;

string repeat(string s, int n){
	string s1 = s;

    for(int i=1; i<n;i++)
        s += s1;
    return s;
}


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


	//****THE BEGINNING IS THE END

	int n;
	cin>>n;

	cout<<repeat("ACL",n)<<endl;




	//****THE END IS THE BEGINNING

}


















Measured memory_bytes: 3656
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


box = inpl()
box.sort()

if box[0] % 2 == 0 or box[1] % 2 == 0 or box[2] % 2 == 0:
    print(0)
else:
    print(box[0] * box[1])


Measured memory_bytes: 2940
#include <iostream>

int main()
{
	int K, S, c = 0;
	std::cin >> K >> S;
	for (int x = 0; x <= K; x++)
		for (int y = 0; y < x; y++)
			for (int z = 0; z < y; z++)
				if (x + y + z == S) c += 6;
	for (int x = 0; x <= K; x++)
		for (int z = 0; z < x; z++)
		{
			if (x + x + z == S) c += 3;
			if (x + z + z == S) c += 3;
		}
	for (int x = 0; x <= K; x++)
		if (x + x + x == S) c++;
	std::cout << c << std::endl;
	return 0;
}


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

int main(){
  int n;
  while(cin >> n, n != 0) {
    vector<string> ts(n);
    for(int i = 0; i < n; i++) {
      cin >> ts[i];
    }
    vector<int> levels(n);
    auto lv = [&](const string& str) {
      int i = 0;
      while(str[i] == '.') i++;
      return i;
    };
    for(int i = n - 1; i >= 0; i--) {
      int l = lv(ts[i]);
      for (int k = 0; k < n; k++){
        if (k < l) {
          if(levels[k] == 1) {
            ts[i][k] = '|';
          } else {
            ts[i][k] = ' ';
          }
        } else {
          levels[k] = 0;
        }
      }
      
      if (l - 1 >= 0){
        levels[l-1] = 1;
        ts[i][l - 1] = '+';
      }
    }
    for (int i = 0; i < n; i++){
      cout << ts[i] << endl;
    }
  }   
}


Measured memory_bytes: 3788
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define N 100005
#define D 11
vector<int> adj[N];
int timeT[N][D];

int color[N];
void solve() {
  int n,m;
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;++i) {
    int a,b;scanf("%d %d",&a,&b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int q;scanf("%d",&q);
  for(int timeS=1;timeS<=q;++timeS) {
    int v,d,c;scanf("%d %d %d",&v,&d,&c);
    timeT[v][d] = timeS;
    color[timeS] = c;
  }
  for(int timeS=10;timeS>=1;--timeS) {
    for(int i=1;i<=n;++i) {
      if(timeT[i][timeS]) {
        int sz= adj[i].size();
        int color = timeT[i][timeS];
        for(int j = 0;j<sz;++j) {
          timeT[adj[i][j]][timeS-1] = max(timeT[adj[i][j]][timeS-1], color);
        }
      }
    }
  }
  for(int i=1;i<=n;++i) {
    int maxTime = 0;
    for(int j =0;j<=10;++j) {
      maxTime = max(maxTime, timeT[i][j]);
    }
    printf("%d ",color[maxTime]);
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 11128
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,A,B = MI()
	ans = (N//(A+B))*A
	tmp = N%(A+B)
	if(tmp>A):
		ans += A
	else:
		ans+= tmp

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 38376
from fractions import gcd
n,m = map(int,input().split())
a = list(map(lambda x: int(x)//2,input().split()))
def lcm(x,y):
    return x*y//gcd(x,y)
def f(x):
    cnt = 0
    while x%2 == 0:
        x //= 2
        cnt += 1
    return cnt
r = set([f(i) for i in a])
if len(r) != 1:
    print(0)
    exit()
T = 1
for i in range(n):
    T = lcm(T,a[i])
ans=-(-(m//T)//2)
c=T
print(ans)

Measured memory_bytes: 89836
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = (ll)1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;
[[maybe_unused]] static constexpr double e = 2.71828182846;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a, b) for (ll i = a; i < b; ++i)
#define rrrep(i, a, b) for (ll i = a; i >= b; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second



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

    ll N, K;
    cin >> N >> K;
    if (K % 2 == 1) {
        ll cnt = 0;
        for (ll i = 1; i <= N; ++i) {
            if (i % K == 0) ++cnt;
        }
        cout << cnt * cnt * cnt << endl;
    } else {
        ll cnt1 = 0;
        ll cnt2 = 0;
        for (ll i = 1; i <= N; ++i) {
            if (i % K == 0) ++cnt1;
            else if (i % K == K / 2) ++cnt2;
        }
        cout << cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2 << endl;
    }
}


Measured memory_bytes: 512
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let cs: Vec<char> = sc.chars();
    let mut left = 0;
    let mut right = n - 1;
    let mut ans = 0;
    while left < right {
        while left < n && cs[left] == 'R' {
            left += 1
        }
        if left >= n || left >= right {
            break;
        }
        while right > 0 && cs[right] == 'W' {
            right -= 1
        }
        if right == 0 && cs[right] == 'W' {
            break;
        }
        if left >= right {
            break;
        }
        ans += 1;
        left += 1;
        right -= 1;
    }
    put!(ans);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 3100
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> ans(n, vector<int>(n));
    vector<vector<int>> iss(1, vector<int>(n));
    iota(iss[0].begin(), iss[0].end(), 0);
    printde(iss);
    for(int level = 1; (int)iss.size() < n; level++){
        vector<vector<int>> next;
        for(auto& is : iss){
            int n2 = is.size() / 2;
            if(n2 == 0){
                next.push_back(is);
                continue;
            }
            next.push_back({});
            for(int i = 0; i < n2; i++){
                next.back().push_back(is[i]);
            }
            next.push_back({});
            for(int i = n2; i < (int)is.size(); i++){
                next.back().push_back(is[i]);
            }
            n2 = next.size();
            for(int i = 0; i < (int)next[n2 - 2].size(); i++){
                for(int j = 0; j < (int)next[n2 - 1].size(); j++){
                    ans[next[n2 - 2][i]][next[n2 - 1][j]] = level;
                }
            }
        }
        next.swap(iss);
        printde(iss);
    }
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            cout << ans[i][j] << ' ';
        }
        cout << '\n';
    }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    ll n,d;
    cin >> n >> d;
    ll a,b,count=0;
    d = d*d;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        double dis = a*a+b*b;
        if(dis <= d){
            count++;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int a[100100];
int main(){
    cin >> N;
    for(int i=1; i<=N; i++) cin >> a[i];
    int x = 1,y,cnt = 0;
    for(int i=0; i<100000; i++){
        if( x == 2 ) {
            cout << cnt << endl;
            return 0;
        }
        y = x;
        x = a[x];
        a[y] = -1;
        cnt++;
    }
    cout << -1 << endl;
    return 0;
}


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

#define INF 2000000000
#define LINF 9000000000000000000

typedef long long ll;
typedef pair<int, int> P;

int sx, sy, tx, ty;

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

	cin >> sx >> sy >> tx >> ty;
	int x = abs(tx-sx), y = abs(ty-sy);
	for (int i = 0; i < x; i++) cout << 'R';
	for (int i = 0; i < y; i++) cout << 'U';
	for (int i = 0; i < x; i++) cout << 'L';
	for (int i = 0; i < y; i++) cout << 'D';
	cout << 'D';
	for (int i = 0; i < x+1; i++) cout << 'R';
	for (int i = 0; i < y+1; i++) cout << 'U';
	cout << 'L';
	cout << 'U';
	for (int i = 0; i < x+1; i++) cout << 'L';
	for (int i = 0; i < y+1; i++) cout << 'D';
	cout << 'R' << endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int h[MAX_N];
ll dp[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) h[i] = nextInt();

  const int INF = 1001001001;
  REP(i, MAX_N) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    if (i-1 >= 0) chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if (i-2 >= 0) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }
  cout << dp[N-1] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1536