akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

//Node treeMinimum(Node x){


//}

//Node treeMaximum(Node x){


//}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return  treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

//Node treeSuccessor(Node x){


//}

//void treeDelete(Node z){
//  Node y; // node to be deleted
//  Node x; // child of y



//}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);

      if ( t != NIL ) printf("yes\n");
      else printf("no\n");

    } 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    //else if ( com[0] == 'd' ){
    //   scanf("%d", &x);
    //  treeDelete(treeSearch(root, x));
    //}
  }

  return 0;
}

Measured memory_bytes: 19360
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)

int v[4][4];

signed main(){
    FASTER;
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin>>v[i][j];
        }
    }
    map<int,int> mp;
    int n;cin>>n;
    while(n--){
        int in;cin>>in;
        mp[in]++;
    }
    int flg=0;
    for(int i=1;i<=3;i++){
        if(mp[v[i][i]]){
            flg++;
        }
    }
    if(flg==3){
        cout<<"Yes";
        return 0;
    }
    
    flg=0;
    for(int i=1;i<=3;i++){
        if(mp[v[i][4-i]]){
            flg++;
        }
    }
    if(flg==3){
        cout<<"Yes";
        return 0;
    }
    
    for(int j=1;j<=3;j++){
        flg=0;
        for(int i=1;i<=3;i++){
            if(mp[v[j][i]]){
                flg++;
            }
        }
        if(flg==3){
            cout<<"Yes";
            return 0;
        }
    }
    
    for(int j=1;j<=3;j++){
        flg=0;
        for(int i=1;i<=3;i++){
            if(mp[v[i][j]]){
                flg++;
            }
        }
        if(flg==3){
            cout<<"Yes";
            return 0;
        }
    }
    
    cout<<"No";
    
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i= 0; i < n; i++){
			String s = in.next();
			Node node = null;
			Node parent = null;
			Node root = null;
			for(int j =0; j < s.length(); j++){
				switch(s.charAt(j)){
				case '[':
					node = new Node(parent);
					if(parent == null){
						parent = node;
						root = node;
					}else{
						parent.children.add(node);
						node.parent = parent;
						parent = node;
					}
					break;
				case ']':
					parent = node.parent;
					node =  node.parent;
					break;
				default:
					String ss = ""+s.charAt(j);
					j++;
					while(s.charAt(j) != ']'){
						ss += ""+s.charAt(j);
						j++;
					}
					j--;
					node.value = Integer.parseInt(ss);
					node.isLeaf = true;
				}
			}
			root.calcValue();
			System.out.println(root.value);
		}
		in.close();
	}
	Node getRoot(Node n){
		while(n.parent != null){
			n = n.parent;
		}
		return n;
	}
	class Node implements Comparable<Node>{
		Node parent;
		ArrayList<Node> children;
		int value;
		boolean isLeaf = false;
		Node(Node p){
			parent = p;
			children = new ArrayList<Node>();
			value = -1;
		}
		void calcValue(){
			if(!canCalc()){
				for(Node n : children){
					n.calcValue();
				}
			}
			Collections.sort(children);
//			System.out.println(children.size());
//			for(Node n : children){
//				System.out.print(n.value + " ");
//			}
//			System.out.println("");
			int a = 0;
			for(int i = 0; i < children.size()/2+1; i++){
				if(children.get(i).isLeaf){
					a += children.get(i).value/2+1;
				}else{
					a += children.get(i).value;
				}
			}
			value = a;
		}
		boolean canCalc(){
			for(Node n : children){
				if(n.value == -1) return false;
			}
			return true;
		}
		@Override
		public int compareTo(Node o) {
			// TODO ?????????????????????????????????????????????
			return this.value - o.value;
		}
	}

}

Measured memory_bytes: 51852
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,K;
int Col[maxn];
int Mx[maxn];
inline int Read(){
	register int ch,a;
	while(ch=getchar(),ch<'0'||ch>'9');a=(ch^48);
	while(ch=getchar(),ch>='0'&&ch<='9')a=(a*10)+(ch^48);
	return a;
}

