akhauriyash/Code-Regression huggingface dataset:
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double

#define pll pair<ll,ll>
#define ff first
#define ss second

#define pb push_back
#define all(x) x.begin(),x.end()

#define MOD  1000000007
const int N = 200005; 

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    pll p[n];
    for(ll i=0;i<n;i++)   cin >> p[i].ff >> p[i].ss;
    vector<ll> v;
    for(ll i=0;i<n;i++)
    {
        v.pb(p[i].ff+p[i].ss);
    }
    sort(all(v));
    ll ans = v[n-1] - v[0];
    v.clear();
    for(ll i=0;i<n;i++)
    {
        v.pb(p[i].ff+p[i].ss);
    }
    sort(all(v));
    ans = max(v[n-1] - v[0],ans);
    v.clear();
    for(ll i=0;i<n;i++)
    {
        v.pb(p[i].ss-p[i].ff);
    }
    sort(all(v));
    ans = max(ans,v[n-1] - v[0]);
    cout<<ans<<"\n";
}

int main()
{
    FAST;
    int t = 1;
 // cin >> t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 8404
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
cont = 0

a.each_with_index do |v, i|
 if i + 1 == v
   tmp = a[i + 1]
   a[i + 1] = v
   a[i] = tmp
   cont += 1
 end
end

p cont


Measured memory_bytes: 8708
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	map<int,int> cnt;
	ll sum = 0;
	int n;
	cin >> n;
	rep(i,0,n){
		int x;
		cin >> x;
		++cnt[x];
		sum += x;
	}
	int q;
	cin >> q;
	while(q--){
		int b,c;
		cin >> b >> c;
		int num = cnt[b];
		cnt[b] = 0;
		cnt[c] += num;
		sum -= 1LL * b * num;
		sum += 1LL * c * num;
		cout << sum << '\n';
	}
}


Measured memory_bytes: 7972
from collections import deque

def bfs(i):
    q = deque()
    q.append(["a"])
    while q:
        p = q.popleft()
        l = len(p)
        if l == i:
            print("".join(p))
        if not len(p) == i:
            for j in range(l + 1):
                if j >= 1:
                    if alph[j - 1] in p:
                        q.append(p + [alph[j]])
                else:
                    q.append(p + ["a"])
        
alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
n = int(input())
bfs(n)

Measured memory_bytes: 22772
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2e5+10;
int min(int a,int b){return a>b?b:a;}
int max(int a,int b){return a>b?a:b;}
bool judge(int pos,int lim,int s,int a[],int b[]){
  reverse(a,a+s);
  reverse(b,b+s);
//printf("::pos=%d lim=%d s=%d\n",pos,lim,s);
//printf("a::");for(int i=0;i<s;i++)printf(" %d",a[i]);printf("\n");
//printf("b::");for(int i=0;i<s;i++)printf(" %d",b[i]);printf("\n");
  int ml=1,mr=lim;
  for(int i=0;i<s;i++){
    if(b[i]==1)ml--;
    else if(b[i]==-1)mr++;
    mr=min(mr,lim);
    ml=max(ml,1);
    if(a[i]==1)mr--;
    else if(a[i]==-1)ml++;
    //printf("i=%d ml=%d mr=%d\n",i,ml,mr);
    if(ml>mr)return true;
  }
  return pos<ml||pos>mr;
}
int main(){
  int n,m,x,y,s,ta[N],tb[N];
  string a,b;
  cin>>n>>m>>s>>x>>y>>a>>b;
  for(int i=0;i<s;i++)if(a[i]=='L')ta[i]=-1;
  else if(a[i]=='R')ta[i]=1;
  else ta[i]=0;
  for(int i=0;i<s;i++)if(b[i]=='L')tb[i]=-1;
  else if(b[i]=='R')tb[i]=1;
  else tb[i]=0;
  if(judge(y,m,s,ta,tb))printf("NO\n");
  else {
    for(int i=0;i<s;i++)if(a[i]=='U')ta[i]=-1;
    else if(a[i]=='D')ta[i]=+1;
    else ta[i]=0;
    for(int i=0;i<s;i++)if(b[i]=='U')tb[i]=-1;
    else if(b[i]=='D')tb[i]=+1;
    else tb[i]=0;
    if(judge(x,n,s,ta,tb))printf("NO\n");
    else printf("YES\n");
  }
}


Measured memory_bytes: 2312
#include<iostream>
typedef long long ll;

