akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
 
 
 
int main() {
    int n;
    scanf("%d",&n);
    int hh;
    scanf("%d",&hh);
    int ww;
    scanf("%d",&ww);

    int a[1000] = {};
    int b[1000] = {};

    rep(i,n){
        int aa;
        scanf("%d",&aa);
        a[i] = aa;
        scanf("%d",&aa);
        b[i] = aa;
    }

    int ans = 0;

    rep(i,n){
        if(a[i] >= hh){
            if(b[i] >= ww){
                ans++;
            }
        }
    }







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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    string S, T;
    int A, B;
    string U;
    cin >> S >> T >> A >> B >> U;
    if(S == U)cout << A - 1 << " " << B;
    else if(T == U)cout << A << " " << B - 1;
    else cout << A << " " << B;
}


Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

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

    int d;
    d=x-a;

    int e;
    e=d/b;

    cout<<d-e*b<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,count=0;
	cin>>n;
  	string s[n];
  	for(int i0=0;i0<n;i0++)
	{
		cin>>s[i0];
	}
  	sort(s,s+n);
  	for(int i=0;i<n-1;i++)
    {
      if(s[i]!=s[i+1])
      {
        count++;
      }
    }
  	cout<<count+1;
	return 0;
}

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

#define llint long long int
#define MOD 1000000007

using namespace std;

int main()
{
    int n, k;

    cin >> n >> k;

    vector<vector<vector<llint>>> dp(n + 1, vector<vector<llint>>(n + 1, vector<llint>(n * n + 1, 0)));

    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k <= n * n + 1; k++)
            {
                if (k + 2 * (j + 1) <= n * n)
                {
                    dp[i + 1][j + 1][k + 2 * (j + 1)] += dp[i][j][k];
                    dp[i + 1][j + 1][k + 2 * (j + 1)] %= MOD;
                }
                if (k + 2 * j <= n * n)
                {
                    dp[i + 1][j][k + 2 * j] += (2 * j + 1) * dp[i][j][k];
                    dp[i + 1][j][k + 2 * j] %= MOD;
                }
                if (j - 1 >= 0 && 0 <= k + 2 * (j - 1) && k + 2 * (j - 1) <= n * n)
                {
                    dp[i + 1][j - 1][k + 2 * (j - 1)] += j * j * dp[i][j][k];
                    dp[i + 1][j - 1][k + 2 * (j - 1)] %= MOD;
                }
            }
        }
    }
    cout << dp[n][0][k] << endl;
}

