akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

struct Edge
{
	int next,to;
}e[MAXN<<1];
int head[MAXN],etot=0;
inline void add(int u,int v)
{
	e[++etot]=(Edge){ head[u],v};
	head[u]=etot;
}

int clr[MAXN],ccnt[3];
void dfs(int u,int fa)
{
	++ccnt[clr[u]];
	for(int i=head[u]; i; i=e[i].next)
	{
		int v=e[i].to;
		if(v==fa) continue;
		clr[v]=!clr[u];
		dfs(v,u);
	}
}

queue<int> q[4];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<n; ++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	
	dfs(1,0);
	
	for(int i=1; i<=n; ++i)
		q[i%3].push(i);
	int c1 = q[1].size();
	int c2 = q[2].size();
	
	if(c1 <= ccnt[0] && c2 <= ccnt[1])
		for(int i=1; i<=n; ++i)
		{
			int x = clr[i]+1;
			if(q[x].empty()) x=0;
			printf("%d ",q[x].front());
			q[x].pop();
		}
	else if(c1 <= ccnt[1] && c2 <= ccnt[0])
		for(int i=1; i<=n; ++i)
		{
			int x = (!clr[i])+1;
			if(q[x].empty()) x=0;
			printf("%d ",q[x].front());
			q[x].pop();
		}
	else if(c1+c2 <= ccnt[0])
		for(int i=1; i<=n; ++i)
		{
			int x;
			if(clr[i]) x=0;
			else if(!q[1].empty()) x=1;
			else if(!q[2].empty()) x=2;
			else x=0;
			printf("%d ",q[x].front());
			q[x].pop();
		}
	else if(c1+c2 <= ccnt[1])
		for(int i=1; i<=n; ++i)
		{
			int x;
			if(!clr[i]) x=0;
			else if(!q[1].empty()) x=1;
			else if(!q[2].empty()) x=2;
			else x=0;
			printf("%d ",q[x].front());
			q[x].pop();
		}
	else printf("-1");
	return 0;
}

Measured memory_bytes: 12672
#正の場合、0の場合、負の場合で分ける
#負の数のみの場合は調整しようがない
#偶数の時は絶対値の大きい順
#奇数の時は絶対値の小さい順
#正の数のみの場合は大きい順
#大きい順

#他は調整できるので、正で大きくする方向で考える(正→0以上)
#負の数は偶数個ないと正にならないので二つ一組で先にかけて考える
#正の数も同様に先にかけて、その中で大きいものを選べば良い

#負の数が奇数個、正の数が奇数個の時(負の数が余る、正の数が余る)
#Kが偶数の時はいい感じに選んでく(N=kの時は仕方ないので全部)
#Kが奇数の時は正の中で最大のものを選ぶ
#負の数が偶数個、正の数が奇数個の時(正の数が余る)
#Kが偶数の時はいい感じに選んでく
#奇数の時は残りの正の中から選ぶ
#負の数が奇数個、正の数が偶数個の時(負の数が余る)
#N=Kの時は全部選ぶ、それ以外の場合は余った負の数はいらない
#Kが奇数の時は残りの正の中で最大のものを選べば良い
#負の数が偶数個、正の数が偶数個の時
#Kが奇数の時は残りの正の中で最大のものを選べば良い

#N=Kの時は別で分けて考えるとすると、負の数及び正の数によらず
#Kが偶数の時は大きいものからいい感じに選んでく
#Kが奇数の時は最後の残り一個は正の残りの中で最大のものを選ぶ
#と簡単に言い換えることができる

#x:配列
mod=10**9+7
def multarray(x):
    ret=1
    for i in x:
        ret*=i
        ret%=mod
    return ret

n,k=map(int,input().split())
a=list(map(int,input().split()))

if n==k:
    print(multarray(a))
    exit()

ap,am=[],[]
for i in range(n):
    if a[i]>=0:
        ap.append(a[i])
    else:
        am.append(a[i])
#絶対値の順番
ap.sort(reverse=True)
am.sort()

if len(am)==0:
    print(multarray(ap[:k]))
    exit()
if len(ap)==0:
    if k%2==0:
        print(multarray(am[:k]))
    else:
        print(multarray(am[::-1][:k]))
    exit()

