akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
	int n, l, min_ = -300, max_= 300;
	long sum = 0;
	cin >> n >> l;
	for (int i = 1; i <= n; i++) {
		int h = l + i - 1;
		sum += h;
		if (h < 0) {
			if (h > min_) {
				min_ = h;
		}
		}
		else {
			if (h < max_) {
				max_ = h;
			}
		}
	}
		if (abs(min_) >= max_ && min_ != -300) {
		cout << sum - max_;
	}
	else {
		if(min_ == -300){ cout << sum - max_; }
		else {
			cout << sum - min_;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sum[110];
char s[110][20],s1[20];
int main()
{
    int n,m,ans=0;
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
	{
		scanf("%s",&s[i]);
		for(register int j=1;j<=i;j++)
			if(!strcmp(s[i],s[j]))
			{
				sum[j]++;
				break;
			}
	}
	scanf("%d",&m);
	for(register int i=1;i<=m;i++)
	{
	    scanf("%s",s1);
	    for(register int j=1;j<=n;j++)
	        if(!strcmp(s[j],s1))
	        {
	            sum[j]--;
	            break;
	        }
	}
	for(register int i=1;i<=n;i++)
	    ans=max(ans,sum[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long a,b;
  cin>>a>>b;
  if((a+b)%2==0) cout<<(a+b)/2<<'\n';
  else cout<<"IMPOSSIBLE"<<'\n';
  return 0;
}


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

int output[10],len;

int main(){
	int n;
	
	while( cin >> n )
	{
		len = 0;
		for( int i = 0;i < 10;i++ ){
			if( n&(1<<i) ){
				output[len] = (1<<i);
				len++;
			}
		}
		for( int i = 0;i < len-1;i++ ){
			cout << output[i] << " ";
		}
		cout << output[len-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
int a[maxn];
int mp[maxn];
int vis[1010];

int gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    vector<int>cnt;
    int f=0;
    for(int i=1;i<=n;i++)
    {
        f=gcd(f,a[i]);
    }
    if(f!=1)
    {
        cout<<"not coprime"<<'\n';
        return 0;
    }
    for(int i=2;i<1005;i++)
    {
        if(vis[i])
            continue;
        cnt.pb(i);
        for(int j=i;j<1005;j+=i)
        {
            vis[j]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(auto &v:cnt)
        {
            if(v*v>a[i])
                break;
            if(a[i]%v==0)
            {
                mp[v]++;
                if(mp[v]>1)
                {
                    cout<<"setwise coprime"<<'\n';
                    return 0;
                }
                while(a[i]%v==0)
                    a[i]/=v;
            }
        }
        if(a[i]>1)
            mp[a[i]]++;
        if(mp[a[i]]>1)
        {
            cout<<"setwise coprime"<<'\n';
            return 0;
        }
    }
    cout<<"pairwise coprime"<<'\n';

}


Measured memory_bytes: 7792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int slen = s.length();
    String t = "";
    int i = 0;
    while(i < slen){
      //いろいろ判断。適合すれば、文字数分iをずらす
      if(s.substring(slen-5-i,slen-i).equals("dream") || s.substring(slen-5-i,slen-i).equals("erase")){
        i += 5;
        continue;
      }else if(s.substring(slen-6-i,slen-i).equals("eraser")){
        i += 6;
        continue;
      }else if(s.substring(slen-7-i,slen-i).equals("dreamer")){
        i += 7;
        continue;
      }else{//どの条件にも適合しないので、等しくならない
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }
}


Measured memory_bytes: 29764
#include <iostream>

using namespace std;
int main()
{
    long long N;
    const long long mod = 1000000007;
    cin >> N;
    long long res = 1;
    for (long long i = 1; i <= N; i++)
    {
        res = res*10%mod;  // 桁あふれを気にすること
    }

    long long not_0_or_9 = 1;
    for (long long i = 1; i <= N; i++)
    {
        not_0_or_9 = not_0_or_9*9%mod;
    }

    long long both_0_9 = 1;
    for (long long i = 1; i <= N; i++)
    {
        both_0_9 = both_0_9*8%mod;
    }

    res = res - not_0_or_9*2 + both_0_9;
    res %= mod;
    res = (res+mod)%mod;        // これはなんのため？

    cout << res;
}

Measured memory_bytes: 3620
N=int(input())
L=list(map(int,input().split()))



def f(l, s):
    return s if l % s == 0 else f(s, l % s)
    
z = f(max(L), min(L))

for i in L:
    z=f(i,z)
ans=10000000000
for i in range(len(L)):
    if L[i]%z==0:
        pass
    elif L[i]%z<ans:
        ans=L[i]%z

if ans==10000000000:
    print(z)
else:
    print(ans)

Measured memory_bytes: 14252
n, m = map(int, input().split())

k = []

for i in range(m):
    k.append(list(map(int, input().split())))

p = list(map(int, input().split()))

ans = 0

for i in range(2**n):
    switch = [0] * n
    for j in range(n):
        if i >> j & 1 == 1:
            switch[j] += 1
    cntt = 0
    for j in range(m):
        cnt = 0
        for s in range(1, k[j][0]+1):
            if switch[k[j][s]-1] == 1:
                cnt += 1
        if cnt%2 == p[j]:
            cntt += 1
    if cntt == m:
        ans += 1

print(ans)

Measured memory_bytes: 42480
<?php
fscanf(STDIN, "%d %d", $N, $X);
$x = array_map("intval", explode(" ", trim(fgets(STDIN))));
$x[] = $X;
$x_min = min($x);
$x = array_map(function($a) use($x_min) {return $a - $x_min;}, $x);

for ($i = 1; $i <= $N; $i++) {
    if (!isset($ans)) {
        $ans = gcd($x[$i - 1], $x[$i]);
    } else {
        $ans = gcd($ans, $x[$i]);
    }
    if ($ans === 1) break;
}
echo $ans;

//最大公約数
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}


Measured memory_bytes: 16884
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));
ll MOD=2019;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll l,r;cin>>l>>r;
    ll ans=INF;
    for(int i=l;i<l+2020;i++)for(int j=r;j>r-2020;j--){
        if(j<=i)break;
        ans=min(ans,(ll)i%2019*j%2019);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

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

        for (int i = 0; i < N; i++) {
            s[i] = sc.next();
            t[i] = sc.nextInt();
        }
        String X = sc.next();


        int time = 0;
        boolean start = false;
        for (int i = 0; i < N; i++) {
            if (start) {
                time += t[i];
            }

            if (X.equals(s[i])) {
                start = true;
            }
        }

        System.out.println(time);

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    string s;
    cin >> s;
    int n = s.size();
    int l, r;
    rep(i, n) {
        if (s[i] == 'A') {
            l = i;
            break;
        }
    }
    rrep(i, n) {
        if (s[i] == 'Z') {
            r = i;
            break;
        }
    }
    cout << r - l + 1 << endl;
}


Measured memory_bytes: 720
#!/usr/bin/env python3
import sys
# import numpy as np
import heapq

def solve(N: int, M: int, A: "List[int]"):
    A = [a*-1 for a in A]
    heapq.heapify(A)
    for m_ in range(M):
        a_ = heapq.heappop(A)
        heapq.heappush(A, int(a_/2))    
    print(sum(A)*-1)

    return



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


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

using namespace std;

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

const int inf = 100000000;

typedef long long ll;

#define MAX_H 8
#define MAX_W 8
int H, W;
char table[MAX_H][MAX_W];
bool checked[MAX_H][MAX_W];

void dfs(int i, int j) {

  if( i < 0 || j < 0 || H < i || W < j ) {
    return;
  }

  table[i][j] = '.';

  char down = table[i+1][j];
  char right = table[i][j+1];
  if( down == '#' &&  right != '#' ) {
    dfs(i+1, j);
  } 
  if( down != '#' &&  right == '#' ) {
    dfs(i, j+1);
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);


  cin >> H >> W;

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> table[i][j];
    }
  }

  dfs(0,0);


  bool res = true;

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(table[i][j] != '.') { res = false; }
    }
  }

  cout << (res ? "Possible" : "Impossible") << "\n";

  // for(int i = 0; i < H; i++) {
  //   for(int j = 0; j < W; j++) {
  //     cout << table[i][j];
  //   }
  //   cout << "\n";
  // }
  // cout << "\n";


  return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [[int(a) for a in input().split()] for _ in range(N)]

ma = -(1<<100)
for k in range(1, 1024):
    s = 0
    for i in range(N):
        s += P[i][bin(F[i] & k).count("1")]
    ma = max(ma, s)
print(ma)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll sieve[10000001]={0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,sum=0;
  cin>>n;
  
  sieve[1]=1;
  for(ll i=2;i<=n;i++) {
      sieve[i]+=2;
      for(ll j=2*i;j<=n;j+=i) {
         // cout<<j;
          sieve[j]++;
          //cout<<sieve[4]<<" ";
      }
  }
  for(ll i=1;i<=n;i++) {
      sum+=(i*sieve[i]);
      //cout<<sieve[i]<<" ";
  }
  cout<<sum;
}

Measured memory_bytes: 81752
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main() {
	ll x, y; cin >> x >> y;
	int cnt = 0;
	for (ll i = x; i <= y; i *= (ll)2)cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
	int n;
	char s[50];
	scanf("%d",&n);
	int i=0,q=0,p=0;
	scanf("%s",s);
	for(i=0;i<n;i++)
	{
		p=0;
		if(s[i]=='A'&&i<n-2)
		{
			if(s[i+1]=='B')
			{
				if(s[i+2]=='C')
				{
					p=1;
				}
			}
		}
		if(p==1)
		q++;
	}
	printf("%d",q);
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>

bool is_match(const std::vector<int>& set, const std::vector<std::vector<int>> &cards) {
	for (const auto& card : cards) {
		int count{ 0 };
		for (const auto& c : card) count += set[c];
		if (count * 8 < set.size() || set.size() * 3 < count * 8) return false;
	}
	return true;
}
void set_random(std::vector<int>& set, std::mt19937& rand) {
	for (auto& b : set) b = rand() & 1;
}
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<std::vector<int>> cards(k, std::vector<int>(n / 2));
	for (auto& card : cards) for (auto& c : card) {
		std::cin >> c; --c;
	}
	std::vector<int> set(n);
	std::mt19937 rand;
	set_random(set, rand);
	while (!is_match(set, cards)) set_random(set, rand);
	for (const auto& s : set) std::cout << s;
	std::cout << std::endl;
}



Measured memory_bytes: 3932
// ALDS1_3_A: Stack

struct Stack {
    top: usize,
    s: [i64; 1000],
}

impl Stack {
    fn new() -> Stack {
        Stack { top: 0, s: [0; 1000] }
    }
    fn push(&mut self, x: i64) {
        self.top += 1;
        self.s[self.top] = x
    }
    fn pop(&mut self) -> i64 {
        self.top -= 1;
        self.s[self.top+1]
    }
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.split_whitespace();

    let mut s = Stack::new();

    while let Some(v) = it.next() {
        match v {
            "+" => {
                let a = s.pop();
                let b = s.pop();
                s.push(a + b);
            },
            "-" => {
                let b = s.pop();
                let a = s.pop();
                s.push(a - b);
            },
            "*" => {
                let a = s.pop();
                let b = s.pop();
                s.push(a * b);
            },
            _ => {
                let a = v.parse::<i64>().unwrap();
                s.push(a);
            }
        }
    }

    println!("{}", s.pop());
}


Measured memory_bytes: 5032
from collections import deque

n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    graph[l-1].append([r-1, d])
    graph[r-1].append([l-1, -d])

x = [None for i in range(n)]

def f():
    for i in range(n):
        if x[i] == None:
            x[i] = 0
            q = deque([i])
            while len(q):
                j = q.popleft()
                for k, d in graph[j]:
                    if x[k] == None:
                        q.append(k)
                        x[k] = x[j] + d
                    elif x[k] != x[j] + d:
                        return False
    return True

if f():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77768
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long
int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        v[i]/=2;
    }
    int lcm=v[0];
    for(int i=1;i<n;i++)
    {
        lcm=(lcm*v[i])/__gcd(lcm,v[i]);
        if(lcm>m)
        {
            cout<<0;
            return 0;
        }
    }   
    for(int i = 0 ; i < n; i++)
    {
        if((lcm/v[i])%2 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans=m/lcm;
    ans=ans/2+ans%2;
    cout<<ans;
}

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//_______________________



int32_t main()
{ 
  io;
  
 
  int a,b,c,k,x;
  cin>>a>>b>>c>>k;

  vector<int> A,B,C,AB,ABC;

  for(int i=0;i<a;i++)
  {
    cin>>x;
    A.push_back(x);
  }

  for(int i=0;i<b;i++)
  {
    cin>>x;
    B.push_back(x);
  }

  for(int i=0;i<c;i++)
  {
    cin>>x;
    C.push_back(x);
  }

  for(int i=0;i<a;i++)
  {
    for(int j=0;j<b;j++)
    {
      AB.push_back(A[i]+B[j]);
    }
  }

  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  AB.resize(k);

  for(int i=0;i<k;i++)
  {
    for(int j=0;j<c;j++)
      ABC.push_back(AB[i]+C[j]);
  }

  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());

  for(int i=0;i<k;i++)
    cout<<ABC[i]<<endl;


 return 0;
}

