akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
struct P{
	int p,id;
	friend bool operator < (P x,P y){
		return x.p==y.p?x.id>y.id:x.p<y.p;
	}
}a[510];
int n,m,ans,l[510],r[510],f[510][300];
int main(){
    read(n);read(m);
    F(i,0,(n<<1)-1){
    	a[i].id=i;r[i]=min((n<<1)-1,(int)floor(sqrt(4*n*n-i*i)));
    	if(i>=n)l[i]=0,a[i].p=r[i];
    	else {l[i]=ceil(sqrt(n*n-i*i));a[i].p=l[i]-1;}
	}
	sort(a,a+2*n);
	F(k,0,n){
		re cnt=0;C(f,0);f[0][0]=1;
		F(i,1,n<<1){
			if(a[i-1].id<n)cnt++;
			F(j,0,min(k,cnt)){
				if(a[i-1].id<n){
					f[i][j]=(ll)f[i-1][j]*(r[a[i-1].id]+1-(2*n-1-a[i-1].id+k-j))%m;
					if(j)(f[i][j]+=(ll)f[i-1][j-1]*(a[i-1].p+1-(i-1-(cnt-j)))%m)%=m;
				}
				else f[i][j]=(ll)f[i-1][j]*(a[i-1].p+1-(i-1-(cnt-j)))%m;
			}
		}
		if(k&1)(ans-=f[2*n][k]-m)%=m;
		else (ans+=f[2*n][k])%=m;
	}
	if(ans<0)(ans%=m)+=m;
	printf("%d",ans);
   	return 0;
}

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

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(2)] for i in range(N)]

for i in range(N):
    A,B=map(int,input().split())
    B=int(B)
    S[i][0]=A
    S[i][1]=B


T=sorted(S,key=lambda x:x[1])
goukei=0

for i in range(N):
    simekiri=T[i][1]
    goukei+=T[i][0]
    if goukei>simekiri:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 42776
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
const int INF = 1e9+7;
char a[maxn][maxn];
int dp[maxn][maxn];		//dp[i][j]´ú±íÖÕµãÎªi,jµÄ·½°¸Êý 
bool vis[maxn][maxn];
long long ans = 0,h,w;

int main() {
	cin>>h>>w;
	for(int i = 1;i <= h;i++) {
		scanf("%s",a[i]+1);
	}
	for(int i = 1;i <= w;i++) {
		if(a[1][i] == '.') dp[1][i] = 1;
		else break;
	}
	for(int i = 1;i <= h;i++) {
		if(a[i][1] == '.') dp[i][1] = 1;
		else break;
	}
	
	for(int i = 2;i <= h;i++) {
		for(int j = 2;j <= w;j++) {
			if(a[i][j] == '.') {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % INF;
			}
		}
	}
	cout<<dp[h][w];
	return 0;
}  

Measured memory_bytes: 6016
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin>>n;
    vector<int> vec(n);
  
  for(int i=0;i<n;i++)cin>>vec[i];
  int ans=0;
  
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)ans+=vec[i]*vec[j];
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main(void){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b>c+d){
		printf("Left");
	}else if(a+b<c+d){
		printf("Right");
	}
	else{
	printf("Balanced");
	}
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
A = []
S = []  #sorted array A
N.times do |i|
  A << gets.to_i
  S << A[i]
end
S.sort!{|a, b| b <=> a }

#p A  #for debug
#p S  #for debug

N.times do |i|
  if A[i] == S[0]  #取り除く奴が最大値の時
    puts S[1]  #全部の大きい順の２番目
  else  #取り除く奴が最大値じゃない時
    puts S[0]  #一番大きいやつ
  end
end


Measured memory_bytes: 10936
using System;
using System.Linq;
using CompLib.Util;
using System.Threading;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();

        int cnt = 0;
        bool f = false;
        for (int i = 0; i < n; i++)
        {
            int d1 = sc.NextInt();
            int d2 = sc.NextInt();
            if (d1 == d2)
            {
                if (!f)
                {
                    cnt = 0;
                    f = true;
                }
                cnt++;
                if (cnt >= 3)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            else
            {
                f = false;
            }
        }
        Console.WriteLine("No");
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27536
#include<stdio.h>

int main(void)
{
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);

  if(a <= 8 && b <= 8)
  {
    printf("Yay!\n");
  }else{
  printf(":(\n");
  }
  return 0;
}