apm2=[]
for i in range(len(am)//2):
    apm2.append((am[2*i]*am[2*i+1],0))
for i in range(len(ap)//2):
    apm2.append((ap[2*i]*ap[2*i+1],1))
apm2.sort(reverse=True)

#+の次にどこを見るのかをチェックしておく
p=0
ans=[]
for i in range(k//2):
    p+=(2*apm2[i][1])
    ans.append(apm2[i][0])

if k%2==0:
    print(multarray(ans))
    exit()

#ここで不正アクセスの可能性を避ける
#プラスが余ってない場合(一個減らして次のマイナス使う)
#余ってる場合もafter_contestで落ちる
#その一個をとるのが最適とは限らず、一個減らして次のマイナスの二個とる場合も
ans_cand=[]
#一個増やす場合
if p!=len(ap):
    ans_cand.append(multarray(ans)*ap[p]%mod)
if p>=2:
    #一個減らして二個増やす場合
    check_i=ans.index(ap[p-1]*ap[p-2])
    #0除算を避ける
    ans[check_i]=ap[p-2]
    ans.append(apm2[k//2][0])
    ans_cand.append(multarray(ans))
print(max(ans_cand))


Measured memory_bytes: 33152
#include<iostream>
using namespace std;
int cmp(const void *a,const void *b){
	return(*(int*)b-*(int*)a);
}
int main(){
	int n,k,l[50],a=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>l[i];
	qsort(l,n,sizeof(int),cmp);
	for(int i=0;i<k;i++){
		a+=l[i];
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
while (n=gets.to_i)!=0
  mat=Array.new(n+1){Array.new(n+1,0)}
  ans=Array.new(n+1){Array.new(n+1)}
  n.times.with_index do |id|
    mat[id]=gets.split.map(&:to_i)
    mat[id][n]=mat[id].inject(:+)
    (n+1).times.with_index do |id2|
      mat[n][id2]+=mat[id][id2]
    end
  end
  mat.each.with_index do |item,id|
    item.each.with_index do |ss,id2|
      ans[id][id2]=format("%5d",ss)
    end
  end
  ans.each do |line|
    puts line.join
  end
end

Measured memory_bytes: 8840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    i64 wf=-llinf,ws=-llinf,wt=-llinf;
    i64 kf=-llinf,ks=-llinf,kt=-llinf;
    i64 p;
    for(i64 i=0LL;i<10LL;++i){
        scanf("%lli",&p);
        if(p>wf){
            wt=ws;
            ws=wf;
            wf=p;
        }
        else if(p>ws){
            wt=ws;
            ws=p;
        }
        else if(p>wt){
            wt=p;
        }
    }
    for(i64 i=0LL;i<10LL;++i){
        scanf("%lli",&p);
        if(p>kf){
            kt=ks;
            ks=kf;
            kf=p;
        }
        else if(p>ks){
            kt=ks;
            ks=p;
        }
        else if(p>kt){
            kt=p;
        }
    }
    printf("%lli %lli\n",wf+ws+wt,kf+ks+kt);
    return 0;
}



Measured memory_bytes: 2048
n = int(input())
branch = [[] for _ in range(n)]
a, b, inda, indb = [], [], [], []
for _ in range(n-1):
    i, j = map(int, input().split())
    i -= 1
    j -= 1
    branch[i].append(j)
    branch[j].append(i)
    a.append(i)
    b.append(j)
    inda.append(len(branch[i])-1)
    indb.append(len(branch[j])-1)

kind = max([len(i) for i in branch])
print(kind)

# DFS
color = [0 for _ in range(n)]
todo = [0]
color[0] = 1
while len(todo) > 0:
    num = todo.pop(-1)
    col = color[num]
    if col == kind:
        col = 1
    else:
        col = col + 1
    for i in range(len(branch[num])):
        if color[branch[num][i]] == 0:
            color[branch[num][i]] = col
            todo.append(branch[num][i])
            branch[num][i] = -col
            if col == kind:
                col = 1
            else:
                col = col + 1
            

for i in range(n-1):
    if branch[a[i]][inda[i]] < 0:
        print(-branch[a[i]][inda[i]])
    else:
        print(-branch[b[i]][indb[i]])

Measured memory_bytes: 94880
#include <stdio.h>
#include <math.h>
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int main() {
	int q;
	double a, b, s, l;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		scanf("%lf%lf", &a, &b);
		s = min(a, b); l = max(a, b);
		if (s == l)
			printf("%lld\n", (long long int)(2 * s - 2));
		else if (s + 1 == l)
			printf("%lld\n", (long long int)(2 * s - 2));
		else
		{
			long long int j;
			j = (long long int)sqrt(a*b);
			for (; j*j < a*b; j++);
			j--;
			if (j*(j + 1) < a*b)
				printf("%lld\n", 2 * j - 1);
			else
				printf("%lld\n", 2 * j - 2);
		}
	}
	return 0;
}

Measured memory_bytes: 128
X = gets.to_i

S = []
X.times do |_|
  S << gets.chomp.to_s
end

h = {}
S.sort.each do |s|
  count = h[s] == nil ? 1 : (h[s] + 1)
  h[s] = count
end

count = h.map do |k, v|
  v
end.max

res = h.select { |k, v| v == count }.map { |k, v| k }
res.sort.each { |r| puts r }


Measured memory_bytes: 60748
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  char X,Y;
  cin >> X >> Y;
  if (X<Y) {
    cout << '<' << endl;
  }
  else {
    if (X==Y) {
      cout << '=' << endl;
    }
    else {
      cout << '>' << endl;
    }
  }
}


Measured memory_bytes: 3608
c1 = 0
c2 = 0
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
for i in range(M) :
    if A[i] < X :
        c1 += 1
    else :
        c2 += 1
print(min(c1,c2))



Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  vector<vector<int> > c(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> c[i][j];
  int y1 = c[1][0] - c[0][0], y2 = c[2][0] - c[1][0];
  if (c[1][1] - c[0][1] != y1 || c[1][2] - c[0][2] != y1 || c[2][1] - c[1][1] != y2 || c[2][2] - c[1][2] != y2) {
    cout << "No\n";
    return 0;
  }
  int x1 = c[0][1] - c[0][0], x2 = c[0][2] - c[0][1];
  if (c[1][1] - c[1][0] != x1 || c[2][1] - c[2][0] != x1 || c[1][2] - c[1][1] != x2 || c[2][2] - c[2][1] != x2) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  ll a[n], b[n];
  ll a_sum = 0, b_sum = 0;
  REP(i, n) {
    cin >> a[i];
    a_sum += a[i];
  }
  REP(i, n) {
    cin >> b[i];
    b_sum += b[i];
  }
  ll cnt = b_sum - a_sum;
  ll a_cnt = cnt, b_cnt = cnt;
  bool ok = true;
  REP(i, n) {
    if (a[i] < b[i]) {
      ll t = (b[i] - a[i] + 1) / 2;
      if (a_cnt < t) {
        cout << "No" << endl;
        return 0;
      }
      a[i] += 2 * t;
      a_cnt -= t;
    }
  }
  REP(i, n) {
    if (a[i] > b[i]) {
      ll t = a[i] - b[i];
      if (b_cnt < t) {
        cout << "No" << endl;
        return 0;
      }
      b[i] += t;
      b_cnt -= t;
    }
  }
  if (2 * a_cnt != b_cnt) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

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

long long n, k;
long long ans = 0;

int main()
{
	scanf("%lld %lld", &n, &k);
	if(k == 0) printf("%lld\n", n * n);
	else {
		for(register int i = max(k, 1ll); i <= n; ++i){
			ans += (n / i) * (i - k) + (n % i >= k ? n % i - k + 1 : 0);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  int ans=0;
  
  for (int i=a; i<b+1; i++){
    int v,w,x,y,z;
    v=i/10000;
    w=(i-v*10000)/1000;
    x=(i-v*10000-w*1000)/100;
    y=(i-v*10000-w*1000-x*100)/10;
    z=i-v*10000-w*1000-x*100-y*10;
    
    if (v==z&&w==y){
      ans++;
    }
}
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,d,x,a;
    cin>>n>>d>>x;
    int sum=0;
    for (int i=0;i<n;i++) {
        int count=0;
        cin>>a;
        for (int j=0;j*a+1<=d;j++) {
            count++;
        }
        sum+=count;
    }
    cout<<sum+x<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
ll n;
int rec(ll x, int a, int b, int c){
  if(x > n) return 0;
  ll next = 10 * x;
  int res = rec(next +3, a + 1, b, c);
  res += rec(next + 5,a, b + 1, c);
  res += rec(next + 7, a, b, c + 1);
  if(a > 0 && b > 0 && c > 0) res++;
  return res;
}

int main(){
  cin >> n;
  ll ans = rec(0, 0, 0, 0);
  cout << ans << endl;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> grid(H, vector<char>());

    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            char tmp;
            cin >> tmp;

            grid[i].push_back(tmp);
            // cout << i << " " << j << " " << tmp << " " << grid.at(i).at(j) << "\n";
        }
    }

    vector<bool> row(H, false);
    vector<bool> col(W, false);
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (grid[i][j] == '#') {
                row[i] = true;
                col[j] = true;
                // cout << "row" << i << " " << row[i] << " col" << j << " " << col[j] << "\n";
            }
        }
    }

    for (int i=0; i<H; i++) {
        if (row[i] == true) {
            for (int j=0; j<W; j++) {
                if (col[j] == true) {
                    cout << grid[i][j];
                }
            }
            cout << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 256
/**
Code by Nitin1184
**/
# include <bits/stdc++.h>
# define ll long long
# define pi 3.14159265358979323846
# define M 1000000007
# define pb push_back
# define mp make_pair
# define ff first
# define ss second
 
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char ch;
    cin>>ch;
    if(ch<96)
        cout<<"A\n";
    else
        cout<<"a\n";
    return 0;
}

Measured memory_bytes: 3636
N = int(input())
Xs = list(map(int, input().split()))
L,R = min(Xs), max(Xs)
cost = 0 if L==R else float("inf")
for p in range(L+1,R):
  cost_p = sum([(xi-p)**2 for xi in Xs])
  cost = cost_p if cost_p < cost else cost
print(cost)

Measured memory_bytes: 3060
LI = lambda: list(map(int, input().split()))

K = int(input())


def main():
    s = 1
    p = 1
    for i in range(1, K + 1):
        if 7 * s % K == 0:
            print(i)
            return
        p = 10 * p % K
        s = (s + p) % K
    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <climits>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

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

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

#define MAXN 310

using namespace std;

int a[MAXN][MAXN], b[MAXN][MAXN];

int n, m, k;

int cnt;

char c;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> c;
			if (c == '#') a[i][j] = ++cnt;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j]) {
				int h = j;
				while (!b[i][h] && h) {
//					if (a[i][j] == 4) cout << h << endl;
					b[i][h] = a[i][j];
					h--;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if (!b[i][m]) {
			int h = m;
			while (!b[i][h] && h) h--;
			int cc = b[i][h];
			while (h <= m) b[i][h++] = cc;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (b[i][j]) {
				int h = i - 1;
				while (!b[h][j] && h) b[h--][j] = b[i][j];
				h = i + 1;
				while (!b[h][j] && h <= n) b[h++][j] = b[i][j];
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << b[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
} 

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    bool flag = false;
    rep(i, n) {
        cin >> a[i];
        if (a[i] > i || (i > 0 && a[i - 1] + 1 < a[i])) {
            flag = true;
        }
    }
    if (flag) {
        puts("-1");
        return 0;
    }
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + 1 == a[i + 1])
            ans++;
        else
            ans += a[i + 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 150
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],val[MAX],ans[MAX];bool vis[MAX];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read(),val[i]=i;
	for(int i=n;i;--i)
	{
		int mx=0,pos=-1;
		for(int j=1;j<=n;++j)
			if(!vis[j]&&val[j]==a[j])
				if(a[j]>mx&&a[j]<=i)mx=a[j],pos=j;
		if(pos==-1){puts("-1");return 0;}
		ans[i]=mx;vis[pos]=true;
		for(int j=pos+1;j<=n;++j)val[j]-=1;
	}
	for(int i=1;i<=n;++i)printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
def sub(c):
    val = 0
    s = 0
    for num in a:
        if c*(s+num)<=0:
            val += abs(s+num-c)
            s = c
        else:
            s += num
        c *= -1
    return val
ans = min(sub(1), sub(-1))
print(ans)

Measured memory_bytes: 86544
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {

            TextReader input = Console.In;

            string str = input.ReadLine();

            int week = 0;
            if (!int.TryParse(str, out week)) {
                return;
            }

            decimal start = 100;

            for (int ii = 0; ii < week; ii++) {
                start *= 1.05m;
                // 切り上げ
                start = Math.Ceiling(start);
            }
            Console.WriteLine(start * 1000m);
        }
    }
}

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

using namespace std;
typedef long long ll;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    int m = max(a, max(b, c));
    int last = m * 3 - sum;
    int cnt = 0;
    if (last % 2 == 0){
        cnt = last / 2;
    }
    else{
        last += 3;
        cnt = last / 2;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
const double PI = acos(-1.0);
using namespace std;
int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    cout << fixed << setprecision(10);
    long double rad = PI * 2 * (
            (long double)H / 12.0 + ((long double)M / 60.0) / 12.0 -
            (long double)M / 60.0);
    long double ans = (long double)(A * A + B * B) - (long double)(2 * A * B) * cosl(rad);
    cout << sqrtl(ans) << endl;
}


Measured memory_bytes: 4084
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstdint>
using namespace std;

int_fast8_t d;
uint_fast32_t M = 0;
uint_fast64_t c, sd = 0, sc = 0;
constexpr int buff_size = 1 << 18;
char buff[buff_size], *ci = buff + buff_size, *ce = ci, ct;

inline char read_input() {
    if (ci == ce) { fread_unlocked(buff, 1, buff_size, stdin); ci = buff; }
	return *ci++;
}

int main() {
    while((ct=read_input())>47) M = (M<<1) + (M<<3) + ct - 48;
    while(M--) {
        d = read_input() - 48;
        read_input();
        for(c=0; (ct=read_input())>47;) c = (c<<1) + (c<<3) + ct - 48;
        sc += c;
        sd += c * d;
    }
    printf("%lld", --sc + --sd / 9);
	return 0;
}


Measured memory_bytes: 384
def main():
    A, B, C = map(int, input().split())
    A, B, C = sorted([A, B, C])
    cnt = 0

    if abs(A-B) % 2 == 0:
        while A != B:
            A += 2
            cnt += 1

        while A != C and B != C:
            A += 1
            B += 1
            cnt += 1

        print(cnt)
    else:
        while B != C:
            A += 1
            B += 1
            cnt += 1

        while A < B:
            A += 2
            cnt += 1

        while A != C:
            B += 1
            C += 1
            cnt += 1

        print(cnt)  
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N = int(input())
data = list(map(int, input().split()))
Alice = 0
Bob = 0
count = 0
while N > count:
  high = data[0]
  point = 0
  for i in range(N):
    if data[i] > high:
      high = data[i]
      point = i
  if count % 2 == 0:
    Alice += high
  else:
    Bob += high
  data[point] = 0
  count += 1
print(Alice - Bob)

Measured memory_bytes: 9192
#include <stdio.h>

int main(void)
{
    int x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4;
    scanf("%d %d %d %d",&x_1,&y_1,&x_2,&y_2);
    x_3 = x_2-(y_2-y_1);
    y_3 = y_2+x_2-x_1;
    x_4 = x_3 - (x_2-x_1);
    y_4 = y_3 - (y_2-y_1);
    printf("%d %d %d %d",x_3,y_3,x_4,y_4);
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))


const double pi = 4*atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

pair<ll,ll> p[MAXN];

int par;

bool inZone(ll x, ll y, ll p) {
	return llabs(x)+llabs(y) < p;
}

void solve(int index) {
	pair<ll, ll> c = p[index];
	ll x = c.F;
	ll y = c.S;
	int left = 34;
	if (par==0){
		x--;
	}
	vector<string> ans;
	while (left) {
		left--;

		ll p = SET(0,left);

		if (inZone(x-p,y,p)){
			ans.pb("R");
			x-=p;
		} else if (inZone(x+p,y,p)) {
			ans.pb("L");
			x+=p;
		} else if (inZone(x,y-p,p)){
			ans.pb("U");
			y-=p;
		} else if (inZone(x,y+p,p)){
			ans.pb("D");
			y+=p;
		} else {
			exit(1);
		}
	}
	reverse(ans.begin(),ans.end());
	for(auto v : ans){
		cout << v;
	}
	if (par==0) {
		cout << "R";
	}

}

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

	int n;
	cin >> n;

	set<int> parities;
	FOR(i,0,n) {
		cin >> p[i].F >> p[i].S;
		parities.insert(llabs(p[i].F+p[i].S)%2);
	}

	if (parities.size() != 1) {
		cout << "-1" << "\n";
		return 0;
	}

	par = *parities.begin();

	if (par == 1) {
		cout << 34 << "\n";
		FOR(i,0,34) {
			if (i) cout << " ";
			cout << SET(0,i);
		}
		cout << "\n";
		FOR(i,0,n){
			solve(i);
			cout << "\n";
		}
	} else {
		cout << 35 << "\n";
		FOR(i,0,34) {
			if (i) cout << " ";
			cout << SET(0,i);
		}
		cout << " 1\n";
		FOR(i,0,n){
			solve(i);
			cout << "\n";
		}
	}

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int h, w; cin >> h >> w;
    vector<vector<int> > a(h, vector<int> (w));
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];

    int ans = INF;
    for(int ii = 0; ii < h; ii++){
        for(int jj = 0; jj < w; jj++){

            int tmp = 0;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    tmp += a[i][j] * min((int)abs(i - ii), (int)abs(j - jj));
                }
            }
            ans = min(ans, tmp);
        }
    }

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


Measured memory_bytes: 3160
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
        ab: [(usize, usize); m]
    }

    let mut good = vec![true; n];

    for (a, b) in ab {
        if h[a - 1] >= h[b - 1] {
            good[b - 1] = false;
        }
        if h[a - 1] <= h[b - 1] {
            good[a - 1] = false;
        }
    }
    let ans = good.iter().filter(|x| **x).count();

    println!("{}", ans);
}