Measured memory_bytes: 43384
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

const int inf = 2e9;

int n, t;
int a[100000];
int c[100000];
int s[100000];

ll calc(int s){
	--s;
	ll s1 = s / 2;
	ll s2 = s - s1;
	return s1 * (s1 + 1) / 2 + s2 * (s2 + 1) / 2;
}

int main(){
	cin >> n >> t;
	rep(i, n){
		cin >> a[i];
	}

	int k = 0;
	int p = inf;
	rep(i, n){
		k = max(a[i] - p, k);
		p = min(a[i], p);
	}

	fill_n(c, n, -1);
	int t = -1;
	p = inf;
	rep(i, n){
		if(a[i] - p == k){
			c[i] = t;
		}
		if(a[i] < p){
			t = i;
			p = a[i];
		}
	}

	fill_n(s, n, 1);
	int ans = 0;
	for(int i = n - 1; i >= 0; --i){
		if(c[i] != -1){
			s[c[i]] += s[i];
		}
		else{
			ans += calc(s[i]);
		}
	}

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<int> ret(n, 0);
    for (int i = 0; i < n - 1; ++i) {
        int a;
        cin >> a;
        ret[a - 1]++;
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}

Measured memory_bytes: 3956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    ll ans = 0;
    int n,h,w;
    cin >> n >> h >> w;
    rep(i,n){
        int a,b;
        cin >>a >> b;
        ans += min(a/h,b/w);
    }
    cout << ans << endl;
}

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

