akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int check = 0;

        for(int i = 0; i <3; i++){
            if(S.charAt(i) == T.charAt(i)){
                check ++;
            }
        }


        System.out.println(check);

    }
}





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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;

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

	rep(i,n)
	{
		int x,y,b,p;
		cin >> x >> y >> b >> p;

		int ret = x*b + y*p;

		b = max(b,5);
		p = max(p,2);

		int res = x*b + y*p;
		res *= 0.8;

		cout << min(ret,res) << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
map<int,int> mp;
 int a[maxn];
 int n;
 ll ans;
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int  i=1;i<=n;i++)
   if(i-a[i]>0) mp[i-a[i]]++;
for(int  i=1;i<=n;i++)
   if(mp[i+a[i]])ans+= mp[i+a[i]];
cout<<ans;
return 0;
}


Measured memory_bytes: 14576
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll N,A,B,C,D;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>A>>B>>C>>D;
    
    rep(i,N-1){
        ll hig=A+D*i-C*(N-1-i);
        ll low=A+C*i-D*(N-1-i);
        if(hig>=B&&low<=B){
            cout1("YES");
            return 0;
        }
    }
    cout1("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
    int H,W,countwhite=0,count;
    bool flag=false;//bool デフォルトはfalse?
    cin >> H >> W;
    vector<vector<char>> v(H+2,vector<char>(W+2));
    for(int i=0;i<H+2;i++){
        for(int j=0;j<W+2;j++){
            if(i==0 || j==0 || i == H+1 || j == W+1){
                v.at(i).at(j) = '#';
            }
            else{
                cin >> v.at(i).at(j);
                if(v.at(i).at(j) == '.'){
                    if(i==H && j==W){
                        continue;
                    }
                    else if(i==1 && j==1){
                        continue;
                    }
                    else{
                        countwhite++;
                    }
                }
            }
        }
    }//inputして最初と最後以外の白の数をカウント

    int dx[4] = {-1,1,0,0};
    int dy[4] = {0,0,-1,1};
    queue<int> q;
    q.push(1);q.push(1);q.push(0);

    while(q.size() !=  0){//DFS
        int x,y,step;
        x = q.front();q.pop();
        y = q.front();q.pop();
        step = q.front();q.pop();

        for(int i=0;i<4;i++){
            if(v.at(x+dx[i]).at(y+dy[i])=='.'){
                if(x+dx[i]==H && y+dy[i]==W){
                    count = step;//たどり着くまでの最短手数
                    flag = true;
                    break;
                }//ゴールにたどり着いたらそこまでの移動距離（ゴールへの移動は除く）をメモ
                v.at(x+dx[i]).at(y+dy[i])='#';
                q.push(x+dx[i]);
                q.push(y+dy[i]);
                q.push(step+1);
            }
        }
        if(flag == true){break;}
    }
    if(flag==true){//たどり着けた場合
        cout << countwhite-count << endl;
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define en "\n"
using namespace std;

const ll M=1e16+7;
int main()
{
    ios::sync_with_stdio(false);
    ll ans,m=M,tem;
    cin>>ans;
    for(int i=0;i<5;i++)
    {
        cin>>tem;
        m=min(m,tem);
    }

    ans-=m;
    ans=max(ans,(ll)0);
    if(ans%m)cout<<5+ans/m+1<<en;
    else cout<<5+ans/m<<en;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	string s; cin >> s;
	int ans = s.size();
	rep(i, s.size() - 1) {
		if (s[i] != s[i + 1]) {
			ans = chmin(ans, max(i + 1, (int)s.size() - (i + 1)));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
function Main(input) {
  lines = input.split('\n')
  N = lines[0] * 1
  s = lines[1].split(" ").map(function(a) { return 1 / a * 1 })
  ans = s.reduce(function(i, a) {
      return i + a
  }, 0)
  console.log(1 / ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 21064
// ABC139_B
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,sum=0,cnt=0;
    cin >> A >>B;
    if((B-1) % (A-1) == 0){
        cnt = (B-1)/(A-1);
    }else{
        cnt =(B-1)/(A-1)+1;
    }

    cout <<cnt <<endl;
}

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

using namespace std;

const int maxn=1e5+5,mod=1e9+5;

typedef long long ll;

int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
       int ans=0;
       while(n)
       {
           ans++;
           n/=k;
       }
       printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;

LL read(){
	char c=getchar();
	LL t=0,f=1;
	while(c>'9'||c<'0') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') t=t*10+c-'0',c=getchar();
	return t*f;
}

int n,op[N],st;
LL sum[N],absum[N]; 
char ch[2];

int main(){
	n=read(),sum[1]=absum[1]=read(),st=op[1]=1;
	for(int i=2,x;i<=n;i++){
		scanf("%s",ch),op[i]=(ch[0]=='-')?-1:1;
		x=read(),sum[i]=sum[i-1]+x*op[i],absum[i]=absum[i-1]+x;
	}
	LL ans=sum[n];
	while(op[st]>0) st++;
	for(int i=2,j=3;i<=n;i=j,j++){
		if(op[i]>0 )continue;
		LL tmp=sum[i-1];
		while(op[j]>0&&j<=n) j++;
		tmp+=(absum[n]-absum[j-1])-(absum[j-1]-absum[i-1]);
		ans=max(ans,tmp);
	}
	printf("%lld\n",ans);
}
/*
3
5 - 1 - 3
5
1 - 20 - 13 + 14 - 5
6
3 - 5 + 1 + 6 - 11 - 13
*/

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

/* Typedefs */

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

/* Consts */

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N;

void solve() {
    cin >> N;
    vector<int> a(N - 1), ans(N);
    for(int i = 0; i < N - 1; i++) {
        cin >> a[i];
        ans[i] = 0;
    }
    for(int i = 0; i < N - 1; i++) ans[a[i] - 1]++;
    for(int i = 0; i < N; i++) {
        cout << ans[i] << "\n";
    }
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    // ll T; cin >> T;
    // while (T--) solve();
    solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 4752
#include <stdio.h>

main(){
  static int a[2000001],c[10001],b[2000001],i,n,k;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  
  k=0;
  for(i=1;i<=n;i++){
    if(a[i]>k) k=a[i];
  }

  for(i=0;i<=k;i++){
    c[i]=0;
  }
  
  for(i=1;i<=n;i++){
    c[a[i]]++;
  }
  
  for(i=1;i<=k;i++){
    c[i]=c[i]+c[i-1];
  }

  for(i=n;i>0;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }

  for(i=1;i<=n;i++){
    if(i > 1) printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 16268
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;
 
double dist( double x1, double y1, double x2, double y2 ){
	return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
 
int main(){
	double x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	double a = dist(x1, y1, x2, y2);
	double b = dist(x2, y2, x3, y3);
	double c = dist(x3, y3, x1, y1);
	double d = max({a, b, c});
	double S = abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;
	double R = S*2/(a+b+c);
	cout << fixed << setprecision(12) << d/(d/R+2) << endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n) {
    if ((n % 10) == 7)  {
      cout << "Yes\n";
      return 0;
    } 
    n /= 10;
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H-h)*(W-w)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    bool use[26] = {};
    for(auto c : s){
        use[c - 'a'] = true;
    }
    REP(i,26){
        if(!use[i]){
            cout << s << char('a' + i) << endl;
            return 0;
        }
    }
    REP(i,26){
        use[i] = false;
    }
    char pre = s[s.size() - 1];
    use[pre - 'a'] = true;
    for(int i = s.size() - 2; i >= 0; i--){
        char c = s[i];
        if(c < pre){
            int t;
            REP(j,26){
                if('a' + j < c) continue;
                if(use[j]){
                    t = j;
                    break;
                }
            }
            cout << s.substr(0, i) << char('a' + t) << endl;
            return 0; 
        }
        pre = c;
        use[c - 'a'] = true;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
def rec_cost(x,acc,plist,clist):
  if x == 1:
    return acc
  else:
    minimum = -1
    for next in plist:
      nextplist = plist.copy()
      nextplist.remove(next)
      candidate = rec_cost(next,acc+clist[x][next],nextplist,clist)
      if minimum == -1:
        minimum = candidate
      elif candidate < minimum:
        minimum = candidate
    return minimum

def cost(n,clist):
  plist = [0,1,2,3,4,5,6,7,8,9]
  plist.remove(n)
  return rec_cost(n,0,plist,clist)

def joisino(a,clist):
  note = [-1,0,-1,-1,-1,-1,-1,-1,-1,-1]
  answer = 0
  for raw in a:
    for number in raw:
      if number != -1:
        if note[number] == -1:
          note[number] = cost(number,clist)
        answer += note[number]
      
  return answer

def i_o():
  h, w = map(int,input().split(" "))
  i = 0 
  clist = []
  while i < 10:
    raw = list(map(int,input().split(" ")))
    clist.append(raw)
    i += 1
  a = []
  i = 1
  while i <= h:
    raw = list(map(int,input().split(" ")))
    a.append(raw)
    i += 1
  return h,w,clist,a

if __name__ == '__main__':
  h,w,clist,a = i_o()
  ans =joisino(a,clist)
  
  print(ans, flush=True)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> grh(n);
  vector<int> cnt(n);
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    grh[s].push_back(t);
    cnt[t]++;
  }
  stack<int> stk;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 0) {
      stk.push(i);
    }
  }
  while (!stk.empty()) {
    int crr = stk.top();
    stk.pop();
    printf("%d\n", crr);
    for(auto nxt : grh[crr]) {
      cnt[nxt]--;
      if (cnt[nxt] == 0) {
        stk.push(nxt);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3736
n = int(input())
list = [input().split(' ') for i in range(n)]
restaurant = [[n+1, list[n][0], int(list[n][1])] for n in range(n)]

restaurant.sort(reverse=True, key=lambda x: x[2])
restaurant.sort(key=lambda x: x[1])
for i,_,_ in restaurant:
    print(i)

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

const int N = 305;
double dp[N][N][N];
bool vis[N][N][N];
int n;
int cnt[5];

double rec(int c1,int c2,int c3)
{
    if(c1+c2+c3==0) return 0;
    double &ret=dp[c1][c2][c3];
    if(vis[c1][c2][c3]==1) return ret;
    vis[c1][c2][c3]=1;
    ret=0.0;
    int rem=n-c1-c2-c3;
    double temp=1.0;
    if(c1>0) temp+=(1.0*c1*rec(c1-1,c2,c3))/(1.0*n);
    if(c2>0) temp+=(1.0*c2*rec(c1+1,c2-1,c3))/(1.0*n);
    if(c3>0) temp+=(1.0*c3*rec(c1,c2+1,c3-1))/(1.0*n);
    ret=(1.0*temp*n)/(n-rem+0.0);
    return ret;
}



int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        int x;
        scanf("%d",&x);
        cnt[x]++;
    }
    double ret=rec(cnt[1],cnt[2],cnt[3]);
    printf("%.12f\n",ret);

}


Measured memory_bytes: 246016
#include <stdio.h>

int main(){
  int n, k;  scanf("%d%d", &n, &k);

  if(n == 1){
    printf("1\n");
    return 0;
  }

  long long int counter = 1;
  do{
    counter++;
    n /= k;
  }while(n / k);

  printf("%lld\n", counter);

  return 0;
}


Measured memory_bytes: 128
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	cnts := map[int]int{}
	for i := 0; i < n; i++ {
		x := nextInt()
		_, ok := cnts[x]
		if ok {
			cnts[x] += 1
		} else {
			cnts[x] = 1
		}
	}
	res := 0
	for _, v := range cnts {
		if v%2 == 1 {
			res++
		}
	}
	fmt.Println(res)
}

// -------- Library --------
var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	v, _ := strconv.Atoi(next())
	return v
}

func nextIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		res[i] = nextInt()
	}
	return res
}


Measured memory_bytes: 7296
#include <stdio.h>
int main(void){
 int h,w;
 int i,j;
 while(1){
     scanf("%d %d",&h,&w);
     if(h == 0 && w == 0)break;
     for(i = 0; i < h;i++){
         for(j = 0;j < w;j++){
             if(i == 0||i == h-1||j == 0||j == w-1){
             printf("#");
         }else {
         printf(".");
     }
         }
     printf("\n");
 }
 printf("\n");
 }
 return 0;
}



Measured memory_bytes: 2564
import math
#X=int(input())
N,M,Q=map(int,input().split())
S=[[]for i in range(Q)]
for i in range(Q):
    a=list(map(int,input().split()))
    S[i]=a
ans=0
T=0
for a in range(1,M+1):
    for b in range(a, M+1):
        for c in range(b, M+1):
            for d in range(c, M+1):
                for e in range(d, M+1):
                    for f in range(e, M+1):
                        for g in range(f, M+1):
                            for h in range(g, M+1):
                                for i in range(h, M+1):
                                    for j in range(i, M+1):
                                        D=[a,b,c,d,e,f,g,h,i,j]
                                        for k in range(Q):
                                            if D[S[k][1]-1]-D[S[k][0]-1]==S[k][2]:
                                                ans+=S[k][3]
                                        if ans>=T:
                                            T=ans
                                        ans = 0
print(T)


Measured memory_bytes: 77092
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll N;
  cin >> N;
  //map<int64_t, int> mp= prime_factor(N);
  ll ans = 0;
  for (auto p : prime_factor(N)) {
    int cnt = 1;
   // cout << p.first << endl;
    while (p.second >= 0) {
      p.second -= cnt;
      cnt++;
      if(p.second>=0){
        ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

struct vertex {
	int estart,estart2;
	int dist;
} v[203];
struct edge {
	int enext,to;
	int cap;
} e[40003];int en;
void addedge(int a,int b,int cap)
{
	e[en].enext = v[a].estart;e[en].to = b;e[en].cap = cap;v[a].estart = en++;
	e[en].enext = v[b].estart;e[en].to = a;e[en].cap = 0;v[b].estart = en++;
}
int dfs(int i,int cap)
{
	if(i == 1) return cap;
	int flow = 0;
	for(int &j = v[i].estart2;cap > 0 && j != -1;j = e[j].enext) {
		int to = e[j].to;
		if(v[to].dist != v[i].dist + 1) continue;
		int val = dfs(to,std::min(cap,e[j].cap));
		flow += val;cap -= val;e[j].cap -= val;e[j^1].cap += val;
	}
	return flow;
}
int n,m;
int a1[103][103],a2[103][103];
std::pair<int,int> pos[20003];
int main()
{
	scanf("%d%d",&n,&m);
	int vn = 2+n*2;
	for(int i = 0;i < vn;++i) {
		v[i].estart = -1;
	}
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < m;++j) {
			int val;
			scanf("%d",&val);--val;
			pos[val] = std::make_pair(i,j);
		}
	}
	for(int i = 0;i < n*m;++i) {
		addedge(2+pos[i].first,2+n+i/m,1);
	}
	assert(en == 2*n*m);
	for(int i = 0;i < n;++i) {
		addedge(0,2+i,0);
		addedge(2+n+i,1,0);
	}
	for(int k = 0;k < m;++k) {
		// get exactly one matching
		for(int i = 0;i < n;++i) {
			++e[2*n*m+4*i].cap;
			++e[2*n*m+4*i+2].cap;
		}
		int flow = 0;
		while(flow < n) {
			// dinic
			for(int i = 0;i < vn;++i) {
				v[i].estart2 = v[i].estart;
				v[i].dist = -1;
			}
			v[0].dist = 0;
			std::queue<int> q;q.push(0);
			while(!q.empty()) {
				int cur = q.front();q.pop();
				for(int j = v[cur].estart;j != -1;j = e[j].enext) {
					if(e[j].cap == 0) continue;
					int to = e[j].to;
					if(v[to].dist == -1) {
						v[to].dist = v[cur].dist + 1;
						q.push(to);
					}
				}
			}
			if(v[1].dist == -1) break;
			flow += dfs(0,n);
		}
		assert(flow == n);
		// get result
		for(int i = 0;i < n*m;++i) {
			if(e[2*i+1].cap > 0) {
				e[2*i+1].cap = 0;
				a1[pos[i].first][k] = i;
				a2[i/m][k] = i;
			}
		}
	}
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < m;++j) printf("%d ",a1[i][j]+1);
		printf("\n");
	}
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < m;++j) printf("%d ",a2[i][j]+1);
		printf("\n");
	}
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const LL MAX = 1e4+10;
const LL INF = 1e16;
LL dp[2][MAX][2];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  VL xs(N+1);
  REP(i,N-1) cin >> xs[i+1];

  fill((LL*)dp, (LL*)dp+MAX*2*2, INF);
  int crt = 0, nxt = 1;
  dp[crt][0][0] = 0;
  REP(i,N){
	fill((LL*)dp[nxt], (LL*)dp[nxt]+MAX*2, INF);
	for(int a=0;a<=i;++a){
	  dp[nxt][a+1][0] = min(dp[crt][a][1] + xs[i+1],
							dp[crt][a][0] + xs[i+1] - xs[i]);
	  dp[nxt][a][1] = min(dp[crt][a][0] + xs[i+1],
						  dp[crt][a][1] + xs[i+1] - xs[i]);
	}
	swap(crt, nxt);
  }

  cout << min(dp[crt][N/2][0], dp[crt][N/2][1]) << endl;

  return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int[] p = new int[m];
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }

        int sum = 0;

        for (int i = 0; i < n; i++) {
            sum = sum + t[i];
        }
        for (int i = 0; i < m; i++) {
            System.out.println(sum - t[p[i] - 1] + x[i]);
        }
    }
}