int h[maxn];
struct Edge{
	int to,nxt;
}e[maxn<<1];int tot_Edge;
inline void AddEdge(int from,int to){
	e[++tot_Edge]=(Edge){to,h[from]};
	h[from]=tot_Edge;
}
inline void dfs(int u,int Rem,int col){
	if(!Col[u])Col[u]=col;
	if(Rem<=Mx[u])return;
	Mx[u]=Rem;
	for(int i=h[u];i;i=e[i].nxt)dfs(e[i].to,Rem-1,col);
}

struct Que{
	int u,d,c;
}q[maxn];

int main(){
	n=Read(),m=Read();
	for(int i=1,u,v;i<=m;i++){
		u=Read(),v=Read();
		AddEdge(u,v),AddEdge(v,u);
	}
	K=Read();
	for(int i=1;i<=K;i++){
		q[i].u=Read(),q[i].d=Read(),q[i].c=Read();
	}
	for(int i=K;i>=1;i--)dfs(q[i].u,q[i].d,q[i].c);
	for(int i=1;i<=n;i++)printf("%d\n",Col[i]);puts("");
	return 0;
}



Measured memory_bytes: 4608
from collections import Counter

ans = int(input())
V = [int(i) for i in input().split()]

v1 = []
v2 = []

for i, v in enumerate(V):
    if i % 2 == 0:
       v1.append(v)
    else:
        v2.append(v)

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

k1, v1 = v1c[0][0], v1c[0][1]
k2, v2 = v2c[0][0], v2c[0][1]

if k1 == k2:
    ans -= v2
    m = 0
    if len(v1c) >= 2:
        m = max(m, v1c[1][1])
    if len(v2c) >= 2:
        m = max(m, v2c[1][1])
    ans -= m
else:
    ans -= v1 + v2

print(ans)


Measured memory_bytes: 21084
#include <atcoder/dsu>
#include <iostream>
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  
  atcoder::dsu d(N);
  
  for(int i=0;i<M;i++){
    int q,u,v;
    cin >> q >> u >> v;
    if(q==0){
      d.merge(u,v);
    }else{
      if(d.same(u,v)){cout << 1 << endl;}else{cout << 0 << endl;}
    }
  }
  return 0;
}

Measured memory_bytes: 3532
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

string s;

int main()
{
	cin >> s;
	int len = s.length();

	for (int i = 0; i < len - 8; i++) {
		cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().unwrap().unwrap();
    let n: i32 = a_line.parse().unwrap();

    writeln!(&mut writer, "{}", n * n * n).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let output = io::stdout();

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2", br"8
",
        ),
        (
            br"1", br"1
",
        ),
    ];

    #[test]
    fn test_a() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <alloca.h>
using namespace std;
#define int long long
vector<int> g[100010];
vector<int> tr[100010];
set< pair<int,int> > *altEdges[100010];
int a[200010],b[200010],w[200010],to[200010];
int uf[200010];
int used[200010];
int res[200010];

vector<int> es;


int root(int x){ return x == uf[x] ? x : uf[x] = root(uf[x]); }
int unite(int x,int y){ x = root(x); y = root(y); uf[x] = y; }
int minCost = 0;

int merge(int x,int y){
	if( altEdges[x]->size() < altEdges[y]->size() ){
		swap(altEdges[x],altEdges[y]);
	}
	unite(x,y);
	for( auto c : *altEdges[y] ){
		int eid = c.second;
		if( root(a[eid]) == root(b[eid]) ){
			altEdges[x]->erase({w[eid],eid});
		}else{
			altEdges[x]->insert({w[eid],eid});
		}
	}
}

vector< pair<int,int> > tour;
int gen(int src){
	stack< pair<int,int> > S;
	S.push({src,-1});
	while( S.size() ){
		src = S.top().first;
		int eid = S.top().second;
		S.pop();
		tour.push_back({src,eid});
		for( auto e : tr[src] ){
			if( e != eid ){
				int dst = src^to[e];
				S.push({dst,e});
			}
		}
	}
}
int dfs(int src,int eid){
	for(int i = 0 ; i < tour.size() ; i++){
		src = tour[i].first;
		eid = tour[i].second;
		for( auto e : g[src] ){
			if( e != eid ){
				altEdges[src]->insert({w[e],e});
			}
		}
		for( auto e : tr[src] ){
			if( e != eid ){
				int dst = src^to[e];
				merge(src,dst);
			}
		}
		if( eid != -1 ){
			while( altEdges[src]->size() ){
				int e2 = altEdges[src]->begin()->second;
				if( root(a[e2]) != root(b[e2]) ) break;
				altEdges[src]->erase({w[e2],e2});
			}
			if( altEdges[src]->size() ){
				res[eid] = minCost - w[eid] + altEdges[src]->begin()->first;
			}else{
				res[eid] = -1;
			}
		}
	}
}


