akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a[200003];
    map<ll,ll>mp;
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    ll f=0;
    for(ll i=0;i<n;i++)
    {
        if(mp[a[i]]>1)
        {
            f=1;
            cout<<"NO"<<endl;
            break;
        }
    }
    if(f==0)
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 14336
program rb
  implicit none
  integer :: N,le,i,R
  character(len=100) :: S

  read(*,*) N
  read(*,*) S
  le=len_trim(S)
  R=0
  do i=1,N
     if(S(i:i).eq.'R') then
        R=R+1
     endif
  enddo
  if(R.gt.(N-R)) then
     write(*,'(a)') 'Yes'
  else
     write(*,'(a)') 'No'
  endif


end program rb


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    int dx[8]={0,1,1,1,0,-1,-1,-1};
    int dy[8]={1,0,-1,1,-1,-1,0,1};
    char s[h][w];
    for(int i=0;i<h;i++){
        string ss;
            cin>>ss;
        for(int j=0;j<w;j++){
            s[i][j]=ss[j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int pt=0;
            if(s[i][j]=='#')cout<<'#';
            else{
                for(int k=0;k<8;k++){
                    if(dx[k]+i>=0 && dx[k]+i<h && dy[k]+j>=0 && dy[k]+j<w && s[dx[k]+i][dy[k]+j]=='#'){
                        pt++;
                    }
                }
                cout<<pt;
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		for(int i=0; i<n; i++)
		{
			float[] x = new float[4];
			float[] y = new float[4];
			
			for(int j=0; j<4; j++)
			{
				x[j] = scanner.nextFloat();
				y[j] = scanner.nextFloat();
			}
			
			float ax = x[1]-x[0];
			float ay = y[1]-y[0];
			float bx = x[3]-x[2];
			float by = y[3]-y[2];

			System.out.println((ax*by-ay*bx==0? "YES" : "NO"));
		}
	}
}

Measured memory_bytes: 29728
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a));
#define MINUS(a) memset(a,-1,sizeof(a));
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};


bool length_cmp( string &a, string &b ){
  return a.size() < b.size();
}

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num * 10 + ( s[i] ^ 48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}

ll mod=1000000007;
ll dx[4] = { 1, 0, -1, 0 };
ll dy[4] = { 0, 1, 0, -1 };
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97


signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(n)
    vector< ll > x(n),y(n),h(n);
    REP( i, 0, n ){
      cin>>x[i]>>y[i]>>h[i];
      if( h[i] > 0 ){
        swap( x[i], x[0] );
        swap( y[i], y[0] );
        swap( h[i], h[0] );
      }
    }
    REP( cx, 0, 101 ){
      REP( cy,0,101){
        ll ch = h[0] + abs( cx - x[0] )+ abs( cy - y[0]);
        bool satis = true;
        for( ll i = 1; i < n; i++ ){
          if( fmax( ch - abs(x[i] - cx) - abs(y[i] - cy ),0 ) != h[i] ){
            satis = false;
          }
        }
        if( satis ){
          puta( cx, cy, ch );
          return 0;
        }
      }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double distmath(int i, int j, double x[], double y[]){
    return sqrt((x[j] - x[i])*(x[j] - x[i]) + (y[j] - y[i])*(y[j] - y[i]));
}

int kai(int n){
    if(n == 1){
        return 1;
    }else{
        return n*kai(n-1);
    }
}

int main(){    
    int N;
    cin >> N;
    double x[N], y[N];
    double dist[N][N]; 

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

    for(int i = 0; i < N; i++){
        for(int j = 1+i; j < N; j++){
            dist[i][j] = distmath(i, j, x, y);
            dist[j][i] = distmath(i, j, x, y);
        }
    }

    double sum = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i != j){
                sum += dist[i][j];
            }
        }
    }

    cout << fixed << setprecision(10) << sum/N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  int ans=0;
  for(int i=0;i<n;i+=2){
    if(a.at(i)%2==1){
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  int l = 1, r = n;
  rep(i, m) {
    int nl, nr;
    cin >> nl >> nr;
    l = max(l, nl);
    r = min(r, nr);
  }
  cout << max(0, r - l + 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int ans;
int a[100000];
int b[100000];
int awa[100000];
int bwa[100000];
int main()
{
	cin>>n;
	rep2(i,1,1+n)
	{
		cin>>a[i];
	}
	rep2(i,1,1+n)
	{
		cin>>b[i];
	}
	rep2(i,1,1+n)
	{
		bwa[i]=bwa[i-1]+b[i];
		awa[i]=awa[i-1]+a[i];
	}
	rep2(i,1,n+1)
	{
		int t=awa[i]+bwa[n]-bwa[i-1];
		if(t>ans)ans=t;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(c, b / a) << endl;
  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;

const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};
int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, 	n)cin>>a[i];
	int ng = 0;
	int ok = 0;
	rep(i,n) ok = max(ok,a[i]);

	while(ok - ng > 1){
		int mid = ok + ng; mid /= 2;
		ll num = 0;
		rep(i,n){
			// a[i] に何回atkすれば全てmid以下になるか
			num += (mid - 1 + a[i]) / mid - 1;
		}
		if(num <= k) ok = mid;
		else ng = mid;
	} 
	cout << ok << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

ll f(ll n) {
	ll res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}

	return res;
}

double g(ll n) {
	return (double)(n) / f(n);
}

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

	vector<ll> res;
	ll base = 1;

	for (int i = 0; i < 15; i++) {
		for (int j = 1; j < 150; j++) {
			res.emplace_back(base * (j + 1) - 1);
		}
		base *= 10;
	}

	sort(begin(res), end(res));
	res.erase(unique(begin(res), end(res)), end(res));

	for (ll i = 0; i < res.size(); i++) {
		for (ll j = i + 1; j < res.size(); j++) {
			if (g(res[i]) > g(res[j])) {
				res.erase(begin(res) + i--);
				break;
			}
		}
	}

	ll k;
	cin >> k;

	for (ll i = 0; i < k; i++) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 384
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
 int a[200000+1];
int main()
{
   int n ;
   cin>>n;
   for(int i =1 ; i<=n; ++i)
   {
       cin>>a[i];
   }
   sort(a+1,a+n+1);
   for(int i=2; i<=n; ++i)
   {
       if(a[i] == a[i-1])
            {cout<<"NO";
            return 0 ;}

   }
   cout<<"YES";
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{



  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long MOD=1000000007l;
  static int INF=10000000;
  static int[] rr=new int[]{1, 0, -1, 0};                                 //rook row move
  static int[] rc=new int[]{0, 1, 0, -1};                                 //rook col move

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); }
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //static variables

  //


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=1000000007l;

    long n=sc.nextLong();
    long a10=1, a8=1, a9=1;
    for(int i=0;i<n;i++){
        a10=(a10*10)%mod;
        a9=(a9*9)%mod;
        a8=(a8*8)%mod;
    }
    long ans=((a10+a8)%mod-2*a9+2*mod)%mod;
    nl(ans);

    out.flush();
  }


  public static long powMOD(long n,long k){                 //n-pow(k)
      if(k==1){
          return n%MOD;
      }
      if(k==0){
          return 1;
      }
      long val=powMOD(n,k/2)%MOD;
      if(k%2==0)return ((val%MOD)*(val%MOD))%MOD;
      else return (((val*val)%MOD)*n)%MOD;
  }


}

class Pair{
  int x; int y;
  Pair(int x,int y){
    this.x=x;
    this.y=y;
  }
}


Measured memory_bytes: 38484
/*   LazyBones
*
*/

#include <bits/stdc++.h>
#include<cctype>
#include <sstream>
#include<ctime>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
#define getarr(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define disparr(a,n) for(int i=0;i<n;i++){cout<<a[i];}cout<<"\n";
#define disparrs(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";
#define disparrl(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\n";}cout<<"\n";
#define mem0(a) memset(a,0,sizeof(a));
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define F first
#define S second
//#define nu 100001
#define M 1000000007
#define mul(x,y) ((ll)(x)*(y))%M
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 0x3f3f3f3f
#define MOD 998244353