Measured memory_bytes: 128
N, M, L = gets.split.map(&:to_i)
a = []
b = []
ans = Array.new(N).map{Array.new(L,0)}
N.times do
  a.push(gets.split.map(&:to_i))
end
M.times do
  b.push(gets.split.map(&:to_i))
end
N.times do |n|
  L.times do |l|
    sum = 0
    M.times do |m|
      sum += a[n][m] * b[m][l]
    end
    ans[n][l] = sum
  end
end
puts ans.map{|r|r*' '}


Measured memory_bytes: 7384
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    string S;
    int K;
    cin >> K;
    cin >> S;
    if ( S.size() <= K ){
        cout << S << endl;
    }
    else{
        REP(int,i,0,K){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
    return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
const  LL mod=1000000007;
vector<int>v;
int main()
{
    LL n;
    cin>>n;
    LL x=1;
    LL y=1,z=1;
    for(int i=1;i<=n;i++)
    {
        x=x*10;
        y=y*9;
        z=z*8;
        x=x%mod;
        y=y%mod;
        z=z%mod;
    }
    LL ans=(x+z)%mod-(2*y)%mod;
    if(ans<0)ans+=mod;
    ans=ans%mod;
    cout<<ans;

}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N;
	cin >> N;
	if(N%2 == 0){
		cout << "0.5" << endl;
	}
	else{
		printf("%0.7lf\n", ((double)(N/2)+1.0)/(double)N);
	}

	return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
    int paSize = printArray.size();
    for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
    if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
vec<ll> v;
int dp[111111];

void init() {
    ll t = 6;
    while (1) {
        if (t > 100000) break;
        v.push_back(t);
        t *= 6;
    }
    t = 9;
    while (1) {
        if (t > 100000) break;
        v.push_back(t);
        t *= 9;
    }
    v.push_back(1);
    uniqueV(v);
}

int main() {
    cin >> n;

    init();
    fill(dp, dp+n+10, 1e8);
    dp[0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < v.size(); j++) {
            if (i+v[j] <= n) {
                dp[i+v[j]] = min(dp[i+v[j]], dp[i]+1);
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
// template version 1.2
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0LL)
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

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

template<typename A, size_t N, typename T> // n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];

  sort(a, a+3);

  cout << a[2]*10 + a[1] + a[0] << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	int N; cin >> N;

	int H,W; cin >> H >> W;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int a,b; cin >> a >> b;
		if (a >= H and b >= W) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i)) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
$mod = 1_000_000_007
io = STDIN
n,m=io.gets.chomp.split.map(&:to_i)
def fact(x)
  (1..x).inject(1){|s,i|s*i%$mod}
end
if n==m
  nn=fact(n)
  puts (nn*nn*2)%$mod
elsif n+1==m
  nn=fact(n)
  puts (nn*nn*m)%$mod
elsif n== m+1
  mm=fact(m)
  puts (mm*mm*n)%$mod
else
  puts 0
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
const double pi=3.1415926535;
char s[maxn];
double x[10],y[10];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    double ans=0;
    double nn=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        nn*=i;
        cin>>x[i]>>y[i];
    }
    double k=1;
    for(int i=1;i<=n-2;i++)
        k*=i;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            double temp=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            temp*=2.0*(n-1);
            temp*=k;
            ans+=temp;
        }
    }
    ans/=nn;

    cout<<fixed<<setprecision(10)<<ans<<'\n';







}


Measured memory_bytes: 3844
from sys import stdin

N = int(stdin.readline())
S = list(input())
R = set()
G = set()
B = set()
for i, s in enumerate(S, 1):
    if s == 'R':
        R.add(i)
    elif s == 'G':
        G.add(i)
    else:
        B.add(i)

b = len(B)
ans = 0
for r in R:
    for g in G:
        M = max(r, g)
        m = min(r, g)
        if 2 * m - M in B:
            ans -= 1
        if 2 * M - m in B:
            ans -= 1
        if (M + m) / 2 in B:
            ans -= 1
        ans += b

