akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
main(){
  int W,Y,x,y,r;
  scanf("%d %d %d %d %d",&W,&Y,&x,&y,&r);
  if(x>=r && y>=r && x+r<=W && y+r<=Y){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

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

void output_array(int arr[], int arr_len)
{
  cout << arr[0];
  for (int i = 1; i < arr_len; ++i)
  {
    cout << ' ' << arr[i];
  }
  cout << endl;
}

int selection_sort(int arr[], int arr_len)
{
  int swap_count = 0;

  for (int i = 0; i < arr_len; ++i)
  {
    int min_index = i;

    for (int j = i; j < arr_len; ++j)
    {
      // Update min_index
      if (arr[j] < arr[min_index])
      {
        min_index = j;
      }
    }

    // If arr[i] is not the minimum element,
    // then swap the two elements
    if (i != min_index)
    {
      swap(arr[i], arr[min_index]);
      ++swap_count;
    }
  }

  return swap_count;
}

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

  int num ,nums[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> num;
    nums[i] = num;
  }

  int swap_count = selection_sort(nums, n);

  output_array(nums, n);
  cout << swap_count << endl;

  return 0;
}


Measured memory_bytes: 3096
n = int(input())
a = list(map(int,input().split()))
a_list = [0 for i in range(10**5)]
q = int(input())
sum_n = 0
ans = []

for num in a:
    a_list[num-1] += 1

for i in range(len(a_list)):
    sum_n += (i+1)*a_list[i]

for i in range(q):
    b, c = map(int,input().split())
    sum_n -= b*a_list[b-1]
    sum_n += c*a_list[b-1]
    a_list[c-1] += a_list[b-1]
    a_list[b-1] = 0
    ans.append(sum_n)

for num in ans:
    print(num)


Measured memory_bytes: 20896
#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

use 5.010;

my @args;
while (<>) {
    chomp;
    push @args, $_;
}

my ($N, $M) = split " ", shift @args;
my $S = shift @args;
my $T = shift @args;


my @S = split "", $S;
my @T = split "", $T;

my $L = saisho($N, $M);
my (%s, %t);
for my $i (0 .. ($N - 1)) {
    $s{$i * $L/$N + 1} = $S[$i];
}
for my $i (0 .. ($M - 1)) {
    $t{$i * $L/$M + 1} = $T[$i];
}

my $ok = 1;
for my $i (keys %s) {
    if (defined $t{$i} and $s{$i} ne $t{$i}) {
        $ok = 0;
        last;
    }
}

if ($ok) {
    say "$L";
} else {
    say "-1";
}

sub saisho {
    my ($a, $b) = @_;
    my $x = $a * $b;
    if ($a < $b) {
        ($a, $b) = ($b, $a)
    }
    my $r = $a % $b;
    while ($r != 0) {
        $a = $b;
        $b = $r;
        $r = $a % $b;
    }
    return $x / $b;
}


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

using namespace std;

typedef long long ll;
double culc(double w,double h){
    double ans;
    ans=w*h;
    
    return ans;
}

int main() {
    int W,H,x,y;cin >> W >> H >> x >> y;
    
    double ans=culc((double)W,(double)H);
    ans/=2;
    int a=(W==x+x)&&(H==y+y);
    
    cout << ans << " " << a << endl;
    
    return 0;

}

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

public class Main {

	void solve() {
		int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt(), e = in.nextInt(), f = in.nextInt();
		int result = a * 100, resSugar = 0;
		double ans = 0;
		for (int cntA = 0; cntA * a * 100 <= f; cntA++) {
			for (int cntB = 0; cntA * a * 100 + cntB * b * 100 <= f; cntB++) {
				for (int cntC = 0; cntA * a * 100 + cntB * b * 100 + cntC * c <= f; cntC++) {
					for (int cntD = 0; cntA * a * 100 + cntB * b * 100 + cntC * c + cntD * d <= f; cntD++) {
						int sugar = cntC * c + cntD * d;
						int water = 100 * (cntA * a + cntB * b);
						if (sugar * 100 <= water * e && sugar * 1.0 / (sugar + water) > ans) {
							ans = sugar * 1.0 / (sugar + water);
							result = sugar + water;
							resSugar = sugar;
						}
					}
				}
			}
		}
		out.println(result + " " + resSugar);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 21076
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

template<int m>
class Prime{
  std::vector<bool> p;
  std::vector<int> ps;
public:
  Prime(){
    p = std::vector<bool>(m,true);
    assert(m>1);
    p[0]=p[1]=false;
    for(int i=4;i<m;i+=2)
      p[i]=false;
    ps.push_back(2);
    for(int i=3;i<m;i+=2){
      if(p[i]){
        ps.push_back(i);
        for(int j=i+i;j<m;j+=i)
          p[j]=false;
      }
    }
  }

  bool isPrime(int n){
    assert(m>n);
    return p[n];
  }

  int operator [] (int n){
    return ps[n];
  }

  int size(){
    return ps.size();
  }
};

int main(){
  Prime<1000000+1000> p;
  ll n;
  while(cin>>n, n){
    long long ans = 1;
    long long org = n;
    for(int i=0; p[i] <= n && (ll)p[i] * p[i] <= org; i++){
      int cc = 0;
      while(n % p[i] == 0){
	cc++;
	n /= p[i];
      }
      if(cc != 0)
	ans *= (cc + 1) + (cc + 1) - 1;
    }

    if(n != 1)
      ans *= 3;

    cout << (ans - 1) / 2 + 1 << endl;
  }
  return 0;
}

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

typedef long long ll;

const int mod = 1000000007;
const int INF = 101234567;

int main() {
    ll n;
    ll ans1, ans2;
    cin >> n;
    vector<ll>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<ll>());
    ans1 = a[0];

    ll x = (ans1+1) / 2;
    int i;
    for (i = 1; i < n; i++) {
        if (a[i] <= x) {
            break;
        }
    }
    if (abs(a[i]-x) > abs(a[i-1]-x)) {
        ans2 = a[i-1];
    } else {
        ans2 = a[i];
    }
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int pos = 0;


		for (int i = 0; i < H; i++) {
			char A[] = sc.next().toCharArray();
			for (int j = 0; j < W; j++) {
				if (A[j] == '#'){
					if (j < pos) {
						System.out.println("Impossible");
						System.exit(0);
					}
					pos = j;
				}
			}
		}




		System.out.println("Possible");


		sc.close();
	}


}


Measured memory_bytes: 10188
n = int(input())
l=sorted(list(map(int,input().split())))
an=l[n-1]
x=l[n-2];cr=n-3;cc=0
for i in range(n-3,-1,-1):
  an+=x
  cc+=1
  if cc!=0 and cc%2==0:
    x=l[cr];cr-=1
  #print(an,x,cr)
print(an)

Measured memory_bytes: 31692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5, INF = 0x3f3f3f3f, M = N << 1;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])