signed main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++)
		altEdges[i] = new set< pair<int,int> >();
	es.resize(m);
	for(int i = 0 ; i < m ; i++){
		cin >> a[i] >> b[i] >> w[i];
		--a[i],--b[i];
		to[i] = a[i] ^ b[i];
		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
		es[i] = i;
	}
	for(int i = 0 ; i < n ; i++) uf[i] = i;
	sort(es.begin(),es.end(),[](int x,int y){return w[x]<w[y];});
	for(auto i : es ){
		if( root(a[i]) != root(b[i]) ){
			unite(a[i],b[i]);
			minCost += w[i];
			used[i] = true;
			tr[a[i]].push_back(i);
			tr[b[i]].push_back(i);
		}
	}
	for(int i = 0 ; i < m ; i++) res[i] = minCost;
	for(int i = 0 ; i < n ; i++) uf[i] = i;
	gen(0);
	reverse(tour.begin(),tour.end());
	dfs(0,-1);
	for(int i = 0 ; i < n ; i++){
		if( root(0) != root(i) ){
			for(int j = 0 ; j < m ; j++) res[j] = -1;
			break;
		}
	}
	for(int i = 0 ; i < m ; i++) cout << res[i] << endl;
	

}

Measured memory_bytes: 94128
use std::io::stdin;fn main(){let mut st = String::new();stdin().read_line(&mut st).unwrap();let s:Vec<char>=st.trim().chars().collect();let mut t=1;let mut c:usize=0;let mut r:[usize;2020]=[0;2020];let m=2019 as usize;for i in (0..s.len()).rev(){let x=(s[i] as usize)-48;c=(c+x*t)%m;r[c]+=1;t=(t*10)%m;};c=0;for i in 0..m{if &1<&r[i] {c+=(r[i]-1)*r[i]/2;}};c+=r[0];println!("{}",c)}

Measured memory_bytes: 3028
#include <stdio.h>
int main(void){
    
    int m, r, f;
    int sum;
    while(1){
        scanf("%d %d %d\n", &m, &r, &f);
        if(m == -1 && r == -1 && f == -1) break;
        if(m == -1 || r == -1){
            printf("F\n");
            continue;
        }
        
        sum = m + r;
        
        if(80 <= sum) printf("A\n");
        else if(65 <= sum && sum < 80) printf("B\n");
        else if(50 <= sum && sum < 65) printf("C\n");
        else if(30 <= sum && sum < 50 && 50 <= f) printf("C\n");
        else if(30 <= sum && sum < 50 && f < 50) printf("D\n");
        if(sum < 30) printf("F\n");
    }
    
    
    return 0;
    
}

Measured memory_bytes: 588
a, b, c, x = [int(input()) for _ in range(4)]
count = 0
for i in range(0,a+1):
    if 10*i > x/50:
            break
    for j in range(0,b+1):
        if 2*j > x/50:
            break
        for k in range(0,c+1):
            if k > x/50:
                break
            if 10*i+2*j+k == x/50:
                count += 1
print(count)

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

int main(){
    char a, b;
    cin >> a >> b;
    if(a == 'H' && b == 'H') cout << 'H';
    if(a == 'H' && b == 'D') cout << 'D';
    if(a == 'D' && b == 'H') cout << 'D';
    if(a == 'D' && b == 'D') cout << 'H';
    return 0;
}

Measured memory_bytes: 3652
import bisect

# 入力
def read_data():
    N_ = int(input())
    L_ = list(map(int, input().split()))
    return N_, L_

#探索
def binarySearch(N :int, L):
    ans = 0
    L.sort()
    # a,b は固定する
    for a_index in range(N):
        for b_index in range(a_index + 1, N):
            sum_of_a_and_b = L[a_index] + L[b_index]
            # c の可動範囲の右端を求める
            c_right_index = bisect.bisect_left(L, sum_of_a_and_b)
            # c の可動範囲は[b_index + 1, c_right_index)
            ans += max(0, c_right_index - b_index - 1)
    print(ans)