Measured memory_bytes: 23764
import sys

def findset(x,element):
    if(x != element[x]):
        element[x] = findset(element[x],element)
    return element[x]

def union(x,y,rank,element):
    link(findset(x,element),findset(y,element),rank,element)

def link(x,y,rank,element):
    if(rank[x] > rank[y]):
        element[y] = x
    else:
        element[x] = y
        if(rank[x] == rank[y]):
            rank[y]+=1

n,q = map(int, input().split());

element = [i for i in range(n)]
rank = [0 for i in range(n)]

for i in range(q):
    query,x,y = map(int, input().split());
    if(query == 0):
        union(x,y,rank,element)
    else :
        if(findset(x,element) == findset(y,element)):
            print(1)
        else:
            print(0)


Measured memory_bytes: 6040
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


const int MAX_COUNT = 100110;
int dp[MAX_COUNT];
const int INF = 1000000007;

int solve(int n, int k, vector <int> h) {
    rep(i, MAX_COUNT) {
        dp[i] = INF;
    }
    dp[0] = 0;
    loop(i, 0, n) {
        for (int j = 1; j <= k; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    return dp[n - 1];
}


int main() {
    int n, k;
    vector<int> h;
    cin >> n >> k;
    rep(i, n) {
        int a;
        cin >> a;
        h.push_back(a);
    }
    int ans = solve(n, k, h);
    cout << ans << "\n";
}


Measured memory_bytes: 1528
#include<stdio.h>

int main(void)
{
	int i,n,h1=0,h2;
	int flg=1,stock=0;
	int ans =0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h2);
		if(h1>h2+1)
			ans=1;
		if(h1-h2==1 && stock ==1)
			stock=0;
		else if(h1-h2==1 && stock == 0)
			ans=1;
		if(h1<h2)
			stock=1;
		h1=h2;
	}
	if(ans==0)
		printf("Yes");
	else
		printf("No");
	return 0;
}
			

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

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop, heapify
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# UnionFind
class UnionFind():
    def __init__(self, n):
        self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

    def get_root(self, x):
        # nodes[x]が負ならxが根
        if self.nodes[x] < 0:
            return x
        # 根に直接つなぎ直しつつ、親を再帰的に探す
        else:
            self.nodes[x]=self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x, y):
        root_x=self.get_root(x)
        root_y=self.get_root(y)
        # 根が同じなら変わらない
        # if root_x == root_y:
        # pass
        if root_x != root_y:
            # 大きい木の方につないだほうが計算量が減る
            if self.nodes[root_x] < self.nodes[root_y]:
                big_root=root_x
                small_root=root_y
            else:
                small_root=root_x
                big_root=root_y
            self.nodes[big_root] += self.nodes[small_root]
            self.nodes[small_root]=big_root

