akhauriyash/Code-Regression huggingface dataset:
from collections import deque

N, X, M = map(int, input().split())

D = deque([X], M)
R = {X: 0}

x = X
for _ in range(min(N-1, M+1)):
  x = (x ** 2) % M
  if x in R:
    l = R[x]
    m = len(D) - l
    q, r = divmod(N - l, m)
    print(sum(D[i] for i in range(l)) + (q+1) * sum(D[i] for i in range(l, l+r)) + q * sum(D[i] for i in range(l+r, l+m)))
    break
  else:
    R[x] = len(D)
    D.append(x)
else:
  print(sum(D))


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string sh; cin >> sh;
	sort(sh.begin(), sh.end());
	if (sh[0] == sh[1] && sh[2] == sh[3] && sh[0] != sh[3])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int f[] = {1, 1, 2, 3, 5, 8, 13, 21};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int h, w, k;
	cin >> h >> w >> k;
	k--;
	vector<vector<ll>> dp(h + 1, vector<ll>(w));
	dp[0][0] = 1;
	for(int i = 1; i <= h; ++i){
		for(int j = 0; j < w; ++j){
			dp[i][j] = dp[i-1][j] * f[j] * f[w - j - 1] % MOD;
			if(j != 0) dp[i][j] += dp[i-1][j-1] * f[j - 1] * f[w - j - 1];
			dp[i][j] %= MOD;
			if(j != w - 1) dp[i][j] += dp[i-1][j+1] * f[j] * f[w - j - 2];
			dp[i][j] %= MOD;
		}
	}
	
	cout << dp[h][k] << "\n";
	return 0;
}


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

 using namespace std;
 int main() {
   char A, B;
   cin >> A >> B;
   if (isdigit(A) && isalpha(B)) cout << "<" << endl;
   else if (isalpha(A) && isdigit(B)) cout << ">" << endl;
   else if (A > B) cout << ">" << endl;
   else if (A == B) cout << "=" << endl;
   else cout << "<" << endl;
 }


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


int main(){
	int n;
	int bl_x = 0;
	int bl_y = 0;
	int tr_x;
	int tr_y;

	cin >> tr_x >> tr_y >> n;
	for(int i = 0; i < n; i++){
		int x, y, a;
		cin >> x >> y >> a;
		switch(a){
			case 1:
				if(x > bl_x) bl_x = x;
				break;
			case 2:
				if(x < tr_x) tr_x = x;
				break;
			case 3:
				if(y > bl_y) bl_y = y;
				break;
			case 4:
				if(y < tr_y) tr_y = y;
				break;
			default:
				break;
		}
	}
	int res_square = (tr_x - bl_x) * (tr_y - bl_y);
	if(tr_x < bl_x) res_square = 0;
	if(tr_y < bl_y) res_square = 0;
	cout << res_square << endl;

	return 0;
}



Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

# b,r = map(str, readline().split())
# A,B = map(int, readline().split())
S = _S()

def main():
    ans = ''
    for _ in range(len(S)):
        ans += 'x'
    return ans
