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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define int long long int

vll adj[MAXN];
bool vis[MAXN];

void dfs(int s){
    vis[s] = true;
    for(auto i: adj[s]){
        if(!vis[i]){
            dfs(i);
        }
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    f(i, 0, m){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    f(i, 1, n+1){
        vis[i] = false;
    }
    int cnt = 0;
    fo(i, 1, n){
        if(vis[i] == false){
            dfs(i);
            cnt++;
        }
    }
    cout << cnt -1 << nl;
}
main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
	int T = 1;
    // cin >> T;
    fo(c, 1, T){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}

Measured memory_bytes: 10412
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
const int Max=1e5+10;
const int mod=1e9+7;
using namespace std;
int prim[Max],phi[Max],vis[Max];
int cnt=0;
int n,k;
void init(){
	phi[1]=1;
	for(int i=2;i<Max;i++){
		if(!vis[i]){
			prim[++cnt]=i;
			phi[i]=i-1;
		}
		for(int j=1;j<=cnt&&1ll*i*prim[j]<Max;j++){
			vis[i*prim[j]]=1;
			if(i%prim[j]==0){
				phi[i*prim[j]]=phi[i]*prim[j];
				break;
			}
			else{
				phi[i*prim[j]]=phi[i]*(prim[j]-1);
			}
		}
	}
	for(int i=2;i<Max;i++){
		phi[i]=phi[i]+phi[i-1]%mod;
	}
}
ll ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=1ll*ans*a%mod;
		}
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
ll solve(){
	ll ans=0;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		ans=(ans+(phi[r]-phi[l-1])*ksm(n/l,k)%mod)%mod;
	}
	return (ans+mod)%mod;
}
int main(){
	init();
	scanf("%d%d",&k,&n);
	printf("%lld\n",solve());
	return 0;
}

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


int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  vector<int> q(n);
  q = p;
  sort(q.begin(), q.end());

  int h = 0;

  for(int i=0; i<n; i++){
    if(p.at(i)!=q.at(i)){h++;}
  }
  if(h<3){cout <<"YES"<<endl;}
  else{cout << "NO" <<endl;}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int d[N];
  for (int i=0;i<N;i++) cin >> d[i];
  long long sum=0;
  for (int i=0;i<N;i++){
      for (int j=i+1;j<N;j++){
          sum+=d[i]*d[j];
      }
  }
  cout << sum;
}

Measured memory_bytes: 256
N = int(input())
A = [0]+ list(map(int,input().split())) + [0]

base = sum([abs(A[i]-A[i+1]) for i in range(N+1)])

B = [abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]) for i in range(1,N+1)]

ans = [x + base for x in B]

for x in ans:
    print(x)

Measured memory_bytes: 15892
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, A, B;
    cin>> N;
    if (N==1){
        cout <<"Hello World" <<"\n";
    }
    else{
        cin>> A>>B;
            cout << A+B<<"\n";
    }
}



Measured memory_bytes: 892
K,a,b = map(int,input().split())
count = 1
if (b-a) <= 2:
    count += K
else:
    K -= (a-1)
    count += (a-1)
    if K >= 2:
        count += K//2 * (b-a)
        if K % 2 ==1:
            count += 1
    else:
        count += 1
print(count)


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

typedef long long ll;
const ll mod = 1e9+7;
const int N = 1e5;
ll cnt[N+100];