def main():
    N,M = MI()
    uf=UnionFind(N)
    get_root, unite, nodes=uf.get_root, uf.unite, uf.nodes

    edge = []
    for i in range(M):
        s,t,c = MI()
        edge.append((c,s,t))


    edge.sort()

    ans = 0
    for cost,u,v in edge:
        if get_root(u)!=get_root(v):
            unite(u,v)
            ans += cost

    print(ans)
if __name__ == '__main__':
    main()
"""
 N,M = MI()
    edge = [[] for _ in range(N)]
    for i in range(M):
        s,t,c = MI()
        edge[s].append((c,t))
        edge[t].append((c,s))
    pri_queue = edge[0]
    heapify(pri_queue)
    spanning = set([0])
    ans = 0
    # print(pri_queue)
    while pri_queue:
        cost,to = heappop(pri_queue)
        if to not in spanning:
            # print(to)
            ans += cost
            spanning.add(to)
            for cost,to in edge[to]:
                heappush(pri_queue,(cost,to))
    print(ans)
"""


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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, K, Q;
   cin >> N >> K >> Q;

   vector<int> count(N + 1, 0);

   for (int i = 1; i <= Q; i++) {
     int tmp;
     cin >> tmp;
     count.at(tmp)++;
   }

   for (int i = 1; i <= N; i++) {
     if (K - Q + count.at(i) <= 0) cout << "No" << endl;
     else cout << "Yes" << endl;
   }
 }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int ans[201];
  int cnt=0;
  while(cin>>a>>b){
    int temp=a+b;
    int n=9;
    int count=1;
    while(1){
      if(n>=temp){
	break;
      }else{
	count++;
	n=n*10+9;
      }
    }
    ans[cnt]=count;
    cnt++;
  }
  for(int i=0;i<cnt;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}
	
      
      
  

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