using namespace std;

int func(int a[5][5], int s, int t)
{
	int u = 1;
	
	for(int i = t; i < 5; i++){
		if(a[s][i] == 1){
			bool f = false;
			int v = i-t+1;
			int w = 1;
			for(int j = s+1; j < 5; j++){
				for(int k = t; k <= i; k++){
					if(a[j][k] == 0){
						f = true;
					}
				}
				if(f){
					break;
				}
				w++;
			}
			u = max(u, v*w);
		} else {
			break;
		}
	}
	
	return u;
}

int main()
{
	int n, a[5][5];
	
	while(cin >> n && n){
		while(n--){
			for(int i = 0; i < 5; i++){
				for(int j = 0; j < 5; j++){
					cin >> a[i][j];
				}
			}
			int s = 0;
			for(int i = 0; i < 5; i++){
				for(int j = 0; j < 5; j++){
					if(a[i][j] == 1){
						s = max(s, func(a, i, j));
					}
				}
			}
			
			cout << s << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>

using namespace std;

//#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
//#define int long long

int main()
{
	int ans = 0;
	stack<char> st;
	string s;
	cin >> s;
	for (auto &it : s)
	{
		if (st.size() && st.top() != it) {
			ans++;
			st.pop();
		}
		else {
			st.push(it);
		}
	}
	cout << ans*2;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define rep(i, n) for( int i = 0; i < n; i++ )

int main(){
    int m, f, r;
    while( cin >> m >> f >> r, m != -1 || f != -1 || r != -1 ){
        if( m == -1 || f == -1 ){
            cout << 'F' << endl;
        }else{
            if( 80 <= m+f ) cout << 'A' << endl;
            else if( 65 <= m+f && m+f < 80 ) cout << 'B' << endl;
            else if( 50 <= m+f && m+f < 65 ) cout << 'C' << endl;
            else if( 30 <= m+f && m+f < 50 ){
                if( 50 <= r ) cout << 'C' << endl;
                else cout << 'D' << endl;
            }
            else cout << 'F' << endl;
        }
    }
}

Measured memory_bytes: 1152
n = int(input())
a = list(input())
b = list(input())
c = list(input())
ans = 0

for i in range(n):
    li = []
    li.append(a[i])
    li.append(b[i])
    li.append(c[i])
    ans += len(set(li))-1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "test"
using namespace std;
const ll N = 100 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
ll dx[2] = {0,1};
ll dy[2] = {1,0};
ll dp1[N][N],dp2[N][N];
ll n,m,i,j;
char a[N][N];
bool chk(ll x,ll y){
    return (x <= n&&y <= m);
}
ll f1(ll x,ll y){
    if (x == n&&y == m) return 0;
    if (dp1[x][y] != -1) return dp1[x][y];
    ll ans = inf;
    for (ll i = 0;i < 2;i++){
        ll p = x + dx[i],q = y + dy[i];
        if (chk(p,q)){
            if (a[p][q] == a[x][y]) ans = min(ans,f1(p,q));
            else{
                if (a[p][q] == '#') ans = min(ans,1 + f1(p,q));
                else ans = min(ans,f1(p,q));
            }
        }
    }
    return dp1[x][y] = ans;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m;
    for (i = 1;i <= n;i++){
        for (j = 1;j <= m;j++) cin>>a[i][j];
    }
    memset(dp1,-1,sizeof(dp1));
    ll p = f1(1,1);
    if (a[1][1] == '#') p++;
    cout<<p;
}


Measured memory_bytes: 384
H,W,D = list(map(int, input().split()))
X = [[0,0] for i in range(H*W+1)]

for i in range(1, H+1):
	A = list(map(int, input().split()))
	for idx, a in enumerate(A):
		X[a] = [i, idx+1]

Q = int(input())
L = []
R = []
S = [0]*(H*W+1)

for i in range(Q):
	l,r = list(map(int, input().split()))
	L.append(l)
	R.append(r)

for i in range(D+1, H*W+1):
	S[i] = S[i-D] + abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])

for i in range(Q):
	print(S[R[i]] - S[L[i]])


Measured memory_bytes: 25008
import math

n = int(input())
sum = (n - 1) * (n - 1) + n * n + n * (n - 1)
for i in range(2, n + 1):
    for j in range(i, n + 1):
        for k in range(j, n + 1):
            otv = math.gcd(math.gcd(i, j), k)
            if i != j and j != k:
                otv *= 6
            elif i != j or j != k:
                otv *= 3
            sum += otv
print(sum)

Measured memory_bytes: 9200
#include<cstdio>

int a[100005];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int flag=0;
	int num=1;
	int t=1;
	for(int i=1;i<n;i++){
		if(flag==0){
			for(int j=i+1;j<=n;j++){
				if(a[j]!=a[i]){
					if(a[j]>a[i]) flag=1;
					else flag=-1;
					i=j-1;
					break;
				}
			}
		}
		else{
			if(flag==1&&a[i+1]<a[i]){
				flag=0;
				t=0;
				num++;
			}
			else if(flag==-1&&a[i+1]>a[i]){
				flag=0;
				t=0;
				num++;
			}
		}	
	}
	if(flag==0&&t==1) printf("1\n");
	else{
		printf("%d\n",num);
	}
	return 0;
}

Measured memory_bytes: 512
#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>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

double a[1010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= 1000; i++){
		a[i] = a[i-1] + i;
	}
	for(int i = 1; i <= 1000; i++){
		a[i] /= (double)(i);
	}
	vector<double> p(n);
	rep(i, n){
		int x;
		cin >> x;
		p[i] = a[x];
	}
	double tmp = 0;
	rep(i, k) tmp += p[i];
	double ans = tmp;
	for(int i = k; i < n; i++){
		tmp -= p[i-k];
		tmp += p[i];
		chmax(ans, tmp);
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
/*input
5 1 5 2 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=205;
const ll maxlg=__lg(maxn)+2;
const ll INF64=1000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll dis[maxn][maxn];
int a[maxn];

int main()
{
	IOS;
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	n--;
	a-=b;
	REP(i,n+1){
		ll cur=i*c-(n-i)*d;
		ll tmp=(d-c)*n;
		if(cur<=a&&a<=cur+tmp){
			YY;
			//cout<<i<<'\n';
			return 0;
		}
	}
	NN;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string st;
int x;
int main()
{
	cin>>st;
	for(int i=0;i<st.size()-1;i++)
	  for(int j=i+1;j<st.size();j++)if(st[i]=='C'&&st[j]=='F')x=1;
	if(x)cout<<"Yes";
	  else cout<<"No";
	return 0;
} 

Measured memory_bytes: 764
#include<stdio.h>

void spin_w(int x[]){
  int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }

  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}

void spin_side(int x[]){
int sai1[6],i;

for(i=0;i<6;i++){
  sai1[i]=x[i];
 }

sai1[1]=x[2];
sai1[2]=x[4];
sai1[3]=x[1];
sai1[4]=x[3];

for(i=0;i<6;i++){
  x[i]=sai1[i];
 }
}


void spin_s(int x[]){
	int sai1[6],i;
	
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
	sai1[5]=x[1];
	
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
}

int main(){
  int i,j,sai1[6],sai2[6],count=0,count2=0;

  for(i=0;i<6;i++){
    scanf("%d",&sai1[i]);
  }
  for(i=0;i<6;i++){
    scanf("%d",&sai2[i]);
  }

  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
    }
  }
  if(count!=6){
		for(i=0;i<=3;i++){
			spin_w(sai1);
			count2++;
		if(sai1[0]==sai2[0])break;
		}
		if(count2==4){
			for(i=0;i<=3;i++){
			spin_s(sai1);
		if(sai1[0]==sai2[0])break;
			}
		}
			
    for(i=0;i<=3;i++){
      spin_side(sai1);
      if(sai1[1]==sai2[1])break;
		}
  }

  count=0;


  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
		}
  }
	
  if(count==6){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

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

struct UnionFind{
	vector<int> rnk,par,num;
	UnionFind(int N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(int i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(int x,int y){
		return (find(x) == find(y));
	}
	int size(int x){
		return num[find(x)];
	}
};

signed main(){
  int N, M; cin >> N >> M;
  vector<int> a(M), b(M);
  for(int i = 0; i < M; i++) {
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
  }
  UnionFind tree(N);
  vector<int> an(M);
  int ans = N * (N - 1)/2;
  for(int i = M - 1; i >= 0; i--){
    an[i] = ans;
    if(!tree.same(a[i], b[i])){
      ans -= tree.size(a[i]) * tree.size(b[i]);
    }
    tree.unite(a[i], b[i]);
  }
  for(int i = 0; i < M; i++) cout << an[i] << endl;
}

Measured memory_bytes: 6016
n = int(input())
a = list(map(int, input().split()))
res = 1
aaa = pow(10,18)
ans = True
if min(a) == 0:
    res = 0
for i in a:
    res *= i
    if res > aaa:
        ans = False
        break
if ans:
    print(res)
else:
    print(-1)


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

struct dice{
	int num[6];
};

int main()
{
	int n;
	dice one;
	for (n = 0; n < 6; n++)
	{
		scanf("%d", &one.num[n]);
	}
	int turn, tmp, i = 2;
	scanf("%d", &turn);
	int top, front;
	for (n = 0; n < turn; n++)
	{
		scanf("%d %d", &top, &front);
		while (1)
		{
			if (one.num[0] == top)break;
			tmp = one.num[0];
			one.num[0] = one.num[1];
			one.num[1] = one.num[5];
			one.num[5] = one.num[4];
			one.num[4] = tmp;
			if (one.num[0] == top)break;
			tmp = one.num[0];
			one.num[0] = one.num[1];
			one.num[1] = one.num[5];
			one.num[5] = one.num[4];
			one.num[4] = tmp;
			if (one.num[0] == top)break;
			tmp = one.num[0];
			one.num[0] = one.num[3];
			one.num[3] = one.num[5];
			one.num[5] = one.num[2];
			one.num[2] = tmp;
			if (one.num[0] == top)break;
			tmp = one.num[0];
			one.num[0] = one.num[3];
			one.num[3] = one.num[5];
			one.num[5] = one.num[2];
			one.num[2] = tmp;
		}
		while (one.num[1] != front)
		{
			tmp = one.num[1];
			one.num[1] = one.num[2];
			one.num[2] = one.num[4];
			one.num[4] = one.num[3];
			one.num[3] = tmp;
		}
		printf("%d\n", one.num[2]);
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

string s;
map< string, string > m = { { "Sunny", "Cloudy" }, { "Cloudy", "Rainy" }, { "Rainy", "Sunny" } };

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> s;
	cout << m[ s ] << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long n; cin >> n;
	map<long long, long long> freq;

	long long ans = 0;
	for (long long i = 1; i <= n; i++) {
		long long a; cin >> a;
		freq[a]++;
		ans += a;
	}

	long long q; cin >> q;
	while (q--) {
		long long b, c; cin >> b >> c;

		if (freq.find(b) != freq.end()) {
			ans -= b * freq[b];
			ans += c * freq[b];
			freq[c] += freq[b];
			freq.erase(b);
		}

		cout << ans << endl;
	}


	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
    s << v[i];
  }
  s << "]";
  return s;
}

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

  int n;
  cin >> n;
  vector<pair<int, int64>> xs;
  int64 total_sum = 0;
  for (int i = 0; i < n; i++) {
    int64 x;
    cin >> x;
    xs.push_back({i, x});
    total_sum += x;
  }
  sort(xs.begin(), xs.end(), [](const auto& p1, const auto& p2) {
    if (p1.second != p2.second) return p1.second > p2.second;
    return p1.first < p2.first;
  });

  vector<int64> rs(n);

  int index = xs[0].first;
  if (index == 0) {
    rs[0] = total_sum;
  } else {
    int64 sum = xs[0].second;
    int64 used = 0;
    for (int i = 1; i < n; i++) {
      const auto& p = xs[i];
      if (DEBUG) cout << p.first << " " << p.second << endl;
      if (p.first < index) {
        rs[index] = sum - (p.second * i) - used;
        used += rs[index];
        index = p.first;
        // cout << rs << endl;
        if (index == 0) {
          rs[0] = total_sum - used;
          break;
        }
      }
      sum += p.second;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << rs[i] << "\n";
  }
}

Measured memory_bytes: 3440
S = str(input())
if S[0] == S[1]:
	if (S[0] != S[2]) & (S[2] == S[3]):
		print('Yes')
	else:
		print('No')
else:
	if (S[:2] == S[2:]) | ((S[0] == S[3]) & (S[1] == S[2])):
		print('Yes')
	else:
		print('No')

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

int main(){
    int k,temp;
    ll ans=0;
    cin >> k;
    for(int i=1; i<k+1; i++){
        for(int j=1; j<k+1; j++){
            for(int l=1; l<k+1; l++){
                ans += gcd(gcd(i,j), l);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
package main

import "fmt"

func main() {
	var N, A int
	fmt.Scan(&N, &A)
	x := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i])
	}
	var dp [52][52][2560]int
	dp[0][0][0] = 1
	for i := 1; i <= N; i++ {
		for j := 0; j <= 50; j++ {
			for k := 0; k <= 2500; k++ {
				tmp := dp[i-1][j][k]
				dp[i][j][k] += tmp
				dp[i][j+1][k+x[i-1]] += tmp
			}
		}
	}
	var ans int
	for j := 0; j <= 50; j++ {
		for k := 0; k <= 2500; k++ {
			if k == A*j {
				ans += dp[N][j][k]
			}
		}
	}
	fmt.Println(ans - 1)
	return
}


Measured memory_bytes: 54272
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int main()
{
fast;

    ll r;
    cin>>r;
    double ans=2*3.1415926*r;
    cout<<ans;
    return 0;
}

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

int main(){
  string a,b;
  cin>>a>>b;
  int x=a.length();
  int y=b.length();
  int dp[3001][3001];
  for(int i=0;i<=x;i++){
    for(int j=0;j<=y;j++){
      dp[i][j]=0;
    }
  }
  for(int i=1;i<=x;i++){
    for(int j=1;j<=y;j++){
       if(a[i-1]==b[j-1]){
       dp[i][j]=1+dp[i-1][j-1];  
       }
      else{
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
//  cout<<dp[x][y]<<endl;
  string s;
  for(int i=x,j=y;i>0&&j>0;){
         if(a[i-1]==b[j-1]){
           s+=a[i-1];
           i--;
           j--;
          }
       else if (dp[i-1][j] > dp[i][j-1])  i--;
         else j--;
    }
  reverse(s.begin(),s.end());
cout<<s<<endl;  
  
}

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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> T;
	if (T[0] == T[2]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[10];
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<string,ll>::iterator iter;
deque<char> deq;

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,d,d1,d2;
    long long int m,n,o,i,j,k=1,money;
    long long int a,a1=0,a2=0,a3=0,ar=1,as=1,at1,inv=0;
    string s;
    char c,c1;
    a=a1=a2=a3=0;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    cin>>s>>n;
    for(i=0;i<s.size();i++) deq.pb(s[i]);
    for(i=0;i<n;i++)
    {
        cin>>a;
        if(a==1) inv=inv^1;     //inverse
        else
        {
            cin>>a1>>c1;
            if(inv==0 && a1==1) deq.push_front(c1);
            else if(inv==1 && a1==2) deq.push_front(c1);
            else if(inv==0 && a1==2) deq.push_back(c1);
            else if(inv==1 && a1==1) deq.push_back(c1);
        }
    }
    k=deq.size();
    for(i=0;i<k;i++)
    {
        if(inv==0) cout<<deq[i];
        else cout<<deq[k-1-i];
    }
    return 0;
}





Measured memory_bytes: 1024
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

map<ii,int> ma; //store (first, second)
map<ii,int> ma2; //store (second, first)

void add(int l, int r)
{
	ma[mp(l,r)]++;
	ma2[mp(r,l)]++;
}

void del(int l, int r)
{
	ma[mp(l,r)]--;
	if(ma[mp(l,r)]==0) ma.erase(mp(l,r));
	ma2[mp(r,l)]--;
	if(ma2[mp(r,l)]==0) ma2.erase(mp(r,l));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n; 
	ll ans = 0;
	vector<ii> vec;
	for(int i=0;i<n;i++)
	{
		int x,y; cin>>x>>y; vec.pb(mp(x,y)); add(x,y);
	}
	//start from largest
	int cur = 1;
	
	{
		ll res=0;
		ll x = 0;
		for(int i=0;i<n;i++)
		{
			if(cur)
			{
				auto it = prev(ma.end());
				ll l = (it->fi).fi; ll r = (it->fi).se;
				if(x<l)
				{
					res += l-x; x=l;
				}
				else if(x>r)
				{
					res += x-r; x=r;
				}
				//cerr<<l<<' '<<r<<'\n';
				del(l,r);
			}
			else
			{
				auto it = ma2.begin();
				ll l = (it->fi).fi; ll r = (it->fi).se;
				swap(l,r);
				if(x<l)
				{
					res += l-x; x=l;
				}
				else if(x>r)
				{
					res += x-r; x=r;
				}
				//cerr<<l<<' '<<r<<'\n';
				del(l,r);
			}
			cur^=1;
		}
		res += abs(x);
		//cerr<<res<<'\n';
		ans=max(ans,res);
	}
	
	assert(ma.empty());
	for(int i=0;i<n;i++) add(vec[i].fi,vec[i].se);
	
	cur = 0;
	
	{
		ll res=0;
		ll x = 0;
		for(int i=0;i<n;i++)
		{
			if(cur)
			{
				auto it = prev(ma.end());
				ll l = (it->fi).fi; ll r = (it->fi).se;
				if(x<l)
				{
					res += l-x; x=l;
				}
				else if(x>r)
				{
					res += x-r; x=r;
				}
				//cerr<<l<<' '<<r<<'\n';
				del(l,r);
			}
			else
			{
				auto it = ma2.begin();
				ll l = (it->fi).fi; ll r = (it->fi).se;
				swap(l,r);
				if(x<l)
				{
					res += l-x; x=l;
				}
				else if(x>r)
				{
					res += x-r; x=r;
				}
				//cerr<<l<<' '<<r<<'\n';
				del(l,r);
			}
			cur^=1;
		}
		res += abs(x);
		ans=max(ans,res);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 14320
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main()
{
  int n,y;
  int a=-1,b=-1,c=-1;
  int m;
  cin >> n >> y;
  m=y-n*1000;
  for(int i=0;i<=n;i++)
  {
    if (m-4000*i>=0&&(m-4000*i)%5000==0 && i-(m-4000*i)/5000>=0){a=(m-4000*i)/5000;b=i-a;c=n-a-b;break;}
  }

  cout << a << ' ' << b << ' ' << c << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
	{
        int table[11][11]={0};
        if(n==0)
			break;
        for(int i=0,in;i<n;i++)
		{
            for(int j=0;j<n;j++)
			{
                cin>>in;
                table[i][j]=in;
                table[n][j]+=in;
                table[i][n]+=in;
            }
        }
        for(int i=0;i<n;i++)table[n][n]+=table[n][i];
        for(int i=0;i<n+1;i++)
		{
            for(int j=0;j<n+1;j++)
            printf("%5d",table[i][j]);
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int cnt[100010];
int main()
{
    int N,M;
    cin >> N >> M;
    vector<vector<int>>p(M,vector<int>());
    rep(i,N){
        int X;
        cin >> X;
        p[X%M].push_back(X);
    }
    rep(i,M){
        sort(p[i].begin(),p[i].end());
    }
    ll ans=0;
    for(int i=0;i<=M-i;i++){
        if((i==0)||(M%2==0&&i==(M/2))){
            ans+=p[i].size()/2;
        }
        else{
            int ci=p[i].size();
            int cres=p[M-i].size();
            
            if(ci>=cres){
                ans+=cres;
                int cn=0;
                rep(j,p[i].size()){
                    if((j>0&&p[i][j]==p[i][j-1])){
                        cn++;j++;
                    }
                }
                ans+=min(cn,(ci-cres)/2);
            }
            else{
                ans+=ci;
                int cn=0;
                rep(j,p[M-i].size()){
                    if((j>0&&p[M-i][j]==p[M-i][j-1])){
                        cn++;j++;
                    }
                }
                ans+=min(cn,(cres-ci)/2);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int a,b; cin >> a >> b;
    if((a+b)%2==0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

using namespace std;

int next(int a, int l)
{
    vector<char> v;
    while(a)
    {
        v.push_back(char('0' + a % 10));
        a /= 10;
    }
    while(v.size()!=l) v.push_back('0');
    sort(v.begin(), v.end());
    int x, y;
    istringstream f(string(v.begin(), v.end())), b(string(v.rbegin(), v.rend()));
    f >> x;
    b >> y;
    return y - x;
}

int main()
{
    int a, l;
    while(cin >> a >> l, a|l)
    {
        map<int, int> map;
        map[a] = 0;
        for(int i=1; ; i++)
        {
            a = next(a, l);
            if(map.find(a) != map.end())
            {
                cout << map[a] << " "  << a << " " << i - map[a] << endl;
                break;
            }
            map[a] = i;
        }
    }
}

Measured memory_bytes: 3188
#include<stdio.h>

#define INF 10000000
#define W 1
#define B 3

int n,M[100][100],d[100],colar[100];

void dijkstra(void){
  int min,i,u,v;

  d[0]=0;

  while(1){
    min=INF;
    for(i=0;i<n;i++){
      if((colar[i]!=B)&&(d[i]<min)){
        min=d[i];
        u=i;
      }
    }

    if(min==INF)
    break;

    colar[u]=B;

    for(v=0;v<n;v++){
      if((colar[v]!=B)&&(M[u][v]!=INF)){
        if((M[u][v]+d[u])<d[v])
        d[v]=M[u][v]+d[u];
      }
    }

  }
}

int main(){
  int i,j,min_t=0,x,k,u,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    colar[i]=W;
    d[i]=INF;
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&x);
      M[u][v]=x;
  }
}

  dijkstra();

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

  return 0;
}



Measured memory_bytes: 1996