akhauriyash/Code-Regression huggingface dataset:
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
// L <= 2019K <= R があれば、ans = 0
// なければ R-L < 2019 であるから、
// M = R-L として、O(M^2) による全探索ができる 
signed main() {
  int L, R;
  cin >> L >> R;
  for (int i = 0; i < 1000000; i++) {
    if (L <= 2019*i && 2019*i <= R) {
      cout << 0 << endl;
      return 0;
    }  
  } 
  // O(1000 + 2019*2019) = O(4*10^6)
  int ans = INF;
  for (int i = L; i < R; i++) {
    for (int j = i+1; j <= R; j++) {
      ans = min(ans, i*j%2019);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
#define iter set<int>::iterator 
int n,a[200200],id[200200];
set<int> s;
bool cmp(int x,int y) {return a[x]>a[y];}
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();
	rep(i,1,n) a[i]=read();
	rep(i,1,n) id[i]=i;
	s.insert(0);s.insert(n+1);
	s.insert(0);s.insert(n+1);
	sort(id+1,id+1+n,cmp);
	ll ans=0;
	rep(i,1,n)
	{
		iter it=s.lower_bound(id[i]),tmp1=it,tmp2=it;tmp1--;
		int a1,a2,b1,b2;
		a1=*tmp1;tmp1--;a2=*tmp1;
		b1=*tmp2;tmp2++;b2=*tmp2;
		if (a1) ans+=1ll*a[id[i]]*(b1-id[i])*(a1-a2);
		if (b1<=n) ans+=1ll*a[id[i]]*(id[i]-a1)*(b2-b1);
		s.insert(id[i]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>


using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	string S;
	cin >> S;

	int cnt = 0;
	int ans = 0;
	for (char c : S) {
		if (c == 'I') {
			cnt++;
		} else if (c == 'D') {
			cnt--;
		}
		ans = max(cnt, ans);
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;

#define MAX_N 105

char str1[MAX_N];
char str2[MAX_N];
char str3[MAX_N];
int len1,len2,len3;
int go1,go2,go3;
int g;

void init(){
    go1 = -1;
    go2 = -1;
    go3 = -1;
    len1 = (int)strlen(str1);
    len2 = (int)strlen(str2);
    len3 = (int)strlen(str3);
}

void GO(char t){
    if(t == 'a'){
        if(go1 == len1-1){
            g = 1;
            return;
        }
        go1++;
        GO(str1[go1]);
    }
    else if(t == 'b'){
        if(go2 == len2-1) {
            g = 2;
            return;
        }
        go2++;
        GO(str2[go2]);
    }
    else{
        if(go3 == len3-1) {
            g = 3;
            return;
        }
        go3++;
        GO(str3[go3]);
    }
}

int main(){
    scanf("%s",str1);
    scanf("%s",str2);
    scanf("%s",str3);
    init();
    GO('a');
    if(g == 1){
        cout<<"A"<<endl;
    }
    else if(g == 2){
        cout<<"B"<<endl;
    }
    else{
        cout<<"C"<<endl;
    }
    return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

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



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n,x;
int a[300000];
bool used[300000];
int main(){
  cin >> n >> x;
  if(x==1 || x == 2*n-1){
    cout << "No" <<endl;
    return 0;
  }
  if(n==2){
    if(x!=2){
      cout <<"No"<<endl;
      return 0;
    }
    cout << "Yes" <<endl;
    REP(i,3){
      cout << i + 1 <<endl;
    }
    return 0;
  }
  cout << "Yes" <<endl;
  if(x!=2){
    a[n+2] = 2;
    used[2] = true;
  }
  if(x!= 2*n-2){
    a[n-2] = 2*n-2;
    used[2*n-2] = true;
  }
  a[n-1] = 1;
  a[n] = x;
  a[n+1] = 2*n-1;
  used[1] = true;
  used[x] = true;
  used[2*n-1] = true;
  int now = 1;
  FOR(i,1,2*n){
    if(a[i] != 0) continue;
    while(used[now]) now++;
    a[i] = now;
    used[now] = true;
  }
  FOR(i,1,2*n){
    cout << a[i] <<endl;
  }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pi 3.141592653589793238

int main( )
{
     int r;
     float ans;
     cin>>r;
     ans =(float) (2.0*pi*r);
     printf("%.20f\n",ans);
     //cout<<fixed<<setprecision(20)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int H,W;
  cin>>H>>W;
  int h,w;
  cin>>h>>w;
  int a=abs(H-h);
  int b=abs(W-w);
  cout<<a*b<<endl;
  
  return 0;
}

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

int wa(int n){
  return n<10?n:wa(n/10)+n%10;
}
int main(){
  int N,A,B;
  int ans=0;
  cin >> N >> A >> B;
  for (int i=1;i<=N;i++){
    if (wa(i)>=A and wa(i)<=B){
      ans+=i;
    }
  }
  cout << ans << endl;
 }


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

using namespace std;
int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    vector<int> A(N);
    vector<int> AA(N);
    for(int i=0; i<N; ++i) {
        cin >> A[i];
        AA[i] = A[i];
    }


    int max=0, max2=0;
    sort(A.rbegin(), A.rend());
    max = A[0];
    max2 = A[1];

    for(int i=0; i<N; ++i) {
        if(AA[i] != max)
            cout << max << endl;
        else
            cout << max2 << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	int n, a, b, c, d;
	char s[200002];
	scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
	scanf("%s", s);

	if (c < d) {
		while (1) {
			if (d - b <= 2) {
				b = d;
				break;
			}
			if (s[b + 1] == '.') {
				b++;
				continue;
			}
			if (s[b + 2] == '.') {
				b += 2;
				continue;
			}
			printf("No\n");
			return 0;
		}
		while (1) {
			if (c - a <= 2) {
				a = c;
				break;
			}
			if (s[a + 1] == '.') {
				a++;
				continue;
			}
			if (s[a + 2] == '.') {
				a += 2;
				continue;
			}
			printf("No\n");
			return 0;
		}
		printf("Yes\n");
	}else{
		int spaceok = 0;
		int index;
		for (int i = b; i <= d; i++) {
			if (s[i - 2] == '.' && s[i - 1] == '.'&&s[i] == '.') {
				spaceok = 1;
				index = i;
				break;
			}
		}
		if (spaceok) {
			//move b
			while (1) {
				if (index - b <= 2) {
					b = index;
					break;
				}
				if (s[b + 1] == '.') {
					b++;
					continue;
				}
				if (s[b + 2] == '.') {
					b += 2;
					continue;
				}
				printf("No\n");
				return 0;
			}
			while (1) {
				if (c - a <= 2) {
					a = c;
					break;
				}
				if (s[a + 1] == '.') {
					a++;
					continue;
				}
				if (s[a + 2] == '.') {
					a += 2;
					continue;
				}
				printf("No\n");
				return 0;
			}
			while (1) {
				if (d - b <= 2) {
					printf("Yes\n");
					return 0;
					break;
				}
				if (s[b + 1] == '.') {
					b++;
					continue;
				}
				if (s[b + 2] == '.') {
					b += 2;
					continue;
				}
				printf("No\n");
				return 0;
			}
		}
		else {
			printf("No\n");
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    for(int n = 1; n <= N; n++){
        ll ans = 0;
        for(int x = 1; x*x <= n; x++){
            for(int y = x; y*y <= n; y++){
                for(int z = y; z*z <= n; z++){
                    ll sum = x*x + y*y + z*z + x*y + y*z + z*x;
                    if(sum == n){
                        if(x == y && y == z) ans += 1;
                        else if(x == y || y == z || z == x) ans += 3;
                        else ans += 6;
                    }
                }
            }
        }

        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3600
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const int L=1e5+1;
vector<int> es[L];
LL N;

bool ok;
int f(int r,int p)
{
	int c=0;
	int sum=1;
	for(int i=0;i<es[r].size();i++){
		int j=es[r][i];
		if(j==p){
			continue;
		}
		int v=f(j,r);
		if(v%2){
			c++;
		}
		sum+=v;
	}
	if((N-sum)%2){
		c++;
	}
	if(c==0||c>=2){
		ok=true;
	}
	return sum;
}

int main(){
    scanf("%lld",&N);
    for(int i = 0 ; i < N-1 ; i++){
		LL a;
		LL b;
        scanf("%lld",&a);
        scanf("%lld",&b);
		es[a].push_back(b);
		es[b].push_back(a);
    }

	f(1,0);
	if(ok){
		cout << "First" << endl;
	}
	else{
		cout << "Second" << endl;
	}


    return 0;
}


Measured memory_bytes: 5888
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let k = scan.read::<i64>();
    let q = scan.read::<usize>();
    let a = scan.readn::<usize>(q);
    let mut sc = vec![0i64;n];
    for i in 0..q {
        sc[a[i]-1] += 1;
    }
    for i in 0..n {
        sc[i] += k - q as i64;
        println!("{}", if sc[i] > 0 {"Yes"} else {"No"});
    }

}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n,x;
int a[1000];
int b[1000];

signed main(){
  cin>>n>>x;
  a[0] = 1;
  b[0] = 1;

  FOR(i,1,n+1){
    a[i] = a[i-1]*2 + 1;
    b[i] = b[i-1]*2+3;
  }

  int ans=0;
  while(n != -1){
    if(x==b[n]){
      ans+=a[n];
      x-=b[n];
    }
    else if(x>b[n]/2){
      ans+=a[n-1]+1;
      x-=b[n]/2 + 1;
    }
    else if(x==b[n]/2){
      ans+=a[n-1];
      x-=b[n]/2;
    }
    else {
      x--;
    }
    n--;
  }


  cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n, k, q;
    cin >> n >> k >> q;
    int p[n];
    for (int i = 0; i < n; i++) {
        p[i] = 0;
    }
    int x;
    for (int i = 0; i < q; i++) {
        cin >> x;
        p[x - 1]++;
    }
    int mnPts = q - k;
    for (int i = 0; i < n; i++) {
        if (p[i] > mnPts) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using boost::string_ref;

using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    bool operator() (const T& t1, const T& t2, const F& f)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};

template<class T>
using less_1st = compare_n<T, 0, less<T>>;

template<class T>
using less_2nd = compare_n<T, 1, less<T>>;

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

    int64_t n;
    cin >> n;
    vector<int64_t> as(n);
    for(auto& a : as) cin >> a;

    unordered_map<int64_t, bool> written;
    
    for(auto a : as){
        written[a] = !written[a];
    }
    
    int count = 0;
    for(auto& p : written)
    {
        if(p.second) count++;
    }
    
    cout << count << '\n';
    return 0;
}



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

#define int long long int 


int32_t main()
{
    int n;
    cin>>n;
    int ans=0;
    int temp=n;
    while(n)
    {
        ans+=n%10;
        n/=10;
    }
    cout<<(temp%ans?"No":"Yes")<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

struct node{
	int x,y,bit,t;
	node(int x,int y,int bit,int t) : x(x) , y(y) , bit(bit) , t(t) {}
};

int x,y;
int sx,sy;
int n;
char c[22][22];
int num[10],d[10],s[10],e[10];
int value[1<<10];
int done[22][22][1<<8][102];
int dx[5]={0,0,1,-1,0},dy[5]={1,-1,0,0,0};

int main(void){
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		memset(value,0,sizeof(value));
		queue<node> que;
		for(int i=0;i<=21;i++){
			for(int j=0;j<=21;j++){
				c[i][j]='#';
			}
		}
		for(int i=1;i<=y;i++){
			for(int j=1;j<=x;j++){
				cin >> c[j][i];
				if(c[j][i]=='P'){
					que.push(node(j,i,0,0));
					c[j][i]='.';
				}
			}
		}
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			num[a]=i;
			scanf("%d%d%d",&d[i],&s[i],&e[i]);
		}
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<n;j++){
                value[i]+=(i>>j&1)*d[j];
            }
            //cout << value[i] << " " << i << endl;
        }
		memset(done,0,sizeof(done));
		int ans=0;
		while(que.size()){
			node q=que.front();que.pop();
			if(q.t>100)continue;
			if(c[q.x][q.y]!='.')continue;
			for(int i=0;i<4;i++){
				int tx=q.x+dx[i];
				int ty=q.y+dy[i];
				if(c[tx][ty]>='0' && c[tx][ty]<='9'){
					int idx=num[c[tx][ty]-'0'];
					if(s[idx]<=q.t && q.t<e[idx])q.bit |= 1<<idx;
				}
			}
			if(done[q.x][q.y][q.bit][q.t]++)continue;
			ans=max(ans,value[q.bit]);
			for(int i=0;i<5;i++){
				que.push(node(q.x+dx[i],q.y+dy[i],q.bit,q.t+1));
			}
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 56788
chomp (my ($n, $p) = split / /, <STDIN>);
my %h;

factorization($p);
if ($p==1) {
  print "1\n";
} elsif ($n==1) {
  print "$p\n";
} else {
  my $ans = 1;
  for my $k (keys %h) {
    my $v = $h{$k};
    while ($v >= $n) {
      $ans *= $k;
      $v -= $n;
    }
  }
  print "$ans\n";
}
sub factorization {
  my $arg = shift;
  for my $i (2..sqrt($arg)) {
    if ($arg % $i == 0) {
      $h{$i}++;
      return ($i, factorization($arg / $i));
    }
  }
  $h{$arg}++ if $arg > 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    int N,Y;
    cin >> N >> Y;
    for (int i=0; i<N+1; ++i)
    {
        for (int j=0; j<N-i+1; ++j)
        {
            if( (int)(Y-10000*i-5000*j)/1000 == N-i-j)
            {
                cout << i << " " << j << " " << N-i-j << endl;
                return 0;
            } 
            // for (int k=0; k<N-i-j+1; ++k)
            // {
            //     if( (Y-10000*i-5000*j)/1000 == N-i-j)
            //     {
            //         cout << i << " " << j << " " << k << endl;
            //         return 0;
            //     } 
            //     // if(Y == 10000*i + 5000*j + 1000*k)
            //     // {
            //     //     cout << i << " " << j << " " << k << endl;
            //     //     return 0;
            //     // }
            // }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
ans = dict()
for i in range(N):
    if S[i] in ans:
        ans[S[i]] += 1
    else:
        ans[S[i]] = 1
ans = sorted(ans.items(), key=lambda x:x[1] , reverse = True)
i = 0
kotae = []
while i < len(ans) and ans[0][1] == ans[i][1]:
    kotae.append(ans[i][0])
    i += 1
kotae.sort()
for j in kotae:
    print(j)

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vi a(n);
	rep(i, n) cin >> a[i];

	priority_queue<int> pq;
	rep(i, n) pq.push(a[i]);

	int t;
	while (true)
	{
		if (m == 0) break;
		t = floor(pq.top() / 2);
		pq.pop();
		--m;
		pq.push(t);
	}

	ll sum = 0;
	rep(i,n)
	{
		sum += pq.top();
		pq.pop();
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1276
/* C */
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

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

	ll N;
	cin >> N;

	vector<ll> cnt;
	while (1) {
		if (N % 26 == 0) {
			cnt.push_back(26);
			N /= 26;
			N--;
		}
		else {
			cnt.push_back(N % 26);
			N /= 26;
		}
		if (N == 0) break;
	}

	reverse(cnt.begin(), cnt.end());
	rep(i, cnt.size()) {
		cout << char('a' + cnt[i] - 1);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,w,e,r;
	cin>>q>>w>>e>>r;
	while(1)
	{
		e-=w;
		if(e<=0)
		{
			printf("Yes");
			break;
		}
		
		q-=r;
		if(q<=0)
		{
			printf("No");
			break;
		}
	}
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int N, M;
vector<vector<int> > G;

vector<bool> seen;
bool rec(int v, int p, int s, int t) {
    if (v == s && p != -1) return true; // Ò»ÖÜ»Ø¤Ã¤Æ¤­¤Æ s ¤Ë‘ø¤Ã¤ÆÀ´¤¿¤é OK
    if (v != s) seen[v] = true;
    for (auto nv :  G[v]) {
        if (nv == p || nv == t || seen[nv]) continue;
        if (rec(nv, v, s, t)) return true;
    }
    return false;
}
        
bool solve() {
    cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    map<int,int> degs;
    for (int v = 0; v < N; ++v) {
		degs[(int)G[v].size()]++;
		if (G[v].size() & 1) return false;
	}

//    for (auto it : degs) if (it.first % 2 != 0) return false;
    if (degs[6] > 0) return true;
    if (degs[4] > 2) return true;
    if (degs[4] <= 1) return false;

    vector<int> four;
    for (int v = 0; v < N; ++v) if (G[v].size() == 4) four.push_back(v);
    int s = four[0], t = four[1];
    seen.assign(N, 0);
    return rec(s, -1, s, t);
}

int main() {
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 7680
/*
D题：
给定n列的方块
第i列高度hi
现在要把它染成红蓝两色
要求满足：
对于任意一个2*2的区域，恰有2个蓝色，2个红色
问方案数
n<=100,h<=10^9
*/
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 105;
const int MOD = 1000000007;
int bin[maxn], h[maxn], f[maxn][3];
int n, mx, res, base = 1;

inline int power(int x, int p) {
	int res = 1;
	while (p) {
		if (p & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD; p >>= 1;
	}
	return res;
}

pii solve(int l, int r, int base) {
	// printf("%d %d %d\n", l, r, base);
	int mn = MOD, cnt = 0;
	pii res = make_pair(0, 0), sub;
	rep (i, l, r)
		if (h[i] < mn) mn = h[i], cnt = 1;
		else if (h[i] == mn) cnt++;
	if (cnt == r - l + 1) {
		res.first = (power(2, r - l + 1) + MOD - 2) % MOD;
		res.second = power(2, mn - base - 1);
		//printf("%d %d %d  %d %d\n", l, r, base, res.fi, res.se);
		return res;
	}
	int remain = r - l + 1, last = 0, tmp = 1;
	int res0 = 1, res1 = 1;
	rep (i, l, r + 1)
		if (!last && h[i] > mn) last = i;
		else if (last && (i > r || h[i] == mn)) {
			remain -= i - last;
			sub = solve(last, i - 1, mn);
			res0 = 1LL * res0 * (sub.fi + 4LL * sub.se) % MOD;
			res1 = 2LL * res1 * sub.se % MOD;
			last = 0;
		}
	res0 = (res0 + MOD - res1) % MOD;
	res.fi = 1LL * res0 * power(2, remain) % MOD;
	res.fi = (res.fi + 1LL * res1 * (power(2, remain) + MOD - 2)) % MOD;
	res.se = 1LL * res1 * power(2, mn - base - 1) % MOD;
	//printf("%d %d %d  %d %d\n", l, r, base, res.fi, res.se);
	return res;
}

int main() {
	scanf("%d", &n);
	rep (i, 1, n) scanf("%d", &h[i]);
	if (n == 1) {
		printf("%d\n", power(2, h[1]));
		return 0;
	}
	rep (i, 1, n)
		if (h[i] > h[i-1] && h[i] > h[i+1]) {
			base = 1LL * base * power(2, h[i] - max(h[i-1], h[i+1])) % MOD;
			h[i] = max(h[i-1], h[i+1]);
		}
	pii tmp = solve(1, n, 0);
	res = 1LL * base * (tmp.fi + 2LL * tmp.se) % MOD;
	printf("%d\n", res);
	return 0;
}


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

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

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n,a) for(int i=a;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
const int INF=1e9;

void solve(){
	int n, w;
  ll INF = 100100100100100;
  cin >> n >> w;
  vi weight(n+1), value(n+1);
  For(i,n,0) cin >> weight[i+1] >> value[i+1];
  vector<vector<ll>> dp(n+1, vector<ll>(100001, INF));
  dp[0][0] = 0;
  for(int i=1; i<=n; i++){
    for(int v=0; v<=100000; v++){
      if(v-value[i]>=0) dp[i][v] = min(dp[i-1][v], dp[i-1][v-value[i]] + weight[i]);
      else dp[i][v] = dp[i-1][v];
    }
  }
  ll ans = 100000;
  while(dp[n][ans] > w) ans--;
  cout << ans;
    	
}



int main()
{
    fin;
    // int t;
    // cin>>t;
    // while(t--){
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 83188
#include<stdio.h>
#include<stdbool.h>

#define MAX 100001

typedef struct {
  int id, time;
} State;

State queue[MAX];
int head, tail;

void push(int id,int tm) {
  queue[tail].id = id, queue[tail].time = tm;
  tail = ((tail+1==MAX)?0:tail+1);
}

State pop() {
  State v = queue[head];
  head = ((head+1==MAX)?0:head+1);
  return v;
}

inline bool empty() { return (tail - head) == 0; }

int n, q;
char P[MAX][200];

void exec() {
  int total_time = 0;
  while( !empty() ) {
    if( queue[head].time > q ) {
      queue[head].time -= q;
      State tmp = pop();
      push(tmp.id,tmp.time);
      total_time += q;
    } else {
      total_time += queue[head].time;
      printf("%s %d\n",P[queue[head].id],total_time);
      pop();
    }
  }
}

int main() {
  int i, T;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;++i) {
    scanf(" %s %d",&P[i][0],&T);
    push(i,T);
  }
  exec();
  return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string S; cin >> S;
  vector<string> vec;
  vector<string> ans;
  vec.push_back(char_to_string(S[0]));
  ans.push_back(char_to_string(S[0]));
  string tmp = "";
  int k = 1;
  REP(i, S.size()) {
    if(i == 0) continue;
    tmp += char_to_string(S[i]);
    if(vec[k - 1] != tmp) {
      vec.push_back(tmp);
      ans.push_back(tmp);
      tmp = "";
      k++;
    }
  }
  cout << vec.size() << endl;
}

Measured memory_bytes: 12516
#pragma GCC optimize("O3")
                #pragma comment(linker, "/stack:200000000")
                #pragma GCC optimize("unroll-loops")
                 
                #include <algorithm>
                #include <bitset>
                #include <cassert>
                #include <chrono>
                #include <cmath>
                #include <complex>
                #include <cstdio>
                #include <cstdlib>
                #include <cstring>
                #include <ctime>
                #include <deque>
                #include <functional>
                #include <iomanip>
                #include <iostream>
                #include <iterator>
                #include <limits>
                #include <climits>
                #include <list>
                #include <map>
                #include <numeric>
                #include <queue>
                #include <random>
                #include <ratio>
                #include <set>
                #include <sstream>
                #include <stack>
                #include <string>
                #include <unordered_map>
                #include <unordered_set>
                #include <utility>
                #include <vector>
                using namespace std;
                 
                typedef long long ll;
                typedef long double LD;
                #define int ll
                #define double LD
                #define pb push_back
                #define mp make_pair
                #define REP(i,n) for (int i = 0; i < n; i++)
                #define loop(i,n) for (int i = 0; i < n; i++)
                #define FOR(i,a,b) for (int i = a; i < b; i++)
                #define REPD(i,n) for (int i = n-1; i >= 0; i--)
                #define FORD(i,a,b) for (int i = a; i >= b; i--)
                #define remax(a,b) a = max(a,b)
                #define remin(a,b) a = min(a,b)
                #define mem(a, b) memset(a, b, sizeof a)
                #define append push_back
                #define all(v) v.begin(),v.end()
                #define F first
                #define S second
                #define print(x) cout << (x) << endl
                #define PRECISION(x) cout << fixed << setprecision(x)
                #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define N 1010
                #define pb push_back
                const double PI=acos(-1);
                const int MOD = 1000000007;
                const int FMOD = 998244353;
                const double eps = 1e-9;
                 
                mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
     			
     			
     			signed main()
     			{
     				string s,t;
     				cin>>s>>t;
     				
     				int si=s.size();
     				int ans=0;
     				loop(i,si)
     				{
     					if(s[i]!=t[i])
     					ans++;
					 }
					 cout<<ans;
				}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// #define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;

int bit[26][N], n;

void update(int i, int idx, int k) {
	while(idx <= n) {
		bit[i][idx] += k;
		idx += idx & -idx;
	}
}

int pref(int i, int idx) {
	int ans = 0;
	while(idx > 0) {
		ans += bit[i][idx];
		idx -= idx & -idx;
	}
	return ans;
}

int rsum(int i, int l, int r) {
	return pref(i, r) - pref(i, l - 1);
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> n;
	string s;
	cin >> s;
	for(int i = 0; i < n; i++) {
		update(s[i] - 'a', i + 1, 1);
	}
	int q;
	cin >> q;
	while(q--) {
		int c;
		cin >> c;
		if(c == 1) {
			int pos;
			char ch;
			cin >> pos >> ch;
			for(int i = 0; i < 26; i++) {
				if(rsum(i, pos, pos)) {
					update(i, pos, -1);
					break;
				}
			}
			update(ch - 'a', pos, 1);
		}
		else {
			int l, r;
			cin >> l >> r;
			int ans = 0;
			for(int i = 0; i < 26; i++) {
				if(rsum(i, l, r)) {
					ans++;
				}
			}
			cout << ans << endl;
		}
	}
	
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool ok = true;
  if (s[0] != 'A') ok = false;
  int c = 0;
  for (int i = 2; i < s.size() - 1; ++i) if (s[i] == 'C') ++c;
  if (c != 1) ok = false;
  c = 0;
  rep(i, s.size()) if (s[i] >= 'a' && s[i] <= 'z') ++c;
  if (c != s.size() - 2) ok = false;
  if (ok) cout << "AC" << endl;
  else cout << "WA" << endl; 
  return 0;
}

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

int n;
long long ans;
string s, st;

void solve(void)
{
	int j = 0;
	bool ok;
	set<string> ss;

	rep(i, 3)
	{
		ok = false;
		while (j < n)
		{
			if (s[j] == st[i])
			{
				ok = true;
				j++;
				break;
			}
			j++;
		}
		if (!ok)
			return;
	}
	if (ok)
		ans++;
}

void dfs(int i)
{
	int j = 0;
	while(j < 10)
	{
		st[i] = j + '0';
		if (i == 2)
			solve();
		else
			dfs(i + 1);
		j++;
	}
}

signed main(void)
{
	ans = 0;
	st.resize(3);
	cin >> n >> s;
	dfs(0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll A, B, N;
  cin >> A >> B >> N;
  if (N >= B - 1)
    cout << (A * (B - 1)) / B << endl;
  else
    cout << (A * N) / B << endl;

  return 0;
}


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

int main(){
    int N,K,i;
    int result=1;

    cin >> N >> K;

    for(i=0;i<N;i++){
        if((2*result)<(result+K)){
            result*=2;
        }
        else{
            result+=K;
        }
    }
    cout << result << endl;
}

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

typedef long long int ll;

ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


int main()
{
    ll n, q, sum = 0;
    vector<ll> c(100001);
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        c[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    vector<pair<ll,ll>> bc(q);
    for(ll i = 0;i < q;i++){
        cin >> bc[i].first >> bc[i].second;
    } 

    for(ll i = 0;i < q;i++){
        sum += (bc[i].second - bc[i].first) * c[bc[i].first];
        c[bc[i].second] += c[bc[i].first];
        c[bc[i].first] = 0;
        cout << sum << "\n";
    }


    return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
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);
        APayment solver = new APayment();
        solver.solve(1, in, out);
        out.close();
    }

    static class APayment {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            System.out.println((int) Math.ceil((double) n / 1000) * 1000 - n);
        }

    }

    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 RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

    }
}



Measured memory_bytes: 32492
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

int c[1005][1005];

int lcs(string s1, string s2){
    int n = s1.size();
    int m = s2.size();
    s1 = " " + s1;
    s2 = " " + s2;
    for(int i = 0; i <= n; i++) c[i][0] = 0;
    for(int i = 0; i <= n; i++) c[0][i] = 0;

    int ans = 0;
    for (int i1 = 1; i1 <= n; i1++){
        for(int i2 = 1; i2 <= m; i2++){
            if(s1[i1] == s2[i2]){
                c[i1][i2] = c[i1-1][i2-1] + 1;
            }else{
                c[i1][i2] = max(c[i1-1][i2], c[i1][i2-1]);
            }
        }
        ans = max(ans, c[i1][m]);
    }
    return ans;
}

int main(){
    int q;
    cin >> q;
    vector<int> ans(q);
    for(int i = 0; i < q; i++){
        string s1, s2;
        cin >> s1 >> s2;
        ans[i] = lcs(s1, s2);
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 7136
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2200;
int a[N][N],h[N][N],l[N][N],r[N][N],map[N][N]; 
int n,m;
char c[N];
int main(){
	//freopen("t.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",c+1);
		for(int j=1;j<=m;j++){
			a[i][j]=(c[j]=='#');
		}
	} 
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			map[i][j]=1^a[i][j+1]^a[i+1][j]^a[i][j]^a[i+1][j+1];
			l[i][j]=r[i][j]=j;h[i][j]=1;
		}
	//	printf("\n");
	}	
	int ans=max(n,m);
	for(int i=1;i<n;i++)
		for(int j=2;j<m;j++)
			if(map[i][j-1]>0 && map[i][j]>0) l[i][j]=l[i][j-1];
	for(int i=1;i<n;i++){
		for(int j=m-2;j>=1;j--) 
			if(map[i][j+1]>0 && map[i][j]>0) r[i][j]=r[i][j+1];
	}
	for(int i=1;i<n;i++){	
		for(int j=1;j<m;j++){
			if(i>1 && map[i-1][j]&&map[i][j]){
				l[i][j]=max(l[i-1][j],l[i][j]);
				r[i][j]=min(r[i-1][j],r[i][j]);
				h[i][j]=h[i-1][j]+1;
			} 
			int len=r[i][j]-l[i][j]+2;
			int wid=h[i][j]+1;
			ans=max(ans,len*wid);
		}
	}	
	printf("%d\n",ans);
	
	return 0;
} 

Measured memory_bytes: 94336
#include<iostream>
using namespace std;
typedef pair<int, int> pii;
pii dxdy[]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char fld[21][21];
int used[20][20];
int W, H;
 
int rec(int i, int j){
 
   if(fld[i][j]=='#') return 0;
   if(used[i][j]) return 0;
   used[i][j]=1;
   int ret=0;
   for(pii dd: dxdy){
      int ni=i+dd.first;
      int nj=j+dd.second;
      if(!(0<=ni&&ni<H&&0<=nj&&nj<W)) continue;
      ret+=rec(ni, nj);
   }
 
   return ret+1;
}
 
int main(){
 
   while(1){
      cin>> W>> H;
      if(!(H||W)) break;
      int sx, sy;
      for(int i=0; i<H; i++){
         for(int j=0; j<W; j++){
            cin>> fld[i][j];
            if(fld[i][j]=='@'){
               sy=i;
               sx=j;
               fld[i][j]='.';
            }
         }
      }
 
      for(int i=0; i<20; i++)for(int j=0; j<20; j++) used[i][j]=0;
      cout<< rec(sy, sx)<< endl;
   }
 
   return 0;
}

Measured memory_bytes: 3084
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    vector<int> a(3);
    REP(i, 3) cin >> a[i];

    SORT(a);

    int ans = (a[2] - a[1]) + (a[1] - a[0]);

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int maxi = a[0];
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		if (maxi >= a[i])ans += maxi - a[i] ;
		else maxi = a[i];
	}

	cout << ans << endl;

	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	sort(A.begin(), A.end());
	vector<pii> B;
	REP(i, N+1){
		int num = upper_bound(A.begin(), A.end(), i) - lower_bound(A.begin(), A.end(), i);
		if(num>0){
			B.push_back(make_pair(num, i));
		}
	}
	sort(B.begin(), B.end());
	int res = 0;
	if(B.size()<=K){
		res = 0;
	}else{
		REP(i, B.size() - K){
		res += B[i].first;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3188
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


void print_vec(vll a)
{
	cout << "start printing the vector\n";
	for (ll i = 0; i < a.size(); i++)
		cout << a[i] << " ";
	cout << "\n";
}
void print_mat(vector<vll> a)
{
	cout << "start printing the matrix\n";
	for (ll i = 0; i < a.size(); i++)
	{
		for (ll j = 0; j < a[i].size(); j++)
		{
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n;
	cin >> n;
	ll curr = 10;
	ll count = 0;
	if (n % 2)
	{
		cout << 0 << "\n";
		return;
	}
	for (ll i = 1; curr <= n; i++)
	{
		if (n / curr == 0)
		{
			break;
		}
		else
		{
			count += (n / curr);
		}
		curr *= 5;
	}
	cout << count << "\n";
}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
int main(){
    int a,b,c,Y;
    scanf("%d %d %d",&a,&b,&c);

    if(a>b){
        Y=a;
        a=b;
        b=Y;
    }
    if(b>c){
        Y=b;
        b=c;
        c=Y;
    }
    if(a>b){
        Y=a;
        a=b;
        b=Y;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;

   }

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n; cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i,n) cin >> s[i] >> t[i];
  string x; cin >> x;
  int tmp;
  rep(i,n) if(s[i]==x) tmp=i;
  cout << accumulate(t.begin()+tmp+1,t.end(),0);
  
  
return 0;
}


Measured memory_bytes: 256