#define RESULT_MAX 50
#define RANK_A     80
#define RANK_B     65
#define RANK_C     50
#define RANK_D     30

typedef struct test{
	int  m;				// 中間試験
	int  f;				// 期末試験
	int  r;				// 再試験
	char rank = 'F';
}TEST;

void SetRank(TEST *t_result);

int main()
{
	TEST t_result[RESULT_MAX];
	int  dataNum = 0;				// 格納したデータ数
	
	for(int i = 0; i < RESULT_MAX; i++, dataNum++)
	{
		// 点数の入力
		cin >> t_result[i].m;
		cin >> t_result[i].f;
		cin >> t_result[i].r;
		
		// 入力値が全て-1の場合、何もしないで終了
		if( (-1 == t_result[i].m) && (-1 == t_result[i].f) && (-1 == t_result[i].r) )
		{
			break;
		}
		
		// rankの設定
		SetRank(&t_result[i]);
	}
	
	// ランクの出力
	for(int i = 0; i < dataNum; i++)
	{
		cout << t_result[i].rank << endl;
	}
	
	return 0;
}

// SetRank()
// Function  : A~D, Fのランク付けをする関数
// Param[out]: TEST構造体 (試験の結果が格納された構造体)
// Return    : なし
// Global    : 
void SetRank(TEST *t_result)
{
	// 欠席はFランク
	if( (-1 == t_result->m) || (-1 == t_result->f) )
	{
		t_result->rank = 'F';
		return;
	}
	
	// 中間試験と期末試験の合計を計算
	int sum;
	sum = t_result->m + t_result->f;
	
	// ランク付け
	if(RANK_A <= sum)
	{
		t_result->rank = 'A';
	}
	else if(RANK_B <= sum)
	{
		t_result->rank = 'B';
	}
	else if(RANK_C <= sum)
	{
		t_result->rank = 'C';
	}
	else if(RANK_D <= sum)
	{
		// 再試験がCランクの閾値を超えた場合、Cランク
		if(RANK_C <= t_result->r)
		{
			t_result->rank = 'C';
		}
		else
		{
			t_result->rank = 'D';
		}
	}
	else
	{
		t_result->rank = 'F';
	}
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<functional>

using namespace std;

typedef long long ll;

template <class Monoid> struct SegTree {
	int N;
	vector<Monoid> node;
	std::function<Monoid(Monoid, Monoid)> operation;
	Monoid unit;//単位元

	SegTree(vector<Monoid>& data, std::function<Monoid(Monoid, Monoid)> op, Monoid U) {
		//データ　演算　単位元
		operation = op;
		unit = U;
		int size = data.size();
		N = 1;
		while (N < size)N <<= 1;
		node.resize(2 * N - 1, unit);

		for (int i = 0; i < size; i++) {
			node[i + N - 1] = data[i];
		}

		for (int i = N - 2; i >= 0; i--) {
			node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

	void update(int pos, Monoid val) {
		pos += N - 1;
		node[pos] = val;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			node[pos] = operation(node[pos * 2 + 1], node[pos * 2 + 2]);
		}
	}

	Monoid getval(int a, int b, int idx, int l, int r = -1) {
		//[a, b)を求める。　使い方はgetval(a, b, );
		if (r == -1)r = N;
		if (b <= l || r <= a)return unit;
		if (a <= l && r <= b)return node[idx];
		Monoid left = getval(a, b, idx * 2 + 1, l, (l + r) / 2);
		Monoid right = getval(a, b, idx * 2 + 2, (l + r) / 2, r);
		return operation(left, right);
	}

	Monoid getval(int a, int b) {
		//ラッパー。
		return getval(a, b, 0, 0, -1);
	}
};

int N, M;
string S;

int main() {
	cin >> N >> M >> S;

	vector<int> tmp(N + 1, 1145141919);
	SegTree<int> dp(tmp, [](int a, int b) {return min(a, b); }, 1145141919);
	dp.update(N, 0);

	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '1')continue;
		dp.update(i, dp.getval(i + 1, min(N + 1, i + 1 + M)) + 1);
	}

	if (dp.getval(0, 1) == 1145141919) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> anslist;
	int nowp = 0;
	while (nowp != N) {
		for (int i = nowp + 1; i <= min(nowp + M, N); i++) {
			if (dp.getval(i, i + 1) != 1145141919 && dp.getval(i, i + 1) != dp.getval(nowp, nowp + 1)) {
				anslist.push_back(i - nowp);
				nowp = i;
				break;
			}
		}
	}

	for (int i = 0; i < anslist.size(); i++)cout << anslist[i] << " ";

	cout << endl;
	return 0;
}