int MODU(int a, int b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll max3(ll a,ll b,ll c)
{
    return max(c,max(a,b));
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll max(ll a,ll b)
{
    return (a>b)?a:b;
}
ll min(ll a,ll b)
{
    return (a<b)?a:b;
}
ld min(ld a,ld b)
{
    return (a<b)?a:b;
}
ll gcd(ll a,ll b)
{
    if(b==1)
    return 1;
    else if(a%b==0)
    return b;
    else
    return gcd(b,a%b);
}
ll mod(ll x){
    if(x>=0)
    return x;
    else
    return -x;
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}

void cycle(vll c,vi& v,int u, ll& val,vi& len,int ini){
    //cout<<u<<endl;
    v[u]=1;
    if(c[u]==u){
        v[u]=2;
        val=1;
        return;
    }
    if(v[c[u]]==2){
        return;
    }
    if (v[c[u]]==1){
        if(v[c[u]]!=ini)
            return;
        val=len[u]+1-len[c[u]];
        //cout<<val<<" hf"<<endl;
        v[u]=2;
        return;
    }
    len[c[u]]=len[u]+1;
    //cout<<u<<endl;
    cycle(c,v,c[u],val,len,ini);
    v[u]=2;
    return;

}



int main()
{
    fastio;
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<H*W-h*W-w*(H-h);
    
}


Measured memory_bytes: 256
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;



#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 5e5 + 120;

ll n;
string str;

int f(int n,int b,char c[])
    
{
    int i=0,k;                                                                                                                                                   
    while(n!=0)
    {
        k=n%b;
        n/=b;
        if(k<0){k-=b;n+=1;}
        if(k>9)c[i]=char(k-10+'A');
        else c[i]=char(k+'0');
        i++;
    }
    return i-1;
}
int main(){FAST;   
    cin >> n;
    if(n == 0)return cout << 0 ,0;
   char b[400];
    int a = -2;
   for(int i = f(n ,a ,b); i > -1; i--)
       cout << b[i];

    
return 0;
}
 










Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string S;
    cin >> S;
    string subS_front = S.substr(0, (S.size()-1)/2);
    string subS_back = S.substr((S.size()+3)/2-1);
    //cout << subS_front << ":" << subS_back << endl;
    string reverseS = S, reverse_subS_front = subS_front, reverse_subS_back = subS_back;
    reverse(reverseS.begin(), reverseS.end());
    reverse(reverse_subS_front.begin(), reverse_subS_front.end());
    reverse(reverse_subS_back.begin(), reverse_subS_back.end());
    if(S == reverseS && subS_front == reverse_subS_front && subS_back == reverse_subS_back)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main()
{
	int n;
	scanf("%d",&n);
	if(n<10)
		cout<<n;
	else
	{
		if(n<100)
			cout<<9;
		else
		{
			if(n<1000)
				cout<<9+n-99;
			else
			{
				if(n<10000)
					cout<<909;
				else
				{
					if(n<100000)
					{
						cout<<909+n-9999;
					}
					else
					{
						cout<<90909<<endl;
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  map<char,char> ans = {
    {'A','T'},
    {'T','A'},
    {'C','G'},
    {'G','C'},
  };
  char c;
  cin >> c;
  cout << ans[c] << endl;
}


Measured memory_bytes: 256
n,m= map(int, input().split())
s= [list(map(int, input().split())) for i in range(m)]


if n==1:
    for i in range(10):
        x = str(i)
        flag=True
        for j in range(m):
            if x[s[j][0] - 1] != str(s[j][1]):
                flag = False

        if flag:
            print(x)
            exit()
    print(-1)
    exit()



for i in range(10**(n-1),10**n):
    x=str(i)
    flag=True
    for j in range(m):
        if x[s[j][0]-1]!=str(s[j][1]):
            flag=False

    if flag:
        print(x)
        exit()

print(-1)

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

int main()
{
    int x;
    cin >> x;
    ll t = 1;
    while(t * (t + 1) / 2 < x) {
        t++;
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int n, a[N];

void solve() {
	cin >> n;
	map <int, int> cnt;
	LL sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		sum += a[i];
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		sum -= 1LL * a * cnt[a];
		sum += 1LL * b * cnt[a];
		cnt[b] += cnt[a];
		cnt[a] = 0;
		cout << sum << endl;
	}
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif
		
	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 8364
unittest
{
	assert( [ "10" ].parse.expand.solve == 5 );
	assert( [ "1111111111111111111" ].parse.expand.solve == 162261460 );
	
	assert( [ "111" ].parse.expand.solve == 27 );		// 追加ケース
	assert( [ "101" ].parse.expand.solve == 15 );		// 追加ケース
	assert( [ "011" ].parse.expand.solve == 9 );		// 追加ケース
	assert( [ "010" ].parse.expand.solve == 5 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto l = input.front;
	return tuple( l );
}

auto solve( string l )
{
	const MOD = 10L ^^ 9 + 7;
	
	auto dp = new Tuple!( long, long )[ 1 + l.length ];
	dp[ 0 ][ 0 ] = 1;
	dp[ 0 ][ 1 ] = 0;
	foreach( i, b; l )
	{
		// i桁目までlと同じにする場合のパターン数を計算
		// (a[i],b[i])は l[i]==1 だったら (1,0)or(0,1) の2パターン、 l[i]==0 だったら (0,0) の1パターン
		dp[ 1 + i ][ 0 ] = ( dp[ i ][ 0 ] * ( b == '1' ? 2 : 1 ) ) % MOD;
		
		// i桁目まででl未満が確定している場合のパターン数を計算
		// i桁目で初めてl未満が確定する場合の(a[i],b[i])は (0,0) の1パターン（ただし、l[i]==0 のときは上に含まれるので0パターン）
		// i-1桁目まででl未満が確定済の場合の(a[i],b[i])は (1,0)or(0,1)or(0,0) の3パターン
		dp[ 1 + i ][ 1 ] = ( ( dp[ i ][ 0 ] * ( b == '1' ? 1 : 0 ) ) + ( dp[ i ][ 1 ] * 3 ) % MOD ) % MOD;
	}
	return ( dp[ $ - 1 ][ 0 ] + dp[ $ - 1 ][ 1 ] ) % MOD;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, t;
    scanf("%d%d",&n,&t);
    int a[n];
    int m;
    int maxdif = 0;
    int c1 = 0, c2 = 0;
    int ans = 0;
    scanf("%d",&a[0]);
    m = a[0];
    for (int i = 1; i < n; i++) {
        scanf("%d",&a[i]);
        int dif = a[i]-m;
        if (dif > maxdif){
            maxdif = dif;
            c1 = 0;
        }
        if (dif == maxdif) c1++;
        m = min(m,a[i]);
    }
    m = a[n-1];
    maxdif = 0;
    for (int i = n-2; i >= 0; i--) {
        int dif = m-a[i];
        if (dif > maxdif){
            maxdif = dif;
            c2 = 0;
        }
        if (dif == maxdif) c2++;
        //printf("%d %d\n",dif,maxdif);
        m = max(m,a[i]);
    }
    //printf("%d %d\n",c1,c2);
    printf("%d",min(c1,c2));

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, n);
    vector<ll> s(2*n,-1);

    int left = n;
    int right = n;

    ll a;
    cin >> a;
    s[left] = a;

    if ( n % 2 == 0 ) {
        for (int i = 1; i < n; i++) {
            cin >> a;
            if ( i % 2 == 1 ) {
                left--;
                s[left] = a;
            } else {
                right++;
                s[right] = a;
            }
        }
    } else {
        for (int i = 1; i < n; i++) {
            cin >> a;
            if ( i % 2 == 1 ) {
                right++;
                s[right] = a;
            } else {
                left--;
                s[left] = a;
            }
        }
    }

    for (int i = left; i < right; i++) {
        cout << s[i] << " ";
    }

    cout << s[right] << "\n";
    return 0;
}

Measured memory_bytes: 5248
<?php
fscanf(STDIN, "%d %d", $n, $k);
$x = (int) ($n / $k);
$y = 0;
if ($k % 2 == 0) {
	$y = $x;
	if ($n % $k >= $k / 2) $y++;
}
echo $x ** 3 + $y ** 3;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

string s[30];
int h,w;
int dist[30][30];

bool is_pos(int i,int j){
   return i<h and j<w and i>=0 and j>=0 and s[i][j] == '.';
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> h >> w;
   f(i,0,h){
      cin >> s[i];
   }
   int ans = 0;
   f(i,0,h){
      f(j,0,w){
         if(s[i][j] == '.'){
            set<array<int,3>> q;
            int mx = 0;
            q.insert({0,i,j});
            vector<vector<int>> dist(h,vector<int>(w,MOD));
            dist[i][j] = 0;
            while(!q.empty()){
               auto v = *q.begin();
               q.erase(q.begin());
               int ff = v[1];
               int ss = v[2];
               vector<pii> itr = {{ff+1,ss},{ff-1,ss},{ff,ss+1},{ff,ss-1}};
               for(auto &e : itr){
                  if(is_pos(e.F,e.S)){
                     if(dist[ff][ss]+1<dist[e.F][e.S]){
                        q.erase({dist[e.F][e.S],e.F,e.S});
                        dist[e.F][e.S] = dist[ff][ss]+1;
                        mx = max(mx,dist[e.F][e.S]);
                        q.insert({dist[e.F][e.S],e.F,e.S});
                     }
                  }
               }
            }
            ans = max(ans,mx);
         }
      }
   }
   cout << ans << '\n';
   return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string X;
  cin >> X;
  int t = 0, s = 0;
  for (int i = 0; i < X.size(); i++)
  {
    if (X[i] == 'T')
    {
      if (s == 0)
        t++;
      else
        s--;
    }
    else
      s++;
  }
  cout << 2 * t << endl;
  return 0;
}


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

int main() {
	int n, q; cin >> n >> q;
	fenwick_tree<ll> fw(n);
	for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		fw.add(i, x);
	}
	for (int i = 0; i < q; ++i) {
		int a, b, c; cin >> a >> b >> c;
		if (a == 0) fw.add(b, c);
		else cout << fw.sum(b, c) << endl;
	}
	return 0;
}

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

int main() {
    string str;
    cin >> str;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int a, b;
        if(s == "print") {
            cin >> a >> b;
            cout << str.substr(a, b - a + 1) << endl;
        }
        else if(s == "reverse") {
            cin >> a >> b;
            for(int i = a, j = b; i <= j; i++, j-- ) {
                char c = str[j];
                str[j] = str[i];
                str[i] = c;
            }
        }
        else {
            string p;
            cin >> a >> b >> p;
            str.replace(a, b- a + 1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    int N;
    cin >> N;
    unordered_map<string, bool> Sorder;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        Sorder[tmp] = true;
    }
    if (Sorder.size() == 4) {
        cout << "Four";
    } else {
        cout << "Three";
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int X;
		cin >> X;

		for( long i = -120; i <= 120; ++i ) {
			for( long j = -120; j <= 120; ++j ) {
				if( i*i*i*i*i - j*j*j*j*j == X ) {
					cout << i << ' ' << j << endl;
					return;
				}
			}
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int left(int i){return i*2;}
int right(int i){return i*2+1;}
int parent(int i){return i/2;}

void maxHeapify(int* A, int i, int H){
	int l = left(i);
    int r = right(i);
    int m = i;
    if(r <= H && A[m] < A[r]) m = r;
    if(l <= H && A[m] < A[l]) m = l;
    if(m != i){
     int s = A[m];
     A[m] = A[i];
     A[i] = s;
     maxHeapify(A, m, H);
    }
}
void buildMaxHeap(int* A, int H){
 for(int i = H; i >= 1; i--){
     maxHeapify(A, i, H);
 }
}

int main()
{
    int n;
    int A[500001];
    cin >> n;
    for(int i=1; i <= n; i++){
     cin >> A[i];   
    }
    buildMaxHeap(A, n);
    for(int i=1; i <= n; i++){
        cout << " " << A[i];
        }
    cout << endl;
}

Measured memory_bytes: 3112
#include<cstdio>
#include<climits>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int N,K;
vector<int> G[10];

int data[11][2000];
int dp[11][2000];

int solve(int i, int k)
{
  if (dp[i][k]) return data[i][k];

  int r;

  if (i == 10) {
    if (k == 0) r = 0;
    else r = INT_MIN;
  } else {

    r = solve(i+1, k);
    for (int j = 0; j < G[i].size() && j < k; j++) {
      r = max(r, G[i][j]+solve(i+1, k-j-1));
    }
  }

  dp[i][k] = 1;
  data[i][k] = r;
  return r;
}

int main()
{
  scanf("%d%d",&N,&K);

  while (N--) {
    int c,g;
    scanf("%d%d",&c,&g);
    G[g-1].push_back(c);
  }

  for (int i = 0; i < 10; i++) {
    sort(G[i].begin(), G[i].end(), greater<int>());
    for (int j = 1; j < G[i].size(); j++) {
      G[i][j] += G[i][j-1] + j * 2;
    }
  }

  printf("%d\n", solve(0,K));
}

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

#define MODNUMBER 1000000007

long long pow_mod(long long a, long long n) {  // a^n mod MODNUMBER
	long long result = 1;
	long long a_i = a;
	long long n_tmp = n;
	while (n_tmp > 0) {
		if (n_tmp & 0b1) {
			result = (result * a_i) % MODNUMBER;
			// cout << result << "\n";
		}
		a_i = a_i * a_i % MODNUMBER;
		n_tmp = n_tmp >> 1;
	}
	return result;
}

long long fact_mod(long long k) {  // k! mod MODNUMBER

	long long result = 1;
	for (int i = 1; i <= k; i++) {
		result = (result * i) % MODNUMBER;
	}
	return result;
}

long long inv_mod(long long k) {  // k^(-1) mod MODNUMBER

	return pow_mod(k, MODNUMBER - 2);
}

/* fact_mod()の途中経過を使いまわす実装にすれば早くなるらしい */
long long comb_mod(long long n, long long k) {  // nCk mod MODNUMBER
	return (fact_mod(n) *
	        inv_mod((fact_mod(k) * fact_mod(n - k)) % MODNUMBER)) %
	       MODNUMBER;
}
int main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);

	int X, Y;
	scanf("%d %d", &X, &Y);

	/*
	    2a+b=x
	    a+2b=y

	    a-b =x-y
	    a+b =(x+y)/3

	    a=(2/3)x-(1/3)y
	    b=(-1/3x)+(2/3)y
	*/

	int a, b;
	if ((X * 2 - Y) % 3 != 0) {
		cout << 0;
		return 0;
	} else {
		a = (X * 2 - Y) / 3;
	}
	if ((-X + 2 * Y) % 3 != 0) {
		cout << 0;
		return 0;
	} else {
		b = (-X + 2 * Y) / 3;
	}
	if (a < 0 || b < 0) {
		cout << 0;
		return 0;
	}
	cout << comb_mod((long long)(a + b), (long long)b);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        long[] xyzk = Console.ReadLine().Split().Select(i => long.Parse(i)).ToArray();
        long[][] abc = new long[3][];
        for(int a = 0; a < abc.Length; a++)
        {
            abc[a]= Console.ReadLine().Split().Select(i => long.Parse(i)).ToArray();
        }
        List<long> ab = new List<long>();
        for(int a = 0; a < xyzk[0]; a++)
        {
            for(int b = 0; b < xyzk[1]; b++)
            {
                ab.Add(abc[0][a]+abc[1][b]);
            }
        }
        ab.Sort();
        ab.Reverse();
        List<long> abc2 = new List<long>();
        for (int a=0;a<Math.Min(xyzk[3],ab.Capacity);a++)
        {
            for (int b = 0; b < xyzk[2]; b++)
            {
                abc2.Add(ab[a]+abc[2][b]);
            }
        }
        abc2.Sort();
        abc2.Reverse();
        for(int a = 0; a < xyzk[3]; a++)
        {
            Console.WriteLine(abc2[a]);
        }
        
        Console.ReadLine();

    }
}

Measured memory_bytes: 63516
#include<stdio.h>

void swap(int x[],int i,int j){
  int tmp;
  tmp=x[i];
  x[i]=x[j];
  x[j]=tmp;
}

void Qsort(int x[],int left,int right){
  int pivot;
  int i,j;
  i=left;
  j=right;
  pivot=x[(left+right)/2];
  
  while(1){
    while(x[i]<pivot) i++;
    while(x[j]>pivot) j--;
    if(i>=j) break;
    
    swap(x,i,j);
    i++;
    j--;
  }
  
  if(left<i-1)
    Qsort(x,left,i-1);
  if(right>j+1)
    Qsort(x,j+1,right);
  
}
  
int main(){
  int n,tmp;
  
  
  scanf("%d",&n);
  int d[n];
  for(int i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  
  Qsort(d,0,n-1);
  
  int b;
  b=n/2;
  printf("%d",d[b]-d[b-1]);
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18

        signed main() {
 
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int l,r,d;
        cin>>l>>r>>d;
        int ans=0;
        for(int i=l;i<=r;i++){
            if(i%d==0)
                ans++;
        }
        cout<<ans;
        

        return 0;
    }


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;

int main(){
	double N,K;
  	cin >> N>>K;
  	double ans = 0;
  	double score = 0;
  	double cont = 1;
  	for(int i = 1; i <= N; i++){
    	score = i;
      	cont=1;
      	//cout << cont/2 << endl;
      	while(score < K){
        	
          	score = score *2;
          	cont = cont/2;
          //cout << cont << endl;
        }
      	//cout << cont << endl;
      	ans += cont * (1/N);
      	
      	cont = 1;
    }
  	cout <<fixed << setprecision(12)<< ans << endl;

}

Measured memory_bytes: 256
N = int(input())
S = input()

d = [0] * (N + 1)
for i in range(N):
    d[i + 1] = d[i] + int(S[i] == "(") - int(S[i] == ")")

a = d[-1]
b = min(d)

print("(" * -b + S + ")" * (a - b))


Measured memory_bytes: 38344
s=input()
if s[0]=="R" and s[1]=="R" and s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R":
    print(2)
elif s[1]=="R" and s[2]=="R":
    print(2)
elif s=="SSS":
    print(0)
else:
    print(1)

Measured memory_bytes: 9044
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

const string YES = "Yes";
const string NO = "No"; 

void solve(long long A, long long B, long long C){
    if(C>=A && C<=B){
        cout<<YES<<endl;
    }
    else cout<<NO<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


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

int main() {
  int N, K, tmp;
  
  cin >> N >> K;
  tmp = 1;
  
  for (int i = 0; i < N; i++) {
    if (tmp * 2 < tmp + K) {
      tmp = tmp * 2;
    } else {
      tmp = tmp + K;
    }
  }
  
  cout << tmp << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int i=6,min=100,s=0,a;
	while (i--) {
		fscanf(stdin, "%d", &a);
		s += a;
		if (a < min) min = a;
		if (i == 2) s -= min, min = 100;
	}
	P(d, s - min);
	return 0;
}

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

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


#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
const int MAXN = 10e5 + 10;

int prefix_sum[MAXN];

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

    int N = II(), Q = II();
    string s; cin >> s;

    for(int i=1; i<N; i++){
        if(s[i] == 'C' && s[i-1] == 'A') prefix_sum[i] = prefix_sum[i-1] + 1;
        else prefix_sum[i] = prefix_sum[i-1];
    }

    while(Q--){
        int l = II()-1, r = II()-1;
        int res = prefix_sum[r];
        if(l > 0) res -= prefix_sum[l-1];
        if(l > 0 && s[l-1] == 'A' && s[l] == 'C') res--;
        cout << res << "\n";
    }


    return 0;
}


Measured memory_bytes: 1408
//14-3 ?¶??????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
    int W,H,N;
    cin >> W >> H >> N;
    int X,Y;
    cin >> X >> Y;
    int ans = 0;
    for(int i=1; i<N; i++){
        int tmpx,tmpy;
        cin >> tmpx >> tmpy;

        ans +=  abs(X-tmpx) + abs(Y-tmpy);
        if((X-tmpx)*(Y-tmpy)>0){
            if(abs(X-tmpx) >= abs(Y-tmpy)) ans -= abs(Y-tmpy);
            else ans -= abs(X-tmpx);
        }

        X = tmpx;
        Y = tmpy;
    }

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


Measured memory_bytes: 3052
searched = set()
def search(nums, cur_comb, n, s):
    #print(searched)
    #print(cur_comb)
    if cur_comb in searched:
        return 0
    else:
        searched.add(cur_comb)
    if sum(cur_comb) > s:
        return 0
    if len(cur_comb) == n:
        if sum(cur_comb) == s:
            return 1
        else:
            return 0
    return sum([search(nums[:i]+nums[i+1:], tuple(sorted(cur_comb + (nums[i],))), n , s) for i in range(len(nums))])
    
while True:
    n, s = map(int,  input().split())
    if n == s == 0:
        break
    searched.clear()
    cnt = search(list(range(10)), (), n, s)
    print(cnt)



Measured memory_bytes: 5636
#include <stdio.h>
int main(void){
  char num[1010];
  int a;
  while(1){
      scanf("%s", &num);
      if(num[0]=='0')
      break;
      else{
        //   printf("%lld\n", num);
      int sum = 0;
      for(int i=0; i<strlen(num); i++){
          sum+=num[i]-'0';
      }
      printf("%d\n", sum);
      }
 
  }
  return 0;
 
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
int h,w,k;
int mark[305];
char a[305][305];
int ans[305][305];
int main(){FAST;
cin>>h>>w>>k;
for(int i=1;i<=h;i++){
  for(int j=1;j<=w;j++){
    cin>>a[i][j];
  }
}
int imp = 1;
for(int i=1;i<=h;i++)mark[i] = 1;
int cur = 1;
for(int i=1;i<=h;i++){
  int much = 0;
  for(int j=1;j<=w;j++){
    if(a[i][j] == '#')much++;
  }
  if(much){
    int gate = 0;
    for(int j=1;j<=w;j++){
      if(a[i][j] == '#' and gate){
        cur++;
      }
      else if(a[i][j] == '#'){
        gate = 1;
      }
      ans[i][j] = cur;
    }
    imp = i;
    cur++;
  }
  else{
    mark[i] = 0;
  }
}
for(int i=imp-1;i>=1;i--){
  if(!mark[i]){
    for(int j=1;j<=w;j++)
      ans[i][j] = ans[i+1][j];
  }
}
for(int i=imp+1;i<=h;i++){
  if(!mark[i]){
    for(int j=1;j<=w;j++)
      ans[i][j] = ans[i-1][j];
  }
}
for(int i=1;i<=h;i++){
  for(int j=1;j<=w;j++){
    cout<<ans[i][j]<<' ';
  }
  cout<<'\n';
}
return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,ans;
  cin>>N;
  vector<int> as(N),uniq_as(N);
  for(int i=0;i<N;i++){cin>>as.at(i);}
  int maxa=*max_element(as.begin(),as.end());
  int mina=*min_element(as.begin(),as.end());
  for(int a=mina;a<=maxa;a++){
    int cost=0;
    for(int i=0;i<N;i++){
      cost+=pow((as.at(i)-a),2);
    }
    if(a==mina){ans=cost;}
    else{ans=min(ans,cost);}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 32


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


a, b, c = lmi()

print("Yes" if c > a + b and 4 * a * b < (c - a - b) ** 2 else "No")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
   int n;
   cin >> n;
   map<char,int> mp;
   rep(i,n)
   {
      char foo;
      cin >> foo;
      if(foo=='Y')
      {
         cout<<"Four"<<endl;
         return 0;
      }
   }
   cout<<"Three"<<endl;
   return 0;
}

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

int main(){
  long long int n;
  cin >>n;
  int a[n+1];
  int b[n];
  long long int ans=0;
  for (int i=0;i<n+1;i++) cin >> a[i];
  for (int i=0;i<n;i++) cin >> b[i];
  for (int i=0;i<n;i++){
    if (a[i]<=b[i]){
      b[i]-=a[i];
      if (a[i+1]>b[i]){
        a[i+1]-=b[i];
        ans+=b[i];
      }else {
        ans+=a[i+1];
        a[i+1]=0;
      }
      ans+=a[i];
    }else {
      ans+=b[i];
    }
  }
  cout << ans;
}


Measured memory_bytes: 1024