akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 100005;
 
int n, m;
int par[N];
int sz[N];
int from[N], to[N];
long long ans[N];
long long now;
 
int anc(int u) {
	if (par[u] == u) {
		return u;
	} else {
		return par[u] = anc(par[u]);
	}
}
 
void join(int u,int v) {
	u = anc(u), v = anc(v);
	if (u == v) {
		return;
	}
	now -= (long long) sz[u] * sz[v];
	sz[u] += sz[v];
	par[v] = u;
}
 
int main() {
	scanf("%d %d", &n, &m);
	
	for (int i = 1; i <= n; ++i) {
		par[i] = i;
		sz[i] = 1;
	}
	
	for (int i = 1; i <= m; ++i) {
		scanf("%d %d", from + i, to + i);
	}
	
	now = (long long) n * (n - 1) / 2;
	
	for (int i = m; i > 0; --i) {
		ans[i] = now;
		join(from[i], to[i]);
	}
	
	for (int i = 1; i <= m; ++i) {
		printf("%lld\n", ans[i]);
	} 
	
}

Measured memory_bytes: 3712
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100005];

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

signed main()
{
	int n=read(), m=read(), ans=0;
	for (int i=1; i<=m; i++) a[i]=read();
	sort(a+1, a+m+1);
	for (int i=1; i<m; i++) a[i]=a[i+1]-a[i];
	sort(a+1, a+m);
	for (int i=1; i<=m-n; i++) ans+=a[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
import bisect
N = int(input())
S = input()

str_dict = {}
for s in S:
    str_dict[s] = []

for i, s in enumerate(S):
    bisect.insort_right(str_dict[s], i)
cnt = 0
for i in range(10):
    for j in range(10):
        for t in range(10):
            test_str = str(i) + str(j) + str(t)
            now_idx = -1
            flg = True
            for k in test_str:
                if not k in str_dict.keys():
                    flg = False
                    break
                try:
                    tmp = str_dict[k][bisect.bisect_left(str_dict[k], now_idx+1)]
                    if tmp != now_idx:
                        now_idx = tmp
                    else:
                        flg = False
                        break
                except:
                    flg = False
                    break
            if flg:
                cnt += 1

print(cnt)

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

int main() {
  int H,W,i,j;
  string T="  ",U,V;
  cin >> H >> W >> U;
  U=' '+U+' ';
  for(i=0;i<W;i++){
    T+=' ';
  }
  for(i=0;i<H-1;i++){
    cin >> V;
    V=' '+V+' ';
    for(j=1;j<W+1;j++){
      if(U.at(j)=='#')cout << '#';
      else{
        int cou=0;
      	for(int I=-1;I<2;I++){
        	if(T.at(j+I)=='#')cou++;
        	if(U.at(j+I)=='#')cou++;
        	if(V.at(j+I)=='#')cou++;
      	}
      	cout << cou ;
      }
    }
    cout <<endl;
    T=U;
    U=V;
  }
  V="";
  for(i=0;i<W+2;i++){
    V+=' ';
  }
  for(j=1;j<W+1;j++){
      if(U.at(j)=='#')cout << '#';
      else{
        int cou=0;
      	for(int I=-1;I<2;I++){
        	if(T.at(j+I)=='#')cou++;
        	if(U.at(j+I)=='#')cou++;
        	if(V.at(j+I)=='#')cou++;
      	}
      	cout << cou ;
      }
    }
    cout <<endl;
}

Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    X = II()
    S = input()
    l = len(S)
    from collections import defaultdict
    memo = {}
    usedAs1 = defaultdict(lambda : False)
    for i in range(l):
        if usedAs1[S[i]]:
            continue
        usedAs1[S[i]] = True
        usedAs2 = defaultdict(lambda : False)
        for j in range(i+1,l):
            if usedAs2[S[j]]:
                continue
            usedAs2[S[j]] = True
            for k in range(j+1,l):
                memo[S[i]+S[j]+S[k]] = True
    print(len(memo.keys()))



if __name__ == '__main__':
    main()

Measured memory_bytes: 40556
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Float_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
use Ada.Float_Text_IO;

procedure hoge is
 n: integer;
 flag: Integer :=0;
begin
 get(n);
 if (n rem 10)=7 then
  flag:=1;
 end if;
 if (n/10 rem 10)=7 then
  flag:=1;
 end if;
 if (n/100 rem 10)=7 then
  flag:=1;
 end if;
 if flag = 1 then
  put_line("Yes");
 else
  put_line("No");
 end if;
end hoge;

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define lowbit(i) ((i)&(-i))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN = 2 * 1e5 + 15;
ll a[MAXN];
int main() {
#ifdef CitricAcid
    freopen ("input.txt", "rt", stdin);
#endif

    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    int k = n - 2;
    ll res = a[n];
    for(int i = n - 1; i >= 1; i--) {
        if(k == 0) break;
        else if(k == 1) {
            res += a[i];
            k--;
        }
        else {
            res += 2 * a[i];
            k -= 2;
        }
    }
    printf("%lld\n", res);

#ifdef CitricAcid
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
/*
# author : CitricAcid
# date : 2020/07/25
*/

Measured memory_bytes: 5372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N;
		long M;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		long[] a = new long[(int) N];
		double check = 0;
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			check += a[i];
		}
		;
		check = check / (4f *M);
		int count = 0;
		while (N - 1 >= 0) {
			count += (a[N - 1] >= check) ? 1 : 0;
			N--;
		}
		System.out.println(count >= M ? "Yes" : "No");
	}
}