Measured memory_bytes: 2552
#include <stdio.h>
#include <string.h>
 
int main(void) {
    int inputN = 0;
    int inputM = 0;
    scanf("%d", &inputN);
    scanf("%d", &inputM);
    // printf("%d\n", inputN);
    // printf("%d\n", inputM);
    int inputPi = 0;
    char inputS[3] = {};
    int param[100001][2] = {};
    int resultAC = 0;
    int resultWA = 0;
    for(int i=0; i<inputM; ++i) {
        scanf("%d", &inputPi);
        scanf("%s", inputS);
        if(strcmp("AC", inputS) == 0) {
            if(param[inputPi][1] == 0) {
                param[inputPi][1] = 1;
                resultAC++;
                resultWA+= param[inputPi][0];
            }
        } else if(strcmp("WA", inputS) == 0) {
            if(param[inputPi][1] == 0) {
                param[inputPi][0]++;
            }
        }
    }
    printf("%d %d\n", resultAC, resultWA);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>s(N);
  vector<ll>date;
   ll sum=0;
  rep(i,N){
    cin>>s[i];
   
    
    if(s[i]%10!=0){
      date.push_back(s[i]);
    }
    
    sum+=s[i];

  }
  
  sort(all(date));
  
  if(sum%10==0&&date.size()==0){
    cout<<0<<endl;
  }
  else if(sum%10==0&&date.size()!=0){
    rep(i,date.size()){
      sum-=date[i];
      if(sum%10!=0){
break;
      }
    }
    
    if(sum%10==0){
      cout<<0<<endl;
    }
    else{
      cout<<sum<<endl;
    }
  }
  else{
cout<<sum<<endl;
  }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.call(in,out);
        out.close();
    }

    public static int twoPower(int n  ,int[] arr){
        int b;
        int count=-1;
        b = arr.length-1 -n;
        while(b!=0){
            b/=2;
            count++;
        }
        return count;
    }

    static class TaskA {
        public void call(InputReader in, PrintWriter out ) {
            int b , n  , k;
            n=in.nextInt();
            k=in.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++){
                arr[i]=in.nextInt();
            }

            int[] dp = new int[n];

            for(int i=dp.length-2; i>=0;i--){
                b=Integer.MAX_VALUE;
                for (int j =1;j+i<dp.length && j<=k;j++)  {
                    int first = Math.abs(arr[i] - arr[j+i]) + dp[j+i];
                    if (first < b) {
                        b = first;
                    }

                }
                dp[i] = b ;
            }
            out.println(dp[0]);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
}