int n, a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  int ans = 0, t = 0;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) {
    if (a[i] > a[i - 1]) {
      ans = max(t, ans);
      t = 0;
      continue;
    }
    t++;
    ans = max(t, ans);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 640
<?php
$attend = [];
for($cnt1 = 0; $cnt1 < 28; $cnt1++){
    $attend[] = trim(fgets(STDIN));
}
 
for($cnt2 = 1; $cnt2 <= 30; $cnt2++){
    if(!in_array($cnt2, $attend)){
        echo $cnt2.PHP_EOL;
    }
}
?>


Measured memory_bytes: 9224
N = int(input())
ans = ''
for i in range(1, 100):
    if N <= pow(26, i):
        N -= 1
        for j in range(i):
            ans = chr(ord('a') + N % 26) + ans
            N //= 26
    else:
        N -= pow(26, i)
    if ans != '':
        break
print(ans)

Measured memory_bytes: 61660
import sys
readline = sys.stdin.readline

def main():
    x1, y1, x2, y2 = map(int, readline().rstrip().split())
    dx = x2 - x1
    dy = y2 - y1
    x3 = x2 - dy
    y3 = y2 + dx
    x4 = x1 - dy
    y4 = y1 + dx
    print(x3, y3, x4, y4)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
# https://atcoder.jp/contests/arc059/tasks/arc059_a

n = int(input())
A = [int(i) for i in input().split()]

ans = 10**9 + 7
for i in range(-100, 101):
    tmp = 0
    for a in A:
        tmp += (i - a)**2
    ans = min(tmp, ans)

print(ans)


Measured memory_bytes: 64708
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
	int x;
  	cin>>x;
  
  switch(x){
    case 3:cout<<"YES"<<endl;
      		break;
    case 5:cout<<"YES"<<endl;
      		break;
    case 7:cout<<"YES"<<endl;  
      		break;
    
    default:cout<<"NO"<<endl;
      		break;
  }
  


}

Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define reps(i, s, n) for(int i = (int)s; i < (int)n; i++)
#define in(i) std::cin >> i;
#define print(i) std::cout << i;
#define println(i) std::cout << i << std::endl;