Measured memory_bytes: 6652
#include<cstdio>
const int mod=1000000007;
int fac[200010],ifac[200010];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
long long C(int n,int m){return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int main(){
	int H,W,A,B,s=0;
	scanf("%d%d%d%d",&H,&W,&A,&B);
	for(int i=*fac=1;i<=H+W;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[H+W]=inv(fac[H+W]);
	for(int i=H+W;i;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
	for(int i=0;i<H-A;i++)s=(s+C(B-1+i,B-1)*C(W-B-1+H-i-1,W-B-1))%mod;
	printf("%d\n",s);
}

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

using namespace std;
typedef long long int ll;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}


int main(){
    int i,j,k,l;
    
    ll n,x;
    cin>>n>>x;
    
    ll len=n+x;
    ll wid=n-x;
    ll cut=x;
    
    while (cut!=0){
        ll u=wid/cut;
        len+=(u+u-1-(wid%cut==0))*cut;
        
        ll _w=wid;
        wid=cut;
        cut=_w%cut;
        
        len+=cut;
    }
    
    cout<<len<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
using namespace std;
int an[101000];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&an[i]);
	int cnt=1;
	bool decr=true;
	bool fir=true;
	for(int i=2;i<=n;i++){
        if(fir){
            fir=false;
            if(an[i-1]<an[i]) decr=true;
            else if(an[i-1]>an[i])decr=false;
            else fir=true;
        }
        else {
            if(decr){
                if(an[i]<an[i-1]){
                    cnt++;
                    fir=true;
                }
            }
            else{
                if(an[i]>an[i-1]){
                    cnt++;
                    fir=true;
                }
            }
        }
//        printf("i=%d %d\n",i,cnt);
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i,0,n){
        cin>>v[i];
        if(i>0){
            v[i]+=v[i-1];
        }
    }
    
    ll ans=1e18;
    rep(i,0,n-1){
        ans=min(ans,abs(v[i]-(v[n-1]-v[i])));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;


signed main(){
    string s,p;
    cin >> s >> p;
    s = s + s;
    int x = s.find(p);
    if(x == string::npos){
        print("No");
    }
    else{
        print("Yes");
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}




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

L = []

for i in range(N - 1):
  if A[i] < A[i + 1]:
    L.append(i)
    s = i + 1
    break
else:
  print(1000)
  exit()

f = True
for i in range(s, N - 1):
  if f and A[i] > A[i + 1]:
    L.append(i)
    f = False
  elif not f and A[i] < A[i + 1]:
    L.append(i)
    f = True

ans = 1000
f = True
for i in L:
  if f:
    k = ans // A[i]
    ans -= A[i] * k
    f = False
  else:
    ans += k * A[i]
    f = True

if not f:
  ans += k * A[-1]

print(ans)



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

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;

	for (int i = 0; i < H; i++) {
		if (i < B) {
			for (int j = 0; j < W; j++) {
				if (j < A) cout << '1';
				else cout << '0';
			}
		}
		else {
			for (int j = 0; j < W; j++) {
				if (j < A) cout << '0';
				else cout << '1';
			}
		}
		cout << endl;
	}
}

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

using namespace std;

int main(void) {
	int H;
	cin >> H;
	while (H != 0) {
		vector< vector<int> > puzz(H,vector<int>(5));
		int drop[5] = {0,0,0,0,0};
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < 5; ++j) {
				cin >> puzz[i][j];
			}
		}

		bool seq = true;
		int point = 0;
		int s,e;
		int len = 1;
		while (seq) {
			seq = false;
			for (int i = 0; i < H; ++i) {
				len = 1;
				s = -1;
				e = -1;
				for (int j = 0; j < 4; ++j) {
					if (puzz[i][j] > 0 && puzz[i][j] == puzz[i][j+1]) {
						++len;
						if (len > 2) {
							s = (j + 1) - len + 1;
							e = j + 1;
						}
					}
					else {
						len = 1;
					}
				}
				if (e > 0) {
					point += (e+1-s)*puzz[i][s];
					for (int j = s; j < e + 1; ++j) {
						puzz[i][j] = -1;
					}
					seq = true;
				}
			}
			for (int i = H - 1; i > 0 ; --i) {
				for (int j = 0; j < 5; ++j) {
					if (puzz[i][j] == -1) {
						int temp = i - 1;
						while (temp >= 1 && puzz[temp][j] == -1) {
							--temp;
						}
						swap(puzz[i][j],puzz[temp][j]);
					}
				}
			}
		}
		cout << point << endl;
		cin >> H;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

long long n, m;
int mod = 1e9 + 7;

int main() {
    cin >> n >> m;
    long long sumX = 0, sumY = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        sumX += (2 * i - n + 1) * x;
        sumX %= mod;
    }
    
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        sumY += (2 * i - m + 1) * y;
        sumY %= mod;
    }
    
    cout << sumX * sumY % mod << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
using namespace std;
static inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int pow(long x, int n, int m){
    long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x, ret %= m;
        x *= x, x %= m;
        n >>= 1; 
    }
    return ret % m;
}

int euler_phi(int n) {
   int ret = n;
   for(int i = 2; i * i <= n; ++i){
       if(n % i == 0) {
           ret -= ret / i;
           while(n % i == 0) n /= i;
       }
   }
   if(n > 1) ret -= ret / n;
   return ret;
}

int main()
{
    int K = 0, c = getchar();
    while(c > 47 && c < 58){
        K = K * 10 + c - 48;
        c = getchar();
    }

    K /= gcd(K, 7);
    if(K == 1){
        putchar('1');
        return 0;
    }

    K *= 9;

    if(gcd(K, 10) != 1) {
        putchar('-');
        putchar('1');
        return 0;
    }

    int res = euler_phi(K);

    int ans = 1000000;
    int now = 10;
    for(int i = 1; i * i <= res; ++i){
        if(res % i == 0) {
            if(now == 1){
                printf("%d\n", i);
                return 0;
            }
            int tmp = res / i;
            if(pow(10, tmp, K) == 1) if(tmp < ans) ans = tmp;
        }
        now *= 10, now %= K;
    }

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

    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

	int N; cin >> N;

	double c1 = N / 1.08;
	double c2 = (N + 1) / 1.08;

	int d1 = (int)c1;
	int d2 = (int)c2 + 1;

	for (int i = d1; i <= d2; ++i) {
		if (i * 108 / 100 == N) {
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(" << endl;

	return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(((A==5)&&(B==5)&&(C==7))||
     	((A==5)&&(B==7)&&(C==5))||
     		((A==7)&&(B==5)&&(C==5))){
    cout << "YES";
  }else{
    cout << "NO";
  }
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int a, b;
  cin >> a >> b;
  cout << a * b <<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

//modの世界の2のn乗を返す
ll safe2pow(int n){
    ll ans = 1;
    rep(i,n){
        ans = ans * 2 % mod;
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<ll> As(n);
    ll ans = 0;
    rep(i,n) cin >> As.at(i);
    rep(i,60){
        int pi = 0 , qi = 0;
        rep(j,n){
            bitset<60> bs(As.at(j));
            if(bs.test(i)){
                qi++;
            } else {
                pi++;
            }
        }
        ans = (ans + pi * safe2pow(i) % mod * qi) % mod;
    }
    cout << ans << endl;
    return 0;
}


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

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

    char AA[N][N];
    char BB[M][M];

    for(size_t y = 0; y < N; y++) {
        for(size_t x = 0; x < N; x++) {
            cin >> AA[y][x];
        }
    }

    for(size_t y = 0; y < M; y++) {
        for(size_t x = 0; x < M; x++) {
            cin >> BB[y][x];
        }
    }

    for(size_t x0 = 0; x0 <= N - M; x0++) {
        for(size_t y0 = 0; y0 <= N - M; y0++) {
            bool tmp = true;
            for(size_t x = 0; x < M; x++) {
                for(size_t y = 0; y < M; y++) {
                    if(AA[y0 + y][x0 + x] != BB[y][x]) {
                        tmp = false;
                    }
                }
            }
            if(tmp) {
                cout << "Yes" << endl;
                return (0);
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
count = 1
ans = 0
for i in range(N - 1):
    if A[i] == A[i + 1]:
        count += 1
    else:
        ans += count % 2
        count = 1
print(ans + count % 2)


Measured memory_bytes: 7388
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

ll x[100003];
int mov[100003][20];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> x[i];
	ll L; int Q; cin >> L >> Q;
	for (int i = 0; i < n; ++i) {
		int lo = i, hi = n;
		while (hi - lo > 1) {
			int mid = lo + (hi - lo) / 2;
			if (x[mid] > x[i] + L) hi = mid;
			else lo = mid;
		}
		mov[i][0] = lo;
	}
	for (int j = 1; j < 20; ++j) {
		for (int i = 0; i < n; ++i) {
			mov[i][j] = mov[mov[i][j - 1]][j - 1];
		}
	}
	for (int i = 0; i < Q; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;
		if (a > b) swap(a, b);
		int pos = a;
		ll ans = 0;
		while (true) {
			int lo = -1, hi = 20;
			while (hi - lo > 1) {
				int mid = lo + (hi - lo) / 2;
				if (mov[pos][mid] >= b) hi = mid;
				else lo = mid;
			}
			if (lo == -1) {
				++ans;
				break;
			}
			ans += (1LL << (ll)lo);
			pos = mov[pos][lo];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    vector<ll> s(n+1);
    unordered_map<ll,ll> uom;
    s[0]=0;uom[0]++;
    ll ans=0;
    for(int i=1; i<=n; i++){
        ll a;cin>>a;
        s[i]=s[i-1]+a;
        if(i>=k)uom[(s[i-k]-i+k)%k]--;
        ans+=uom[(s[i]-i)%k];
        uom[(s[i]-i)%k]++;
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 10056
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int N, R;
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
        String[] line = new String[num];
        String[][] s = new String[num][10];
        for(int i=0; i<num; i++){
          line[i] = sc.next();
          s[i] = line[i].split("");
        }
        int count = 0;
        int aNum = 0;
        int bNum = 0;
        int baNum= 0;
        int check = 0;
        for(int i=0; i<num; i++){
          for(int j=0; j<line[i].length()-1; j++){
            if(s[i][j].equals("A") && s[i][j+1].equals("B")) count++;
            if(j == 0 && s[i][j].equals("B")) {
              bNum++;
              check = 1;
            }
            if(j == line[i].length()-2 && s[i][j+1].equals("A")) {
              if(check == 1){
                baNum++;
                aNum++;
              }
              else aNum++;
            }
          }
          check = 0;
        }
        int plus = (aNum <= bNum) ? aNum : bNum;
        //if(aNum == num && bNum == num) plus--;
        if(baNum > 0 && baNum == aNum && baNum == bNum) plus -= 1;
		System.out.println(count+plus);
        //System.out.println(aNum);
        //System.out.println(bNum);
	}
}

Measured memory_bytes: 48376
// Code for C - Snuke Festival
#include <bits/stdc++.h>
using namespace std;


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

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

  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);

  REP(i,N) {
    cin >> A[i];
  }

  REP(i,N) {
    cin >> B[i];
  }

  REP(i,N) {
    cin >> C[i];
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(C.begin(), C.end());

  long long int total = 0;
  REP(i,N) {
    int b = B[i];

    int a_count;
    {
      int left = -1;
      int right = N;
      while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if ( A[mid] < b ) {
          right = mid;
        } else {
          left = mid;
        }
      }

      a_count = N - right;
    }

    int c_count;
    {
      int left = -1;
      int right = N;
      while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if ( C[mid] > b ) {
          right = mid;
        } else {
          left = mid;
        }
      }

      c_count = N - right;
    }

    total += (long long)a_count * c_count;
  }

	cout << total << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int INF=1001001001;
struct edge{
    int to,cost,num;
    edge(int to,int cost,int num)
        :to(to),cost(cost),num(num){}
};

struct data{
    int pos,cost,money;
    data(int pos,int cost,int money)
        :pos(pos),cost(cost),money(money){}

    bool operator<(const data &d)const{
        return cost>d.cost;
    }
};

int N,M,L;
vector<edge>G[100];
int dist[100][101];

void solve(){
    fill_n(*dist,100*101,INF);
    dist[0][L]=0;
    priority_queue<data>que;
    que.push(data(0,0,L));

    while(que.size()){
        data d=que.top();que.pop();
        if(dist[d.pos][d.money]<d.cost)continue;
        for(int i=0;i<G[d.pos].size();i++){
            edge &e=G[d.pos][i];
            if(dist[e.to][d.money]>d.cost+e.num){
                dist[e.to][d.money]=d.cost+e.num;
                que.push(data(e.to,dist[e.to][d.money],d.money));
            }
            if(e.cost<=d.money&&dist[e.to][d.money-e.cost]>d.cost){
                dist[e.to][d.money-e.cost]=d.cost;
                que.push(data(e.to,dist[e.to][d.money-e.cost],d.money-e.cost));
            }
        }
    }

    int mi=INF;
    for(int i=0;i<=L;i++)mi=min(mi,dist[N-1][i]);
    cout<<mi<<endl;
}

int main(){
    while(cin>>N>>M>>L,N||M||L){
        fill_n(G,100,vector<edge>());
        for(int i=0;i<M;i++){
            int a,b,c,d;
            cin>>a>>b>>c>>d;a--;b--;
            G[a].push_back(edge(b,c,d));
            G[b].push_back(edge(a,c,d));
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 1736
s=0
t=[]
n=int(input())
for j in range(n):
    i=int(input())
    s+=i
    if i%10!=0:
        t.append(i)
if t==[]:
    t.append(s)
if s%10!=0:
    print(s)
else:
    print(s-min(t))

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;
    vector<int> A(N+1);
    REP(i,N+1){ cin >> A[i]; }

    vector<int> B(N);
    REP(i,N){ cin >> B[i]; }

    ll count = 0;
    REP(i,N){
       ll e = min(B[i], A[i]);
       count += e;
       B[i] -= e;
       e = min(B[i], A[i+1]);
       A[i+1] -= e;
       count += e;
    }

    cout << count << endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    int l;
    int length = 3;
    int input[length];
    for(int i = 0;i < length && cin>>l;i++){
        input[i] = l;
    }
    string out;
    if(input[0] < input[1] && input[1] < input[2]) out = "Yes";
    else out = "No"; 
    cout << out << endl;
    return 0;
}  



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 100002;
ll n,ans;
vector<ll> a,b,c;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		ll k;
		cin>>k;
		a.pb(k);
	}
	FOR(i,0,n){
		ll k;
		cin>>k;
		b.pb(k);
	}
	FOR(i,0,n){
		ll k;
		cin>>k;
		c.pb(k);
	}
	SORT(a);
	SORT(b);
	SORT(c);
	ans=0;
	FOR(i,0,n){
		ll an,cn;
		cn=n-POSU(c,b[i]);
		an=POSL(a,b[i]);
		ans+=cn*an;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3316
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def same(x, y):
    return find(x) == find(y)

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x


N, M = map(int, input().split())
par = [-1 for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)

print(-min(par))

Measured memory_bytes: 14764
#include <iostream>
#include <set>

using namespace std;

int sum(int arr1[], int n, int a, int b) {
    int x = arr1[a - 1];
    arr1[a - 1] = b;
    int sm = 0;
    for (int i = 0; i < n; ++i) {
        sm += arr1[i];
    }
    arr1[a-1] = x;
    return sm;
}

int main() {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    int t;
    cin >> t;
    for (int j = 0; j < t; ++j) {
        int a, b;
        cin >> a >> b;
        cout << sum(arr, n, a, b) << '\n';
    }
    return 0;
}




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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

    int cnt = 0;
    char prev = s[0];
    rep(i, s.size()) {
        if(prev != s[i]) {
            cnt++;
            prev = s[i];
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512