using namespace std;

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

 if(N==1 && M==1){cout<< 1 << endl;}
 else if(N==1 && M >=2){cout << M - 2 << endl;}
 else if(N>=2 && M == 1){cout << N-2 << endl;}
 else if(N>=2 && M>=2){cout << (N-2)*(M-2) << endl;}
 
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,x;
    cin>>n>>x;
    vector<ll>l(n+1);
    ll ans=1;
    rep(0,i,n){
        cin>>l[i+1];
        l[i+1]+=l[i];
        if(l[i+1]<=x){
            ++ans;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := scanInt()-1, scanInt()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	ans := 0
	all := mpow(2, n-1) - 1

	var dfs func(p, v int) int
	dfs = func(p, v int) int {
		res := 1

		for _, to := range g[v] {
			if to == p {
				continue
			}
			t := dfs(v, to)
			res += t
			ans -= mpow(2, t) - 1
			ans %= mod
		}

		ans += all - mpow(2, n-res) + 1
		ans %= mod

		return res
	}

	dfs(0, 0)

	ans *= mpow(div(1, 2), n)
	ans %= mod

	fmt.Fprintln(wr, (ans+mod)%mod)
}

const mod = 1000000007

func mpow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 == 1 {
			res = res * a % mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}

func div(b, c int) int {
	a, p, x, u := c, mod, 1, 0
	for p != 0 {
		t := a / p
		a, p = p, a-t*p
		x, u = u, x-t*u
	}
	res := b * x % mod
	if res < 0 {
		res += mod
	}
	return res
}


Measured memory_bytes: 67072
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,u,v;
  cin >> n>> u >> v;
  u--;
  v--;
  vector<vector<ll>> G(n);

  for(ll i=0;i<n-1;i++){
    ll a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }

  vector<ll> d1(n,-1);//uからの距離
  vector<ll> d2(n,-1);//vからの距離

  queue<int> que;

  que.push(u);
  d1[u]=0;

  while(!que.empty()){
    int p=que.front();
    que.pop();

    for(int i=0;i<G[p].size();i++){
      if(d1[G[p][i]]==-1){
        d1[G[p][i]]=d1[p]+1;
        que.push(G[p][i]);
      }
    }
  }
  
  que.push(v);
  d2[v]=0;

  while(!que.empty()){
    int p=que.front();
    que.pop();

    for(int i=0;i<G[p].size();i++){
      if(d2[G[p][i]]==-1){
        d2[G[p][i]]=d2[p]+1;
        que.push(G[p][i]);
      }
    }
  }

  ll m=0;
  for(ll i=0;i<n;i++){
    if(G[i].size()==1){
      if(d1[i]<d2[i])m=max(m,d2[i]);
    }
  }
  cout << m-1 << endl;

}

Measured memory_bytes: 10856
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2000;
const int mod=1e9+7;
int n,k,ans;
int f[maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k)
{
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    n=read(),k=read();
    f[0]=1;
    for (int i=1;i<n;i++)
	{
	    for (int j=i;j;j--)
	        f[j]=(f[j+1]+f[j-1])%mod;
	    f[0]=(f[1]+f[0])%mod;
	}
    f[n-k]=((f[n-k]-f[n-k+1])%mod+mod)%mod;
    ans=1ll*f[n-k]*power(2,max(n-k-1,0))%mod;
    printf("%d\n",ans);
    return 0;
}


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

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N;
  cin >> N;
  int A[N+1] = {};
  int sum = 0;
  for(int i = 1; i <= N; i++){
    cin >> A[i];
    sum += abs(A[i] - A[i-1]);
  }
  sum += abs(A[N]);
  int B[N+1] = {};
  for(int i = 1; i <= N; i++){
    B[i] = abs(A[(i+1)%(N+1)] - A[i])
          + abs(A[i] - A[i-1])
           - abs(A[(i+1)%(N+1)] - A[i-1]);
  }

  for(int i = 1; i <= N; i++){
    printf("%d\n", sum - B[i]);
  }



  return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

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

    long long ans=0;
    for(int i=1;i<=n;i++) {
        if(i%3!=0&&i%5!=0&&i%15!=0) {
            ans+=i;
        }
    }
    cout<<ans<<endl;
}




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