print(ans)


Measured memory_bytes: 9560
gets
a = gets.split.map &:to_i
resulta = {}
resultb = {}
a.size.times{|i|
    if a[i] >= 3200
        resulta[i + 8] = true
    else
        resultb[a[i] / 400] = true
    end
}
min = resultb.size == 0 ? "1" : resultb.size.to_s
max = (resulta.size + resultb.size).to_s
puts min + " " + max

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	
	vector <int> nums(n);
	vector <int> divisors;
	int gcd;
	
	for (int i = 0; i < n; ++i) {
		cin >> nums[i];
	}
	gcd = nums[0];
	
	for (int i = 0; i < n; ++i) {
		gcd = GCD(gcd, nums[i]);
	}
	
	for (int i = 1; i <= sqrt(gcd); ++i) {
		if (gcd % i == 0) {
			cout << i << endl;
			divisors.push_back(i);
		}
	}
	
	for_each(divisors.rbegin(), divisors.rend(), [&](int &i){
		if (i * i != gcd) {
			cout << gcd / i << endl;
		}
	});
	
	
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vs s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vvi d(n, vi(m));
  for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
    if (i + j == 0) d[i][j] = s[i][j] == '#';
    else {
      d[i][j] = 1e19;
      if (i) d[i][j] = min(d[i][j], d[i-1][j] + (s[i][j] != s[i-1][j]));
      if (j) d[i][j] = min(d[i][j], d[i][j-1] + (s[i][j] != s[i][j-1]));
    }
  }
  if (s[n-1][m-1] == '#') ++d[n-1][m-1];
  cout << d[n-1][m-1] / 2 << endl;
  return 0;
}


Measured memory_bytes: 384
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int x , y;