print(main())


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

 using namespace std;

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

   vector<int> W(N);

   for (int i = 0; i < N; i++) cin >> W.at(i);

   int ans = 10000;
   for (int i = 0; i < N - 1; i++) {
     int S1 = 0, S2 = 0;
     for (int j = 0; j < i + 1; j++) S1 += W.at(j);
     for (int k = i + 1; k < N; k++) S2 += W.at(k);
     ans = min(ans, abs(S1 - S2));
     if (ans == 0) break;
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<int> parent;
vector<map<string, int> > child;
vector<bool> isFile;

void addFile(int curr, const string& s, int i)
{
    ++ i;
    if(i >= s.size()){
        isFile[curr] = true;
        return;
    }

    int j = s.find('/', i);
    if(j == string::npos)
        j = s.size();

    string t = s.substr(i, j-i);
    if(child[curr].find(t) == child[curr].end()){
        parent.push_back(curr);
        child.resize(child.size() + 1);
        child[curr][t] = child.size() - 1;
        isFile.push_back(false);
    }

    int next = child[curr][t];
    addFile(next, s, j);
}

int findFile(int curr, const string& s, int i)
{
    if(curr == -1)
        return -1;

    ++ i;
    if(i >= s.size()){
        if(isFile[curr] && i > s.size())
            return curr;
        else if(child[curr].find("index.html") != child[curr].end() && isFile[child[curr]["index.html"]])
            return child[curr]["index.html"];
        else
            return -1;
    }

    if(isFile[curr])
        return -1;

    int j = s.find('/', i);
    if(j == string::npos)
        j = s.size();

    string t = s.substr(i, j-i);
    if(t == ".")
        return findFile(curr, s, j);
    else if(t == "..")
        return findFile(parent[curr], s, j);
    else if(child[curr].find(t) != child[curr].end())
        return findFile(child[curr][t], s, j);
    else
        return -1;
}

int main()
{
    for(;;){
        int n, q;
        cin >> n >> q;
        if(n == 0)
            return 0;

        parent.assign(1, -1);
        child.assign(1, map<string, int>());
        isFile.assign(1, false);

        for(int i=0; i<n; ++i){
            string s;
            cin >> s;
            addFile(0, s, 0);
        }

        for(int i=0; i<q; ++i){
            string s, t;
            cin >> s >> t;

            int a = findFile(0, s, 0);
            int b = findFile(0, t, 0);

            if(a == -1 || b == -1)
                cout << "not found" << endl;
            else if(a == b)
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
    }
}

Measured memory_bytes: 1272
meta = input().split(' ')

num = int(meta[0])
dist = int(meta[1])

count = 0

for i in range(num):
    cdn = [int(s) for s in input().split(' ')]
    if cdn[0] ** 2 + cdn[1] ** 2 <= dist ** 2:
        count += 1

print(str(count))


Measured memory_bytes: 9132
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

const int N = 1e5 + 7;
const long long oo = 1e18L + 5;

int n, k, w[101], v[101];

int main() {
    cin >> n >> k;
    vector<vector<ll> > dp(n + 1, vector<ll>(k + 1, 0));
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int rem_weight = k; rem_weight >= 0; rem_weight--) {
            if (rem_weight >= w[i]) {
                dp[i + 1][rem_weight - w[i]] = max(dp[i + 1][rem_weight - w[i]], dp[i][rem_weight] + v[i]);
            }
            dp[i + 1][rem_weight] = max(dp[i][rem_weight], dp[i + 1][rem_weight]);
        }
    }
    cout << dp[n][0] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; return;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); 
const int N=3e5+5;
int h,w,temp,x,y;
pr a[100][100];
bool dp[100][100][80*160+500+1];
void solve()
{
 // we can prove that max diff will not exceed max. value of a,b;
 //hence dp state is reach index i,j with diff k;
 dp[1][0][0]=1;
 dp[0][1][0]=1;
 
 FOR(i,1,h) FOR(j,1,w) FOR(k,0,80*160+500)
 if(dp[i-1][j][k] or dp[i][j-1][k])
 {
  x=abs(a[i][j].first-a[i][j].second);
  dp[i][j][x+k]=1;
  dp[i][j][abs(x-k)]=1;
 }
 FOR(k,0,80*160+500) if(dp[h][w][k]) cut(k);
 //cout<<"lol \n";
}
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  cin>>h>>w;
  FOR(i,1,h)FOR(j,1,w) cin>>a[i][j].first;
  FOR(i,1,h)FOR(j,1,w) cin>>a[i][j].second;
  solve();
}

Measured memory_bytes: 68028
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
#define mkp make_pair
#define pb push_back
#define pf push_front
#include <string>
#define I ll i,j;
#define J ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll mod=1000000007;
ll mod2=998244353;
ll OO=1e18;
ll david_villa_pow(ll x,ll n){if (n==0)return 1;ll u=david_villa_pow(x,n/2);u=u*u;if (n%2==1)u=u*x;return u;}
ll up(ll x,ll y){if (x%y==0) return x/y; return x/y+1;}
using namespace std;

ll n;
pair <ll,ll> p[200200];
ll dp[200200];
ll Ans[1000100];


ll upd(ll indx,ll st,ll en,ll element,ll val)
{
    if (st==en)
       return Ans[indx]=val;
    ll r1,r2;
    if (element<=(st+en)/2){
        r1=upd(indx*2,st,(st+en)/2,element,val);
        r2=Ans[indx*2+1];
    }
    else
    {
        r1=Ans[indx*2];
        r2=upd(indx*2+1,(st+en)/2+1,en,element,val);
    }
    return Ans[indx]=max(r1,r2);
}

ll query(ll indx,ll st,ll en,ll L,ll R)
{
    if (st>=L&&R>=en)
        return Ans[indx];
    if (st>R||L>en)
        return 0;
    ll r1=query(indx*2,st,(st+en)/2,L,R);
    ll r2=query(indx*2+1,(st+en)/2+1,en,L,R);
    return max(r1,r2);
}

int main()
{
    I;
    cin >>n;
    for (i=1;i<=n;i++)
        cin >>p[i].first;
    for (i=1;i<=n;i++)
        cin >>p[i].second;
    dp[n]=p[n].second;
    upd(1,1,300000,p[n].first,dp[n]);
    ll mx=dp[n];
    for (i=n-1;i>=1;i--)
    {
        dp[i]=query(1,1,300000,p[i].first+1,300000)+p[i].second;
        upd(1,1,300000,p[i].first,dp[i]);
        mx=max(mx,dp[i]);
    }
    cout <<mx<<endl;
    return 0;
}