int main(){
  int N, M, R; std::cin >> N >> M >> R;
  std::vector<int> r(R);
  for(auto i=0; i<R; ++i){
    std::cin >> r[i];
    --r[i];
  }
  auto d = std::vector<std::vector<int>>(N, std::vector<int>(N, 99999999));
  for(auto i=0; i<M; ++i){
    int a, b, c; std::cin >> a >> b >> c;
    --a;
    --b;
    d[a][b] = std::min(d[a][b], c);
    d[b][a] = std::min(d[b][a], c);
  }
  for(auto k=0; k<N; ++k)
    for(auto i=0; i<N; ++i)
      for(auto j=0; j<N; ++j){
	d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
	d[j][i] = d[i][j];
      }
  std::sort(r.begin(), r.end());
  auto min = 9*99999999;
  do{
    auto myd = 0;
    for(auto i=0; i<R-1; ++i)
      myd += d[r[i]][r[i+1]];
    min = std::min(min, myd);
  }while(std::next_permutation(r.begin(), r.end()));
  std::cout << min << '\n';
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var W, a, b int
	fmt.Scan(&W, &a, &b)
	aStart := a
	aEnd := a + W
	bStart := b
	bEnd := b + W

	if aStart <= bStart {
		if aEnd >= bStart {
			fmt.Println(0)
		} else {
			fmt.Println(bStart - aEnd)
		}
	} else {
		if aEnd <= bStart {
			fmt.Println(0)
		} else {
			fmt.Println(aStart - bEnd)
		}
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, x, m;
int vis[N] = {};
long long ans[N] = {};
int main() {
    cin >> n >> x >> m;
    x %= m;
    ans[1] = x;
    vis[x] = 1;
    int r = -1, d;
    for (int i = 2; i <= n; i++) {
        x = x * x % m;
        ans[i] = ans[i - 1] + x;
        if (vis[x]) {
            r = vis[x];
            d = i - vis[x];
            break;
        }
        vis[x] = i;
    }
    if (r == -1) cout << ans[n] << '\n';
    else {
        long long f = (n - r) / d, rr = (n - r) % d;
        cout << ans[r + rr] + (ans[r + d] - ans[r]) * f << '\n';
    }
    return 0;
}

Measured memory_bytes: 4332
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define chushihua(x,y) memset(x,y,sizeof x)
using namespace std;
const int MAXX = 100000 + 10;
const double PI = 3.14159265358979323846;
const ll mod = 1000000007;
int main() {
	int  t;
	int  n;
	int a[11];
	while (cin >> n >> t) {
		chushihua(a, 0);
		for (int i = 0; i < t; i++) {
			int x;
			scanf("%d", &x);
			a[x] = 1;
		}
		//for (int i = 0; i < 10; i++) {
		//	cout << a[i] << endl;
		//}
		for (int i = n;; i++) {
			int flag = 1;
			int j = i;
			while (j) {
				int y = j % 10;
				//cout << y << endl;
				j /= 10;
				if (a[y] == 1) {
					flag = 0;
				}
			};
			if (flag == 1) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
a = 0
w = 0
t = 0
r = 0
for i in range(n):
    if s[i]  == "AC":
        a += 1
    elif s[i] == "WA":
        w += 1
    elif s[i] == "TLE":
        t += 1
    else:
        r += 1
print("AC x",str(a))
print("WA x",str(w))
print("TLE x",str(t))
print("RE x",str(r))

Measured memory_bytes: 16332
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// my code goes here
		
		var s = Console.ReadLine().Split().ToArray();
		var a = Console.ReadLine().Split().Select(nyan => int.Parse(nyan)).ToArray();
		string u = Console.ReadLine();
		
		if(u == s[0]){
			a[0] -= 1;
		}else{
			a[1] -= 1;
		}
		
		Console.WriteLine(string.Join(" ", a));
		
		

	}
}

Measured memory_bytes: 13396
i = int(input())

dic = {}
for j in range(i):
    word = input()
    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1


dic2 = sorted(dic.items(), key=lambda x:x[1])
k = len(dic2)-1
s = 0
ans = []
for p in range(len(dic2)):
    t = dic2[k][1]
    ans.append(dic2[k][0])
    k -= 1
    if t == dic2[k][1]:
        s = 1
    else:
        break
ans.sort()
for ak in ans:
    print(ak)

Measured memory_bytes: 45780
#include<bits/stdc++.h>
using namespace std;
set<int>pattern[26];

int main(){
	string s,t;
	cin>>s>>t;
	for(int i=0; s[i]; i++){
		pattern[(int)(s[i]-'a')].insert(i);
	}
	for(int i=0; i<26; i++){
		if(pattern[i].size()){
			vector<int>arr;
			for(set<int>::iterator it = pattern[i].begin(); it!=pattern[i].end(); it++){
				arr.push_back(*it);
			}
			for(int j=1; j<arr.size(); j++){
				if(t[arr[0]]!=t[arr[j]]){
					cout<<"No";
					return 0;
				}
			}
		}
		pattern[i].clear();
	}
	
	for(int i=0; t[i]; i++){
		pattern[(int)(t[i]-'a')].insert(i);
	}
	for(int i=0; i<26; i++){
		if(pattern[i].size()){
			vector<int>arr;
			for(set<int>::iterator it = pattern[i].begin(); it!=pattern[i].end(); it++){
				arr.push_back(*it);
			}
			for(int j=1; j<arr.size(); j++){
				if(s[arr[0]]!=s[arr[j]]){
					cout<<"No";
					return 0;
				}
			}
		}
		pattern[i].clear();
	}
	cout<<"Yes";
}

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

using namespace std;

typedef long long int big;

int main(){
    big i=1,j=1,k=1;
    big n;
    cin>>n;
    big sum=0;
    for(big i=1;i<=n;i++){
        for(big j=1;j<=n;j++){
            for(big k=1;k<=n;k++){
                sum+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vs vector<string>
#define mii map<int, int>

void show(auto a){
  int i = 1;
  while(i < a.size()){
    cout<<a[i]<<" ";
    i++;
  }
  cout<<endl;
}


int main(){
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  vi h(n+1);
  for(int i = 1; i <= n; i++) cin>>h[i];
  vi dp(n+1, 0);
  dp[2] = abs(h[2] - h[1]);
  for(int i = 3; i <= n; i++){
  	dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]));
  }
  // show(dp);
  cout<<dp[n]<<endl;

  

	



}

Measured memory_bytes: 1024
#include<stdio.h>

void marge(int [],  int, int ,int);
void margeSort( int [],int, int);
int L[250002],R[250002],count;

int main(){

  int left, mid, right,i,j,n1,n2,sumdata;
  int A[500000];

  scanf("%d",&sumdata);

  for(i = 0; i < sumdata; i++){

    scanf("%d",&A[i]);

  }

  margeSort(A,0,sumdata);

  for(i = 0; i < sumdata; i++){

    if(i == sumdata -1){

      printf("%d\n",A[i]);

    }

    else{
    printf("%d",A[i]);
    printf(" ");

    }

  }

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

  return 0;

}

void marge( int A[], int left, int mid, int right){ /*???????????????????????????????????????????????±???*/

  int n1,n2,i,j,k;

  n1 = mid -left; /*?????????????????????????????????????´???°*/
  n2 = right - mid; /*??????????????????????????????*/

  for(i = 0; i < n1  ; i++){

    L[i] = A[left + i];
  }

  for(i = 0; i <  n2  ; i++){

    R[i] = A[mid + i];
  }

  L[n1] = 2000000000;
  R[n2] = 2000000000;

  i = 0;
  j  = 0;

  for(k = left; k < right  ; k++){

    if(L[i] <= R[j]){

      count = count + 1;

      A[k] = L[i];

      i = i + 1;
      

    }

    else{

      count = count + 1;

      A[k] = R[j];

      j = j + 1;


    }

  }
}

void margeSort( int A[],int left, int right){

  int i,j,mid;

  if(left + 1 < right){

    mid = (left + right) /2;

    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left, mid, right);

      }
}

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

using namespace std;

#define sc scanf
#define pf printf
#define pb push_back
#define pbk pop_back
#define mk_pr make_pair

typedef long long intl;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<string> vss;
typedef queue<int> qi;

const int MX = 112345;
int a[3][102], b[3][102];

int main() {
  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n;
  cin>>n;
  for(int i=1; i<=2; i++) {
    for(int j=1; j<=n; j++) {
      cin>>a[i][j];
    }
  }

  for(int i=1; i<=2; i++) {
    for(int j=1; j<=n+1; j++) {
      b[i][j] = a[i][j] + max( b[i-1][j], b[i][j-1] );
    }
  }

  cout<<max(b[2][n+1], b[1][n+1])<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        setFact(200000);

        long ans = 0;
        long now = 0;
        long mul = fact[N];
        for (int i = 0; i < N; i++)
        {
            now += A[i];
            now += A[N - 1 - i];
            now %= mod;

            if (i == N - 1)
            {
                now *= revFact[2];
                now %= mod;
            }

            //ans += now * mul / fact[N - i];
            ans += now * mul % mod * powmod(N - i, mod - 2);
            ans %= mod;
        }
        Console.WriteLine(ans);

    }

    long[] fact; //階乗
    long[] revFact; //階乗の逆元
    void setFact(int N)
    {
        fact = new long[N];
        revFact = new long[N];
        fact[0] = 1;
        for (int i = 1; i < N; i++)
        {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        revFact[N - 1] = powmod(fact[N - 1], mod - 2);
        for (int i = N - 2; i >= 0; i--)
        {
            revFact[i] = revFact[i + 1] * (i + 1);
            revFact[i] %= mod;
        }
    }

    long mod = 1000000007;
    long powmod(long a, long p)
    {
        long ans = 1;
        long mul = a;
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod)
        {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }
        return ans;
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



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

int main(){
	int a, b;
	cin >> a >> b;
	if(a > b) cout << "a > b" << endl;
	if(a < b) cout << "a < b" << endl;
	if(a == b) cout << "a == b" << endl;
	return 0;
}

Measured memory_bytes: 1156
/** Binary Search */

#include <stdio.h>

int main(){
  int i,n,q,cnt=0;
  
 /** S[]
   * the number of S[]
   */
  scanf("%d", &n);
  int S[n]; //+1 is for the sentinel.
  //input data
  for(i=0;i<n;i++){
    scanf(" %d", &S[i]);
  }

 /** T[]
   * the number of T[]
   */
  scanf("%d", &q);
  int T[q];
  //input data
  for(i=0;i<q;i++){
    scanf(" %d", &T[i]);
  }

  /* Binary Search
  */
  for(i=0;i<q;i++){
    int key = T[i]; //??????????????¢?´¢
    int mid, left=0, right=n;
    while(left<right){ //right(??????)??????.
//      printf("mid: %d, left: %d, right: %d, key: %d, S[mid]: %d\n",mid,left,right,key,S[mid]); //@@
      mid = (left + right) / 2; //?¬????mid (int????°???°???????????¨???) 
      if(S[mid]==key){
        cnt++;
        break;
      }else if(key<S[mid]){ //??????????????????
        right = mid; //right=m-1??§???????????????????????????????????????
      }else if(S[mid]<key){ //??????????????????
        left = mid + 1;
      }
    }
  }
  
  printf("%d\n",cnt);
  
  return 0;
}

Measured memory_bytes: 1184
N,n,v,w,i,t,m,*p;s(){scanf("%d,%d",&v,&w);}main(W){for(;s(),W=v;){int c[1001]={0};for(s(),n=v;n--;)for(s(),m=i=W+1,p=c;i--;*p++-*c||m--)i>=w&&*p<(t=p[w]+v)&&(*p=t);printf("Case %d:\n%d\n%d\n",++N,*c,m);}return 0;}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
const int N=10002;
int S,T,cur[N<<1],fir[N<<1],dep[N<<1];
char map[N];
struct edge{
	int to,wi,nx;
}eg[N*400];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10+c-48,(c=getchar())>='0'&&c<='9');
	return x;
}

inline void add(int a,int b,int v){
	static int cnt=1;
	eg[++cnt]=(edge){b,v,fir[a]};
	fir[a]=cnt;
	eg[++cnt]=(edge){a,0,fir[b]};
	fir[b]=cnt;
}

inline bool bfs(){
	static int que[N<<1];
	memset(dep,0,sizeof(dep));
	int hd=0,tl=1;
	que[0]=S+N;
	dep[S+N]=1;
	while(hd!=tl){
		int x=que[hd++];
		for(int i=cur[x]=fir[x];i;i=eg[i].nx){
			int y=eg[i].to;
			if(!dep[y]&&eg[i].wi){
				dep[y]=dep[x]+1;
				que[tl++]=y;
			}
		}
	}
	return dep[T];
}

int dfs(int x,int t){
	if(x==T) return t;
	int tt=t,tp;
	for(int &i=cur[x];i;i=eg[i].nx){
		int y=eg[i].to,v=eg[i].wi;
		if(v&&tt&&dep[y]==dep[x]+1&&(tp=dfs(y,std::min(v,tt)))){
			eg[i].wi-=tp;
			eg[i^1].wi+=tp;
			tt-=tp;
		}
		if(!tt) break;
	}
	return t-tt;
}

int main(){
#ifndef ONLINE_JUDGE
//	freopen("b.in","r",stdin);
#endif
	int R=nxi(),C=nxi();
	for(int i=1;i<=R;++i){
		for(int j=1;j<=C;++j){
			char c;
			while((c=getchar())!='S'&&c!='T'&&c!='.'&&c!='o');
			if(c=='S') S=(i-1)*C+j;
			if(c=='T') T=(i-1)*C+j;
			map[(i-1)*C+j]=c;
		}
	}
	if((S-1)/C==(T-1)/C||S%C==T%C){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=R;++i){
		for(int j=1;j<=C;++j){
			int now=(i-1)*C+j;
			if(map[now]=='.'||map[now]=='T') continue;
			if(map[now]!='S') add(now,now+N,1);
			for(int k=1;k<=R;++k){
				char tp=map[(k-1)*C+j];
				if(k!=i&&(tp=='o'||tp=='T')){
					add(now+N,(k-1)*C+j,1);
				}
			}
			for(int k=1;k<=C;++k){
				char tp=map[(i-1)*C+k];
				if(k!=j&&(tp=='o'||tp=='T')){
					add(now+N,(i-1)*C+k,1);
				}
			}
		}
	}
	int ans=0;
	while(bfs()){
		ans+=dfs(S+N,N);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 47488
#include<stdio.h>

#define MAX_WORD_SIZE (11)
#define MAX_LINE_SIZE (1001)
#define EOT_SIZE      (12)

int main(void)
{
        char w[MAX_WORD_SIZE] = { 0 };
        char t[MAX_LINE_SIZE] = { 0 };
        const char eot[EOT_SIZE] = "END_OF_TEXT";
        int i, is_eot, word_counter;

        is_eot = -1;
        word_counter = 0;

        scanf("%s", w);

        while(EOF != scanf("%s", t)){

                for(i=0; i < EOT_SIZE; i++){

                        if(eot[i] == '\0' && t[i] == '\0'){
                                is_eot = 1;
                                break;
                        }

                        if(t[i] != eot[i]){
                                break;
                        }
                }

                if(is_eot > 0){
                        break;
                }

                for(i=0; i < MAX_WORD_SIZE; i++){
                        if(t[i] == '\0' && w[i] == '\0'){
                                word_counter++;
                                break;
                        }

                        if(t[i] != w[i] && t[i] != (w[i] & 0x5f)){
                                break;
                        }
                }
        }
        printf("%d\n", word_counter);

        return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
using namespace std;
#define int long long

signed main(){
    int n;
    while(cin >> n){
        int q; cin >> q;
        vector<int> a(n,0);
        for(int i = 0; i < n; ++i) cin >> a[i];
        int x;
        for(int i = 0; i < q; ++i) {cin >> x;
int ans{};
            //syaku
           // int left = 0;
            int right = 0;
            int sum = 0;
            int left = 0;
//            for(int right = left; i < n; ++i){
            for(left = 0; left < n; ++left){
                for(; (right < n) && (sum + a[right] <= x); ++right)
                        sum += a[right];
              /*while(right < n && sum + a[right] <= x){
                  sum += a[right];
                  ++right;
              }*/

                ans += (right-left);

                if(right == left) ++right;
                else sum -= a[left];
            }

cout << ans << endl;


        }
   }



    return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif

vector<ll> seq;
ll ans[100005],dp[100005];

int main()
{
    IOS();
    ll n,q;
    cin >> n >> q,seq.pb(n);
    while(q--)
    {
        ll x;
        cin >> x;
        while(!seq.empty()&&seq.back()>=x)
            seq.pop_back();
        seq.pb(x);
    }
    dp[SZ(seq)]=1;
    for(int i=SZ(seq)-1;i>0;--i)
    {
        dp[i]+=dp[i+1],dp[i-1]+=(seq[i]-seq[i-1])/seq[i-1]*dp[i];
        ll cm=seq[i]%seq[i-1];
        while(cm>seq[0])
        {
            int x=upper_bound(ALL(seq),cm)-seq.begin();
            dp[x-1]+=cm/seq[x-1]*dp[i];
            cm%=seq[x-1];
        }
        ans[cm]+=dp[i];
    }
    ans[seq[0]]+=dp[0]+dp[1];
    for(int i=n-1;i>0;--i)
        ans[i]+=ans[i+1];
    for(int i=1;i<=n;++i)
        cout << ans[i] << "\n";
}

Measured memory_bytes: 4212
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenCoins solver = new BGoldenCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenCoins {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long n = nl();
            long ans = (n / 500) * 1000 + ((n % 500) / 5) * 5;
            pn(ans);

        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 21076
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535
int main()
{
  float x=0,y=0,r;
  int i,j,d=90;
  for(;;){
    scanf("%d,%d",&i,&j);
    if(i==0&&j==0)break;
    r=d*PI/180;
    x+=i*cos(r);
    y+=i*sin(r);
    d-=j;
  }
  printf("%d\n%d\n", (int)x,(int)y);
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  ll a[SIZE],b[SIZE];
  ll t = 0;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%lld%lld",a+i,b+i);
  }

  for(int i=n-1;i>=0;i--){
    a[i] += t;
    ll s = (b[i]-(a[i]%b[i]))%b[i];
    t += s;
  }
  
  printf("%lld\n",t);
  
  
  return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, A, B, v[100009];
int main() {
	scanf("%d %d %d", &N, &A, &B); A -= B;
	for (int i = 0; i < N; i++) scanf("%d", &v[i]);
	int l = 0, r = 1000000009;
	while (r - l > 1) {
		int m = (l + r) >> 1;
		long long res = 0;
		for (int i = 0; i < N; i++) {
			long long val = v[i] - 1LL * B * m;
			if (val >= 1) res += (val + A - 1) / A;
		}
		if (res <= m) r = m;
		else l = m;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 640
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))

ans = 0
pt = len(B)-1
for i,sa in enumerate(SA):
    while(pt>=0):
        if sa + SB[pt] <= K:
            ans = max(ans,i+pt)
            break
        pt-=1
print (ans)





Measured memory_bytes: 47652
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  mll m;
  rep(i, N) {
    ll a;
    cin >> a;
    m[a]++;
  }
  COUT(m.size());
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)

long long MOD;

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

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


int main(){
    int N;
    cin >> N;
    vector<int> P(N*N);
    REP(i, N*N){
        cin >> P[i];
        P[i]--;
    }
    vector<vector<int>> A(N, vector<int>(N, 1<<30));
    vector<vector<bool>> B(N, vector<bool>(N, false));

    queue<pair<int, int>> que;
    REP(i, N){
        A[0][i] = A[N-1][i] = A[i][0] = A[i][N-1] = 1;
        que.emplace(0, i);
        que.emplace(N-1, i);
        que.emplace(i, 0);
        que.emplace(i, N-1);
    }
    while(!que.empty()){
        auto z = que.front(); que.pop();
        int y = z.first;
        int x = z.second;
        for(int d=0; d<4; d++){
            int y2 = y + dy[d];
            int x2 = x + dx[d];
            if(y2 < 0 || y2 >= N) continue;
            if(x2 < 0 || x2 >= N) continue;
            if(A[y2][x2] > A[y][x]+1){
                A[y2][x2] = A[y][x]+1;
                que.emplace(y2, x2);
            }
        }
    }
    int ans = 0;
    for(int p : P){
        int y = p / N;
        int x = p % N;
        ans += A[y][x] - 1;
        A[y][x]--;
        que.emplace(y, x);
        while(!que.empty()){
            auto z = que.front(); que.pop();
            int y = z.first;
            int x = z.second;
            for(int d=0; d<4; d++){
                int y2 = y + dy[d];
                int x2 = x + dx[d];
                if(y2 < 0 || y2 >= N) continue;
                if(x2 < 0 || x2 >= N) continue;
                if(!B[y2][x2]){
                    if(A[y2][x2] > A[y][x]+1){
                        A[y2][x2] = A[y][x]+1;
                        que.emplace(y2, x2);
                    }
                }else{
                    if(A[y2][x2] > A[y][x]){
                        A[y2][x2] = A[y][x];
                        que.emplace(y2, x2);
                    }
                }
            }
        }
        B[y][x] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num;
  cin >> num;
  
  vector<int> list(num);
  
  for(int i = 0; i< list.size(); i++) {
    cin >> list.at(i);
  }
  
  int target  = 0;
  bool result = true;
  
  for(auto n : list) {
    
    if(target <= n-1) {
      target = n-1;
    }
    else if(target <= n) {
      target = n;
    }
    else if(target > n) {
      result = false;
      break;
    }
  }
  if(result) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 6005;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int n, tot, rk[MAXN];
string res[MAXN], dp[MAXN];
int la, lb, a[MAXN], b[MAXN];
int main() {
	read(n), scanf("\n%s", s + 1);
	for (int i = 1; i <= 2 * n; i++)
		if (s[i] == 'a') a[++la] = i, rk[i] = la;
		else b[++lb] = i, rk[i] = lb;
	int last = 0;
	for (int i = 1; i <= n; i++) {
		if (i == n || max(a[i], b[i]) < min(a[i + 1], b[i + 1])) {
			if (a[i] < b[i]) {
				res[++tot] = ""; int Max = 0;
				for (int j = last + 1; j <= i; j++)
					if (a[j] > Max) {
						res[tot] += "ab";
						Max = b[j];
					}
			} else {
				res[++tot] = "";
				for (int j = last + 1; j <= i; j++) {
					string tmp = "";
					for (int k = last * 2 + 1; k <= i * 2; k++)
						if (rk[k] >= j) tmp += s[k];
					chkmax(res[tot], tmp);
				}
			}
			last = i;
		}
	}
	for (int i = tot; i >= 1; i--)
		dp[i] = max(dp[i + 1], res[i] + dp[i + 1]);
	cout << dp[1] << endl;
	return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<string>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
    char S[101][101];
	int A[101];
	int B[101];
	for (int i = 0; i < 101; ++i) {
		A[i] = 0;
		B[i] = 0;
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> S[i][j];
			if (S[i][j] == '#') {
				A[i] = 1;
				B[j] = 1;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		if (A[i]) {
			for (int j = 0; j < W; ++j) {
				if (B[j]) {
					cout << S[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
vvi f;
int ans=0;
void search(int x,int y){
    vi v={1,0,-1,0,1};
    rep(i,4){
        if(f[y+v[i]][x+v[i+1]]==1){
            f[y+v[i]][x+v[i+1]]=0;
            ans++;
            search(x+v[i+1],y+v[i]);
        }
    }
}

int main(void){
    int w,h;
    while(cin>>w>>h,w){
        ans=0;
        f=vvi(h+2,vi(w+2,0));
        int x,y;
        rep(i,h)rep(j,w){
            char c; cin>>c;
            if(c=='.')f[i+1][j+1]=1;
            if(c=='@')y=i+1,x=j+1;
        }
        search(x,y);
        cout<<ans+1<<endl;
    }
}

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;

int main(){
    int n;
    char a[100] = {0};

    scanf("%d", &n);

    int ans = 1;
    for(int i = 2; i <= n; i *= 2){
        ans = i;
    }

#if 0
    int j;
    for(int i = 1; i <= n; ++i){
        j = i;
        for(;;){
            if((j % 2) == 0){
                a[i]++;
                j = j / 2;
            }else break;
            //printf("%d\n", j);
            if(j == 0) break;
        }
    }

    int max = a[1];
    int ans = 1;
    for(int i = 1; i <= n; ++i){
        //printf("%d\n", a[i]);
        if(max < a[i]){
            max = a[i];
            ans = i;
        }
    }
#endif

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

    return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>

int main(void){
  long long N, K;
  scanf("%lld", &N);

  for (K = 1;; K++) {
    if(N == K*(K-1)/2) break;
    if(N < K*(K-1)/2){
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n%lld\n", K);
  K--;
  long long dp[K][K], num = 1;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      if(j <= i) dp[i][j] = num++;
    }
  }

  for (int i = 0; i < K; i++) {
    printf("%lld ", K);
    for (int j = 0; j < K; j++) {
      printf("%lld%c", j <= i?dp[i][j]:dp[j][i], j == K-1?'\n':' ');
    }
  }
  printf("%lld ", K);
  for (long long i = 1; i <= K; i++) {
    printf("%lld%c", i*(i+1)/2, i == K?'\n':' ');
  }

  return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>
int isprime(int n){//?´???°???????????¢??°
	int i;
	for(i = 2; i*i <= n; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main(){
	int n, i;
	while(1){//0?????\?????????????????§?????????
		scanf("%d", &n);
		if(n == 0) break;
		for(i = n; n >= 5; i--){
			if(isprime(i) == 1 && isprime(i-2) == 1){
				printf("%d %d\n", i-2, i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1028
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long a,b,sum;
  int cnt;
  while(cin >> a >> b){
    sum = a + b;
    cnt = 0;
    while(sum>0){
      sum /= 10;
      cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12

// li dp(int sum, vector<int>& v, int pos, vector<vector<vector<li>>> &mem, int need) {
//   if (pos == v.size()) {
//     if (sum == 0 && need == 0) return 1;
//     else return 0;
//   }
//   if (sum == 0 && need == 0) return 1;
//   if (sum < 0) return 0;
//   if (need < 0) return 0;
//   if (mem[pos][sum][need] != -1) return mem[pos][sum][need];
//   return mem[pos][sum][need] = dp(sum - v[pos], v, pos + 1, mem, need - 1) + dp(sum, v, pos + 1, mem, need);
// }

// li dp(int sum, vector<int>& v, int pos, vector<vector<vector<li>>>& mem, int cnt, int a) {
//   if (pos == v.size()) {
//     if (cnt == 0) return 0;
//     if (sum % cnt == 0 && sum / cnt == a) return 1;
//     return 0;
//   }
//   if (mem[pos][sum][cnt] != -1) return mem[pos][sum][cnt];
//   return mem[pos][sum][cnt] = dp(sum + v[pos], v, pos + 1, mem, cnt + 1, a) + dp(sum, v, pos + 1, mem, cnt, a);
// }

li dp(int sum, vector<int>& v, int pos, vector<vector<li>>& mem) {
  if (pos == v.size()) {
    if (sum == 0) return 1;
    return 0;
  }
  if (mem[pos][2500 + sum] != -1) return mem[pos][2500 + sum];
  return mem[pos][2500 + sum] = dp(sum + v[pos], v, pos + 1, mem) + dp(sum, v, pos + 1, mem);
}

void _main(int tc) {
  int n, a;
  cin >> n >> a;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  rep(i, n) v[i] -= a;
  int eps = 50;
  vector<vector<li>> mem(n + 1, vector<li>(2 * 50 * 50 + 1 + eps, -1));
  li ans = dp(0, v, 0, mem) - 1;
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 2304
while True:
  H, W = list(map(int, input().split()))
  if H == 0 and W == 0:
    break
  else:
    for i in range(H):
      if i == 0 or i == H - 1:
        print('#' * W)
      else:
        print('#' + '.' * (W-2) + '#')
    print()


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

int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	char ss[110];
	int i,c;
	c=0;
	while(0<=scanf("%s",ss)){
		for(i=0;i<=strlen(ss)-1;i++){
			if(ss[i]!=ss[strlen(ss)-i-1])break;
		}
		
		if(i==strlen(ss))++c;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,a[100003];
int dp[100003];
int main(){std::ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i];
}
dp[1]=0;
dp[2]=abs(a[1]-a[2]);
for(int i=3;i<=n;i++){
	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
//	cout<<dp[i]<<endl;
}
cout<<dp[n]<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





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

long long dp[100010][3];
template<class T> void chmin(T &a, T b) {
  if (a>b) {
    a = b;
  }
}
template<class T> void chmax(T &a, T b) {
  if (a<b) {
    a = b;
  }
}

int main() {
  int n; cin >> n;
  int a[n][3];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        chmax(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < 3; j++) {
    chmax(ans,dp[n][j]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 7112