Measured memory_bytes: 36028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  inf 2e18
#define  mod 1000000007
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mp make_pair
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  vstr vector<string>
#define  mpii map<int ,int>
#define  mpll map<long long int,long long int >
#define  max3(v,b,ser) max(v,max(b,ser))
#define  min3(v,b,ser) min(v,min(b,ser))
#define  setbits(x) __builtin_popcountll(x)
#define  zerobits(x) __builtinctzll(x) //zeros after rightmost set bit
#define  w(t) ll t; cin>>t; while(t--)
#define  vin(v,m) for(int i=0;i<m;i++){ll x;cin>>x; v.pb(x);}
#define  for0(i,m) for(int i=0;i<m;i++)
#define  for1(i,m) for(int i=1;i<=m;i++)
#define  forn(i,v,b) for(int i=v;i<=b;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(v,val) memset(v,val,sizeof(v))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  eb emplace_back
#define  bs binary_search
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(v, b, ser, d) cerr<<#v<<": "<<v<<" | "<<#b<<": "<<b<<" | "<<#ser<<": "<<ser<<" | "<<#d<<": "<<d<<endl
#define  FF first
#define  SS second
#define  yes "YES"
#define  no "NO"
#define  PI 3.141592653589793238462643383279502884L
#define printv(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" "
// find_by_order(p)  returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.(If not present)
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll Ceil(ll v, ll b) {return v / b + (v % b != 0);}
ll Logn(ll m, ll r) {return (m > r - 1) ? 1 + Logn(m / r, r) : 0;}
ll fastModExp(ll v, ll b) { ll res = 1; while (b > 0) { if (b & 1)res = (res * v) % mod; v = (v * v) % mod; b = b >> 1; } return res;}
ll GCD(ll a, ll b) { if (b == 0)return a; else  return GCD(b, a % b);}
//Chrnlgy: Binary Search,Greedy,XY,dfs and similar
ll LCM(ll v, ll b) {return v / GCD(v, b) * b;}