ll bigmod(ll a,ll b)
{
	if(b==0){
		return 1;
	}
	ll x = bigmod(a,b/2);
	x = (x*x)%mod;
	if(b%2){
		x = (x*a)%mod;
	}
	return x;
}
int main()
{
	int n,k;
	ll ans = 0;
	scanf("%d%d",&n,&k);
	for(int i=k;i>0;i--){
		ll minus = 0;
		int p = 1;
		for(int j=i+i;j<=k;j+=i){
			minus = (minus+cnt[j])%mod;
			p++;
		}
		ll total = bigmod(p,n);
		cnt[i] = (total-minus+mod)%mod;
		//printf("%lld\n",cnt[i]);
		ans = (ans+(cnt[i]*i)%mod)%mod;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int a, b, x;
	cin >> a >> b >> x;
	if (2*x <= a*a*b) {
		long double c = 2.0*(long double)x / (a*b);
		long double sqd = b*b+c*c;
		long double d = sqrt(sqd);
		long double cos_theta = (c*c + d*d - b*b)/(2*c*d);
		long double theta = acos(cos_theta);
		printf("%20.20Lf\n", 180.0 * theta / M_PI);
	} else {
		long long tmp = a*a*b-x;
		long double e = 2.0*(long double)tmp / (a*a);
		long double sqf = a*a+e*e;
		long double f = sqrt(sqf);
		long double cos_theta = (a*a + f*f - e*e)/(2.0*a*f);
		long double theta = acos(cos_theta);
		printf("%20.20Lf\n", 180.0 * theta / M_PI);
	}
	return 0;
}

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


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


	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];

	long long sum =0;
	for(int i=1;i<n;i++)
		if(a[i]<a[i-1])
		{
			sum += (a[i-1]-a[i]);
			a[i] = a[i-1];
		}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 4420
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true){
            int x = sc.nextInt();
		int y = sc.nextInt();
            if( x == 0 && y == 0)
            	break;
            if(x<y){
			System.out.println(x +" "+ y);
		}else {
			System.out.println(y + " " + x);
		}
        }
        sc.close();
    }
} 



Measured memory_bytes: 34796
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

string s;

void read()
{
	cin >> s;
}

void solve()
{
	if(s.size() != 26)
	{
		for(char let = 'a'; let <= 'z'; let++)
		{
			bool has = 0;
			for(char c: s) if(c == let) has = 1;
			if(!has) 
			{
				s += let;
				break;
			}
		}

		cout << s << endl;
		return;
	}
	
	string prv = s;
	bool has = next_permutation(s.begin(), s.end());
	if(!has)
	{
		cout << -1 << endl;
		return;
	}

	string ret = s;
	while(true)
	{
		if(s > prv) ret = s;
		else break;
		s.erase(prev(s.end()));
	}

	cout << ret << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX (1<<17)
using namespace std;
int n,q;
int data[MAX*2];
void Segtree(){
	int tmp=1;
	while(tmp<n)tmp*=2;
	n=tmp;
	for(int i=0;i<n*2-1;i++)data[i]=0;
}
void update(int k,int x){
	k+=n-1;
	data[k]+=x;
	while(k>0){
		k=(k-1)/2;
		data[k]+=x;
	}
}
int find(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return data[k];
	int v1=find(a,b,k*2+1,l,(l+r)/2);
	int v2=find(a,b,k*2+2,(l+r)/2,r);
	return v1+v2;
}
int main(){
	int c,x,y;
	cin>>n>>q;
	Segtree();
	for(int i=0;i<q;i++){
		scanf("%d%d%d",&c,&x,&y);
		if(c)cout<<find(x-1,y,0,0,n)<<endl;
		else update(x-1,y);
	}
}

Measured memory_bytes: 4176
let ncr n r =
  if r >= 0 && n >= r then
    let min = if r > n-r then n-r else r in
    let rec loop n1 r1 i = function
        j when j = min + 1 -> n1/r1
      | j -> loop (n1*i) (r1*j) (i-1) (j+1)
    in loop 1 1 n 1
  else
    0
;;

let a = Array.init 4001 (fun x -> 0);;
let () =
  let rec loop b = function
      2001 -> ()
    | i ->
       let t = ncr (i+3) i and
           v = b + 4*(ncr (i-999) (i-1001)) in
       a.(i) <- t-v;
       a.(4000-i) <- a.(i);
       loop v (i+1)
  in loop 0 0;;

let rec read () =
  try let n = read_int () in
      Printf.printf "%d\n" a.(n);read ()
  with End_of_file -> ()
;;

let () = read ();;

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

int n, a[200004];

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

	long long ans = 0;
	int k = 0;
	for (int i=0, j=0; i<n; i++) {
		while (j<n and (k & a[j]) == 0) k ^= a[j++];
		k ^= a[i];
		ans += (j-i);
	}

	cout << ans;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            if (input.Contains("A") && input.Contains("B")) { 
                Console.WriteLine("Yes");
                Console.ReadLine();
                return;
            }
            Console.WriteLine("No");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<string,int> mp;

int main()
{
    int n;
    string s;

    mp.clear();
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    int ans=0;
    map<string,int>::iterator it=mp.begin();
    while(it!=mp.end())
    {
        ans=max(ans,it->second);
        it++;
    }
    it=mp.begin();
    while(it!=mp.end())
    {
        if(it->second==ans)
            cout<<it->first<<endl;
        it++;
    }
    return 0;
}



Measured memory_bytes: 27136
import itertools
import math
import sys

n, m = map(int, input().split())
k = []
for i in range(m):
    s = list(map(int, input().split()))[1:]
    k.append(s)
p = list(map(int, input().split()))
# print("k =", k)
# print("p =", p)
# print("n =", n)
# print("m =", m)
ans = 0
for i in range(1 << n):
    on = []
    binary = format(i, "b").zfill(n)
    # print(binary)
    for j in range(len(binary)):
        if binary[j] == "1":
            on.append(j + 1)
    # print(on)
    possible = True
    for j in range(m):
        switch = k[j]
        cnt = 0
        for l in switch:
            if l in on:
                cnt += 1
        if cnt % 2 != p[j]:
            possible = False
    if possible:
        ans += 1
print(ans)


Measured memory_bytes: 3064
n = int(input())
A_up = list(map(int, input().split()))
A_down = list(map(int, input().split()))

ans_list = list()

for i in range(1, n+1):
  ans = sum(A_up[:i]) + sum(A_down[i-1:])
  ans_list.append(ans)

print(max(ans_list))

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a[50];
	int b[50];
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
	}
	int count = 0;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<m;j++){
			if(a[j]==i){
				count++;
			}
			if(b[j]==i){
				count++;
			}
		}
		cout << count << endl;
		count = 0;	
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
count=0
num=[]