int main() {
    int K, A, B;
    std::cin >> K >> A >> B;
    int i;
    for(i = K; i <= B; i += K);
    i -= K;
    if(B >= i && A <= i)
        std::cout << "OK";
    else
        std::cout << "NG";
    
    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll n,k; cin>>n>>k;
    ll ans=0;
    while(n>=1){
        n=n/k;
        ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, s.size()) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3912
// cpy frm Chris' sol
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

ll a[200002];
multiset <ll>s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,ans(0); cin >> n;
    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
        s.insert(a[i]);
    }
    sort(a,a+n);
    for (int i = n - 1; i >= 0; i--)
    {
		if (s.find(a[i]) == s.end())
			continue;

		s.erase(s.find(a[i]));
		for (int j = 31; j > 0; j--) {
			// cout << " " << j << endl;
			ll pow2 = (1LL << j);
			auto target = s.find(pow2 - a[i]);

			if (target != s.end()) {
				s.erase(target);
				ans++;
				break;
			}
		}
    }
    cout << ans << endl;
}


Measured memory_bytes: 11264
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
const int maxn=200005;
LL n,a[maxn],ans[maxn];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=2;i<=n;++i)
		ans[1]^=a[i];
	for(int i=2;i<=n;++i)
		ans[i]=(a[i-1]^a[i]^ans[i-1]);
	for(int i=1;i<=n;++i){
		if(i!=1)
			printf(" ");
		printf("%lld",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 6776
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

n, m = map(int, readline().split())
graph = [[] for _ in range(n * 3)]
for i in range(m):
    u, v = map(int, readline().split())
    u -= 1
    v -= 1
    graph[u].append(v + n)
    graph[u + n].append(v + 2 * n)
    graph[u + 2 * n].append(v)
s, t = map(lambda x: int(x) - 1, readline().split())
inf = float('inf')
q = deque([s])
dist = [inf] * (3 * n)
dist[s] = 0

while q:
    now = q.popleft()
    for next in graph[now]:
        if dist[next] != inf:
            continue
        dist[next] = dist[now] + 1
        if next == t:
            print(dist[next] // 3)
            exit()
        q.append(next)
print(-1)


Measured memory_bytes: 60128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
   ll a,b,c,d;cin >> a >> b >> c >> d;
   ll r = b-a+1;
   if(c>d) swap(c,d);
   ll db = b/c+b/d-b/lcm(d,c);
   a--;
   ll da = a/c+a/d-a/lcm(d,c);
   ll ans = r - (db-da);
   cout << ans;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}



Measured memory_bytes: 3660
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>


int main(int argc, char *argv[])
{
	int n,m;
	cin >>n>>m;
	

	cout<< n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }

        long ts = 1;
        long as = 1;
        for (int i = 0; i < n; i++) {
            long nn = Math.max((ts + t[i] - 1) / t[i], (as + a[i] - 1) / a[i]);
            ts = nn * t[i];
            as = nn * a[i];
        }
        System.out.println(ts + as);
    }

}