Measured memory_bytes: 12032
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod=1000000007;
int num[2000],fac[2000],cnt;

int add(int x,int y)
{return (x+y)%mod;}
int sub(int x,int y)
{return (x-y+mod)%mod;}
int mul(int x,int y)
{return 1LL*x*y%mod;}
int fpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1)ans=mul(x,ans);
		y>>=1,x=mul(x,x);
	}
	return ans;
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i*i<=n;++i)
	  if(n%i==0)
	    {
	    	fac[++cnt]=i;
	    	if(i*i<n)
	    	  fac[++cnt]=n/i;
	    }
	sort(fac+1,fac+1+cnt);
	int ans=0;
	for(int i=1;i<=cnt;++i)
	{
		num[i]=fpow(k,(fac[i]+1)>>1);
		for(int j=1;j<i;++j)
		  if(fac[i]%fac[j]==0)
		    num[i]=sub(num[i],num[j]);
		if(fac[i]%2==0)ans=add(ans,mul(num[i],fac[i]>>1));
		else ans=add(ans,mul(num[i],fac[i]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL a,b,c,d,ans;
    cin >> a >> b >> c >> d;
    if (abs(a-b) <= d && abs(b-c) <= d ){
        cout <<"Yes" << endl;
    }else if(abs(a-c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  if len(s) < 2:
    print(-1)
  
  for i in range(len(s)-1):
    if s[i] == s[i+1]:
      print(i+1, i+2)
      return
    if i+2 < len(s) and s[i] == s[i+2]:
      print(i+1, i+3)
      return
  print(-1, -1)    

if __name__=='__main__':
  main()



Measured memory_bytes: 3188
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
    	long A=0,B=0,C=0,AA=0;
		bool H=0;
		int i=2,j=2;
	
		cin >> A;
		cin >> B;
		cin >> C;

		AA=A;

		if(A==1){
			H=1;
		}else if(((A%2)==0)&&((B%2)==0)&&((C%2)==1)){
			H=0;
		}else{
			while((A%B)!=0){
				if(C==(A%B)){
					H=1;
					break;
				}
				A=A+AA;
			}
		}
		
		if(H==1){
			cout << "YES" << endl; 
		}else if(H==0){
			cout << "NO" << endl;
		}
    	return 0;
    }

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = list(map(int,input().split()))

sumn = {0}
for i in a:
    sumn |= {i + x for x in sumn}
for i in b:
    if i in sumn:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repc(i, b, e) for(auto i = (b); i != (e); i++)

int main() {
    ll n;
    vector<ll> v;
    cin >> n;
    ll t;
    rep(i, n) {
        cin >> t;
        v.push_back(t);
    }
    ll sum = 0;
    rep(i, n) {
        cin >> t;
        t = v.at(i) - t;
        if(t > 0) {
            sum += t;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

dic = {}
for i in range(len(s)):
    c = s[i]
    if c not in dic:
        dic[c] = []
    dic[c].append(i)

repeat = 0
focus = 0
ans = 0
for i in range(len(t)):
    c = t[i]
    if c not in dic:
        ans = -1
        break
    if dic[c][-1] < focus:
        repeat += 1
        focus = dic[c][0]+1
    else:
        l = 0
        r = len(dic[c])
        while l < r:
            mid = (r+l)//2
            if(dic[c][mid] < focus):
                l = mid + 1
            else:
                r = mid
        focus = dic[c][l]+1
print(ans if ans == -1 else repeat*len(s)+focus)


Measured memory_bytes: 7540
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    long long i,j,e=1,n,m,x;
    long long a[3];
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    for(i=0;i<2;i++)
    {
        if(a[i]==a[i+1])
        {
            e++;
        }
    }
    if(e==2)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int di[] = {0, 1, 0, -1};
int dj[] = {-1, 0, 1, 0};
int h, w;
vector<string> field;
bool dfs(int ci, int cj, int ck) {
    field[ci][cj] = '@';
    for (int dk = 0; dk < 4; dk++) {
        int nk = (ck - 1 + dk + 4) % 4;
        int ni = ci + di[nk], nj = cj + dj[nk];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (ni == 0 && nj == 0) return true;
        if (field[ni][nj] == '.') {
            if (dfs(ni, nj, nk)) return true;
        }
    }
    field[ci][cj] = 'x';
    return false;
}

int main() {
    while (cin >> h >> w, h) {
        field.resize(h);
        for (string& row: field) cin >> row;
        bool ok = dfs(0, 0, 0);
        ok &= field[0][0] == '@';
        ok &= field[h - 1][0] == '@';
        ok &= field[0][w - 1] == '@';
        ok &= field[h - 1][w - 1] == '@';
        puts(ok ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
	
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  for(ll i = 1; i < n; i++){
    ans *= (k-1);
  }
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math

#n = int(input())
n, l = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

kotae = 0

if (0 < l) :
    kotae = n * (n - 1) / 2 + n * l - l
elif (0 < n + l -1) :
    kotae = n * (n - 1) / 2 + n * l
else :
    kotae = n * (n - 1) / 2 + n * l - (n + l -1)

print(int(kotae))


Measured memory_bytes: 3060
S = input()
if S == 'SSS':
    print(0)
elif S == 'SSR':
    print(1)
elif S == 'SRS':
    print(1)
elif S == 'RSS':
    print(1)
elif S == 'SRR':
    print(2)
elif S == 'RSR':
    print(1)
elif S == 'RRS':
    print(2)
elif S == 'RRR':
    print(3)


Measured memory_bytes: 9044
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n;
    cin >> n;
    set<string> appeared;
    string fs;
    cin >> fs;
    char last = fs[fs.size()-1];
    appeared.insert(fs);
    REP(i, n-1) {
        string s;
        cin >> s;
        if(s[0] != last) {
            cout << "No" << endl;
            return 0;
        }
        if(appeared.find(s) != appeared.end()) {
            cout << "No" << endl;
            return 0;
        }
        appeared.insert(s);
        last = s[s.size()-1];
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

vector<ll> a;

ll dp(vector<vector<ll>> &memo,int l,int r){
  if(memo.at(l).at(r)!=-1e18) return memo.at(l).at(r);
  if(l==r)  return memo.at(l).at(r)=0;
  if(l>r) return -1e18;

  memo.at(l).at(r)=max(-dp(memo,l,r-1)+a.at(r-1),-dp(memo,l+1,r)+a.at(l));
  //cout << l << "," << r << "," << memo.at(l).at(r) << endl;
  return memo.at(l).at(r);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  a.resize(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  vector<vector<ll>> memo(N+1,vector<ll>(N+1,-1e18));
  cout << dp(memo,0,N) << endl;

  return 0;
}

Measured memory_bytes: 71040
input_line = input().split(" ")
N, M = list(map(int, input_line))

H = list(map(int, input().split(" ")))
road_list = [[] for _ in range(N)]
for i in range(M):
	a_i, b_i = list(map(int, input().split(" ")))
	road_list[a_i-1].append(H[b_i-1])
	road_list[b_i-1].append(H[a_i-1])
good_hills = 0
for i, road in enumerate(road_list):
	if len(road) == 0:
		good_hills += 1
	elif H[i] > max(road):
		good_hills += 1

print(good_hills)

Measured memory_bytes: 23120
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Initialize
N = int(input())
S = list(input())

def output(start, end):
    ans = ""
    for i in range(start):
        ans += "("
    for i in S:
        ans += i
    for i in range(end):
        ans += ")"
    return ans

stock = 0
lack_start = 0
lack_end = 0

for s in S:
    if s == '(':
        stock += 1
    elif s == ')':
        if stock > 0:
            stock -= 1
        else:
            lack_start += 1

lack_end = stock
print(output(lack_start, lack_end))


Measured memory_bytes: 3064
// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e7 + 20;

int spf[N];
ll d[N];

void solve() {
  spf[1] = 1;
  for (int i = 2; i < N; i++) {
    if (spf[i] == 0) {
      for (int j = i; j < N; j += i) spf[j] = i;
    }
  }
  d[1] = 1;
  for (int i = 2; i < N; i++) {
    if (spf[i] == i) {
      d[i] = 2;
    } else {
      int a = 1, cnt = 0;
      int no = i;
      while (no > 1 && no % spf[i] == 0) {
        no /= spf[i];
        a = a * spf[i];
        cnt++;
      }
      if (no == 1) {
        d[i] = cnt + 1;
      } else {
        int b = i / a;
        d[i] = d[a] * d[b];
      }
    }
  }
  // for (int i = 1; i < 20; i++) cout << d[i] << " ";

  ll ans = 0;
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) ans += (d[i] * i);
  cout << ans;
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 120808
N,M = map(int,input().split())
A = [int(a) for a in input().split()]
S = sum(A)
m = S/(4*M)
count = 0
for i in range(N):
    if A[i] >= m:
        count += 1
if count >=M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
 
using namespace std;
 
int main()
{
    std::ios_base::sync_with_stdio(false);
     
    string cmd, key;
    int n;
    set<string> dic;
 
    cin >> n;
 
    while(cin >> cmd >> key) {
        if(cmd == "insert") {
            dic.insert(key);
        } else if(cmd == "find") {
            if(dic.find(key) != dic.end()) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
 
}

Measured memory_bytes: 27812
#include <stdio.h>

int main(void){
	int a,b,sum,ans,i;

	while(scanf("%d %d",&a,&b)!=EOF){
		sum = a+b;
		ans = 0;
		i = 0;
		for(i=0; sum>0; i++){
			sum = sum / 10;
			
		}
	printf("%d\n", i);
	}
	
	return 0;

}


Measured memory_bytes: 1976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
     ll x,k,d,ans=0,s;
     cin>>x>>k>>d;
     ll m=x%d;
     if(m<0)m+=d;
     //cout<<m<<endl;
     s=abs(m-x)/d;
     ll m1=m-d;
     ll s1=abs(m1-x)/d;
     if(s1<s)
     {
         s=s1;
     }
     //cout<<s<<endl;
     if(x>0)
         {
             ans=x-s*d;
         }
         else
         {
             ans=x+s*d;
         }
     if(k<s)
     {
         if(x>0)
         {
             ans=x-k*d;
         }
         else
         {
             ans=x+k*d;
         }
         cout<<abs(ans)<<endl;
     }
     else if((k-s)%2==0)
     {

         cout<<abs(ans)<<endl;
     }
     else
     {
         if(abs(ans-d)<abs(ans+d))
         {
             cout<<abs(ans-d)<<endl;
         }
         else
         {
            cout<<abs(ans+d)<<endl;
         }
     }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for (ll i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 
int main() {
  ll ac=0,wa=0,tle=0,re=0,n,c,aan,m,w,memo=0,sx=0,sy=1,ans=0,gx,gy;
  string ka,ss;
  bool flag=true,flag1=false;
  cin>>n;
  rep(i,n){
    cin>>ka;
    if(ka=="AC")ac++;
    if(ka=="WA")wa++;
    if(ka=="TLE")tle++;
    if(ka=="RE")re++;
  }
  vector<int> kosuu(n);
  
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3784
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:map(int,input().split())

n=int(input())
a=list(mii())

bad=0
want=[]
for i in range(n):
    if a[i]>i+1:
        bad=1
        break
    want=want[:a[i]-1]+[a[i]]+want[a[i]-1:]

if bad:
    print(-1)
else:
    for i in want:
        print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a); i<=(b); i++)
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;
 
typedef long long ll;
 
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<char> dq;
    REP(i,0,n-1){
        dq.pb(s[i]);
    }
    int white=0,red=0;
    ll st=0,en=n-1;
    ll ans=0;
    while(en>=0 && dq[en]=='W') en--;
    while(st<en){
        //cout << dq[st] << " " << dq[en] << endl;
        bool change=false;
        if(dq[st]=='W' && dq[en]=='R'){
            //cout << st << " " << en << endl;
            ans++;
            st++;
            en--;
            change=true;
        }
        while(st<n && dq[st]=='R'){
            st++;
            change=true;
        }
        while(en>=0 && dq[en]=='W'){
            en--;
            change=true;
        }
        if(!change) break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3864
S = input()
ans = 0
if len(S) == 1:
    ans += int(S)
for i in range(2**(len(S)-1)):
    binary =list(bin(i)[2:].zfill(len(S)-1))
    S_divide = []
    index = 0
    for j in range(len(S)-1):
        if binary[j] == "1":
            S_divide.append(S[index:j+1])
            index = j+1
        if j == len(S)-2:
            S_divide.append(S[index:])
#    print(S_divide)
    for k in range(len(S_divide)):
        ans += int(S_divide[k])
print(ans)
            
    
        

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main( int argc, char *argv[] ) 
{
	char w[11];
	char p[1001];
	int i, cnt;
	
	scanf( "%s", w );
	i = 0;
	while( w[i] ) { w[i++] = tolower( w[i] ); }
	
	cnt = 0;
	while( EOF != scanf( "%s", p ) ) {
		if( 0 == strcmp( "END_OF_TEXT", p ) ) { break; }
	
		i = 0;
		while( p[i] ) { p[i++] = tolower( p[i] ); }
		if(  0 == strcmp( w, p ) ) {
			cnt++;
		}
	}
	
	printf( "%d\n", cnt );
 
   return 0;
}	

Measured memory_bytes: 556
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    ll n;
    in(n);
    vector<ll> a(n),b(n),plus;
    in(a);
    in(b);
    ll x,minus=0,plussum=0,minusn=0;
    rep(i,n){
        x=a[i]-b[i];
        if(x>0){
            plus.push_back(x);
        }
        if(x<0){
            minus+=x;
            minusn++;
        }
    }
    sort(rall(plus));
    rep(i,plus.size()){
        plussum+=plus[i];
        plus[i]=plussum;
    }
    if(plussum<-minus){
        out(-1);
        return 0;
    }
    minus=-minus;
    ll ans=(ll)(lower_bound(all(plus),minus)-plus.begin())+minusn+1;
    if(minus==0)ans=0;
    //if(*(lower_bound(all(plus),minus))==minus)ans--;
    out(ans);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

int N;

int solve(){
    if(N % 2 == 1) return 0;
    int ans = 0;
    N /= 2;
    rep(i,26){
        ans += N/5;
        N /= 5;
    }
    return ans;
}

signed main(){
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define all(x) x.begin(),x.end()
#define rep(i,m,n) for(int i=m ; i<n ; i++)
#define forr(i,m,n) for(int i=m ; i<=n ; i++)
#define clr(v,val) memset(v,val,sizeof(v))
#define endl '\n'
#define pb push_back
#define pff push_front
#define re return
const int N = 1e5 + 5;
const ll mod=int(1e9)+7;
using namespace std;
int main()
{
ll t,a,k; cin>>t>>a>>k;
ll tmp=k;
k-=min(t,k);
t-=min(tmp,t);
a-=min(k,a);
cout<<t<<" "<<a;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;

int main(){
  ll x;cin >> x;
  ull k,d;cin >> k >> d;


  if( abs(x) >= (ll)k*d ){
    cout << abs(x)-k*d << endl;
    return 0;
  }
  ll now = x;
  for(ll i=1;i<=k;++i){
    if( now > 0 ) now -= d;
    else now += d;
    if( (x >= 0 && now <= 0) || (x <=0 && now >= 0) ){
      if( (k-i)%2 == 0 ){
        cout << abs(now) << endl;
      }else{
        cout << abs(abs(now)-(ll)d) << endl;
      }
      return 0;
    }
  }

  
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;


public class Main{
	
	static final int[] days = new int[]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		while(true){
			int month = sc.nextInt(); if(month == 0) break;
			int day = sc.nextInt();
			System.out.println(whatDay(month, day).toString());
		}
		sc.close();
	}
	
	static int fromJanuary1(int month, int day){
		int result = 0;
		for(int i = 0; i < month - 1; i++) result += days[i];
		return result + day - 1;
	}
	
	static Days whatDay(int month, int day) {
		int fromjan1 = fromJanuary1(month, day);
		int days = fromjan1 % 7;
		if(days == 0) return Days.Thursday;
		else if(days == 1) return Days.Friday;
		else if(days == 2) return Days.Saturday;
		else if(days == 3) return Days.Sunday;
		else if(days == 4) return Days.Monday;
		else if(days == 5) return Days.Tuesday;
		else return Days.Wednesday;
	}
}

enum Days{
	Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

Measured memory_bytes: 17380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define ll long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define per(i,a,n) for(int i = n-1; i >= a; i--)

ll cnt[26];

int main() {
  ll H, W;
  cin >> H >> W;

  rep(i,0,H) {
    rep(j,0,W) {
      char c;
      cin >> c;
      cnt[c-'a']++;
    }
  }

  ll one = 0, two = 0;
  if (H%2 && W%2) {
    one = 1;
    two = H + W - 2;
  }
  else if (H%2) {
    two += W;
  }
  else if (W%2) {
    two += H;
  }
  ll four = H*W - two - one;

  rep(i,0,26) {
    ll f = min(four/4,cnt[i]/4);
    cnt[i] -= f*4;
    four -= f*4;

    ll t = min(two/2,cnt[i]/2);
    cnt[i] -= t*2;
    two -= t*2;

    ll o = min(one,cnt[i]);
    cnt[i] -= o;
    one -= o;

    if (cnt[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define mx3(a,b,c) max(max(a,b),c)
#define pq priority_queue<long long int> 
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
 
int solve(int a[],int b[],int c[],int i,int n,int ch,int dp[][4])
{
    if(i>n)
        return 0;
    if(i==n)
    {
        if(ch==1)
            return max(b[i],c[i]);
        else if(ch==2)
            return max(a[i],c[i]);
        else if(ch==3)
            return max(a[i],b[i]);
        return mx3(a[i],b[i],c[i]);
    }
    if(dp[i+1][1]==-1)
        dp[i+1][1] = a[i+1] + solve(a,b,c,i+2,n,1,dp);
    if(dp[i+1][2]==-1)
        dp[i+1][2] = b[i+1] + solve(a,b,c,i+2,n,2,dp);
    if(dp[i+1][3]==-1)
        dp[i+1][3] = c[i+1] + solve(a,b,c,i+2,n,3,dp);
    dp[i][1] = a[i] + max(dp[i+1][2],dp[i+1][3]);
    dp[i][2] = b[i] + max(dp[i+1][1],dp[i+1][3]);
    dp[i][3] = c[i] + max(dp[i+1][1],dp[i+1][2]);
    if(ch==1)
        dp[i][0] = max(dp[i][2],dp[i][3]);
    else if(ch==2)
        dp[i][0] = max(dp[i][1],dp[i][3]);
    else if(ch==3)
        dp[i][0] = max(dp[i][2],dp[i][1]);
    else
        dp[i][0] = max(max(dp[i][2],dp[i][1]),dp[i][3]);
    return dp[i][0];
}

int main()
{
    flash;
    ll t,n,q,k,i,j;
    t=1;
    int dp[100001][4];
    while(t--)
    {
        cin>>n;
        int a[n],b[n],c[n];
        FOR(i,0,n)  cin>>a[i]>>b[i]>>c[i];
        memset(dp,-1,sizeof(dp));
        cout<<solve(a,b,c,0,n-1,0,dp)<<endl;
    }
}

Measured memory_bytes: 8448
import itertools
n, m, q = map(int, input().split())
lst = []
for _ in range(q):
    lst.append(list(map(int, input().split())))

comb = list(itertools.combinations_with_replacement([_ for _ in range(1,m+1)], n))

ans = 0
for c in comb:
    p = 0
    for l in lst:
        if c[l[1] - 1] - c[l[0] -1] == l[2]:
            p += l[3]
    ans = max(ans, p)
print(ans)

Measured memory_bytes: 21496
n = int(input())
factors = []
p = 2
m = n
while p * p <= m:
    if m % p == 0:
        m //= p
        factors.append(p)
        #m //= p
    else:
        p += 1
if m != 1:
    factors.append(m)
print(f'{n}:', *factors)


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

int main()
{
  string s,t;
  cin>>s>>t;
  int n=s.length();
  int m=t.length();
  int dp[n+1][m+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=m;j++)
    {
      if(i==0 || j==0)
      {
        dp[i][j]=0;
      }
    }
  }
  string r;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
     	if(s[i]==t[j])
        {
          dp[i+1][j+1]=dp[i][j]+1;
         
        }
      else
      {
     	dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
     
      }
    }
  }
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=m;j++)
    {
      if(i==0 || j==0)
      {
        dp[i][j]=0;
      }
    }
  }
  
   int i=n;
  int j=m;
 
 while(dp[i][j]>0)
 {
 	if(dp[i][j]==max(dp[i][j-1],dp[i-1][j]))
 	{
 		if(dp[i][j-1]>=dp[i-1][j])
 		{
 			j--;
 			
 		}
 		else
 		{
 			i--;
 			
 		}
 	}
 	else
 	{
 		i--;
 		j--;
 		r+=s[i];
 		
 	}
 }
 for(int i=r.size()-1;i>=0;i--)
 {
 	cout<<r[i];
 }
}

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

#define rep(i,n) for(int (i) = 0;i < (int)(n);(i)++)
int main(){
    int m,f,r;
    char rating;
    while(1){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        else if(m == -1 || f == -1) rating = 'F';
        else if(m + f >= 80) rating = 'A';
        else if(m + f >= 65) rating = 'B';
        else if(m + f >= 50) rating = 'C';
        else if(m + f >= 30){
            rating = 'D';
            if(r >= 50) rating = 'C';
        }
        else rating = 'F';
        
        cout << rating << endl;
    }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	for (int i = 0; i < h; i++) cin >> s[i];

	int ans = 0;
	for (int bit = 0; bit < (1 << h); bit++) {
		for (int tib = 0; tib < (1 << w); tib++) {
			vector<string> t = s;
			for (int i = 0; i < h; i++) if (bit >> i & 1) {
				for (char &e : t[i]) e = 'x';
			}
			for (int i = 0; i < w; i++) if (tib >> i & 1) {
				for (int j = 0; j < h; j++) t[j][i] = 'x';
			}

			int cnt = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (t[i][j] == '#') cnt++;
				}
			}
			if (cnt == k) ans++;
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
long long pl=0;
long long x[100000000];
int main()
{
long long n,a,b;
cin>>n>>a>>b;
x[0]=0;
for(long long i=1;i<=n;i++)
{
cin>>x[i];
	if(i>1)
	{
	if(a*(x[i]-x[i-1])<=b)
	pl+=a*(x[i]-x[i-1]);
	else
	pl+=b;
	}
}
cout<<pl;
}



Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
    int n,i;
    cin >> n;
    int ara[n];
    for(i=0;i<n;i++){
        cin >> ara[i];
    }
    for(i=0;i<n;i++){
        if(ara[i]%2==0){
            if(!((ara[i]%3 ==0) || (ara[i]%5==0))){
                cout << "DENIED\n";
                return 0;
            }
        }
    }
    if(i==n) cout << "APPROVED\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<cassert>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	ll n, x;
	cin >> n >> x;
	ll g = 0;
	for (int i = 0; i < n; i++) {
		ll t;
		cin >> t;
		t = abs(x - t);
		if (i == 0) g = t;
		else g = gcm(g, t);
	}
	cout << g << endl;
}

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

int W, H;
int board[10][10][3];
int R_end, C_end;

bool solve(int row, int column) {
//	cout << "@" << row << "," << column << endl;
	int nex_row, nex_column;
	nex_row = row+1;
	nex_column = column + nex_row / H;
	nex_row = nex_row % H;

	if(row >= R_end && column >= C_end && !(row == R_end && column == C_end)) {
//		cout << "err" << endl;
		return false;
	}

	if(board[row+1][column+1][0] == 1) {
		if((board[row][column+1][1] & 2) || (board[row+1][column][1] & 1))
			return false;
		board[row+1][column+1][1] = 0;
		board[row+1][column+1][2] = 0;
		return solve(nex_row, nex_column);
	}
	else {
		if((board[row][column+1][1] & 2) && (board[row+1][column][1] & 1)) {
//			cout << "@" << row << "," << column << ":";
//			cout << board[row+1][column][2] << " " << board[row][column+1][2] << endl;
			if(row == R_end && column == C_end && board[row+1][column][2] == board[row][column+1][2])
				return true;
			if((row != R_end || column != C_end) && board[row+1][column][2] == board[row][column+1][2])
				return false;

			board[row+1][column+1][1] = 0;
			
			int cp[10];
			for(int i = 0; i < H; i++)
				cp[i] = board[(row+i)%H+1][column+(row+i)/H][2];

			int tmp = board[row+1][column][2];
			for(int i = 0; i < H; i++) {
				if(board[(row+i)%H+1][column+(row+i)/H][2] == tmp) 
					board[(row+i)%H+1][column+(row+i)/H][2] = board[row][column+1][2];
			}
			board[row+1][column+1][2] = board[row][column+1][2];
			if(solve(nex_row, nex_column))
				return true;

			for(int i = 0; i < H; i++)
				board[(row+i)%H+1][column+(row+i)/H][2] = cp[i];
		}
		else if(board[row][column+1][1] & 2) {
			board[row+1][column+1][2] = board[row][column+1][2];
			for(int i = 0; i < 2; i++) {
				if(board[row+1+i][column+1+!i][0] == 0) {
					board[row+1][column+1][1] = i+1;
					if(solve(nex_row, nex_column))
						return true;
				}
			}
		}
		else if(board[row+1][column][1] & 1) {
			board[row+1][column+1][2] = board[row+1][column][2];
			for(int i = 0; i < 2; i++) {
				if(board[row+1+i][column+1+!i][0] == 0) {
					board[row+1][column+1][1] = i+1;
					if(solve(nex_row, nex_column))
						return true;
				}
			}
		}
		else {
			if(board[row+2][column+1][0] || board[row+1][column+2][0])
				return false;
			board[row+1][column+1][1] = 3;
			int mx = 0;
			for(int i = 0; i < H; i++)
				mx = max(mx, board[(row+i)%H+1][column+(row+i)/H][2]);
			board[row+1][column+1][2] = mx+1;
			return solve(nex_row, nex_column);
		}
	}

	return false;
}

int main() {
	while(cin >> W >> H, W || H) {
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				board[i][j][0] = 1;
				board[i][j][1] = 0;
				board[i][j][2] = 0;
			}
		}

		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				cin >> board[i+1][j+1][0];

		R_end = C_end = 0;
		for(int i = 0; i < W; i++) {
			for(int j = 0; j < H; j++) {
				if(board[j+1][i+1][0] == 0) {
					R_end = j; C_end = i;
				}
			}
		}
		
//		cout << "*" << R_end << " " << C_end << endl;

		if(solve(0,0))
			cout << "Yes" << endl;
		else 
			cout << "No" << endl;
	}
}

Measured memory_bytes: 1156
import sys
a,b = map(int,input().split())
s = list(input())
if len(s) != a + b + 1:
    print("No")
else:
    if s[a] != "-":
        print("No")
    else:
        for i in range(a):
            if s[i] == "-":
                print("No")
                sys.exit()
        for j in range(a+1,len(s)):
            if s[j] == "-":
                print("No")
                sys.exit()
        print("Yes")

Measured memory_bytes: 3064