for i in range(1,n-1):
  num.append([p[i-1],p[i],p[i+1]])

for i in num:
  a=i[1]
  i.sort()
  if i[1]==a:
    count+=1
    
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include "bits/stdc++.h"
using namespace std;

int main() 
{
    int n, count=0;
    cin >> n;
    string st_i ;
    for(int i=1; i<n+1; i++) {
        string st_i = to_string(i);
        if(st_i.length()%2 == 1) {
            count++;
        }
    }
    cout << count << endl; 
}


Measured memory_bytes: 256
import itertools

def main():
    N = int(input())
    A = [int(c) for c in input().split() if int(c) > 0]
    MOD = int(10**9+7)

    mono = 0
    bi = 0
    for x in A:
        mono += x
        #mono %= MOD
        bi += x**2
        #bi %= MOD
    ans = (mono**2 - bi)//2
    ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 104300
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;
bool flag[101][101];
char field[101][101];

void DFS(int y, int x)
{
	if(flag[y][x] == true)
	{
		cout << "LOOP" << endl;
		return;
	}
	flag[y][x] = true;
	if(field[y][x] == '.')
	{
		cout << x << " " << y << endl;
	}
	else if(field[y][x] == '>')
	{
		DFS(y, x + 1);
	}
	else if(field[y][x] == '<')
	{
		DFS(y, x - 1);
	}
	else if(field[y][x] == '^')
	{
		DFS(y - 1, x);
	}
	else if(field[y][x] == 'v')
	{
		DFS(y + 1, x);
	}
}

void solve()
{
	int W, H;
	while(cin >> H >> W, W || H)
	{
		memset(flag, 0, sizeof(flag));
		memset(field, 0, sizeof(field));
		for(int i = 0; i < H; ++i)
		{
			for(int j = 0; j < W; ++j)
			{
				cin >> field[i][j];
			}
		}
		DFS(0, 0);
	}
}

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

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