Measured memory_bytes: 39372
(stdin => {
  // Define Function
  const getA = v => Math.pow(v, 3)

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const X = parseInt(inputs[0], 10)

  console.log(getA(X))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> sum(n, 0);
  map<ll, int> cnt;
  rep(i, n) {
    if (i) sum[i] = sum[i - 1];
    sum[i] += a[i];
    cnt[sum[i]]++;
  }

  ll ans = 0;
  rep(i, n) {
    ll v = (a[i] - sum[i]) * -1;
    ans += cnt[v];
    cnt[sum[i]]--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <string.h>

int maxlen(int str[10]);

int main(void){
  char str[10];
  int acgt[10], i, j, k, len;

  scanf("%s", str);
  for(i=0;i<10;i++){
    acgt[i]=0;
    if(str[i]=='A'||str[i]=='C'||str[i]=='G'||str[i]=='T'){
      acgt[i]+=1;
      for(j=i+1;j<strlen(str);j++){
        if(str[j]=='A'||str[j]=='C'||str[j]=='G'||str[j]=='T'){
          acgt[i]+=1;
        }else{
          break;
        }
      }
    }
  }
  len=0;
  for(k=0;k<strlen(str);k++){
    if(len<acgt[k]){
      len=acgt[k];
    }
  }
  printf("%d\n", len);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;
string a;
string b;
int n;
int m;
int dp[3001][3001];
int dpp[3001][3001];
string s;
int ans = 0;

void printVector(vector<char> s){
    for(auto x:s){
        cout<<x<<"";
    }
    cout<<endl;
}
int rec(int i , int j){
//    cout<<i<<" "<<j<<endl;
    if(i==-1 || j==-1){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(a[i]==b[j]){
        return dp[i][j]  = 1 + rec(i-1 , j-1);
    }
    else{
        return dp[i][j]  = max(rec(i-1 , j) , rec(i,j-1));
    }
}

void f(int i , int j){
    if(i==-1 || j==-1){
        return;
    }

    if(a[i]==b[j]){
        s+=a[i];
        f(i-1 , j-1);
    }
    else{
        if (dp[i-1][j]>dp[i][j-1]){
            f(i-1,j);
        }
        else{
            f(i,j-1);
        }
    }
}




void solve(){
    cin>>a;
    cin>>b;
    for(int i = 0 ; i < 3001 ; i++) for(int j = 0 ; j < 3001 ; j++) dp[i][j] = -1,dpp[i][j]=-1;
    n = a.size()-1;
    m = b.size()-1;
    ans = rec(n,m);
    f(n,m);
    reverse(s.begin(),s.end());
//    cout<<ans<<endl;
    cout<<s<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 144592
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <iterator>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(n % 2 == 1) cout << "No" << endl;
  else{
    bool flag = false;
    for (int i = 0; i < n/2; i++) {
      if(s[i] != s[i+n/2]) flag = true;
    }
    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
#include <cstdio>
int main()
{
    int r;
    scanf("%d", &r);
    if (r < 1200) {
        printf("ABC\n");
        return 0;
    }
    if (r < 2800) {
        printf("ARC\n");
        return 0;
    }
    printf("AGC\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<4;i++){
		if(s[i]=='+')ans++;
		else ans--;
	}
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define endl '\n'
#define ll long long

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    if(A > 12) {
        cout << B << endl;
    }

    else if(A > 5) {
        cout << B/2 << endl;
    }

    else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#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--)

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

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

int main()
{
    int i, n;
    cin >> n;
    double a[n], total=0;
    for(i=0; i<n; i+=1)
        cin >> a[i];
    sort(a, a+n);
    total=(a[0]+a[1])/2;
    for(i=2; i<n; i+=1)
        total=(total+a[i])/2;
    cout << total << endl;
}

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

int main() {
  ll ans;
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  for(int i = 1; i < n; i++){
    int over = a[i] + a[i-1] - x;
    if (over > 0) {
      ans += over;
      if (a[i] - over < 0) {
        a[i-1] -= over - a[i];
        a[i] = 0;
      } else {
        a[i] -= over;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <iostream>
//#include <boost/math/common_factor.hpp>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

#define all(x) x.begin(), x.end()
#define reg(i,x) for(ll i=0;i<x;i++)
#define regi(i,a,x) for(ll i=a;i<x;i++)
#define rev(i,n) for(ll i=n-1;i>0;i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//const ll INF = 1e18;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
ll MAXN=10e9;
int main()
{
    int n,ans=0;
    cin>>n;
    vi v(n);
    reg(i,n) cin>>v[i];
    sort(all(v));
    reg(i,n)
    {
        regi(j,i+1,n)
        {
            regi(k,j+1,n)
            {
                if(v[i]+v[j]>v[k] && v[j]+v[k]>v[i] && v[i]+v[k]>v[j] && v[i]!=v[j] && v[i]!=v[k] && v[j]!=v[k]) ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
int N;
long long A[100010];
long long dp[100010][2];
int GCD(long long x, long long y) { return x ? GCD(y % x, x) : y; }
int main() {
    int N;
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    dp[0][0] = A[0];
    dp[0][1] = 0;
    if(A[1] > A[0]) {
        dp[1][0] = A[1];
        dp[1][1] = 0;
    } else {
        dp[1][0] = A[0];
        dp[1][1] = 1;
    }
    long long maxN = 0;
    int maxi;
    rep(i, 0, 3) {
        if(i == 0) {
            long long GCDN = GCD(A[1], A[2]);
            if(GCDN > maxN) {
                maxN = GCDN;
                maxi = i;
            }
        }
        if(i == 1) {
            long long GCDN = GCD(A[0], A[2]);
            if(GCDN > maxN) {
                maxN = GCDN;
                maxi = i;
            }
        }
        if(i == 2) {
            long long GCDN = GCD(A[0], A[1]);
            if(GCDN > maxN) {
                maxN = GCDN;
                maxi = i;
            }
        }
    }
    dp[2][0] = maxN;
    dp[2][1] = maxi;
    rep(i, 3, N) {
        long long oldGCD = GCD(dp[i - 1][0], A[dp[i - 1][1]]);
        long long newGCD = GCD(dp[i - 1][0], A[i]);
        // cout << oldGCD << endl;
        //     cout << newGCD<< endl;
        if(oldGCD > newGCD) {
            dp[i][0] = oldGCD;
            dp[i][1] = i;
        } else {
            dp[i][0] = newGCD;
            dp[i][1] = dp[i - 1][1];
        }
    }
    cout << dp[N - 1][0] << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int a, b;
    cin >> a >> b;
    if(a<=5) cout << 0 << endl;
    else if(a<=12) cout << b/2 << endl;
    else cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int64_t N, M, X;
    cin >> N >> M >> X;
    vector<vector<int64_t>> C(N, vector<int64_t>(M + 1));
    for (int i = 0; i < N; i++){
        for (int j = 0; j < M + 1; j++){
            cin >> C.at(i).at(j);
        }
    }
    int64_t ans = 1000000000000;
    for (int i = 0; i < pow(2, N); i++){
        int64_t a = i, sum = 0;
        vector<int64_t> e(M);
        bool T = true;
        for (int j = 0; j < N; j++){
            if (a & 1){
                sum += C.at(j).at(0);
                for (int k = 1; k < M + 1; k++){
                    e.at(k - 1) += C.at(j).at(k);
                }
            }
            a >>= 1;

        }
        for (int j = 0; j < M; j++){
            if (e.at(j) < X){
                T = false;
            }
        }
        if (T){
            ans = min(sum, ans);
        }
    }
    if (ans == 1000000000000){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int ma = (n-1)*(n-2)/2;
  if(ma<k) cout << "-1" << endl;
  else{
    vector<pair<int,int>> ans;
    for(int i=1;i<=n-1;++i) ans.push_back(make_pair(i,n));
    int cal=ma-k;
    int tmp1,tmp2;
    tmp1=1;
    tmp2=2;
    for(int j=0;j<cal;++j){
      ans.push_back(make_pair(tmp1,tmp2));
      tmp2++;
      if(tmp2==n){
        tmp1++;
        tmp2=tmp1+1;
      }
    }
    cout << ans.size() << endl;
    for(auto p : ans){
      cout << p.first << " " << p.second << endl;
    }
  }
  return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))

struct ab{
	int a;
	int b;
};

int compare_int(const void *a,const void *b){
	struct ab A=*(struct ab*)a,B=*(struct ab*)b;
	if(A.a>B.a)return 1;
	else if(A.a==B.a)return A.b-B.b;
	return -1;
}

long long dp[3001][6001];
int main(){
	int n,t,i,j;
	long long ans=0;
	struct ab ab[3000];
	scanf("%d%d",&n,&t);
	for(i=0;i<n;i++)scanf("%d%d",&ab[i].a,&ab[i].b);
	qsort(ab,n,sizeof(struct ab),compare_int);
	for(i=0;i<n;i++){
		for(j=0;j<t+ab[n-1].a;j++){
			if(j>=ab[i].a&&j-ab[i].a<t)dp[i+1][j]=max(dp[i][j],dp[i][j-ab[i].a]+ab[i].b);
			else dp[i+1][j]=dp[i][j];
		}
	}
	for(i=0;i<t+ab[n-1].a;i++)ans=max(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 140924
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c,x;
	cin >> a >> b >> c;
	if (c > b/a) {
		x = b / a;
		cout << x << endl;
	}
	else {
		cout << c << endl;
	}


}

Measured memory_bytes: 256
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def full(shape, full_value):
    if isinstance(shape, tuple):
        sha = shape[::-1]
        ret = [full_value] * sha[0]
        for s in sha[1:]:
            ret = [ret.copy() for i in range(s)]
        return ret
    else:
        return [full_value] * shape


'''
例
4 6
#..#..
.x...#
....#.
#.#...

明かりは一つだけおく。
全探索なら4*10**6 でギリ間に合わなさそう?

前処理で縦にいくつ照らせるか事前にわかるのでは?(だめ、わからん)

ある点を調べたときにそこが縦にいくつ伸ばせるのか更新していくのは?
→良さそう

'''
H, W = read_ints()
S = read_map(H)
# まわりを壁でfill
MAP = ['#' * (W + 2)]
for s in S:
    MAP.append('#' + s + '#')
MAP.append('#' * (W + 2))


tate = []
yoko = []
for _ in range(H + 2):
    tmp = [0] * (W + 2)
    tate.append(tmp)
for _ in range(H + 2):
    tmp = [0] * (W + 2)
    yoko.append(tmp)

# yokoの構築
for i in range(H + 2):
    pre = '#'
    for j in range(1, W + 2):
        if pre == '#' and MAP[i][j] == '.':
            s = j
            pre = '.'
        if pre == '.' and MAP[i][j] == '#':
            t = j
            cnt = t - s
            pre = '#'
            for k in range(s, t):
                yoko[i][k] = cnt

# tateの構築
for j in range(W + 2):
    pre = '#'
    for i in range(1, H + 2):
        if pre == '#' and MAP[i][j] == '.':
            s = i
            pre = '.'
        if pre == '.' and MAP[i][j] == '#':
            t = i
            cnt = t - s
            pre = '#'
            for k in range(s, t):
                tate[k][j] = cnt

ans = 0
from itertools import product
for i, j in product(range(H + 2), range(W + 2)):
    if MAP[i][j] == '#':
        continue
    ans = max(ans, tate[i][j] + yoko[i][j] - 1)

print(ans)


Measured memory_bytes: 135388
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 200002;
const int mo = 1e9 + 7;

int n, q, s[maxn], t[maxn], x[maxn];

struct treeNode {
	bool lazy;
	int l, r, minv;
} segTree[maxn<<2];

void build(int idx, int st, int en) {
	segTree[idx].lazy = false;
	segTree[idx].l = st;
	segTree[idx].r = en;
	segTree[idx].minv = INT_MAX;

	if (st < en-1) {
		int mid = (st + en)>>1;
		build(idx*2, st, mid);
		build(idx*2+1, mid, en);
	}
}

void pushDown(int idx) {
		segTree[idx].lazy = false;
		int v = segTree[idx].minv;
		segTree[idx*2].minv = min(segTree[idx*2].minv, v);
		segTree[idx*2+1].minv = min(segTree[idx*2].minv, v);

		segTree[idx*2].lazy = segTree[idx*2+1].lazy = true;
}

void sumUp(int idx) {
	segTree[idx].minv = min(segTree[idx*2].minv, segTree[idx*2+1].minv);
}

void update(int idx, int st, int en, int v) {
	// if (v == 10)
	// 	printf("%d %d %d %d %d\n", idx, segTree[idx].l, segTree[idx].r, segTree[idx].minv, (int)segTree[idx].lazy);
	if (segTree[idx].l + 1 == segTree[idx].r) {
		segTree[idx].minv = min(segTree[idx].minv, v);
		return;
	}

	if (st <= segTree[idx].l && segTree[idx].r <= en) {
		if (v < segTree[idx].minv) {
			segTree[idx].minv = v;
			segTree[idx].lazy = true;
			return;
		}

		if (segTree[idx].lazy)
			return;
	}

	if (segTree[idx].lazy)
		pushDown(idx);

	int mid = (segTree[idx].l + segTree[idx].r) >> 1;
	if (st < mid)
		update(idx*2, st, en, v);
	if (en > mid)
		update(idx*2+1, st, en, v);

	sumUp(idx);
}

int query(int idx, int pos) {
	if (segTree[idx].l + 1 == segTree[idx].r)
		return segTree[idx].minv;
	
	if (segTree[idx].lazy)
		pushDown(idx);

	if (pos < (segTree[idx].l + segTree[idx].r) / 2)
		return query(idx*2, pos);
	else
		return query(idx*2+1, pos);
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> q;
	for (int i = 0; i < n; ++i)
	{
		cin >> s[i] >> t[i] >> x[i];
		s[i] = max(0, s[i] - x[i]);
		t[i] = max(0, t[i] - 1 - x[i]);
	}

	vector<int> d(q);
	for (int i = 0; i < q; ++i)
		cin >> d[i];

	build(1, 0, q);

	for (int i = 0; i < n; ++i)
		if (s[i] <= t[i] && t[i] >= d[0] && s[i] <= d[q-1]) {
			int l = 0, r = q-1, st = 0, en = 0;

			while (l < r) {
				int mid = l + ((r-l)>>1);
				if (d[mid] >= s[i])
					r = mid;
				else
					l = mid+1;
			}

			if (d[l] > t[i])
				continue;

			st = l;
			r = q-1;
			while (l < r) {
				int mid = l + ((r-l)>>1) + 1;
				if (d[mid] <= t[i])
					l = mid;
				else
					r = mid-1;
			}

			en = l;
			// printf("i:%d st:%d %d\n", i, st, en);
			update(1, st, en+1, x[i]);
		}

	for (int i = 0; i < q; ++i) {
		int cur = query(1, i);
		// cout << "i:" << i << " " << cur <<endl;
		if (cur == INT_MAX)
			cout << -1 << endl;
		else
			cout << cur << endl;
	}

	return 0;
}

Measured memory_bytes: 15488
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> h >> w >> n;
  ans = max(h, w);
  ans = (n + ans - 1) / ans;
  Cout(ans);

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e5 + 5, MOD = 1e9 + 7;
ll n, ans;
ll x[MAX_N], y[MAX_N];
ll par[MAX_N];
ll len[MAX_N];
vector <ll> vec[MAX_N];
set <ll> Set[MAX_N];

ll root (ll v) {
	return par[v] == v? v: par[v] = root(par[v]);
}

bool cmp (ll a, ll b) {
	return len[root(a)] > len[root(b)];
}

void add (ll id1, ll id2) {
	for (auto it: Set[id1])
		Set[id2].insert(it);

	len[id2] = Set[id2].size();
	par[id1] = id2;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (ll i = 0; i < MAX_N; i++)
		par[i] = i;

	for (ll i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		vec[y[i]].push_back(x[i]);
		Set[x[i]].insert(y[i]);
		len[x[i]]++;
	}

	for (ll i = 0; i < MAX_N; i++)
		if (1 < vec[i].size()) {
			sort(vec[i].begin(), vec[i].end(), cmp);
			for (ll j = 1; j < vec[i].size(); j++)
				if (root(vec[i][j]) != root(vec[i][0]))
					add(root(vec[i][j]), root(vec[i][0]));
		}

	for (ll i = 0; i < MAX_N; i++)
		ans += len[root(i)];

	cout << ans - n << "\n";
	return 0;
}

Measured memory_bytes: 29696
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls x << 1
#define rs x << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
const db pi = acos(-1.0);
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n;
string s;
vector<int> a;

ll dfs(int i, ll ans, ll now)
{
    if(i >= n) return ans + now;
    return dfs(i + 1, ans + now, a[i]) + dfs(i + 1, ans, now * 10 + a[i]);
}

int main()
{
    cin >> s;
    n = s.size();
    rep(i, 0, n - 1) a.pb((int)s[i] - '0');
    cout << dfs(1, 0, a[0]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n,x,m ;
int arr[500005] ;
string str ;

void solve()
{
    cin >> n >> x >> m ;
    vector<int> v ;
    set<int> s ;
    int power = x ;
    int rem = n ;
    int rep = 0 ;
    int ans = 0 ;
    while(rem>0)
    {

        power %= m ;
        if(s.find(power)!=s.end())
        {
            rep = power ;
            break ;
        }
        ans += power ;
        v.pb(power) ;
        s.insert(power) ;
        power*=power ;
        rem-- ;
    }
    if(rem == 0)
    {
        cout << ans ;
        return ;
    }
    int sum = 0 ;
    int cnt = 0 ;
    int ind = v.size() ;
    for(int i=v.size()-1 ; i>=0 ; i--)
    {
        sum += v[i] ;
        ind = i ;
        cnt++ ;
        if(v[i] == rep)
            break ;
    }
    int t = rem/cnt ;
    ans += t*sum ;
    rem -= t*cnt ;
    for(int i=ind ; i<v.size()&&rem ; i++)
    {
        ans += v[i] ;
        rem-- ;
    }
    cout << ans ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


Measured memory_bytes: 5944
s = raw_input()[::-1]
while len(s):
    if s.startswith("maerd"):
        s = s[5:]
    elif s.startswith("remaerd"):
        s = s[7:]
    elif s.startswith("esare"):
        s = s[5:]
    elif s.startswith("resare"):
        s = s[6:]
    else:
        print "NO"
        exit()
print "YES"


Measured memory_bytes: 2868
h,w,k_=map(int,input().split())
mod=pow(10,9)+7
if w==1:
  print(1)
  exit()
# 遷移の仕方
sen=[[0]*3 for _ in range(w)]
for j in range(2**(w-1)):
  yoko=[0]*(w-1)
  for k in range(w-1):
    if (j>>k) & 1:
      yoko[k]=1
  flg=True
  for k in range(w-2):
    if yoko[k]==1 and yoko[k+1]==1:
      flg=False
      break
  if not flg:continue
  for k in range(w):
    if k==0:
      if yoko[k]==1:
        sen[k+1][0]+=1
      else:
        sen[k][2]+=1
    elif k<w-1:
      if yoko[k]==1:
        sen[k+1][0]+=1
      elif yoko[k-1]==1:
        sen[k-1][1]+=1
      else:
        sen[k][2]+=1
    else:
      if yoko[k-1]==1:
        sen[k-1][1]+=1
      else:
        sen[k][2]+=1

import numpy as np 
dp=np.zeros((h+1,w),int)
dp[0,0]=1
for i in range(h):
  dp[i+1,0]=sen[0][2]*dp[i,0]+sen[0][1]*dp[i,1]
  for j in range(1,w-1):
    dp[i+1,j]=sen[j][2]*dp[i,j]+sen[j][1]*dp[i,j+1]+sen[j][0]*dp[i,j-1]
  dp[i+1,w-1]=sen[w-1][2]*dp[i,w-1]+sen[w-1][0]*dp[i,w-2]
  dp[i+1]%=mod
print(dp[h,k_-1])
#print(dp)

Measured memory_bytes: 27160
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  if (D == 25)
    cout << "Christmas" << endl;
  else if (D == 24)
    cout << "Christmas Eve" << endl;
  else if (D == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        double mLess = 1d / (4 * m);

        int[] arr = new int[n];
        double total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (arr[i] / total >= mLess) count++;

            if (count >= m) break;
        }

        System.out.println(count >= m ? "Yes" : "No");
    }
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	char letras[a];
	char orden[]="ABC";
	cin>>letras;
	int contador=0;
	for(int i=0;i<a-2;i++){
		if(letras[i]==orden[0] && letras[i+1]==orden[1] && letras[i+2]==orden[2]){
			contador++;
		}
	}
	cout<<contador;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define li 100005
#define mp make_pair
#define lo long long 
#define pb push_back
#define inf 1000000000000
#define md 1000000007
lo int n,x[1005],y[1005],h[1005];
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld %lld",&x[i],&y[i],&h[i]);
	}
	for(lo int cx=0;cx<=100;cx++){
		for(lo int cy=0;cy<=100;cy++){
			lo int mx=inf,last=-1,flag=0,olmadi=0;
			for(lo int i=1;i<=n;i++){
				lo int topla=abs(cx-x[i])+abs(cy-y[i]);
				if(h[i]==0) {mx=min(mx,topla);if(last!=-1 && mx<last){olmadi=1;break;};flag=1;}
				else{
					lo int hh=h[i]+topla;
					if(flag==1 && hh>mx){olmadi=1;break;}
					if(last!=-1 && hh!=last){olmadi=1;break;}
					last=hh;
				}
			}
			if(olmadi==0){
				if(last!=-1 && last>=1){
					printf("%lld %lld %lld\n",cx,cy,last);
					return 0;
				}
				else if(mx>=1){
					printf("%lld %lld %lld\n",cx,cy,mx);
					return 0;
				}
			}
		}
	}
	return 0;
}


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

int main() {
  ll n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  bool ans = true;
  rep(i, n - 1) if(s[i] == '#' && s[i + 1] == '#' && i > a && (i < c || i < d))
      ans = false;
  if(c == d)
    ans = false;
  else if(c > d) {
    bool ok = false;
    ll cnt = 0;
    rep(i, n) {
      if(s[i] == '.')
        cnt++;
      else
        cnt = 0;
      if(b < i && cnt > 2 && i <= d + 1) ok = true;
    }
    if(!ok) ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

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

int main(){
    long long N,M,AC,sum;
    AC=sum=0;
    cin>>N>>M;
    vector<long long>P(M);
    vector<string>S(M);
    vector<long long>A(N);
    vector<long long>B(N);
    for(long long i=0;i<N;i++){
        A[i]=0;
        B[i]=0;
    }
    for(long long i=0;i<M;i++){
        cin>>P[i]>>S[i];
    }
    for(long long i=0;i<M;i++){
        if(A[P[i]-1]==0){
            if(S[i]=="WA"){
                B[P[i]-1]++;
                //cout<<P[i]<<endl;
            }
            if(S[i]=="AC"){
                A[P[i]-1]=1;
                AC++;
                sum+=B[P[i]-1];
                //cout<<sum<<endl;
            }
        }
    }
    cout<<AC<<" "<<sum<<endl;
}


Measured memory_bytes: 8064