Measured memory_bytes: 33852
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int,int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
long long mod = 1e9 + 7;
vector<int> graph[100004];
int used[100005] = { 0 };
void dfs(int now) {
	used[now] = 1;
	for (int i = 0; i < graph[now].size(); i++) {
		int to = graph[now][i];
		if (used[to] == 0) {
			used[to] = 1;
			dfs(to);
		}
	}
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout <<fixed<< setprecision(16);
	int n, m;
	cin >> n >> m;
	int x, y, z;
	for (int i = 0; i < m; i++) {
		cin >> x >> y >> z;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (used[i] == 0) {
			ans += 1;
			dfs(i);
		}
	}
	cout << ans;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	cout<<(a&1 && b&1 ? "Yes" : "No")<<'\n';
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        // 温度の入力
        int ondo = int.Parse(Console.ReadLine());
        // 金額判定
        String Answer = "No";
        if(30 <= ondo){
          Answer = "Yes";
        }
        // 結果出力
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 17644
n = int(input())
S = input()
cnt = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      i_pos = S.find(str(i))
      if i_pos == -1:
        continue
      j_pos = S.find(str(j),i_pos+1)
      if j_pos == -1:
        continue
      k_pos = S.find(str(k),j_pos+1)
      if k_pos == -1:
        continue
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
//#include <algorithm> //no rotate
#include <vector>
using namespace std;
int main(){
	int n,k,m,i;
	for(;cin>>n>>k>>m,n;){
		vector<int>vec(n);
		for(i=0;i<n;i++)vec[i]=i+1;
		i=(m-1)%vec.size();
		vec.erase(vec.begin()+i);
		for(;vec.size()>1;vec.erase(vec.begin()+i))if(i+=(k-1)%vec.size(),i>=vec.size())i-=vec.size();
		cout<<vec[0]<<endl;
	}
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
int main(){
	string sa,sb,sc;
	getline(cin,sa);
	getline(cin,sb);
	int i,j=0,k=0,len;
	len=sa.size()+sb.size();
	for(i=0;i<len;i++){
		if(i%2==1) sc+=sb[j++];
		else sc+=sa[k++];
	}
	cout<<sc;
	return 0;
}

Measured memory_bytes: 256
n,*a=$<.read.split.map &:to_i
r=[0]*n
c=1
t=0
n.times do |i|
  r[t]+=1
  if a[i]<c
    t+=1
    c=a[i-1]
  end
  c+=2
end
cc=0
tt=1
n.downto(1) do |i|
  cc+=r[n-i]
  tt*=i-(n-cc)
  tt%=(10**9+7)
end
p tt




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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int n;
vi mul(const vi &v, const vi &p){
    vi nv(n-1);
    for (int i = 0; i < n-1; i++) nv[i] = v[p[i]];
    return nv;
}

vi exp(vi &v, vi &p, ll k){
    if (k == 0) {
        vi res(n-1);
        iota(res.begin(), res.end(), 0);
        return res;
    }
    if (k & 1){
        return mul(exp(v, p, k-1), p);
    }
    vi tmp = exp(v, p, k/2);
    return mul(tmp, tmp);
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    int m; cin >> m;
    ll k; cin >> k;
    vi brr(m);
    for (int i = 0; i < m; i++){
        cin >> brr[i];
        brr[i] -= 2;
    }
    vi diff;
    for (int i = 0; i < n-1; i++){
        diff.push_back(arr[i + 1] - arr[i]);
    }
    vi p(n-1);
    iota(p.begin(), p.end(), 0);
    for (int i = 0; i < m; i++){
        swap(p[brr[i]], p[brr[i]+1]);
    }
    vi perm(n-1), np(n-1);
    iota(perm.begin(), perm.end(), 0);
    for (; k; k >>= 1){
        if (k & 1){
            for (int i = 0; i < n-1; i++){
                np[i] = perm[p[i]];
            }
            perm = np;
        }
        for (int i = 0; i < n-1; i++){
            np[i] = p[p[i]];
        }
        p = np;
    }
    ll ans = arr[0];
    cout << ans << endl;
    for (int i = 0; i < n-1; i++){
        ans += diff[perm[i]];
        cout << ans << endl;
    }
}


Measured memory_bytes: 3704
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a: usize,
        b: usize,
        k: usize,
    }
    let mut time = 0;
    for i in a..b+1 {
        time+=1;
        if time <= k {
            println!("{}", i);
        } else if time >= b - a - k + 2 {
            println!("{}", i);
        }
    }
}

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