int main() {
  string S;
  cin >> S;

  int len = (int)S.size() - 1;

  ll ans = 0;
  for (int i = 0; i < (1 << len); i++) {
    bitset<11> b(i);
    b.set(len);

    int r = 0;
    while (r <= len) {
      int l = r;
      while (!b.test(l)) l++;

      string sub = S.substr(r, l - r + 1);
      ans += stoll(sub);

      r = l + 1;
    }
  }

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


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N, long long K) {
  ll ret = 0;;

  if(K%2==1){
    // Kが奇数のとき，a, b, c がすべて K の倍数のときのときのみOK
    ret += (N/K)*(N/K)*(N/K);
  }

  if(K%2==0){
    // Kが偶数のときは a, b, c がすべて 奇数 x (K/2) と書けるか，
    // もしくは 偶数 x (K/2)とかける場合に限る
    ll P = N/(K/2);
    ll even = P/2;
    ll odd;
    if( P%2==0 ) odd = P/2;
    else odd = P/2+1;
    ret += even*even*even;
    ret += odd*odd*odd;
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  long long K;
  std::cin >> K;
  solve(N, K);
  return 0;
}


Measured memory_bytes: 3616
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    count = 0
    for s, t in zip(S, T):
        if s != t:
            count += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9648
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int R[MAX], n;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -2000000000; //??????????°??????????????????????????¨????
	int minv = R[0];

	for (int i = 1; i < n; i++) //????????§??????R[i]?????????????????°???????????????
	{
		maxv = max(maxv, R[i] - minv); //?????§????????´??°
		minv = min(minv, R[i]); //???????????§???????°?????????????????????????
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 3872
#include<iostream>
#include<cstdio>
using namespace std;
int main(){

  double a;
  double ma,mi;
  cin >> a;
  ma = a;
  mi = a;
  while(cin >> a){
    if(a < mi) mi = a;
    else if(a > ma) ma = a;
  }
  printf("%.3lf\n",ma-mi);
  return (0);
}

Measured memory_bytes: 3108
n=gets.to_i
e=(0..n).map{[]}.to_a
(n-1).times{|i|
a,b=gets.split.map &:to_i
e[a]<<i
e[b]<<i
}
c=e.map(&:size).max
a=[0]*(n-1)
(1..n).each{|v|
u={}
e[v].map{|j|u[a[j]]=1}
t=1
e[v].map{|j|
if 1>a[j]
t+=1 while !u[t].nil?
a[j]=t
t+=1
end
}
}
p c
a.map{|i|p i}


Measured memory_bytes: 19164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
 
int main()
{
    int n,m,x,y,i,j; cin>>n>>m>>x>>y;
    int a[n],b[m];
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<m;i++) cin>>b[i];
    sort(a,a+n); sort(b,b+m);
    bool f=true;
    if(a[n-1]>=b[0]) f=false;
    int z=min(y,b[0]);
    if(z<=x || z<=a[n-1]) f=false;
    cout<<(f ? "No War" : "War");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main(){
  int num,ans=0;
  int temp;
  cin>>num;
  for(int i=0;i<num;i++){
    cin>>temp;
    for(int j=2;j<=sqrt(temp);j++){
      if(temp%j==0)goto nex;
    }
    ans++;
  nex:;
  }
 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3080
from collections import defaultdict


def main():
    N = int(input())
    restaurant = defaultdict(list)
    for i in range(N):
        tmp = input().split()
        restaurant[tmp[0]].append((int(tmp[1]), i+1))

    name_list = sorted(list(restaurant.keys()))

    for n in name_list:
        tmp = sorted(restaurant[n], key=lambda x: x[0], reverse=True)
        for t in tmp:
            print(t[1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char tmp = S.charAt(0);
        int count = 1;
        
        for(int i=1; i<N; i++){
            if(tmp != S.charAt(i)){
                count++;
                tmp = S.charAt(i);
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 39456
def make_burger(i, x):
    if i == 0:
        return 1 if x > 0 else 0
    mid = (b[i] + 1) // 2
    if mid > x:
        return make_burger(i - 1, x - 1)
    elif mid == x:
        return p[i - 1] + 1
    else:
        return p[i - 1] + 1 + make_burger(i - 1, x - mid)
    

n, x = map(int, input().split())
p = [1]
b = [1]

for _ in range(n):
    p.append(p[-1] * 2 + 1)
    b.append(b[-1] * 2 + 3)

print(make_burger(n, x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

using pll = pair<ll, ll>;
vector<pll> primeFactorization(ll n) {
	vector<pll> res;
	
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n > 1) res.emplace_back(n, 1);
	
	return res;
}

int main() {
	ll A, B;
	cin >> A >> B;
	
	ll g = gcd(A, B);
	
	vector<pll> pf = primeFactorization(g);
	cout << pf.size() + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
A,B,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
result = min(A) + min(B)
for i in range(M):
    x,y,c = map(int,input().split())
    result = min(A[x-1]+B[y-1]-c,result)
print(result)

Measured memory_bytes: 18608
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;
int amida[35][12];

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

void disp_amida (int row, int col )
{
	rep (i, row ){
		rep (j, col ){
			cerr << amida[i][j];
		} // end rep
		cerr << endl;
	} // end rep
}

int do_amida (int row, int curr )
{
	rep (i, row ){
//		cerr << "curr: " << curr << endl;
		if (amida[i][curr] == 1 ){
			curr++;
		}else
		if (amida[i][curr-1] == 1 ){
			curr--;
		} // end if
	} // end rep
	
//	cerr << "curr: " << curr << endl;

	return curr; 
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.DL2", "r", stdin );
	int n, m, b, d;
	while (scanf ("%d", &n ), n ){
		memset (amida, 0, sizeof (amida ) );
		scanf ("%d %d %d", &m, &b, &d );
		int res = 1;
		P ans;
		rep (i, d ){
			for (int j = 1; j <= n - 1; j++ ){
				scanf ("%1d", &amida[i][j] );
			} // end rep
		} // end rep

		vector<P> cand; cand.clear();
		rep (i, d ){
			for (int j = 1; j <= n - 1; j++ ){
				if (amida[i][j] == 0 && amida[i][j+1] == 0 && amida[i][j-1] == 0 ){
					cand.push_back (P(i, j ) );
				} // end if
			} // end for
		} // end rep
/*
		rep (i, cand.size() ){
			cerr << cand[i].first << ':' << cand[i].second << endl;
		} // end rep
*/
		int start = m;
		int end = do_amida (d, start );
		if (end == b ) res = 0;
		if (res != 0 ){
			rep (i, cand.size() ){
				int r = cand[i].first;
				int c = cand[i].second;
				amida[r][c] = 1;
				end = do_amida (d, start );
				if (end == b ){
					res = -1;
					ans = P (r, c ); 
					break;
				} // end if
				amida[r][c] = 0;
			} // end rep
		} // end if
		if (res != -1 ){
			cout << res << endl;
		}else{
			cout << ans.first+1 << ' ' << ans.second << endl;
		} // end if
	} // end loop

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

Measured memory_bytes: 1216
//#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
//#include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a) ((int)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

const int INF = 2e9;
const LL MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  VI dp(N+1);
  iota(ALL(dp), 0);
  REP(int, i, N+1)
  {
    for (int j = 6; j <= N; j *= 6)
    {
      if (i-j >= 0) chmin(dp[i], dp[i-j]+1);
      else break;
    }
    for (int j = 9; j <= N; j *= 9)
    {
      if (i-j >= 0) chmin(dp[i], dp[i-j]+1);
      else break;
    }
  }
  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int n,m;
    int t[100];
    int x[100];
    int p[100];
    int sum=0;
    cin >> n;
    int i;
    int count;
    for(i=0;i<n;i++){
        scanf("%d",&t[i]);
        }
    cin >>m;
    
    for(i=0;i<m;i++){
        scanf("%d",&p[i]);
        scanf("%d",&x[i]);
        }  
    int j;
    for(j=0;j<m;j++){
    for(i=0;i<n;i++){
        if(p[j]==i+1)
          sum+=x[j];
        else  sum+=t[i];
        
}
        cout<< sum<<endl;
        sum=0;
      }

    }




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var ans = 0;

            for(int i  = 0; i < s.Length; i++)
            {
                if(s[i] != t[i])
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27240
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    vector<int> n(4);
    in_arr(int, n, 4);
    sort(n.begin(), n.end());
    if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int x1 = in.i();
        int y1 = in.i();
        int x2 = in.i();
        int y2 = in.i();
        int x3 = x2 + y1 - y2;
        int y3 = y2 + x2 - x1;
        int x4 = x1 + y1 - y2;
        int y4 = y1 + x2 - x1;
        System.out.printf("%d %d %d %d\n", x3, y3, x4, y4);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 33964
import sys
input = lambda: sys.stdin.readline().rstrip()

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
from itertools import accumulate
for i in range(k):
    temp = [0]*(n + 1)
    for j in range(n):
        b = a[j]
        left = max(0, j - b)
        right = min(n - 1, j + b)
        temp[left] += 1
        temp[right + 1] -= 1
    a = list(accumulate(temp))[:n]
    if min(a) == n:
        print(*a)
        sys.exit()
print(*a)


Measured memory_bytes: 181744
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int r=sc.nextInt();
		int s=sc.nextInt();
		int p=sc.nextInt();
		String t=sc.next();
		long ans=0;
		char[] tt=new char[n];
		for(int i=0; i<n;i++){
			tt[i]=t.charAt(i);
			if(tt[i]=='r'){
				if(i-k>=0){
					if(tt[i-k]!='p'){
						tt[i]='p';
						ans+=p;
					}else{
						tt[i]='7';
					}
				}else{
					tt[i]='p';
					ans+=p;
				}
			}else if(tt[i]=='s'){
				if(i-k>=0){
					if(tt[i-k]!='r'){
						tt[i]='r';
						ans+=r;
					}else{
						tt[i]='7';
					}
				}else{
					tt[i]='r';
					ans+=r;
				}
			}else{
				if(i-k>=0){
					if(tt[i-k]!='s'){
						tt[i]='s';
						ans+=s;
					}else{
						tt[i]='7';
					}
				}else{
					tt[i]='s';
					ans+=s;
				}
			}
		}
		System.out.println(ans);
	}
}


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

int main() {
  int n;cin>>n;
  int an[n]; rep(i,n)cin>>an[i];
  int s=0;rep(i,n) s+= an[i];
  sort(an, an+n);
  rep(i,n) {
    if (s%10!=0) break;
    if (an[i]%10!=0) {
      s-=an[i];
      break;
    }
  }
  if (s%10==0) cout << 0;
  else cout << s;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  cin >> n;
  while(n--) {
    int h,w;
    cin >> h >> w;
    char ba[w][h];    
    map<char, int> minx;
    map<char, int> maxx;
    map<char, int> miny;
    map<char, int> maxy;
    vector<char> v;
    REP(y,h) {
      REP(x,w) {
        char c;
        cin >> c;
        ba[x][y] = c;
        if (c == '.') continue;
        if (minx.count(c) == 0) {
          v.push_back(c);
          minx[c] = x;
          maxx[c] = x;
          miny[c] = y;
          maxy[c] = y;
        } else {
          minx[c] = min(minx[c], x);
          maxx[c] = max(maxx[c], x);
          miny[c] = min(miny[c], y);
          maxy[c] = max(maxy[c], y);
        }
      }
    }
    // FOR(it, v) {
    //   cout << *it << endl;
    //   printf("%d,%d  %d,%d\n", minx[*it], miny[*it], maxx[*it], maxy[*it]);
    // }
    sort(ALL(v));
    bool dame;
    do {
      char tmp[w][h];
      memcpy(tmp, ba, sizeof(ba));
      dame = 0;
      FOR(it, v) {
        char c = *it;
        // REP(y,h) {
        //   REP(x,w) {
        //     cout << tmp[x][y];
        //   }
        //   cout << endl;
        // }
        for (int y = miny[c]; y<= maxy[c]; ++y) {
          for (int x = minx[c]; x<= maxx[c]; ++x) {
            if (tmp[x][y] == c || tmp[x][y] == '*') {
              tmp[x][y] = '*';
            } else {
              dame = 1;
            }
          }
        }
      }
      if (!dame)
        break;
    }while(next_permutation(ALL(v)));
    if (dame) {
      cout << "SUSPICIOUS" << endl;
    } else {
      cout << "SAFE" << endl;
    }
  }
}

Measured memory_bytes: 908
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String longest="";
		String sentence;
		int maxlength=0;
		int max2 = 0;
		int count[] = new int[1000];
		sentence= sc.nextLine();//???????????\???
		String max[]=sentence.split(" ");
		
		for(int  i = 0; i<max.length;i++){//?????§?????????????????????
			for(int j = 0; j < max.length;j++){
				if(max[i]=="")continue;
				if(max[j]=="")continue;
				if(max[i].equals(max[j])){//????????????????????????
					count[i]++;
				}
			}
			if(max2<count[i]){//?????§????????´??°
				max2 = count[i];
			}
		}
		for(int i = 0;i<max.length;i++){
			if(max[i].length()>maxlength){
				longest = max[i];
				maxlength = max[i].length();
		}
		
		}
		for(int i = 0; i<max.length;i++){
			if(count[i]==max2){
				System.out.println(max[i]+" "+longest);
				break;
			}
		}
	}
}

Measured memory_bytes: 26076
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == "." :
                print("No")
                exit()
print("Yes")

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

#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;

int D[600][600] = {};
int main() {
    int n, c; cin >> n >> c;
    loop (c, i) loop (c, j) cin >> D[i][j];
    int ccnt[3][50] = {};
    loop (n, i) loop (n, j) {
        int k; cin >> k;
        ccnt[(i + j) % 3][k - 1]++;
    }

    ll ans = 1LL << 59;
    loop (c, k0) loop (c, k1) loop (c, k2) {
        if (k0 == k1 || k1 == k2 || k2 == k0) continue;
        int k[3] = { k0, k1, k2 };
        ll cost = 0;
        loop (3, i) loop (c, j) {
            cost += ccnt[i][j] * D[j][ k[i] ];
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x)                                                              \
  int n;                                                                       \
  while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define fin << '\n'
#define __ << " " <<
#define ___ << " "
#define bash push_back
#define ALL(x) x.begin(), x.end()
#define SWAP(a, b) ((a != b) && (a += b, b = a - b, a -= b))
//#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef vector<pii> vpi;
typedef greater<pii> gpi;
typedef priority_queue<pii, vpi, gpi> dijk;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
static const signed int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
template <class T> T abs(T &x) { return x < 0 ? -x : x; }
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;
}
int qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int n, m;
int a[1005];
int b[1005];
int c[1005][20];
int d[1000];
int e;
int mem[10005][5000];

int dp(int i, int x) {
  if (x == e)
    return 0;
  if (i == m)
    return INF;
  if (~mem[i][x])
    return mem[i][x];

  return mem[i][x] = min(dp(i + 1, x), dp(i + 1, x | d[i]) + a[i]);
}

inline void solve() {

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    for (int j = 0; j < b[i]; j++) {
      cin >> c[i][j];
      d[i] |= 1 << (c[i][j] - 1);
    }
  }
  e = (int)pow(2.0, n) - 1;
  memset(mem, -1, sizeof(mem));
  int ret = dp(0, 0);
  cout << (ret == INF ? -1 : ret) << endl;
}
struct xyz {
  xyz() {
    cin.tie(0), ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  };
} xyzzy;
signed main() {
  solve();
  return 0;
}


Measured memory_bytes: 195840
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>
using namespace std; 

void solve(){

}

int main(){
 int l, r, n; 
 cin >> l >> r >> n; 
 cout << r/n - (l-1)/n << "\n"; 
 return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int min_o(int h[],int n){
    int a=0,b=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        if(i%2==0) a=min(a+abs(h[i]-h[i-2]),b+abs(h[i-1]-h[i]));
        else b=min(b+abs(h[i]-h[i-2]),a+abs(h[i-1]-h[i]));
    }
    if(n%2==0) return b;
    else return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    cout<<min_o(h,n);
	return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int k,q,d[5100],dd[5100];
signed main(){
  cin>>k>>q;rep(i,k)cin>>dd[i];
  rep(_,q){
    int n,x,m, zero = 0;cin>>n>>x>>m;
    x %= m;
    rep(i,k){
      d[i] = dd[i] % m;
      if(!d[i])zero++;
    }
    int sum = 0;
    rep(i,k)sum += d[i];
    sum *= (n-1)/k;
    zero *= (n-1)/k;
    sum += x;
    rep(i,(n-1)%k){
      sum += d[i];
      if(!d[i])zero++;
    }
    int ret = n-1-zero-(sum/m);
    cout << ret << endl;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

int main() {
  static const double pi = 3.141592653589793;
  std::cout << std::setprecision(9);
  double a, b, x;
  cin >> a >> b >> x;

  double tan = 0.0;
  if(x >= a * a * b / 2) {
    tan = 2 * b / a - 2 * x / a / a / a;
  }
  else {
    tan = a * b * b / 2 / x;
  }
  double theta = atan(tan);
  double ans = theta * 180 / pi;
  cout << ans << endl;
}

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c; cin >> a >> b;
  if(b/10 == 0) {
    c = a*10 + b;
  }
  else if(b/100 == 0) {
    c = a*100 + b;
  }
  else {
    c = a*1000 + b;
  }
  bool square = 0;
  int i = 1;
  while(i * i <= c) {
    if(i * i == c) {
      square = 1;
    }
    i++;
  }
  if(square) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main() {
  string n;
  cin >> n;
  
  for (char c : n) {
    if ( c == '1') 
      cout << 9;
    else 
      cout << 1;
  }
  
  return 0;
}

Measured memory_bytes: 256
N=int(input())
M_list = [int(x) for x in input().split()]


while True:
  if len(M_list)==1:
    break
    
  Min_M=min(M_list)
  M_list_temp = [x for x in M_list if x%Min_M!=0 or x == Min_M]
  mod_list=[Min_M]
  mod_list.extend([ x%Min_M for x in M_list if x%Min_M!=0 ])
  mod_list=list(set(mod_list))
  
  M_list=mod_list
  
print(M_list[0])

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

int main() {
	int a,b,c;
	scanf("%d%d%d", &a, &b, &c);
	int ct=0;
	while (1) {
		if (a%2==1||b%2==1||c%2==1) break;
		if (a==b && b==c) {
			ct=-1;
			break;
		}
		int x=b/2+c/2;
		int y=c/2+a/2;
		int z=b/2+a/2;
		a=x; b=y; c=z;
		ct++;
	}
	printf("%d\n", ct);
}


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

int main()
{
   string S,T;
   cin>>S>>T;
  
   int count =0;
  
   for(int i=0;i<S.length();i++)
   {
   		if(S[i]!=T[i]) count++;
   }
   cout << count;
  return 0;
}

Measured memory_bytes: 3444
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;

int solve() {
    return n * (n + 1) / 2;
}

void input() {
    cin >> n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char x;
    scanf("%c",&x);

    if(x>='A' && x<='Z')
    {
        printf("A\n");
    }
    else if(x>='a' && x<='z')
    {
        printf("a\n");
    }
    return 0;
}


Measured memory_bytes: 1592