Measured memory_bytes: 55220
char s[102];
A(){
	char a[101],b[101],t,t2;
	return sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b);
}
B(){
	short*q;
	char*p=s,l=0;
	if(*(q=p++)=='^>'){
		for(;*(q=++p)=='=Q';p++)l++;
		if(l>0&&*p=='~'&&*++p=='~'&&*++p==0)
			return 1;
	}
	return 0;
}
main(){
	scanf("%*d\n");
	for(;~scanf("%[^\n]\n",s);){
		if(A())
			puts("A");
		else if(B())
			puts("B");
		else
			puts("NA");
	}
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn lower_bound<F>(l: usize, r: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    l
}

fn solve() {
    let q = get!(usize);
    let ab = get!(usize, usize; q);


    for (a, b) in ab {
        if a==b {
            println!("{}", (a-1)*2);
            continue;
        }
        let (a,b) = if a>b {
            (b,a)
        } else {
            (a,b)
        };

        let k = a*b;
        let crit = |x: usize| -> bool {
            let t1 = (x+1)/2;
            let t2 = x+1-t1;
            t1*t2 >= k
        };
        const INF: usize = 10_000_000_000;
        let res = lower_bound(0,INF, crit)-1;
        println!("{}",res);
    }
}


Measured memory_bytes: 8572
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque
from math import ceil

n = int(readline())
a = sorted([int(readline()) for i in range(n)])
c = deque(a[:ceil(n / 2)])
d = deque(a[ceil(n / 2):])
b = deque(a[n // 2:])
a = deque(a[:n // 2])
check_1 = deque([a.popleft()])
check_2 = deque([d.pop()])
for i in range(n // 2):
    if i % 2 == 0:
        check_1.appendleft(b.pop())
        check_2.appendleft(c.popleft())
        if len(b) == 0:
            if len(a) != 0:
                check_1.append(a.popleft())
                check_2.append(d.pop())
            break
        check_1.append(b.pop())
        check_2.append(c.popleft())
    else:
        check_1.appendleft(a.popleft())
        check_2.appendleft(d.pop())
        if len(a) == 0:
            if len(b) != 0:
                check_1.append(b.pop())
                check_2.append(c.popleft())
            break
        check_1.append(a.popleft())
        check_2.append(d.pop())
cnt_1 = 0
cnt_2 = 0
for i in range(1, n):
    cnt_1 += abs(check_1[i - 1] - check_1[i])
    cnt_2 += abs(check_2[i - 1] - check_2[i])
print(max(cnt_1, cnt_2))


Measured memory_bytes: 9320
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	// sqrt(a) + sqrt(b) < sqrt(c)
	// a + b + 2 * sqrt(ab) < c
	// 2 * sqrt(ab) < c - a - b
	// 4ab < (c-a-b)^2
	d := c - a - b
	if d > 0 && 4*a*b < d*d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

#define R (long long)(1e9 + 7)
#define INF (long long)(1e16L + 5)
#define ll long long
#define grid vector<vector<ll>>

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

struct dsu
{
    vector<int> rank, parent, num;
    dsu(int n)
    {
        rank.assign(n, 0);
        parent.resize(n);
        num.assign(n, 1);
        for(int i = 0; i < n; i++)
            parent[i] = i;
    }
    int find_set(int i)
    {
        if(i == parent[i])
            return i;
        return parent[i] = find_set(parent[i]);
    }
    bool is_same_set(int i, int j)
    {
        if(find_set(i) == find_set(j))
            return true;
        return false;
    }
    void union_set(int i, int j)
    {
        if(!is_same_set(i, j))
        {
            int u = find_set(i), v = find_set(j);
            if(rank[u] == rank[v])
            {
                parent[v] = u;
                rank[u] += 1;
                num[u] += num[v];
            }
            else if(rank[u] > rank[v])
                parent[v] = u, num[u] += num[v];
            else 
                parent[u] = v, num[v] += num[u];
        }
    }

};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    dsu d(n);
    for(int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        d.union_set(u, v);
    }
    int ans = 1;
    for(int i = 0; i < n; i++)
    {
        ans = max(ans, d.num[d.find_set(i)]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5568
n,a,b,c,d = map(int,input().split())
s = input()
S = s[:max(c,d)]
#print(S)
l = len(S)
C = True
D = False
for i in range(l-1):
  if i >= min(a,b) and S[i]=='#' and S[i+1]=='#':
    C = False
    break
  if c > d and d > i >= max(a,b)-1:
    if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
      D = True
      
if not C:
  print('No')
elif C and not D:
  if c < d:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

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

int main(void) {
int a, b, c, d;
int e=0;
cin >> a >> b >> c;
for(int i=0; i < b; i++){
d = (a * i)%b;
if(d==c){
e=1;
}
}
if(e==1){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;

  ll a,b;
  cin>>a>>b;
  ll h[N];

  rep(i,N){
    cin>>h[i];
  }



  int ng = -1; // 最初のindexより1つ前 ngとokは場合により入れ替え
  int ok = 1000000000; // 最後のindexより1つあと
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    bool noo=false;

    ll ct=0;
    rep(i,N){
      ct+=max((ll)0,((h[i]-b*mid)+(a-b-1))/(a-b));
    }
    ( ct>mid ? ng : ok ) = mid;

  }

  cout<< ok<<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  scanf("%d %d", &n, &w);
  vector<int>pt(n);
  vector<int>wt(n);
  for(int i=0;i<n;i++){
    scanf("%d", &wt[i]);
    scanf("%d", &pt[i]);
  }
//   for(int i=0;i<n;i++)
//     cout<<wt[i]<<" ";
//   cout<<"\n";
//   for(int i=0;i<n;i++)
//     cout<<pt[i]<<" ";  
//   cout<<"\n";
  vector<vector<long long> >dp(n+1, vector<long long>(w+1,0));
  for(int i=1;i<=n;i++){
    for(int j=0;j<=w;j++){
      if(j>=wt[i-1])
        dp[i][j]=max(dp[i-1][j], pt[i-1]+ dp[i-1][j-wt[i-1]]*1LL);
      else
        dp[i][j]= max(dp[i][j], dp[i-1][j]);
        //cout<<dp[i][j]<<" ";
    }
  }
cout<<dp[n][w]<<"\n";
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>

#define pb push_back

using namespace std;

int nxt, memo[500010];
vector<int> adj[500010], radj[500010], urut, scc;
bool visited[500010];

void dfs1(int pos) {
	visited[pos] = true;
	for (int i = 0; i < (int) adj[pos].size(); i++) {
		nxt = adj[pos][i];
		if (!visited[nxt])
			dfs1(nxt);
	}
	urut.pb(pos);
}

void dfs2(int pos) {
	visited[pos] = true;
	for (int i = 0; i < (int) radj[pos].size(); i++) {
		nxt = radj[pos][i];
		if (!visited[nxt])
			dfs2(nxt);
	}
	scc.pb(pos);
}

int dist(int pos) {
	int ret = 0;
	if (memo[pos] != -1)
		return memo[pos];
	for (int i = 0; i < (int) radj[pos].size(); i++)
		ret = max(ret, dist(radj[pos][i]));
	memo[pos] = ++ret;
	return ret;
}

int main() {
	int n, a, b, lst, tot, ans = -1;
	bool valid = true;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b);
		a = min(b, i);
		b = max(b, i);
		lst = ((a - 1) * (n - a + n) / 2) + b - a;
		for (int j = 2; j < n; j++) {
			scanf("%d", &b);
			a = min(b, i);
			b = max(b, i);
			nxt = ((a - 1) * (n - a + n) / 2) + b - a;
			adj[lst].pb(nxt);
			radj[nxt].pb(lst);
			lst = nxt;
		}
	}
	tot = n * (n - 1) / 2;
	memset(visited, false, sizeof visited);
	for (int i = 1; i <= tot; i++)
		if (!visited[i])
			dfs1(i);
	memset(visited, false, sizeof visited);
	for (int i = tot - 1; i >= 0; i--) {
		nxt = urut[i];
		if (!visited[nxt]) {
			scc.clear();
			dfs2(nxt);
			if ((int) scc.size() > 1) {
				valid = false;
				break;
			}
		}
	}
	memset(memo, -1, sizeof memo);
	if (valid)
		for (int i = 1; i <= tot; i++)
			ans = max(ans, dist(i));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 61552
h, w = list(map(int, input().split()))
#h, w = list(map(int, input().split()))
a = []
for i in range(h):
    x = input()
    if "#" in x:
        a.append(x)

w90 = []
for i in range(w):
    x = ""
    for j in range(len(a)):
        x += a[j][i]

    if "#" in x:    
        w90.append(x)

for i in range(len(w90[0])):
    for j in range(len(w90)):
        print(w90[j][i], end="")
    print()


Measured memory_bytes: 4468
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

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

char s[51][51];

int main(){
	int H,W;
	cin>>H>>W;
	REP(i,H){
		REP(j,W){
			cin>>s[i][j];
		}
	}
	bool can=false;
	REP(i,H){
		REP(j,W){
			if(s[i][j]=='#'){
				can=false;
				REP(k,4){
					int nx=i+dx[k];
					int ny=j+dy[k];
					if(nx>=0||nx<H||ny>=0||ny<W){
						if(s[nx][ny]=='#'){
							can=true;
							break;
						}
					}
				}
				if(!can){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
import copy
H,W,K=map(int,input().split())
CC=[0]*H
for i in range(H):
    CC[i]=list(input())

count=0
shar=0
kurokuro=0
for i in range(H):
    kurokuro=CC[i].count('#')+kurokuro


#print(kurokuro)
ans=0
for i in range(2**(H+W)):
    kuro=kurokuro
    c=copy.deepcopy(CC)

    for j in range(H+W):
        if((i>>j) & 1):
            if(j<H):
                for q in range(W):
                    if(c[j][q]=='#'):
                        shar=shar+1
                        c[j][q]='.'
                kuro=kuro-shar

                shar=0
            else:
                for q in range(H):
                    if(c[q][j-H]=='#'):
                        shar=shar+1
                        c[q][j-H]='.'

                kuro=kuro-shar
                shar=0

    if(kuro==K):
        ans=ans+1
print(ans)


Measured memory_bytes: 72240
#include <iostream>


using namespace std;

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

  if(S.back()=='s')
  {
    S+='e';
    S+='s';
  }
  else
  {
    S+='s';
  }

  cout<<S<<endl;

  return 0;
}

Measured memory_bytes: 3624
def solve():
    seq1 = raw_input()
    seq2 = raw_input()
 
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
 
n = input()
for i2 in range(n):
    print solve()

Measured memory_bytes: 6432
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>


#include <math.h>


using namespace std;


class Solution {
public:
    void solve(int num, std::istream& in, std::ostream& out) {
		string str; in >> str;
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '?') {
				str[i] = 'D';
			}
		}
		out << str;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
	//int T; in >> T;
	//for(int i = 0;i < T;i++)
		//solution.solve(i+1, in, out);
	solution.solve(0, in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 3480
def InsertionSort(a, N, Gap):
    c = 0
    for i in range(Gap, N):
        v = a[i]
        j = i - Gap
        while j >= 0 and a[j] > v:
            a[j+Gap] = a[j]
            j -= Gap
            c += 1
        a[j+Gap] = v
    return a, c

def ShellSort(a, N):
    cnt = 0
    G = [1]
    for i in range(1, N):
        if (3*G[i-1]+1) <= N:
            G.append(3*G[i-1]+1)
        else:
            break
            
    for g in G[::-1]:
        a, c = InsertionSort(a, N, g)
        cnt += c
    return a, cnt, G


N = int(input())
A = []
cnt = 0

for _ in range(N):
    A.append(int(input()))


sorted_A, cnt, G = ShellSort(A, N)
print(len(G))
print(*G[::-1])
print(cnt)
print(*sorted_A, sep="\n")

Measured memory_bytes: 63112
#include<stdio.h>
int MIN(int x,int y){return x>y?y:x;}
int main(void){
	int n;
	scanf("%d",&n);
	char s[n+1];
	scanf("%s",s);
	int ans=n;
	int east[n+1],west[n+1];
	east[0] = west[0] = 0;
	for(int i=1;i<=n;i++){
		if(s[i-1]=='W'){
			west[i]=west[i-1]+1;
			east[i]=east[i-1];
		}else{
			west[i]=west[i-1];
			east[i]=east[i-1]+1;
		}
	}
	for(int i=1;i<=n;i++)ans = MIN(ans,west[i-1]+east[n]-east[i]);
	printf("%d",ans);
	return 0;
}

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

fn main() {
  let r: f64 = read();
  let g: f64 = read();

  let ans = r + ((g - r) * 2.0);

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


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int& a : A) {
        cin >> a;
    }
    for (int& b : B) {
        cin >> b;
    }
    for (int& c : C) {
        cin >> c;
    }

    ll ans = 0;
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    for (int& b : B) {
        ll a = lower_bound(A.begin(), A.end(), b) - A.begin();
        ll c = C.end() - upper_bound(C.begin(), C.end(), b);
        ans += a * c;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007


int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>x>>y;
	for(ll i=2;x<=y;i++,m++){
		x=x*2;
	}
	cout<<m-1;
	
}

Measured memory_bytes: 3648
N = int(input())

def factoring(k): #kを因数分解し、素因数とその個数を辞書に入れて返す。
    import math
    dic = dict()
    n = int(math.sqrt(k))+2
    for i in range(2, n):
        count = 0
        while k%i == 0:
            count += 1
            k = k//i
        if count != 0:
            dic[i] = count
    if k != 1: #sqrt(k)までチェックしてもkが1になっていない --> kが素因数
        dic[k] = 1
    return dic



def make_divisors(n):
    import math
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0: #割り切れるとき
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

dic1 = factoring(N - 1)

# 素因数分解をすることにより、約数の個数を求める
ans = 1
for i in dic1:
    ans *= (dic1[i] + 1)

ans -= 1 #約数の1つである1は使えない
# print (ans)

lst = make_divisors(N) #Nの約数を全列挙

for i in lst:
    if i == 1:
        continue
    flag = False
    if (N // i) % i == 1:
        flag = True
    else:
        x = 1
        while N % x == 0:
            if x == N:
                flag = True
                break
            if (N // x) % i == 1:
                flag = True
                break
            x *= i
    if flag:
        ans += 1



print (ans)
# print (dic1)
# print (lst)

Measured memory_bytes: 3280
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    H = list(map(int, input().split()))
    m = 0
    for i in range(N-1):
        if H[i] >= H[i+1]:
            m += 1
        else:
            m = 0
        ans = max(ans, m)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14168
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N,K,R,S,P,score = 0;
    cin >> N >> K >> R >> S >> P;
    string T,Q;
    cin >> T;
    REP(i,N){
        if(K>i){
            if(T[i] == 'r'){
                score += P;
                Q += "P";
            }else if(T[i] == 's'){
                score += R;
                Q += "R";
            }else if(T[i] == 'p'){
                score += S;
                Q += "S";
            }
        }else{
            if(T[i] == 'r'&&Q[i-K] != 'P'){
                score += P;
                Q += "P";
            }else if(T[i] == 's'&&Q[i-K] != 'R'){
                score += R;
                Q += "R";
            }else if(T[i] == 'p'&&Q[i-K] != 'S'){
                score += S;
                Q += "S";
            }else{
                Q += "N";
            }
        }
    }
    cout <<score<< "\n";
}

Measured memory_bytes: 640
import numpy as np

N =  int(input())
num_arr = np.array(list(map(int, input().split())))
right_num_arr = np.array(list(range(1,N+1,1)))

dif = [abs(i) for i in num_arr - right_num_arr]

if dif == [0]*N:
  print("YES")
elif (sorted(set(dif))[0] == 0)&(len(set(dif))==2):
  print("YES")
else:
  print("NO")


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

int main(){
  int a,b;cin >> a >> b;
  cout << max({a+b,a-b,a*b}) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  char c,s[1201];
  int i,diff='a'-'A';
  for(i=0;i<1201;i++){
    scanf("%c",&c);
    if(c=='\n'){
      s[i]='\0';
      break;
    }
    else{
      if(c>='a'&&c<='z'){
	c=c-diff;
      }
      else if(c>='A'&&c<='Z'){
	c=c+diff;
      }
      s[i]=c;
    }
  }
  printf("%s\n",s);
  
}

Measured memory_bytes: 948
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
  int N, K;
  cin >> N >> K;
  vector<int> vi(N);

  for(int i  =0; i < N; i++){
    cin >> vi[i];
  }
  int i = 0;
  while(1){
    i++;
    N -= K;
    if(N <=  0){
      break;
    }
    N++;
  }
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

//    int64_t ans = 0;
//    for (auto i = 20; i > 0; i--) {
//        ans = (a * i)/b - (i/b * a);
//        cout << i << ":" << ans << endl;
//    }
//    cout << ans << endl;

    if(n < b) cout << (a * n)/b - (n/b) * a << endl;
    else cout << (a * (n / b * b - 1)/b - ((n / b * b - 1)/b * a)) << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e5) + 7;

int n;
ll a[N], pre[N];

int main() {

    // freopen("in.in", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
        pre[i] = (pre[i - 1] + a[i]) % mod;
    }
    ll res = 0;
    for (int i = 2; i <= n; ++i) {
        res = (res + a[i] * pre[i - 1] % mod) % mod;
    }
    printf("%lld\n", res);

    return 0;
}

Measured memory_bytes: 6844
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

ll solve(int w, int h) {
  int a = h / 3;
  if (h % 3) {
    return ((ll)(a + 1) * w) - ((ll)a)*w;
  }
  return 0;
}

ll solve2(int w, int h) {
  const ll INF = 1e15 - 1;

  ll mini = INF;
  rep(i, 1, w) {
    ll a = i;
    ll x = a * h;
    ll b = h / 2;
    ll y = b * (w - i);

    ll z = x;
    if (h % 2) {
      b++;
      z = b * (w - i);
    }
    amin(mini, max({ x, y, z }) - min({ x, y, z }));
  }
  return mini;
}
void Calc() {

  var(int, h, w);
  ll mini = solve(w, h);
  amin(mini, solve(h, w));
  amin(mini, solve2(h, w));
  amin(mini, solve2(w, h));

  cout << (mini) << endl;




}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
#define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x)  cout<<it<<endl;
#define pi pair<int,int>
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y) 
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
using namespace std;
typedef long long ll;
const ll P=1e9+7;
const int maxn=2e5+5;
ll comb(ll n, ll m){
	if(m>n) return 0;
	if(m>n-m) m=n-m;
	ll ans=1;
	for(int i=1;i<=m;i++)
		ans*=n,ans/=i,n--;
	return ans;
}
map<int,int> cnt;
int a[maxn];
int main(){   
	int n;
	sc(n);
	for(int i=1;i<=n;i++){
		sc(a[i]);
		cnt[a[i]]++;
	}
	ll ans=0;
	for(auto it:cnt)
		ans+=comb(it.se,2);
	for(int i=1;i<=n;i++){
		ans-=comb(cnt[a[i]],2);
		cnt[a[i]]--;
		ans+=comb(cnt[a[i]],2);
		printf("%lld\n",ans);
		ans-=comb(cnt[a[i]],2);
		cnt[a[i]]++;
		ans+=comb(cnt[a[i]],2);
	}
}

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

int main() {
    int n;
    string divisible = "No";
    cin >> n;


    for (int d=1; d <= 9; d++) {
        if (n % d == 0){
            int quot = n/d;
            if (quot <10){
                divisible = "Yes";
            }
        }

    }
    cout << divisible << "\n";


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s1, s2;
  int s, t;
  int a[1001][1001];
  int cost;
  cin >> s1;
  cin >> s2;
  s = s1.length();
  t = s2.length();

  rep(j, t+1){
    a[0][j] = j;
  }

  rep(i, s+1){
    a[i][0] = i;
  }


  rep(i, s){
    rep(j, t){
      if(s1[i] == s2[j]){
        cost = 0;
      }else{
        cost = 1;
      }

      a[i+1][j+1] = min(a[i][j+1] + 1, min(a[i+1][j] + 1, a[i][j] + cost));
      // cout << a[i+1][j+1] << " " << i + 1 << " " << j + 1 << endl;
    }
  }

  cout << a[s][t] << endl;


}


Measured memory_bytes: 7148
/*氏名：保坂優介, 学籍番号：200441141
  概要：*/

#include<stdio.h>

int main(void)
{
    int i, j, k, n, m, l;
    long a[101][101], b[101][101], c[101][101] = { 0 };

    scanf("%d %d %d", &n, &m, &l);

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
        {
            scanf("%ld", &a[i][j]);
        }
    }

    for (i = 0; i < m; i++)
    {
        for (j = 0; j < l; j++)
        {
            scanf("%ld", &b[i][j]);
        }
    }

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

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < l; j++)
        {
            printf("%ld", c[i][j]);
            if (j != l-1)
            {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>

int main() {
        int x, y, z;

        if(scanf("%3d %3d %3d", &x, &y, &z) == 0) {
                perror("scanf");
                return 1;
        }

        printf("%d %d %d\n", z, x, y);

        return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], M = I[1];
		var P = new int[M];
		var Y = new int[M];
		for (var i = 0; i < M; i++)
		{
			I = G;
			P[i] = I[0];
			Y[i] = I[1];
		}
		var cities = new List<int>[N];
		for (var i = 0; i < N; i++) cities[i] = new List<int>();
		for (var i = 0; i < M; i++) cities[P[i] - 1].Add(i);
		for (var i = 0; i < N; i++) cities[i].Sort((p, q) => Y[p].CompareTo(Y[q]));
		var rank = new int[M];
		for (var i = 0; i < N; i++) for (var j = 0; j < cities[i].Count; j++) rank[cities[i][j]] = j;
		for (var i = 0; i < M; i++) WriteLine($"{P[i]:d6}{rank[i] + 1:d6}");
	}
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 1000005;
const int INF = 1001001001;
const int MOD = 1000000007;

bool isPairwise(const vector<int> &v) {
    for (int i = 2; i < MAX; ++i) {
        if (2 <= v[i]) return false;
    }

    for (int i = 2; i < MAX; ++i) {
        bool flg = v[i];
        for (int j = i + i; j < MAX; j += i) {
            if (flg && v[j]) return false;
            flg ^= v[j]; 
        }
    }
    return true;
}

bool isSetwise(const vector<int> &v) {
    int gcd = v[0];
    for (auto &i : v) gcd = __gcd(gcd, i);
    return gcd == 1;
}

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

    vector<int> A(N);
    for (auto &i : A) cin >> i;

    vector<int> count(MAX);
    for (auto &i : A) count[i]++;

    if (isPairwise(count)) {
        cout << "pairwise coprime" << endl;
    } else if (isSetwise(A)) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }
}

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

#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;

void solve(){
    int n;
    cin>>n;
    ld a[n+1];
    rep(i,1,n+1){cin>>a[i];}

    ld dp[n+1][n+1];
    memset(dp,0,sizeof(dp));

    dp[0][0]=1;

    rep(i,1,n+1){
        rep(j,0,n+1){
            if(j==0){dp[i][j]=dp[i-1][j]*(1-a[i]);continue;}
            
            dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
            
        }


    }

    
    ld ans=0;
    rep(i,n/2+1,n+1){

        ans+=dp[n][i];
    }

    cout<<fixed<<setprecision(10)<<ans;

    
}



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

    int t=1,i=1;
    //cin>>t;
    

    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }

    return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000


int main(){
	long long A,B;
	cin>>A;
	
	cout<<3*A*A<<endl;
	
	
		
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    
    do {
        cin >> n;
    } while (n <= 0 || n > 10000);

    long* a = new long[n];
   
    long sum = 0;
    long max = -1000001;
    long min = 1000001;

    for (int i = 0; i < n; i++) {
         do {
             cin >> a[i];
         } while (a[i] < -1000000 || a[i] > 1000000);

         sum += a[i];

         if (a[i] < min) {
	     min = a[i];
         } 

         if (a[i] > max) {
	     max = a[i];
         }
    }
      
    cout << min << " " << max << " " << sum << endl; 
   
    delete[] a;
   
    return (0);
}
   

Measured memory_bytes: 1280
//ABの全探索->結果の絞り込み->結果とCの全探索の解法
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int K = sc.nextInt();
		long A[] = new long[X];
		long B[] = new long[Y];
		long C[] = new long[Z];
		for(int i=0;i<X;i++)A[i]=sc.nextLong();
		for(int i=0;i<Y;i++)B[i]=sc.nextLong();
		for(int i=0;i<Z;i++)C[i]=sc.nextLong();
		sc.close();
		
		long tmp[] = new long[X*Y];
 
		int cnt = 0;
		for(int i=0;i<X;i++) {
			for(int j=0;j<Y;j++) {
					tmp[cnt]=A[i]+B[j];
					cnt++;
			}
		}
		rsort(tmp);
		
		long ans[] = new long[Math.min(K,X*Y)*Z]; 
		int cnt2 = 0;
		for(int i=0;i<Math.min(K,X*Y);i++) {
			for(int j=0;j<Z;j++) {
					ans[cnt2]=tmp[i]+C[j];
					cnt2++;
			}
		}
		
		
		rsort(ans);
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<K;i++) {
			sb.append(ans[i]+"\n");
		}
		System.out.println(sb.toString());
	}

	//long型を逆順にソートするメソッド
	static void rsort(long[] a) {
		Arrays.sort(a);
		int len = a.length;
		for (int i = 0; i < len / 2; i++) {
			long tmp = a[i];
			a[i] = a[len - 1 - i];
			a[len - 1 - i] = tmp;
		}
	}
}


Measured memory_bytes: 61764
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		s.close();
		int ct=0;
		for(int i=0;i<c;i++){
			ct++;
			if(b>0){
				b--;
				ct++;
			}else if(a>0){
				a--;
			}else{
				break;
			}
		}
		while(b>0){
			b--;
			ct++;
		}
		System.out.println(ct++);
	}
}

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

int main(){
	
	int n; cin>>n;
	string s; cin>>s;
	
	vector r(n,0); 
	vector g(n,0);
	vector b(n,0);
	for(int i=n-1; i>=0; i--){
		if(i<n-1) r.at(i) = r.at(i+1);
		if(i<n-1) g.at(i) = g.at(i+1);
		if(i<n-1) b.at(i) = b.at(i+1);
		if(s.at(i)=='R') r.at(i)++;
		if(s.at(i)=='G') g.at(i)++;
		if(s.at(i)=='B') b.at(i)++;
	}
	int64_t cnt{};
	for(int i=0; i<n-2; i++){
		for(int j=i; j<n-1; j++){
			char si=s.at(i), sj=s.at(j);
			if((si=='R'&&sj=='G')||(si=='G'&&sj=='R')){
				cnt += b.at(j+1);
			}
			if((si=='G'&&sj=='B')||(si=='B'&&sj=='G')){
				cnt += r.at(j+1);
			}
			if((si=='B'&&sj=='R')||(si=='R'&&sj=='B')){
				cnt += g.at(j+1);
			}
		}
	}
	int w{1};
	while(1){
		if(0+w+w>=n) break;
		for(int i=0; i<n-2; i++){
			if(i+w+w>=n) continue;
			int si=s.at(i), sj=s.at(i+w), sk=s.at(i+w+w);
			if((si!=sj)&&(sj!=sk)&&(sk!=si)) --cnt;
		}
		w++;
	}
	
	cout << cnt << endl;
}

Measured memory_bytes: 3692
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

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

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Dijkstra {
public:
    using T = long long int;
    typedef pair<T, int> P; //firstは最短距離、secondは頂点の番号
    const T inf = (T) 5e15;
    struct edge {
        int to;
        T cost;
    };

    int V;                  //超点数
    vector<vector<edge>> G; //グラフ,G[i]はiから出る辺の集合,G[i][j]はiから出る辺のj番目の辺
    vector<T> d;           //最短距離

    //0origin
    Dijkstra(int N) {
        V = N;
        G = vector<vector<edge >>(N);
        d = vector<T>(N);
    };

    void dijkstra(int s) {
        priority_queue<P, vector<P>, greater<P>> que;
        fill(d.begin(), d.end(), inf);
        d[s] = 0;
        que.push(P(0, s));

        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            for (int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost && !(d[e.to] == inf && d[v] == inf)) {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }

    /* 頂点fromに頂点toに達するコストcostの辺を貼る */
    void addEdge(int from, int to, T cost) {
        edge e;
        e.to = to;
        e.cost = cost;
        G[from].push_back(e);
    }

    T getDist(int v) {
        return d[v];
    }
};


class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int n;
        int k;
        cin >> n;
        cin >> k;
        vector<ll> h(n);
        rep(i, 0, n) cin >> h[i];

        Dijkstra dij(n);

        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n && j <= i + k; ++j) {
                ll dist = abs(h[j] - h[i]);
                dij.addEdge(i, j, dist);
            }
        }

        dij.dijkstra(0);
        ll ans = dij.getDist(n - 1);

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 207736
import math

I = lambda: list(map(int, input().split()))
n, d, a = I()
l = []
for _ in range(n):
	x, y = I()
	l.append([x,y])
l.sort()

j = 0
limit = []
for i in range(n):
	while l[j][0] - l[i][0] <= 2*d:
		j+=1
		if j == n: break
	j-=1
	limit.append(j)

ans = 0
num=[0]*(n+1)
cnt=0
for i in range(n):
	l[i][1]-=(ans-cnt)*a
	damage_cnt=max(0,(l[i][1]-1)//a + 1)
	ans+=damage_cnt
	num[limit[i]]+=damage_cnt
	cnt+=num[i]
print(ans)

Measured memory_bytes: 91992
import java.util.*;

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

        int count = 0;
        boolean a = false;
        boolean b = false;
        boolean c = false;
        for (int i = 0; i < N; i++) {
            String s = S.charAt(i) + "";
            if (s.equals("A")) {
                a = true;
                b = false;
                c = false;
            } else if (s.equals("B") && a && !b && !c) {
                b = true;
                c = false;
            } else if (s.equals("C") && a && b && !c) {
                c = true;
                count++;
            } else {
                a = false;
                b = false;
                c = false;
            }
        }

        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    for(int i = 0; i < m; i++) {
        int t;
        cin >> t;
        a[t] = 1;
    }
    auto dp = make_v<ll>(n + 10);
    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 0) {
            dp[i] = dp[i - 1];
            if(i > 1) {
                dp[i] += dp[i - 2];
            }
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1408