int main()
{
   FIFO;
   ll d, t, s;
   cin >> d >> t >> s;
   double x = (double)d / s;
   if (t >= x)
      cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main(){
    int m, f, r;

    while(1){
        scanf("%d%d%d", &m, &f, &r);

        if(m + f + r == -3)break;
        else if(m == -1 || f == -1 || m+f<30)printf("F\n");
        else if(m+f>=80)printf("A\n");
        else if(m+f>=65)printf("B\n");
        else if(m+f>=50 || r>=50)printf("C\n");
        else if(m+f>=30)printf("D\n");

    }

    return 0;

}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(void)
{
    for(;;){
        int e;
        cin >> e;
        int m = 1<<26;
        if (e == 0){return 0;}
        for(int z = 0 ; z*z*z <= e ; z++){
            for(int y = 0 ; y*y + z*z*z <= e ; y++){
                int x = e - y*y - z*z*z;
                if(x + y + z < m){
                    m = x + y + z;
                }
            }
        }
        cout << m << endl;
    }
}


Measured memory_bytes: 3052
<?php
$stdin = trim(fgets(STDIN));
$judge = 0;

while(true){
	$judge = 0;
	if(strlen($stdin) >= 7 && $judge == 0){
		if(strcmp("dreamer", substr($stdin, strlen($stdin) - 7, strlen($stdin))) == 0){
			$stdin =  substr($stdin, 0, strlen($stdin) - 7);
			$judge = 1;
		}
	}
	if(strlen($stdin) >= 6 && $judge == 0){
		if(strcmp("eraser", substr($stdin, strlen($stdin) - 6, strlen($stdin))) == 0){
			$stdin =  substr($stdin, 0, strlen($stdin) - 6);
			$judge = 1;
		}
	}
	if(strlen($stdin) >= 5 && $judge == 0){
		if(strcmp("dream", substr($stdin, strlen($stdin) - 5, strlen($stdin))) == 0){
			$stdin =  substr($stdin, 0, strlen($stdin) - 5);
			$judge = 1;
		}elseif(strcmp("erase", substr($stdin, strlen($stdin) - 5, strlen($stdin))) == 0){
			$stdin =  substr($stdin, 0, strlen($stdin) - 5);
			$judge = 1;
		}
	}

	if(strcmp("", $stdin) == 0){
		printf("YES");
		break;
	}elseif($judge == 0){
		printf("NO");
		break;
	}
}
?>

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

int main(int argc, const char * argv[]) {
    string S;
    int count = 0;
    int maxv = 0;
    
    cin >> S;
    for (unsigned int i = 0; i < S.length(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            count++;
        } else {
            maxv = max(count, maxv);
            count = 0;
        }
    }
    maxv = max(count, maxv);
    
    cout << maxv << endl;
    
    return 0;
}

Measured memory_bytes: 256
#import sys

#input = sys.stdin.readline
import math
#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True


def main():
#    h,w,a,b = map(int, input().split())
    n = int(input())
    s = input()
    a = s[0:n//2]
    b = s[n//2:]
    if a==b:
        print("Yes")
    else:
        print("No")





if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'




int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	string s="";
	for(int i=0;i<max(n,m);i++)
	{
		s+=min(n,m)+'0';
	}
	cout<<s<<endl;

}

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);

    while ( a > 0 && c > 0 ) {
        c -= b;
        if ( c <= 0 )
            break;
        a -= d;
    }

    if ( a > 0 )
        printf("Yes\n");
    else
        printf("No\n");

    return EXIT_SUCCESS;
}


Measured memory_bytes: 1648
#include<stdio.h>