int main(void){
    int N;
    double ans = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        double A;
        cin >> A;
        ans += 1.0 / A;
    }
    printf("%10.10f\n", 1.0 / ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    static final long MODVAL = 998244353L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        if(N > K) {
            long modulo = N / K;
            N -= modulo * K;
        }
        if(N==K) {
            System.out.println("0");
            return;
        }
        System.out.println(String.format("%d", Math.min(Math.abs(N-K), Math.abs(N))));
    }
}


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

int main(){
  int h,w; cin >>h >>w;
  char s[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        if(s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#'){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
}

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

const int mxN = 1e5 + 5;
bool done[mxN];
int WA[mxN];

int main() {
	int n, m;
	cin >> n >> m;
	int ac = 0, wa = 0;
	for(int i = 1; i <= m; ++i) {
		int p;
		cin >> p;
		string s;
		cin >> s;
		if(done[p])
			continue;
		if(s == "AC") {
			wa += WA[p];
			++ac;
			done[p] = true;
		}
		else
			++WA[p];
	}
	cout << ac << ' ' << wa;
}


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

namespace abc064_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if ((a[0] * 100 + a[1] * 10 + a[2]) % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int ans = 0;

		for (int i = 0; i <= n / r; i++) {
			for (int j = 0; j <= n / g; j++) {
				if (r * i + g * j > n)
					break;
				if ((n - r * i - g * j) % b == 0)
					ans++;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  map<int, int> mp;
  for(int i=0; i<N; ++i){
    int x; cin >> x;
    ++mp[x];
  }
  auto it = mp.begin();
  int res = 0;
  while(it != mp.end()){
    if((it->second)&1) ++res;
    ++it;
  }
  cout << res << "\n";
  return 0;  
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
main(){
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",s);
			d[i]=strlen(s);
		}
		for(i=0;i<n;i++){
			p=i;
			for(j=0;j<5;j++){
				q=a[j];
				while(q>0){
					q-=d[p];p++;
				}
				if(q<0){
					p=-1; break;
				}
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    unordered_set<int64_t> s1, s2, s3;
    for (auto c : s) {
        auto k = c - '0';

        for (auto l : s2) {
            s3.insert(l * 10 + k);
        }

        for (auto l : s1) {
            s2.insert(l * 10 + k);
        }

        s1.insert(k);
    }

    cout << s3.size() << endl;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
l=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    l[a]+=b
inc=0
for i in range(10**5+1):
    inc+=l[i]
    if inc>=k:
        print(i)
        break


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

int main() {
  int N, M;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) cin >> T[i];
  cin >> M;
  vector<vector<int>> drink(M, vector<int>(2));
  for (int i = 0; i < M; i++) cin >> drink[i][0] >> drink[i][1];

  int sum = accumulate(T.begin(), T.end(), 0);
  for (int i = 0; i < M; i++) {
    cout << sum - T[ drink[i][0] - 1] + drink[i][1] << endl;
  }
}


Measured memory_bytes: 256
n = input()
s = raw_input()
right = 0
for i in xrange(n):
    if s[i] == '(':
        right += 1
    else:
        right = max(right-1, 0)
left = 0
for i in xrange(n-1, -1, -1):
    if s[i] == ')':
        left += 1
    else:
        left = max(left-1, 0)
print '('*left+s+')'*right

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

int main() {
  int s, ans;
  ans = 0;
  cin >> s;
  ans += s % 10;
  s /= 10;
  ans += s % 10;
  s /= 10;
  ans += s % 10;
  cout << ans << endl;
}

Measured memory_bytes: 256
s=input()
n=len(s)
if n%2==0:
  t=list(s[:n//2])
  u=list(s[n//2:])
  t.reverse()
  cnt=0
  for i in range(len(t)):
    if t[i]==u[i]:
      continue
      
    else:
      cnt+=1
  
else:
  t=list(s[:n//2])
  u=list(s[n//2+1:])
  t.reverse()
  cnt=0
  for i in range(len(t)):
    if t[i]==u[i]:
      continue
      
    else:
      cnt+=1
      
      
print(cnt)
  

Measured memory_bytes: 3064