N, L = read_data()
binarySearch(N, L)

Measured memory_bytes: 42716
#include<stdio.h>
int partition(int p, int r);

int A[100000],n;

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

  k=partition(0,n-1);
  
  printf("[%d] ",A[k]);
  
  for(i=k+1;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
  
  return 0;
}
int partition(int p, int r){
  int tmp,x,i,j;
  
  x = A[r];
  i = p-1;
  for (j =p;j<r;j++){
    if (A[j] <= x){
      i = i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
      printf("%d ",A[i]);
    }
  }
  
  tmp=A[r];
  A[r]=A[i+1];
  A[i+1]=tmp;

  return i+1;
}
	   



Measured memory_bytes: 2120
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 40

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}


#define DIVISOR 1000000007
#define AB_MAX 200000

uint64_t get_power2(int n) {
    uint64_t ans = 1;
    uint64_t power2[32];
    power2[0] = 2;
    int i;
    for(i = 1; i < 31; i++) {
        power2[i] = (power2[i-1]*power2[i-1])%DIVISOR;
    }
    for(i = 0; i < 31; i++) {
        if(!(n & (1<<i))) continue;
        ans = (ans * power2[i])%DIVISOR;
    }
    return ans;
}

uint64_t inv_factorial[AB_MAX];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a==0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y - b/a * p.x, p.x};
}

void prep_inv(int n) {
    inv_factorial[0] = inv_factorial[1] = 1;
    int i;
    for(i = 2; i <= n; i++) {
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1]*inv)%DIVISOR;
    }
}

uint64_t get_combi(int n, int a) {
    uint64_t ans = 1;
    uint64_t i;
    // calc numerator
    for(i = n-a+1; i <= n; i++) {
        ans = (ans * i)%DIVISOR;
    }
    ans = (ans * inv_factorial[a])%DIVISOR;
#ifdef DEBUG
    printf("get_combi: %llu\n", ans);
#endif
    return ans;
}