int main()
{
    int number,i,j;
   // printf("Enter the number\n");
    scanf("%d",&number);

    int primes[100006];

    //populating array with naturals numbers
    for(i = 2; i<=100006; i++)
        primes[i] = i;

    i = 2;
    while ((i*i) <= 100006)
    {
        if (primes[i] != 0)
        {
            for(j=2; j<100006; j++)
            {
                if (primes[i]*j > 100006)
                    break;
                else
                    // Instead of deleteing , making elemnets 0
                    primes[primes[i]*j]=0;
            }
        }
        i++;
    }

    for(i = 2; i<=100006; i++)
    {
        //If number is not 0 then it is prime
        if (primes[i]!=0 && primes[i]>=number){
            printf("%d\n",primes[i]);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    long long x,k,d;
    cin>>x>>k>>d;
	if(x<0)
		x=-x;
    long long r=x/d;
    long long y=x%d;
    if(r>=k)
    {
    	cout<<x-k*d<<endl;
    	return 0;
	}
	else
	{
		long long a=y,b=y-d;
		if((k-r)%2==1)
			a+=d;
		if((k-r-1)%2==1)
			b-=d;
		cout<<min(abs(a),abs(b))<<endl;
	}
	return 0;
}


Measured memory_bytes: 3696
#include<stdio.h>
int main(void)
{
	int n,i,j;
	double v[50],box;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&v[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(v[i]>v[j]){
				box=v[i];
				v[i]=v[j];
				v[j]=box;
			}
		}
	}
	for(i=0;i<n-1;i++){
		v[i+1]=(v[i]+v[i+1])/2.0;
	}
	printf("%lf\n",v[n-1]);
	return 0;
}

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

int main() {
    int n;
    ll sum=0;
    cin>>n;
    map<ll,ll> mp;
    vector<int> a(n);
    rep(i,n) {
        cin>>a[i];
        mp[a[i]]++;
    }
    for (auto it : mp) sum+=it.second*(it.second-1)/2;
    rep(i,n) {
        ll val=mp[a[i]];
        ll before=val*(val-1)/2;
        ll after=(val-1)*(val-2)/2;
        cout<<sum+after-before<<endl;
    }
}   


Measured memory_bytes: 10240
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A_idx(N);
    rep(i, N) {
        int A;
        cin >> A;
        A_idx[i] = make_pair(A, i + 1);
    }
    sort(A_idx.begin(), A_idx.end());
    rep(i, N) {
        cout << A_idx[i].second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=3e5+10;
int main()
{
//    freopen("D:\\untitled3\\in","r",stdin);
    sync;
    int n,k;
    cin>>n>>k;
    int ans=0;
    while (n)
    {
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;
    for(int a=0; a<=n && a*10000<=y; a++) {
        int ry1 = y - a * 10000;
        int rn1 = n - a;
        for(int b=0; b<=rn1 && b*5000<=ry1; b++) {
            int ry2 = ry1 - b * 5000;
            int rn2 = rn1 - b;
            if(rn2>=0 && rn2*1000==ry2) {
                cout << a << " " << b << " " << rn2 << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int num,train,taxi;

    scanf("%d%d%d",&num,&train,&taxi);
    
    if(num*train<taxi||num*train==taxi){
        printf("%d\n",num*train);
    }
    else if(num*train>taxi){
        printf("%d\n",taxi);
    }
   

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define pll             pair<ll,ll>
#define pii             pair<int,int> 
#define mp(a,b)         make_pair(a,b)
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define vb 				vector<bool>
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define FOR(i,a,b) 		for(ll i = a; i <= b ; i++)
#define forn(i,n) 		for(ll i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			ll t;cin>>t;while(t--)
 
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF				INT_MAX
#define INFL			LLONG_MAX
#define max1(x,y) (x)>(y)?(x):(y)
#define ss second
#define ff first
#define MAXN 1000000001

int main(){
    fast
    ll n;
    cin>>n;
    ll arr[n][3];
    forn(i,n){
        forn(j,3)
        cin>>arr[i][j];
    }
    FOR(i,1,n-1){
        arr[i][0]+=max(arr[i-1][1],arr[i-1][2]);
        arr[i][1]+=max(arr[i-1][0],arr[i-1][2]);
        arr[i][2]+=max(arr[i-1][1],arr[i-1][0]);
    }
    cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]))<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;
int MOD = 1e9 + 7;

int main(){
    string s,t; cin >> s >> t;
    string ss = s + s; //sを2つ連結させた文字列
    ll n = s.size();

    vector<vector<ll> > Pos(2 * n + 1,vector<ll>(26,-1)); //文字種chがi文字目以降にでてくる最初の位置

    for(int i=2*n-1;i>=0;i--){
        for(int j=0;j<26;j++){
            Pos[i][j] = Pos[i+1][j];
        }
        Pos[i][ss[i] - 'a'] = i;
    }

    int index = 0, loop = 0;
    for(auto ti : t){
        if(Pos[index][ti - 'a'] == -1){
            cout << -1 << endl;
            return 0;
        }
        if(Pos[index][ti - 'a'] >= n){
            loop++;
            index = Pos[index][ti - 'a'] % n + 1;
        } else {
            index = Pos[index][ti - 'a'] + 1;
        }
    }

    cout << index + loop * n << endl;
}

Measured memory_bytes: 49152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int h, w;
	cin >> h >> w;
	vector<string> maze(h);
	rep(i,h) cin >> maze[i];
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (maze[i][j] == '#') continue;
			queue<pii> q;
			vector<vector<int>> d(h, vector<int> (w, INF));
			q.push(make_pair(i, j));
			d[i][j] = 0;
			while (!q.empty()) {
				auto p = q.front(); q.pop();
				for (int k = 0; k < 4; k++) {
					int ny = dy[k] + p.first;
					int nx = dx[k] + p.second;
					if (0 <= ny && ny < h && 0 <= nx && nx < w && maze[ny][nx] != '#' && d[ny][nx] == INF) {
						q.push(make_pair(ny, nx));
						d[ny][nx] = d[p.first][p.second] + 1;
					}
				}
			}
			int mx = 0;
			rep(x,h) rep(y,w) {
				if (d[x][y] == INF) continue;
				mx = max(mx, d[x][y]);
			}
			ans = max(ans, mx);
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<ll> V(N+1);

    for(int i = 1; i <= N; i++){
        int tmp = i;
        for(int j = 2; j * j <= tmp ; j++){
            while(tmp % j == 0){
                V[j]++;
                tmp /= j;
            }
        }
        V[tmp]++;
    }

    ll ans = 1;
    for(int i = 2; i <= N; i++){
        // cout << i << ": " << V[i] << endl;
        ans = ans * (V[i] + 1) % INF;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a =s.indexOf("A");
		int b=s.lastIndexOf("Z");
		System.out.println(b-a+1);

	}

}


Measured memory_bytes: 28592
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
#define ll long long
ll Euclid(ll a,ll b){
	ll tmp;
	if (a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	ll r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}

int main(){
	ll N,X;
	cin >> N>>X;
	ll i;
  ll a,b;
	cin >> a;
	a=abs(a-X);
	for(i=1;i<N;i++){
		cin >> b;
		b=abs(b-X);
		a=Euclid(a,b);
	}
  cout << a;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<typename T1, typename T2>
inline bool cmn (T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
inline bool cmx (T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int md = 1e9 + 7;
inline void mad(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline void msb(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
template<typename T>
class run_length_encoding {
  vector<pair<int, T>> rle;
  public:
    run_length_encoding(
        vector<T> input
      ) :
      rle()
      {
        int cnt = 0;
        for (auto it = input.begin(); it != input.end(); it++) {
          auto jt = next(it); cnt++;
          if (jt == input.end() || *it != *jt) {
            rle.emplace_back(cnt, *it);
            cnt = 0;
          }
        }
      }
    auto const& code () const {return rle;}
};
int main() {
  int n, m; string s;
  cin >> n >> m >> s;
  vector<int> a(m);
  for (int i = 0; i < m; i++) a[i] = s[0] == s[i];
  auto rle = run_length_encoding<int>(a).code();
  if (rle.size()  == 1) {
    vector<int> dp(n + 1, 0);
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
      mad(dp[i], dp[i - 1]);
      mad(dp[i], dp[i - 2]);
    }
    for (int i = n; i >= 1; i--) msb(dp[i], dp[i - 1]);
    int ret = 1;
    for (int i = 1; i < n; i++) {
      mad(ret, mul(i + 1, dp[n - i]));
    }
    cout << ret << endl;
    return 0;
  }
  if (n & 1) {
    cout << 0 << endl;
    return 0;
  }
  n >>= 1;
  int k = n;
  for (auto it = rle.begin(); it < rle.end() - 1; it += 2) {
    int m = it->first;
    if (m & 1) cmn(k, (m + 1) >> 1);
    else if (it == rle.begin()) cmn(k, (m + 2) >> 1);
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    mad(dp[i], dp[i - 1]);
    mad(dp[i], dp[i - 1]);
    if (i - k - 1 >= 0) msb(dp[i], dp[i - k - 1]);
  }
  for (int i = n; i >= 1; i--) msb(dp[i], dp[i - 1]);
  int ret = 0;
  for (int i = 0; i < k; i++) {
    mad(ret, mul(i + 1, dp[n - i]));
  }
  mad(ret, ret);
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3576
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int k = sc.nextInt(); int c = sc.nextInt();
        String s = sc.next();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) if (s.charAt(i) == 'x') a[i] = 1;
        int [] l = new int[k + 1];
        int [] r = new int[k + 1];
        for (int i = 0, j = 1; i < n; ) {
            if (a[i] == 1) i++;
            else {
                if (j <= k) l[j] = i;
                i += c + 1; j++;
            }
        }
        for (int i = n - 1, j = k; i >= 0; ) {
            if (a[i] == 1) i--;
            else {
                if (j >= 0) r[j] = i;
                i -= (c + 1); j--;
            }
        }
        for (int i = 1; i <= k; i++) if (l[i] == r[i]) out.println((l[i] + 1));
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 48340
#!/usr/bin/env python3

def main():
    A = list(map(int, input().split()))

    D1 = abs(A[1] - A[0])
    D2 = abs(A[2] - A[1])
    D3 = abs(A[0] - A[2])

    print(D1 + D2 + D3 - max(D1, D2, D3))


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)




int main() {
	ll N;
	std::cin >> N;
	vll h(N);
	rep(i, 0, N) {
		std::cin >> h[i];
	}

	vll t(N + 1, 0);
	rep(i, 1, N) {
		t[i + 1] = t[i] + abs(h[i] - h[i - 1]);
		if (i > 1) {
			t[i + 1] = min(t[i + 1], t[i - 1] + abs(h[i] - h[i - 2]));
		}
	}
	std::cout << t[N] << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }else if(6<=a && a<=12){
    cout<<b/2<<endl;
  }else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

// *** ABC060 at 2018/02/19

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solveA();
    }

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        String[] w = sc.nextLine().split(" ");
        String tmp = null;
        for (String c : w) {
            if (tmp == null) {
                tmp = c.substring(c.length() - 1, c.length());
            } else {
                if (tmp.equals(c.substring(0, 1))) {
                    tmp = c.substring(c.length() - 1, c.length());
                } else {
                    System.out.println("NO");
                    return;
                }
            }
        }
        System.out.println("YES");
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

Measured memory_bytes: 23764
from collections import deque
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
if n==2:
	print(a[0])
	exit(0)
ans=a[0]
d=deque()
d.append(a[1])
d.append(a[1])
for i in range(2,n):
	x=a[i]
	ans+=d.popleft()
	d.append(x)
	d.append(x)
print(ans)


Measured memory_bytes: 33128
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
	int k = 0;
	while(true) {
		int payment;
		cin >> payment;
		if ( payment == 0 ) break;
		if ( k != 0 ) cout << endl;
		int coin10;
		cin >> coin10;
		int coin50;
		cin >> coin50;
		int coin100;
		cin >> coin100;
		int coin500;
		cin >> coin500;
		int sum = coin10 * 10 + coin50 * 50 + coin100 * 100 + coin500 * 500;
		int dif = sum - payment;
		int ret500 = dif / 500;
		int ret100 = dif % 500 / 100;
		int ret50 = dif % 100 / 50;
		int ret10 = dif % 50 / 10;
		coin10 = max( 0, coin10 - ret10 );
		coin50 = max( 0, coin50 - ret50 );
		coin100 = max( 0, coin100 - ret100 );
		coin500 = max( 0, coin500 - ret500 );
		if ( coin10 != 0 ) cout << "10 " << coin10 << endl;
		if ( coin50 != 0 ) cout << "50 " << coin50 << endl;
		if ( coin100 != 0 ) cout << "100 " << coin100 << endl;
		if ( coin500 != 0 ) cout << "500 " << coin500 << endl;
		k = 1;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    string S;
    cin >> S;
    long B = 0, ans = 0;
    for(auto i: S){
        if(i == 'B'){
            B++;
        }else{
            ans += B;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1156
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int LEN = 393;

int lower[LEN], upper[LEN], point[LEN];
int dp[LEN + 1][LEN + 1];
int melody[LEN];

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> lower[i] >> upper[i] >> point[i];
    }

    int m;
    cin >> m;
    rep(i, m)
    {
        cin >> melody[i];
    }

    irep(i, n) irep(j, LEN)
    {
        if (i == 0) {
            dp[i][j] = j == 0 ? 0 : -1;
        } else {
            dp[i][j] = dp[i - 1][j];
            for (int k = lower[i - 1]; k <= upper[i - 1]; k++) {
                if (j - k >= 0 && dp[i][j - k] >= 0) {
                    dp[i][j] = max(dp[i][j], dp[i][j - k] + point[i - 1]);
                }
            }
        }
    }

    rep(i, m)
    {
        if (dp[n][melody[i]] < 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    rep(i, m)
    {
        cout << dp[n][melody[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define li long long int
void Oli(){
string s;
cin>>s;
int mx = 0;
int h =0;
for(int i=0;i<s.size();i++){
    if (s[i] == 'R'){
        h++;
    }
    else {
        mx = max (h, mx);
        h =0;
    }
}
mx = max (h, mx);
cout<<mx<<endl;
}
int main(){
int times = 1;
//cin>>times;
while(times--)
Oli();
}


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

using namespace std;

int main(void)
{
  int point;
  vector<int> science;
  vector<int> society;

  for(int i=0;i<6;i++)
    {
      cin >> point;
      
      if(i<4)
	science.push_back(point);
      else
	society.push_back(point);

    }

  sort(science.begin(),science.end(),greater<int> ());
  sort(society.begin(),society.end(),greater<int> ());
  
  cout << science[0]+science[1]+science[2]+society[0] << endl;

  return 0;
}



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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, q;

ll p[MAXN], pref[MAXN], pref1[MAXN][2];
pair <ll, int> X[MAXN];

ll get(int a, int b) {
  return pref[b] - pref[a - 1];
}

pii get_int(int k, ll x) {
  ll lo = 0, hi = 1e9, mid;
  while (lo != hi) {
    mid = (lo + hi) / 2;
    int vece = upper_bound(p + 1, p + n + 2, x + mid) - p;
    int manje = lower_bound(p + 1, p + n + 2, x - mid) - p;
    if (vece - manje >= k) hi = mid;
    else lo = mid + 1;
  }
  int R = upper_bound(p + 1, p + n + 2, x + lo) - p;
  int L = lower_bound(p + 1, p + n + 2, x - lo) - p;
  R--;
  if (R - L + 1 > k) R--;
  return {L, R};
}

pii pom[MAXN];
int pom1[MAXN];

ll solve(int t) {
  if (pom[t].fi == 0) {
    return pref1[n][n % 2];
  }

  int L = pom[t].fi;
  int R = pom[t].sec;
  int poz = n - pom1[t] + 1;

  ll ret = get(poz, n);

  if (poz - R > 1) {
    ret += p[poz - 1];
    if (L - 2 > 0) ret += pref1[L - 2][L % 2];
  }
  else {
    ret += pref1[L - 1][!(L % 2)];
  }
  return ret;
}

ll ans[MAXN];

int main() {
  scanf("%d %d",&n,&q);
  REP(i, n) scanf("%lld",&p[i + 1]);
  REP(i, q) {
    scanf("%lld",&X[i].fi);
    X[i].sec = i;
  }
  sort(X, X + q);
  FOR(i, 1, n + 1) {
    pref[i] = pref[i - 1] + p[i];
    REP(j, 2) pref1[i][j] = pref1[i - 1][j];
    pref1[i][i % 2] += p[i];
  }

  p[n + 1] = 1e9 + 200;

  reverse(X, X + q);
  int tmp = 0;
  REP(i, q) {
    if (X[i].fi >= p[n]) continue;
    int L, R;
    do {
      tmp++;
      auto T = get_int(tmp, X[i].fi);
      L = T.fi;
      R = T.sec;
      //TRACE(tmp _ X[i].fi _ L _ R _ n -tmp + 1);
    } while (R < n - tmp + 1);
    tmp--;
    //TRACE(X[i].fi _ tmp);
    pom[X[i].sec] = get_int(tmp, X[i].fi);
    pom1[X[i].sec] = tmp;
  }
  REP(i, q) ans[i] = solve(i);
  REP(i, q) printf("%lld\n",ans[i]);
  return 0;
}


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

int siguma(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N , A, B;
    cin >> N >> A >> B;

    int total = 0;
    for(int i = 1; i <= N; i++){
        int sum = siguma(i);
        if(A <= sum && sum <= B){
            total += i;
        }

    }

cout << total << endl;
}

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

int main(){
  int n,i;
  int a[100];

  cin >> n;
  for(i=0;i<n;i++)cin >> a[i];
  for(i=0;i<n;i++)cout << a[i] << ((i==n-1)?'\n':' ');
  for(int j=1;j<n;j++){
    int key = a[j];
    i = j-1;
    while(i>=0 && a[i]>key){
      a[i+1] = a[i];
      i--;
    }
    a[i+1] = key;
    for(i=0;i<n;i++)cout << a[i] << ((i==n-1)?'\n':' ');
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <climits>
#include <string>

using namespace std;
typedef long long ll;

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

int h, w;

void dfs(vector<string>& f, int y, int x)
{
    f[y][x] = 'r';
    
    const int dy[] = {1, 0, -1, 0};
    const int dx[] = {0, 1, 0, -1};
    
    rep(i, 4){
        int py = y + dy[i];
        int px = x + dx[i];
        if(py==0 || py==h || px==0 || px==w) continue;
        if(f[py][px] == '#'){
            dfs(f, py, px);
        }
    }
}

int main()
{
    cin >> h >> w;
    
    vector<string> field(h);
    rep(i, h) cin >> field[i];
    
    vector<string> red = field;
    
    rep(i, h){
        rep(j, w){
            char c = field[i][j];
            if(i == 0) c = '#';
            if(j%2 == 0) c = '#';
            if(i == h-1) c = '.';
            cout << c;
        }
        cout << endl;
    }
    
    cout << endl;
    
    rep(i, h){
        rep(j, w){
            char c = field[i][j];
            if(i == h-1) c = '#';
            if(j%2 == 1) c = '#';
            if(i == 0) c = '.';
            cout << c;
        }
        cout << endl;
    }

}


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

enum tag_type {tanri, fukuri};

int main() {
	int m;
	int year;
	int n;
	int type;
	double riritsu;
	int cost;
	long genpon;

	cin >> m;
	for(int _i; _i < m; _i++) {
		long tmp;
		long max = 0;

		cin >> genpon >> year >> n;

		for(int i = 0; i < n; i++) {
			cin >> type;
			cin >> riritsu;
			cin >> cost;

			tmp = genpon;
			if(type == tanri) {
				int sum_rishi = 0;
				for(int j = 0; j < year; j++) {
					int rishi = tmp * riritsu;
					tmp -= cost;
					sum_rishi += rishi;
				}
				tmp += sum_rishi;
			}

			else {
				for(int j = 0; j < year; j++) {
					tmp = tmp + tmp * riritsu - cost;
				}
			}

			if(tmp > max)
				max = tmp;
		}

		cout << max << endl;
	}

	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a,b,c;
  cin >> a >> b;
  ll ans= a+b;
  ans = max(a-b, ans);
  ans = max(a*b, ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define ull unsigned long long
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	char s[15];
	scanf("%s",s);
	if( strcmp(s,"hi")==0 ||
		strcmp(s,"hihi")==0 ||
		strcmp(s,"hihihi")==0 ||
		strcmp(s,"hihihihi")==0 ||
		strcmp(s,"hihihihihi")==0 ){
		printf("Yes");
	}else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
#define mo 1000000007
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=65;
int l,r,lenl,lenr,pl[N],pr[N],dp[N][2][2],ans;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
int dfs(int pos,int x1,int x2){
    if(!pos) return 1;
    if(dp[pos][x1][x2]!=-1) return dp[pos][x1][x2];
    int &res=dp[pos][x1][x2];res=0;
    int t1=x1?pl[pos]:0,t2=x2?pr[pos]:1;
    for(int y=t1;y<=t2;y++)
        for(int x=t1;x<=y;x++)
            res=(res+dfs(pos-1,x1&(x==t1),x2&(y==t2)))%mo;
    return res;
}
signed main(){
    memset(dp,-1,sizeof(dp));
    l=read(),r=read();
    while(l){
        pl[++lenl]=l&1;
        l>>=1;
    }
    while(r){
        pr[++lenr]=r&1;
        r>>=1;
    }
    for(int i=lenl;i<=lenr;i++) ans=(ans+dfs(i-1,i==lenl,i==lenr))%mo;//枚举哪个最高位为1 
    write(ans);
    return 0;
}

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

int main(){
    string s,t;cin>>s>>t;
    int N=s.size();
    map<char,int> mp1_s,mp2_s,mp1_t,mp2_t;
    //mp1 文字が現れた回数
    //mp2 文字に割り当てられた数字
    
    int k=0,j=0;
    for(int i=0;i<N;i++){
        if(mp1_s[s[i]]==0){
            mp1_s[s[i]]++;
            mp2_s[s[i]]=k;
            s[i]=k;
            k++;
        }
        else s[i]=mp2_s[s[i]];
        
        if(mp1_t[t[i]]==0){
            mp1_t[t[i]]++;
            mp2_t[t[i]]=j;
            t[i]=j;
            j++;
        }
        else t[i]=mp2_t[t[i]];

        if(s[i]!=t[i]) {
            cout<<"No"<<endl;
            goto lol;
        }

    }
    cout<<"Yes"<<endl;

    lol:
    
    return 0;

}

Measured memory_bytes: 776