int main(){
  cin >> x >> y;
  int ans = abs(-x - y) + 1;
  if(x <= y)
    ans = min(ans , y - x);
  else
    ans = min(ans , x - y + 2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
program abc117d
  implicit none
  integer(8) n, k, i, v
  integer(8), dimension(:), allocatable :: a

  read *, n, k
  allocate(a(n))
  read *, a
  v = 0
  do i = 39, 0, -1
     if (count(btest(a, i)) * 2 <= n .and. v + 2**i <= k) then
        v = v + 2**i
     end if
  end do
  print *, sum(ieor(a, v))
end program abc117d


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N+2,0);
	unordered_map<ll, ll> m;
	for (ll i = 1; i < N + 1; i++) {
		cin >> a[i];
		m[a[i]] = i;
	}
	m[0] = 0; m[N + 1] = N + 1;
	set<ll> used;
	used.insert(0); 
	used.insert(N + 1);
	ll ans = 0;
	for (ll i = 1; i < N+1; i++) {
		ans += i * (m[i] - *--used.lower_bound(m[i])) * (*used.upper_bound(m[i]) - m[i]);
		used.insert(m[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19656
n = int(input())

s_dic = {}

for i in range(n):
    tmp = str(input())
    if tmp not in s_dic:
        s_dic[tmp] = 1
    else:
        s_dic[tmp] += 1

tmp = max(s_dic.values())
max_s_key = [s_value[0] for s_value in s_dic.items() if s_value[1] == tmp]

max_s_key = sorted(max_s_key)

for i in max_s_key:
    print(i)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const ll INF = 1ll<<61;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

class Dijkstra {
private:
    int N;
    vvii E;

    void init(int n) {
        E.resize(0); E.clear();
        N = n; E.resize(n);
    }

public:
    Dijkstra() {}
    Dijkstra(int n) { init(n); }

    void add(int from, int to, int cost) {
        E[from].push_back(ii(to, cost));
    }


    vi solve(int s) {
        vi dis(N, INF);
        vector<bool> vis(N);
        dis[s] = 0;

        min_priority_queue<ii> q;
        q.push(ii(0, s));

        while (!q.empty()) {
            int t, d;
            tie(d, t) = q.top(); q.pop();

            if (vis[t]) continue;
            vis[t] = true;

            FORE (p, E[t]) {
                ll next = p.first, c = p.second;
                if (vis[next]) continue;
                if (dis[t] + c < dis[next]) {
                    dis[next] = dis[t] + c;
                    q.push(ii(dis[next], next));
                } else if (dis[t] + c == dis[next]) {
                }
            }
        }
        return dis;
    }
};

// 銀貨は2500まいあれば足りる
const ll COIN = 2510;

Dijkstra dij;
ll N, M, S;

int main() {
    cin >> N >> M >> S;
    dij = Dijkstra(N*COIN);
    REP (i, M) {
        int u, v, a, b;
        cin >> u >> v >> a >> b; u--; v--;
        FOR (c, a, COIN) {
            dij.add(u*COIN + c, v*COIN + c-a, b);
            dij.add(v*COIN + c, u*COIN + c-a, b);
        }
    }
    REP (i, N) {
        int c, d;
        cin >> c >> d;
        REP (cc, COIN-c) {
            dij.add(i*COIN+cc, i*COIN+cc+c, d);
        }
    }
    vi res = dij.solve(min(S, 2500ll));
    FOR (i, 1, N) {
        ll ans = INF;
        REP (c, COIN) CHMIN(ans, res[i*COIN+c]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 23732
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define L 1000
int st[N];
int point_st;



void stack(int n);
int pop();

int main(void){

int i=0,j,n,a,b;
char c[L];
char d[12];

	scanf("%[0-9 +*-]",c);

	while(c[i] != '\0'){
 	
		switch(c[i]){

			case ' ':
			break;

			case '+':
			b=pop();
			a=pop();
			stack(a+b);
			break;

			case '-':
			b=pop();
			a=pop();
			stack(a-b);
			break;

			case '*':
			b=pop();
			a=pop();
			stack(a*b);
			break;

			default:
			a=0;
			while(c[i]<='9' && c[i]>='0'){
				a=a*10+c[i]-'0';
				i++;
			}
			stack(a);

			break;

		}
		i++;
 	}

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

 }


void stack(int n){

	st[point_st] = n;
	point_st++;

	return;
}

int pop(){

	point_st--;
	return st[point_st];
}

Measured memory_bytes: 1828
def rd(n):
    if n==0:
        return input("")
    if n==1:
        return int(input())
    if n==2:
        return map(int,input().split())
    if n==3:
        return list(map(int,input().split()))
def solve():
    n=rd(1)
    A=rd(3)
    d={0:0,1:0,2:0}
    for i in range(n):
        if(A[i]%4==0):
            d[2]+=1
        elif(A[i]%2==0):
            d[1]+=1
        else:
            d[0]+=1
    if((d[0]>d[2]+1) or (d[0]==d[2]+1 and d[1]!=0)):
        print('No')
    else:
        print('Yes')

solve()

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;//res%=MOD;
    n*=n;//n%=MOD;
    k>>=1;
  }
  return res;
}
int d[123456][35];//d[i][j]:iから2^j日で行けるところ
//main
signed main(){
  int N,L,Q;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  cin>>L>>Q;
  std::vector<int> a(Q),b(Q);
  for(int i=0;i<Q;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    if(a[i]>b[i])swap(a[i],b[i]);
  }
  for(int i=0;i<N;i++){
    int l=i+1,r=N;
    while(r-l>1){
      int m=(r+l)>>1;
      if(v[m]<=v[i]+L)l=m;
      else r=m;
    }
    d[i][0]=l;
  }
  for(int j=0;j<35;j++)d[N][j]=N;
  for(int j=1;j<35;j++)
    for(int i=0;i<N;i++)
      d[i][j]=d[d[i][j-1]][j-1];
  for(int i=0;i<Q;i++){
    int ans=0;
    int s=a[i],g=b[i];
    for(int j=34;j>=0;j--){
      if(d[s][j]<=g){
        ans+=pw(2,j);
        s=d[s][j];
      }
    }
    if(s!=g)ans++;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 31872
#include<iostream>
typedef long long int llint;
using namespace std;
int main() {
	llint n;
	cin >> n;
	llint x = n / 11;
	n %= 11;
	if (n == 0) {
		cout << 2 * x << endl;
	}
	else if (n > 6) {
		cout << 2 * (x + 1) << endl;
	}
	else {
		cout << 2 * x + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int digsum (int x) {
  int ans = 0;
  while (x != 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

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

  int ans = 1000;
  for (int a = 1; a < n; a++) {
    int b = n - a;
    ans = min(ans, digsum(a) + digsum(b));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s == "SSS")
  {
    cout << 0 << endl;
  }
  if (s == "SSR" || s == "SRS" || s == "RSS" || s == "RSR")
  {
    cout << 1 << endl;
  }
  if (s == "SRR" || s == "RRS")
  {
    cout << 2 << endl;
  }
  if (s == "RRR")
  {
    cout << 3 << endl;
  }
  
  
  return 0;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<int> vW(N+1, 0), vE(N+1, 0);
	for(int i = 0; i < N; ++i){
		vW[i+1] += vW[i];
		if(S[i] == 'W') vW[i+1]++;
		vE[i+1] += vE[i];
		if(S[i] == 'E') vE[i+1]++;
	}
	int ans = (int)1e9;
	for(int i = 0; i < N; ++i){
		int now = vW[i] + (vE[N] - vE[i+1]);
		if(ans > now) ans = now;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3076
function main(input){
    var input = input.split('\n')
    var input_list = input[1].split(' ')
    var array = new Array(input_list.length)
    var counter = 0

    for(var i=0; i < array.length; i++){
        array[i] = input_list[i]
    }
    while(true){
        //配列走査
        for(var i=0; i<array.length; i++){
            //奇数のとき
            if(array[i]%2!=0){
                console.log(counter)
                return;
            }
            //偶数のときかつ配列が最後のとき
            if(i==array.length-1){
                for(var j=0; j<array.length;j++){
                    array[j] = array[j]/2
                }
                counter +=1
            }
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 9420
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, M, i, a, b;
	scanf("%d%d", &N, &M);
	int *c = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		c[i] = 0;
	}
	for(i = 0; i < M; i++){
		scanf("%d%d", &a, &b);
		a--;
		b--;
		if(a == 0){
			c[b]++;
		}
		if(b == 0){
			c[a]++;
		}
		if(a == N - 1){
			c[b]++;
		}
		if(b == N - 1){
			c[a]++;
		}
	}
	for(i = 1; i < N - 1; i++){
		if(c[i] == 2){
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

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

int main(){
	int m,K;cin>>m>>K;
	if(m==0){
		if(K==0)puts("0 0");
		else puts("-1");
		return 0;
	}
	if(m==1){
		if(K==0)puts("0 0 1 1 ");
		else puts("-1");
		return 0;
	}
	if(K>=(1<<m)){
		puts("-1");return 0;
	}
	rep(i,1<<m){
		if(i!=K)cout<<i<<' ';
	}
	cout<<K<<' ';
	for(int i=(1<<m)-1;i>=0;i--){
		if(i!=K)cout<<i<<' ';
	}
	cout<<K<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long> a(n * 3);
	for (int i = 0; i < n * 3; i++) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[n * 3 - 2 - i * 2];
	}
	cout << ans << endl;
}


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

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

	int N, M;
	scanf("%d %d", &N, &M);

	vector<vector<int>> A(M, vector<int>(2));
	vector<bool> connect_1(N + 1, false);
	vector<bool> connect_N(N + 1, false);

	for (int i = 0; i < M; i++) {
		scanf("%d %d", &A[i][0], &A[i][1]);
	}

	for (int i = 0; i < M; i++) {
		if (A[i][0] == 1) {
			connect_1[A[i][1]] = true;
		}
		if (A[i][1] == N) {
			connect_N[A[i][0]] = true;
		}
	}

	for (int i = 0; i < N + 1; i++) {
		if (connect_1[i] && connect_N[i]) {
			printf("POSSIBLE");
			return 0;
		}
	}

	printf("IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 11264
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, A, B, C = in_nn()
    l = list(map(int, read().rstrip().split()))

    comb = list(itertools.product(range(4), repeat=N))
    ans = 10**9 + 7

    for c in comb:
        if (0 in c) and (1 in c) and (2 in c):
            t = [0] * 3
            m = [-10] * 3
            for i in range(N):
                if c[i] == 3:
                    continue
                t[c[i]] += l[i]
                m[c[i]] += 10

            m[0] += abs(t[0] - A)
            m[1] += abs(t[1] - B)
            m[2] += abs(t[2] - C)

            ans = min(ans, sum(m))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10996
#include<stdio.h>



void trace(int A[],int N);
void insertsort(int A[],int N);




int main(void){

 
  
  int N,i,j;
  
  scanf("%d",&N);

  int A[N];
  for(i=0;i<N;i++){scanf("%d",&A[i]);}

  
  trace(A,N);
  insertsort(A,N);

    return 0;
}





void trace(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");


}





void insertsort(int A[],int N){
  int j,i,v;
  int k;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while((j>=0)&&(A[j]>v)){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}




Measured memory_bytes: 2064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  string a,b;
  cin >> a >> b;
  string s = a+b;
  bool flag = false;
  for(int i = 1; i <= 317; i++) {
    int tmp = stoi(s);
    if(tmp == i*i) {
      flag = true;
      break;
    }
  }
  if(flag) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int a[15][15],g[105][105];
int main()
{
	int n,m,i,j,x,y,k,l,o,O,cnt=200;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)for(j=1;j<=m;++j)scanf("%d",&a[i][j]);
	memset(g,-1,sizeof(g));
	for(i=1;i<=n;++i)for(j=1;j<=m;++j)
	{
		for(o=x=0;x<=100&&!o;++x)for(y=0;y<=100&&!o;++y)if(g[x][y]>=0&&g[x][y]+x*i+y*j==a[i][j])o=1;
		if(o)continue;
		for(x=0;x<=100&&!o;++x)for(y=0;y<=100&&!o;++y)if(g[x][y]<0&&x*i+y*j<=a[i][j])
		{
			for(O=0,k=1;k<=n&&!O;++k)for(l=1;l<=m&&!O;++l)if(x*k+y*l+a[i][j]-x*i-y*j<a[k][l])O=1;
			if(!O){g[x][y]=a[i][j]-x*i-y*j;o=1;++cnt;}
		}
		if(!o)return 0*puts("Impossible");
	}
	printf("Possible\n202 %d\n",cnt);
	for(i=1;i<=100;++i)printf("%d %d X\n",i,i+1);
	for(i=102;i<=201;++i)printf("%d %d Y\n",i,i+1);
	for(i=0;i<=100;++i)for(j=0;j<=100;++j)if(g[i][j]>=0)printf("%d %d %d\n",i+1,202-j,g[i][j]);
	puts("1 202");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int M;
    cin >> M;
    cout << 24 + 24 - M << endl;
} 

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  cout << N * N << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string s[3] = {"Sunny", "Cloudy", "Rainy"};
  string T;
  cin >> T;
  if (T[0] == 'S') {
    print(s[1]);
  } else if (T[0] == 'C') {
    print(s[2]);
  } else {
    print(s[0]);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
ostream& operator<<(ostream &os, const vector<int> &st){
  for(int i=0;i<(int)st.size();++i){
    if(i==(int)st.size()-1) os << st[i] << endl;
    else os << st[i] << " ";
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vvi tree(n);
  REP(i,n-1){
    int a,b;
    cin >> a >> b;
    tree[a-1].eb(b-1);
    tree[b-1].eb(a-1);
  }
  vi c(n);
  REP(i,n) cin >> c[i];
  sort(rALL(c));
  if(n==1){
    cout << 0 << endl;
    cout << c[0] << endl;
    return 0;
  }
  queue<int> q;
  q.push(0);
  vi d(n);
  vb used(n,false);
  int id = 0;
  while(!q.empty()){
    int now = q.front();
    q.pop();
    if(used[now]) continue;
    used[now] = true;
    d[now] = c[id++];
    REP(i,tree[now].size()){
      int nx = tree[now][i];
      if(used[nx]) continue;
      q.push(nx);
    }
  }
  cout << accumulate(c.begin()+1,c.end(),0LL) << endl;
  cout << d;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;
    cin>>n>>s;
    ll a[n+1];
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    }
    ll ans=0;
    vector<ll> dp(s+1,0);
    for(int i=1;i<=n;i++){
    	for(int j=s-a[i];j>=0;j--){
    		dp[0]=i;
    		if(j==s-a[i]){
    			ans+=(dp[j]*(n-i+1))%mod;
    			ans%=mod;
    		}
    		else if(j==0){
    			dp[j+a[i]]+=i;
    		}
    		else dp[j+a[i]]+=dp[j];
    		dp[j+a[i]]%=mod;
    	}
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/* 
 *Author : Sisir Ramanan
 *Date : 
 */
 
#include <bits/stdc++.h>

using namespace std;

int main(){

    string s, t;
    cin >> s;
    cin >> t;


    const int n = (int) s.size();
    const int m = (int) t.size();
 
    // initialize dp array
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));

    // fill dp table 
    for(int i = 0; i <= n; ++i){
        for(int j=0; j <= m; ++j){
            if(i==0 || j==0)
                dp[i][j] = 0; // for empty character lcs
            else if(s[i-1] == t[j-1])  // case 1
                dp[i][j] = 1 + dp[i-1][j-1];
            else if(s[i-1] != t[j-1])      // case 2 
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    // length of lcs
    int len = dp[n][m];
    // resulting string
    vector<char> ans(len);

    // backtrack along the dptable to get the characters
    int i=n, j=m; // start with last cell
    int index = len;  // index to store result in ans

    while(i > 0 && j > 0 ){
        
        if(s[i-1] == t[j-1]){
            ans[index-1] = s[i-1];
            index--;
            i--;
            j--;
        } else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        } else {
            j--;
        }

    }

    for(auto c:ans ){ cout << c; }
    cout << endl;
    


	return 0;
}



Measured memory_bytes: 38792
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int P_rank, Q_rank;
  int p, q;
  P_rank = 1;
  Q_rank = 1;
  int answer;
  std::vector<int> rest_vec;
  int tmp_rank;

  int N;
  std::cin >> N;
  for(int i = 1; i <= N; i++){
    rest_vec.push_back(i);
  }
  for(int i = 0; i < N; i++){
      std::cin >> p;

      tmp_rank = 0;
      for(auto j : rest_vec){
	if(j <= p){
	tmp_rank++;
	}else{
	  continue;
	}
      }
      int kaijou = 1;
      for(int i = 1; i < rest_vec.size(); i++){
	kaijou *= i;
      }
      rest_vec.erase(rest_vec.begin() + tmp_rank -1);
      P_rank = P_rank + (tmp_rank-1) * kaijou;
  }

  for(int i = 1; i <= N; i++){
    rest_vec.push_back(i);
  }
  for(int i = 0; i < N; i++){
      std::cin >> q;

      tmp_rank = 0;
      for(auto j : rest_vec){
	if(j <= q){
	tmp_rank++;
	}else{
	  continue;
	}
      }
      int kaijou = 1;
      for(int i = 1; i < rest_vec.size(); i++){
	kaijou *= i;
      }
      rest_vec.erase(rest_vec.begin() + tmp_rank -1);
      Q_rank = Q_rank + (tmp_rank-1) * kaijou;
  }

  answer = P_rank - Q_rank;
  if(answer < 0){
    answer = - answer;
  }
  std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int intcat(int, int, int);

int main(){
  int n, m, l;
  char a[3];
  scanf("%d", &n);
  m=n/100;
  l=intcat(m, m, m);
  if(l<n)
    l=intcat(m+1, m+1, m+1);
  printf("%d\n", l);

  return 0;
}

int intcat(int x, int y, int z){
  int k;
  char buf[256];
  sprintf(buf, "%d%d%d", x, y, z);
  sscanf(buf, "%d", &k);
  return k;
}

Measured memory_bytes: 128
def solve(arr)
  return 0 if arr.uniq.size == 1

  mode = arr.group_by{|e| e}.max_by{|_,v| v.size}.first
  return arr.count{|x| x != mode}
end

n = gets.to_i
v = gets.chomp.split(" ").map(&:to_i)
ve = v.select.with_index {|e,i| i%2==0}
vo = v.select.with_index {|e,i| i%2==1}

if v.uniq.size == 1
  puts n/2
  exit
end

ve_group = ve.group_by{|e| e}.sort_by{|_,v| v.size}
ve_mode = ve_group[-1].first

vo_group = vo.group_by{|e| e}.sort_by{|_,v| v.size}
vo_mode = vo_group[-1].first

if ve_mode == vo_mode
  if ve.uniq.size == 1
    count = vo.size - vo_group[-2][1].size + ve.size - ve_group[-1][1].size
  elsif vo.uniq.size == 1
    count = ve.size - ve_group[-2][1].size + vo.size - vo_group[-1][1].size
  else
    count = [vo.size - vo_group[-2][1].size + ve.size - ve_group[-1][1].size,
             ve.size - ve_group[-2][1].size + vo.size - vo_group[-1][1].size].min
  end
else
  count = ve.size - ve_group[-1][1].size + vo.size - vo_group[-1][1].size
end

puts count


Measured memory_bytes: 28668
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	vector<ll>A;
	cin >> N;
	rep(i, N) {
		ll a;
		cin >> a;
		A.push_back(a);
	}
	vector<ll>B;
	cin >> M;
	rep(i, M) {
		ll b;
		cin >> b;
		B.push_back(b);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.begin());
	vector<ll>C;
	set_difference(A.begin(),A.end(),B.begin(),B.end(),back_inserter(C));
	for (int i = 0; i <C.size();++i) {
		cout << C[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#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())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define PB push_back
#define MP make_pair
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; }

int main(void) {
  int d,g; cin >> d >> g;
  int p[d],c[d],premain[d];
  FOR(i,0,d-1){
    cin >> p[i] >> c[i];
    premain[i] = p[i];
  }

  int n = d;

  int qsumans = 1001001001;

	// {0, 1, ..., n-1} の部分集合の全探索
	for (int bit = 0; bit < (1<<n); ++bit) {
    int ratesum = 0;
    int qsum = 0;
    FOR(i,0,d-1) p[i] = premain[i];

		for (int i = 0; i < n; ++i) {
			if (bit & (1<<i)) { // i が bit に入るかどうか
				ratesum += (i+1) * 100 * p[i] + c[i];
        qsum += p[i];
			}
		}
    // cout << bit << " " << ratesum << endl;
    for (int i = n-1; i >= 0; --i) {
			if(!(bit & (1<<i))) { // i が bit に入るかどうか
				while(ratesum<g && p[i]>0){
          ratesum += (i+1) * 100;
          ++qsum;
          --p[i];
        }
			}
		}

    if(ratesum>=g) chmin(qsumans,qsum);
	}

  cout << qsumans << endl;

  

  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//number of edges in a graph equal (v[i].size() ka summation of all the vertices)/2
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll int n;
    cin>>n;
    ll int z;
    ll int i,s=0;
    for(i=1;i<=n;i++)
    {
    	if(i%3!=0 && i%5!=0 )
    		s=s+i;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const int mod=1e9+7;
int n;
long double solve(int i,int j,long double* p,vector<vector<long double>> &dp,vector<vector<bool>> &vis){
    //cout<<i<<" "<<j<<"\n";
    if(i>=n) return 1;
    if(j<=0) return 1;
    if(j>n-i) return 0;
    if(vis[i][j]) return dp[i][j];
    vis[i][j]=1;
    if(n-i==j){
        //cout<<i<<"\n";
        dp[i][j]=p[i]*solve(i+1,j-1,p,dp,vis);
    }
    else{
        dp[i][j]=p[i]*solve(i+1,j-1,p,dp,vis)+((1-p[i])*(solve(i+1,j,p,dp,vis)));
    }
    //cout<<dp[i][j]<<"\n";
    return dp[i][j];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    cin>>n;
    long double p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
        //cout<<p[i]<<" ";
    }
    //cout<<"\n";
    cout<<fixed<<setprecision(10);

    //memset(dp,-1,sizeof(dp));
    vector<vector<long double>> dp((n+1),vector<long double>((n+3)/2,1));
    vector<vector<bool>> vis((n+1),vector<bool>((n+3)/2,0));
    cout<<solve(0,(n+1)/2,p,dp,vis);
    return 0;
}


Measured memory_bytes: 74812
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int A, B;
    cin >> A >> B;
    cout << A * B - (A + B - 1) << endl;
    return 0;
}


Measured memory_bytes: 256