int main(void) {
    int n, a, b;
    get_int3(&n, &a, &b);
    uint64_t ans = get_power2(n) - 1; // n_C_0 = 1
#ifdef DEBUG
    printf("%llu\n", ans);
#endif
    prep_inv(b);
    ans = (ans + DIVISOR - get_combi(n, a))%DIVISOR;
    ans = (ans + DIVISOR - get_combi(n, b))%DIVISOR;
    printf("%d\n", (int)ans);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
int main(){
  ll N,count=0;
  cin>>N;
  ll x=N+1;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
    if(vec.at(i)<=x){
      x=vec.at(i);
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
//#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define MOD (int)(1E9 + 7)
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
int n, m, q;
vector<tuple<int, int, int, int>> v;
int solve(vi& a, int cur, int fst, int pos)
{
    if (pos == n + 1)
    {
        int nxt = 0;
        for (int i = 0; i < q; i++)
        {
            int ai, bi, ci, di;
            tie(ai, bi, ci, di) = v[i];
            if (a[bi] - a[ai] == ci)
                nxt += di;
        }
        cur = max(cur, nxt);
    }
    else
        for (int i = fst; i <= m; i++)
            a[pos] = fst, cur = max(cur, solve(a, cur, i, pos + 1));
    return cur;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    v = vector<tuple<int, int, int, int>>(q);
    for (int i = 0; i < q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        v[i] = make_tuple(a, b, c, d);
    }
    vi res(n + 1);
    cout << solve(res, 0, 1, 0) << endl;
    GAME_OVER;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define abs(n) ( (n) < 0 ) ? -(n) : (n)

int main(void){

  //入力
  string s;
  cin >> s;
  
  //最初からAを検索
  int A, Z;
  A = s.find('A');
  
  //後ろからZを検索
  reverse(s.begin(), s.end());
  Z = s.find('Z');
  
  cout << (s.size() - Z) - A << endl;

  return 0;
}

Measured memory_bytes: 640
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    string s;cin >> s;
    int count = 0;
    rep(bit,(1<<s.size())) {
        string k = "";
        rep(i,s.size()) {
            if(1&(bit>>i)) k+=s[i];
            else {
                if(k!=""){
                    count+=stol(k);
                    // cout << k << endl;
                }
                k="";
            }
        }
        if(k!="") {
            count+=stol(k);
            // cout << k << endl;
        }
    }
    cout << count << endl;
    return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double
#define DUMP(v) "," #v ":" << v


int main(){
  string s, t;
  cin >> s >> t;

  // 最長マッチしている箇所を見つけ、マッチしていない文字数を答える
  int maxmatch = 0;
  const auto difflen = (int)(s.size() - t.size());
  for (int i = 0; i <= difflen; ++i) {
    int tmpmatch = 0;
    rep(j,t.size()) {
      if (s[i+j] == t[j]) tmpmatch++;
    }
    if (maxmatch < tmpmatch) {
      maxmatch = tmpmatch;
    }
  }

  ll ans = t.size() - maxmatch;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<sstream>
#include<map>
using namespace std;
 
#define N 100000
#define fs first
#define sc second
typedef pair<int,int> P;

P par[N];
int rank[N];
 
void init(int n){
  for(int i=0;i<n;i++)par[i] = P(i,0);
}
 
P find(int a){
  if(par[a].fs == a)return par[a];
  P tmp = find(par[a].fs);
  return par[a] = P(tmp.fs,tmp.sc + par[a].sc);
}
 
bool same(int a,int b){
  return (find(a).fs == find(b).fs);
}
 
int dis(int a, int b){
  if(!same(a,b))return 100000000;
  return par[b].sc - par[a].sc;
}

bool unite(int a,int b,int cost){
  P x = find(a);
  P y = find(b);
   
  
  if(same(x.fs,y.fs)){
    if(dis(a,b) != cost)return false;
  }else{
    if(rank[x.fs]<rank[y.fs]){
      par[x.fs] = P(y.fs,y.sc-x.sc-cost);
    }else{
      par[y.fs] = P(x.fs,x.sc-y.sc+cost);
      if(rank[x.fs] == rank[y.fs])rank[x.fs]++;
    }
  }
  return true;
}

int main(){
  char c;
  int a,b,w,n,m;

  while(cin >> n >> m,n||m){
    init(n);
    for(int i=0;i<m;i++){
      cin >> c;
      if(c=='?'){
	cin >> a >> b;
	a--; b--;
	if(same(a,b))cout << par[b].sc - par[a].sc << endl;
	else cout << "UNKNOWN\n";
      }else{
	cin >> a >> b >> w;
	a--; b--;
	unite(a,b,w);
      }
    }
  }
}

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int nxt = 1, cnt_break = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == nxt) {
            ++nxt;
        } else {
            ++cnt_break;
        }
    }
    cout << (cnt_break > n - 1 ? -1 : cnt_break) << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
const int64_t MX = 1e18;
int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  rep(i, N){
    if (A.at(i)  == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  int64_t out = 1;
  for (int64_t i: A){
    if((MX / out)< i){
      cout << -1 << endl;
      return 0;
    }
    out *= i;
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 4044
#include <stdio.h>

int main()
{
  char s[11];
  scanf("%s", s);

  int count = 0;
  int max;

  for(int i=0; i<10; i++)
  {
    if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')
    {
      count++;
    }
    else
    {
      if(max < count)
      {
        max = count;
      }
      count = 0;
    }
  }
  if(max < count)
  {
    max = count;
  }

  printf("%d\n",max);

  return 0;
}

Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const int MOD = 1e9 + 7;
class Modint {
public:
	long long val;

	Modint (long long _val = 0)
		: val((_val + MOD) % MOD) {}

	Modint operator+ (Modint other) {
		return Modint(val + other.val);
	}

	void operator+= (Modint other) {
		val += other.val;
		val %= MOD;
	}

	Modint operator- () {
		return Modint(MOD - val);
	}

	Modint operator- (Modint other) {
		return Modint(val + MOD - other.val);
	}

	void operator-= (Modint other) {
		val += MOD - other.val;
		val %= MOD;
	}

	Modint operator* (Modint other) {
		return Modint(val * other.val);
	}

	void operator*= (Modint other) {
		val *= other.val;
		val %= MOD;
	}

	bool operator== (Modint other) {
		return val == other.val;
	}

	bool operator!= (Modint other) {
		return val != other.val;
	}
};

Modint exp (Modint a, int k) {
	if (k == 0) {
		return Modint(1);
	} else if (k % 2 == 0) {
		Modint half = exp(a, k / 2);
		return half * half;
	} else {
		return a * exp(a, k - 1);
	}
}

Modint inv (Modint a) {
	return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
	out << p.val;
	return out;
}


int main() {

	long long  n, k; cin >> n >> k;
	vector<long long > pref(n + 1, 0);
	iota(pref.begin(), pref.end(), 0);
	for (long long  i = 1; i <= n; i++) pref[i] += pref[i - 1];

	Modint ans = 1;
	for (long long  i = k; i <= n; i++) {
		long long  left = pref[i - 1] - pref[0];
		long long  right = pref[n] - pref[n - i];

		ans += Modint(right - left + 1);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 4468
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b, c) = {
        let v: Vec<String> = read_vec();
        (v[0].clone(), v[1].clone(), v[2].clone())
    };

    let a: Vec<char> = a.chars().collect();
    let b: Vec<char> = b.chars().collect();
    let c: Vec<char> = c.chars().collect();

    let last_a = a[a.len()-1];

    let head_b = b[0];
    let last_b = b[b.len()-1];

    let head_c = c[0];

    if last_a == head_b && last_b == head_c {
       println!("YES");
    } else {
       println!("NO");
    }

}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	//変数の宣言
	int n,t,a;
	int h[1010];
	int i;
	double kionsa;
	double minkionsa;
	int num;
	
	//データの読み込み
	scanf("%d",&n);
	scanf("%d %d",&t,&a);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	minkionsa=fabs(t-h[0]*0.006-a);
	num=0;
	
	for(i=0;i<n;i++){
		kionsa=fabs(t-h[i]*0.006-a);
//		printf("%d番目の気温差は%lf\n",i,kionsa);
		if(minkionsa>kionsa){
			minkionsa=kionsa;
			num=i;
		}
	}
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",num+1);
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n;
  cin >> n;
  if (n < 600)
    cout << 8 << endl;
  else if (n < 800)
    cout << 7 << endl;
  else if (n < 1000)
    cout << 6 << endl;
  else if (n < 1200)
    cout << 5 << endl;
  else if (n < 1400)
    cout << 4 << endl;
  else if (n < 1600)
    cout << 3 << endl;
  else if (n < 1800)
    cout << 2 << endl;
  else if (n < 2000)
    cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        ll m = n / i;
        ans += m * (m + 1) / 2 * i;
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3644
N = int(input())
s = input()
s_r = []
s_b = []
for i in range(len(s)):
    if s[i] == 'B':
        s_b.append(s[i])
    else:
        s_r.append(s[i])
if len(s_r) > len(s_b):
    print('Yes')
else:
    print('No')

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    long long x;
    cin >> x;
    long long ans = ((2 * x + 10) / 11);
    if (x % 11 == 6) ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=1e18;
main(){
    int pos=0;
    for(int i=1;i<=5;++i){
        int x;
        cin>>x;
        if(x==0)pos=i;
    }
    cout<<pos<<endl;
}


Measured memory_bytes: 3492
import java.util.Scanner;
class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   while(sc.hasNextInt()){
	   int b=sc.nextInt();
	   int c=sc.nextInt();
	   System.out.println(String.valueOf(b+c).length()
);
   }
    }
}

Measured memory_bytes: 26588
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define mod 1000000007



int main()
{
 //O_O ;
   ll a,b,k;
   cin>>k>>a>>b;ll p=0;
  for(ll i=a;i<=b;i++)
    if(i%k==0)
    p=1;
  if(p)
    cout<<"OK"<<nn;
   else

    cout<<"NG"<<nn;



    return 0;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
}

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

int main() {
    int N,s=0;
    cin >> N;
    vector<int> A(N),r(N);
    rep(i,N) {
        cin >> A.at(i);
        s += A.at(i);
    }
    
    r.at(0) = s;
    rep(i,N/2)
        r.at(0) -= 2 * A.at(i*2+1);
    rep(i,N-1)
        r.at(i+1) = 2*A.at(i) - r.at(i);
    rep(i,N)
        cout << r.at(i) << " ";
    cout << endl;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


Measured memory_bytes: 256
use std::io;
use std::io::{BufRead, Write};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (a, b, c): (usize, usize, usize) = {
        let mut split = buf.split_whitespace();
        (
            split.next().unwrap().parse().unwrap(),
            split.next().unwrap().parse().unwrap(),
            split.next().unwrap().parse().unwrap(),
        )
    };
    let max = *[a, b, c].iter().max().unwrap();
    let rem = max * 3 - a - b - c;
    let result = if rem % 2 == 1 { rem + 3 } else { rem } / 2;
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "2 5 4
",
            "2\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "2 6 3
",
            "5\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "31 41 5
",
            "23\n",
        );
    }
}


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

#define index(i) (((i) + n) % n)

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    ll count = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    for (;;) {
        ll count1 = count;
        for (int i = 0; i < n; i++) {
            if (b[index(i-1)] + b[index(i+1)] <= b[index(i)]) {
                int s = b[index(i-1)] + b[index(i+1)];
                int t = (b[i] - a[i]) / s;
                b[index(i)] -= s*t;
                count += t;
            }
        }
        if (count1 == count) break;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            count = -1;
            break;
        }
    }
    cout << count << endl;
}



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

ll f(P a, P b) {
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int main() {
    random_device seed_gen;
    mt19937_64 engine(seed_gen());

    ll n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    ll ans = 0;
    ll mi, ma;
    rep(i, n) {
        if (i == 0) {
            mi = p[i].second; ma = p[i].second;
        }
        else {
            mi -= p[i].first - p[i - 1].first;
            ma += p[i].first - p[i - 1].first;
            ans = max(ans, max(abs(p[i].second - mi), abs(p[i].second - ma)));
            mi = min(p[i].second, mi);
            ma = max(p[i].second, ma);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6344
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

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

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	string s;
	int k;
	cin >> s >> k;

	const int n = s.size();
	bool same = true;
	rep(i, n) if(s[0] != s[i]) same = false;

	if(same) {
		const ll ans = 1LL * n * k / 2LL;
		cout << ans << endl;
		return 0;
	}

	vector<ll> base;

	rep(l, 1, 3){
		vector<int> num;

		string t = "";
		rep(loop, l) t += s;
		const int m = t.size();

		char prv = t[0];
		int cnt = 0;

		rep(i, m){
			if(t[i] == prv){
				cnt++;
			} else {
				num.push_back(cnt);
				prv = t[i];
				cnt = 1;
			}
		}
		num.push_back(cnt);
		
		ll tmp = 0LL;
		for(auto &elem: num) tmp += 1LL * elem / 2LL;
		base.push_back(tmp);
	}

	const ll ans = base[0] + 1LL * (k - 1) * (base[1] - base[0]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

int main() {
    int N;
    cin >> N;
    vi h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    vi dp(N, INF);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; ++i) {
        dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1],
                    abs(h[i] - h[i - 2]) + dp[i - 2]);
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import javax.transaction.xa.Xid;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, k;
	static long mod = 1000000007;
	static int[][] memo;
	static String s;
	static HashSet<Integer> nodes;
	static HashSet<Integer>[] ad, tree;
	static boolean[] vis, taken;
	static int[] a;
	static TreeSet<Long> al;
	static long[] val;
	static ArrayList<String> aa;
	static char[] b;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		k = sc.nextInt();
		long ans = modPow(k, n);
		// System.out.println(ans);
		long[] ol = new long[k+1];
		for (int i = k; i >= 2; i--) {
			long ti = modPow(k / i, n);
            for(int j=i+i;j<=k;j+=i)
            	ti=(ti-ol[j]+mod)%mod;
			ans = (ans - ti + mod) % mod;
			long l = ti * i % mod;
			ans = (ans + l) % mod;
			ol[i]=ti;
		}
		System.out.println(ans);
		out.flush();
	}

	static long modPow(long a, long e)

	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res = (res * a) % mod;
			a = (a * a) % mod;
			e >>= 1;
		}
		return res;
	}

	static long gcd(long a, long b) {

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

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 33868
#include<stdio.h>
#include<math.h>
int main(void){
	int c=0,turn,go;
	double x=0,y=0;
	do{
		scanf("%d,%d",&go,&turn);
		x=x+sin(((c*1.0)/180)*(atan(1.0)*4.0))*go;
		y=y+cos(((c*1.0)/180)*(atan(1.0)*4.0))*go;
		c=c+turn;
	}while(turn!=0||go!=0);
	printf("%d\n%d\n",(int)(x),(int)(y));
	return 0;
}

Measured memory_bytes: 604