akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int d;
    cin >> d;
    vint c(26);
    cin >> c;
    vector<vint> s(d, vint(26));
    REP(i,d){
        REP(j, 26) { cin >> s[i][j]; }
    }
    vint t(d);
    cin>>t;
    REP(i, d) { t[i]--; }
    ll score = 0;
    vint last(26, -1);
    REP(i, d) {
        int nowcont = t[i];
        last[nowcont] = i;
        score += s[i][nowcont];
        REP(j, 26) { score -= c[j] * (i - last[j]); }
        cout << score << endl;
    }
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	ll n; cin >> n;
	ll a[100005], b[100005], c[100005];
	ll sum[100005];
	map<ll, ll> m;
	rep(i, 0, n){
		cin >> a[i];
		sum[0] += a[i];
		m[a[i]]++;
	}
	ll q; cin >> q;
	rep(i, 1, q+1) cin >> b[i] >> c[i];
	rep(i, 1, q+1){
		ll d = c[i]-b[i];
		sum[i] = sum[i-1]+m[b[i]]*d;
		m[c[i]] += m[b[i]];
		m[b[i]] = 0;
	}
	rep(i, 1, q+1) cout << sum[i] << endl;
	return 0;
}

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

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

int main() {
	int n;
	cin >> n;
	cout << (n % s(n) ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if(a * b > c * d)
    {
        printf("%d",a*b);
    }
    else 
    {
        printf("%d",c*d);
    }
}

Measured memory_bytes: 1712
N=int(input())
A=map(int,input().split())
zero=0
two=0
four=0
for a in A:
    if a%2==0:
        if a%4==0:
            four+=1
        else:
            two+=1
    else:
        zero+=1
# if zero<=four:
#     print("Yes")
# else:
#     print("No")
if two==0:
    if zero<=four+1:#1 4 1 4 1
        print("Yes")
    else:
        print("No")
else:#two exist
    #two まとめればそこは無視できる
    if zero<=four:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 11096
#include <stdio.h>
#include <stdlib.h>
  
int mas[3][3];
int cpy[3][3];
  
void input() {
  int i, j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      scanf("%d", &mas[i][j]);
}
  
void output() {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) printf("%3d", mas[i][j]);
    puts("");
  }
}
  
void copy(int m[3][3], int t[3][3]) {
  int i, j;
  
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++) m[i][j] = t[i][j];
}
  
int calc() {
  int i, sum = 0;
  for(i = 0; i < 9; i++) {
    int v = mas[i/3][i%3];
    if(v) {
      v--;
      sum += abs(i/3-v/3)+abs(i%3-v%3);
    }
  }
  return sum;
}
  
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
  
void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
  
int is_in(int x, int y) {
  return 0<=x&&x<3&&0<=y&&y<3;
}
  
int dfs(int x, int y, int p, int dep, const int lim) {
  int i, h = calc();
  //output();
  if(h == 0) return dep;
  //printf("%d %d %d\n", h, lim, p);
  if(dep+h > lim) return -1;
  
  for(i = 0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i], res;
    if(~p && i == (p+2)%4) continue;
    if(!is_in(nx, ny)) continue;
    swap(&mas[y][x], &mas[ny][nx]);
    res = dfs(nx, ny, i, dep+1, lim);
    if(~res) return res;
    swap(&mas[y][x], &mas[ny][nx]);
  }
  
  return -1;
}
  
void get_empty(int *x, int *y) {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) {
      if(!mas[i][j]) {
    *x = j;
    *y = i;
    return;
      }
    }
  }
}
  
int solve() {
  int x, y, lim, ans;
  get_empty(&x, &y);
  for(lim = 0; lim < 50; lim++) {
    copy(cpy, mas);
    if((ans = dfs(x, y, -1, 0, lim)) != -1) return ans;
    copy(mas, cpy);
  }
  return -1;
}
  
int main() {
  input();
  printf("%d\n", solve());
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    ll x;
    cin>>n>>x;
    ll a[n],ex,ans=0;
    for (i=0;i<n;i++)
        cin>>a[i];
    for (i=0;i<n-1;i++)
    {
        if (a[i]+a[i+1]>x)
        {
            ex=a[i]+a[i+1]-x;
            ans+=ex;
            if (ex<=a[i+1])
                a[i+1]-=ex;
            else
            {
                a[i]-=(ex-a[i+1]);
                a[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
program hrn;
 var
  s1,s2,t:string;
  l1,l2,i,j,f:longint;
 begin
  readln(s1);l1:=length(s1);
  readln(s2);l2:=length(s2);
  if l1<>l2 then f:=1;
  for i:=l2 downto 1 do t:=t+s2[i];
  if s1<>t then f:=1;
  if f=1 then writeln('NO')
         else writeln('YES');
 end.


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int h = in(), w = in(), d = in();
  vector2d<int> a(h, vector<int>(w));
  vector<pair<int, int>> idx(h * w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      a[i][j] = in() - 1;
      idx[a[i][j]] = mp(i, j);
    }
  }

  vector<int64_t> dist(h * w, 0);
  for (int i = 0; i + d < h * w; ++i) {
    dist[i + d] = dist[i] + abs(idx[i].fs - idx[i + d].fs) + abs(idx[i].sc - idx[i + d].sc);
  }

  int q = in();
  while (q--) {
    int l = in() - 1, r = in() - 1;
    cout << dist[r] - dist[l] << endl;
  }
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n,m; cin>>n>>m;
	vector<vector<pair<int,ll>>> G;
	rep(i,n){
		vector<pair<int,ll>> v; G.PB(v);
	}
	rep(i,m){
		int a,b; ll c; cin>>a>>b>>c; a--; b--;
		G[a].PB(MP(b,-c));
	}
	vector<ll> d(n,LINF); d[0]=0LL;
	bool negative=false;
	rep(i,n*2){
		rep(v,n){
			if(d[v]==LINF) continue;
			for(auto e: G[v]){
				if(d[e.first]>d[v]+e.second){
					d[e.first]=d[v]+e.second;
					if(e.first==n-1&&i==n*2-1) negative=true;
				}
			}
		}
	}
	if(!negative) cout<<-d[n-1]<<endl;
	else cout<<"inf"<<endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  long long sum = 0;
  vector<int> v(100001);
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    v[a] += 1;
    sum += a;
  }
  int Q;
  cin >> Q;
  vector<long long> sums(Q);
  for(int i = 0; i < Q; i++){
    int b,c;
    cin >> b >> c;
    v[c] += v[b];
    sum += v[b]*(c-b);
    v[b] = 0;
    sums[i] = sum;
  }
  for(int i = 0; i < Q; i++) cout << sums[i] << endl;
}


Measured memory_bytes: 4532
#include <stdio.h>
 
int main(void)
{
    char c;
    int s[26]={0},i,j;
    while(scanf("%c",&c)!=EOF)for(j=0;j<26;j++)if(c==j+'a'||c==j+'A')s[j]++;
    for(i=0;i<26;i++)printf("%c : %d\n",i+'a',s[i]);
    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<vector>
#include<string>

int main() {
	int h, w, n;
	std::cin >> h >> w >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++)std::cin >> a[i];
	std::vector<std::vector<int>>s(h, std::vector<int>(w));
	int count = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			s[i][j] = count;
			a[count - 1]--;
			if (a[count - 1] == 0) {
				count++;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i % 2)printf("%d ", s[i][w - j - 1]);
			else printf("%d ", s[i][j]);
		}
		printf("\n");
	}
}

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

int main() {
    int H,W;
    string S;
    cin >> H >> W;
    //とりあえず一行目だけを考える
    for(int i = 0; i<W+2; i++){
        cout << "#";
    }
    cout << endl;
    for(int i = 0; i < H; i++){
        cin >> S;
        cout << "#" << S << "#" << endl;
    }
    for(int i = 0; i < W+2; i++){
        cout << "#";
    }
    
}

Measured memory_bytes: 3512
N,M = map(int, raw_input().split())
D = [input() for _ in range(N)]
C = [input() for _ in range(M)]
T = [[10**9]*(N+1) for _ in range(M+1)]
T[0][0] = 0
for i in range(M):
    for j in range(N+1):
        if j<N:
            T[i+1][j+1] = min(T[i+1][j+1], T[i][j]+C[i]*D[j])
        T[i+1][j] = min(T[i+1][j], T[i][j])
print T[M][N]

Measured memory_bytes: 17776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll mod = 1e9 + 7; 
ll BIT1[3010], BIT2[3010];

void add1(int A, ll B) {
	while (A <= 3005) {
		BIT1[A] = (BIT1[A] + B) % mod;
		A += A & -A;
	}
}
ll query1(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae = (kotae + BIT1[A]) % mod;
		A -= A & -A;
	}
	return kotae;
}
void add2(int A, ll B) {
	while (A > 0) {
		BIT2[A] = (BIT2[A] + B) % mod;
		A -= A & -A;
	}
}
ll query2(int A) {
	ll kotae = 0;
	while (A <= 3005) {
		kotae = (kotae + BIT2[A]) % mod;
		A += A & -A;
	}
	return kotae;
}

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

	
	int N;
	cin >> N;
	string S;
	cin >> S;

	ll dp[3001][3001] = {};
	dp[0][1] = 1;

	rep1(i, N - 1) {
		memset(BIT1, 0, sizeof(BIT1));
		memset(BIT2, 0, sizeof(BIT2));
		rep1(j, i) {
			if (S[i - 1] == '<') add1(j + 1, dp[i - 1][j]);
			if (S[i - 1] == '>') add2(j, dp[i - 1][j]);
		}
		rep1(j, i + 1) dp[i][j] = (query1(j) + query2(j)) % mod;
	}

	ll kotae = 0;
	rep1(i, N) kotae = (kotae + dp[N - 1][i]) % mod;
	co(kotae);

	Would you please return 0;
}

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

int n, lW;
vector<int> v,w;
vector<vector<int>> dp;

int main(){
    cin >> n >> lW;
    v.assign(n+1, 0);
    w.assign(n+1, 0);
    dp.assign(n+1, vector<int>(lW+1, 0));
    for(int i=1; i<n+1; i++) cin >> v[i] >> w[i];
    
    for(int i=1; i<n+1; i++){
        for(int j=1; j<lW+1; j++){
            if(j-w[i]<0){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
        }
    }

    cout << dp[n][lW] << endl;
}


Measured memory_bytes: 6788
#include<stdio.h>
int main()
{
	int i,n,count;
	long min=1000000,max=-1000000,sum=0;
	scanf("%d",&count);
	for(i=0;i<count;i++)
{
	scanf("%d",&n);
	if(min>n) min=n;
	if(max<n) max=n;
	sum+=n;	
}
	printf("%ld %ld %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
	int N,K,a,X,Y;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N <= K)
		a = X*N;
		else
			a = X*K+Y*(N-K);
printf("%d\n",a);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int a, b=2;
	cin >> a ;
	if (a % b == 0) {
		cout << a / b;
	}
	else {
		cout << a / b + 1;
	}
}

Measured memory_bytes: 256
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(A[k-1])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int2,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n,x;
void solve()
{
    cin>>n;
    int flag=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x%2==0)
        {
            if(x%3==0||x%5==0)continue;
            flag=1;
        }
    }
    if(flag)cout<<"DENIED";
    else cout<<"APPROVED";
}
int32_t main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
   int N, M, X;
   std::cin >> N >> M >> X;
   int A[M];
   for(int i=0; i<M; ++i)
      std::cin >> A[i];

   int cost[2] = {0, 0};
   for(int i=0; i<M; ++i){
      ++cost[A[i]<X ? 0:1];
   }
   std::cout << (cost[0]<cost[1] ? cost[0]:cost[1]) << std::endl;

   return 0;
   
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static void exec(Scanner in, PrintWriter out) {
		in.nextInt();
		int Q = in.nextInt();
		String S = in.next();
		int[] t = new int[S.length()];
		for (int i = 0; i < t.length - 1; i += 1) {
			if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
				t[i + 1] = t[i] + 1;
			} else {
				t[i + 1] = t[i];
			}
		}
		for (int i = 0; i < Q; i += 1) {
			int l = Integer.parseInt(in.next());
			int r = Integer.parseInt(in.next());
			out.println(t[r - 1] - t[l - 1]);
		}
	}

	public static void main(String[] args) {
		PrintWriter w = new PrintWriter(System.out);
		exec(new Scanner(System.in), w);
		w.flush();
	}
}


Measured memory_bytes: 52740
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
 
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 
 
/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 
 
// Following code is used to print LCS 
int index = L[m][n]; 
 
// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 
 
// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 
 
	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 
 
// Print the lcs 
cout << lcs; 
} 
 
/* Driver program to test above function */
int main() 
{ 
string X,Y;
  cin>>X>>Y;
int m = X.length(); 
int n =Y.length(); 
lcs(X, Y, m, n); 
return 0; 
} 

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

int main() {
    int n;
    cin >> n;
    bool flg = false;
    for (int i = 1; i < 10; ++i) {
        if (n%i == 0) {
            int a = n/i;
            if (1<=a && a<=9) flg = true;
        }
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int next(vector<vector<int>>& rsk,char c,int tmp){
  if(df)print(rsk[c-'a']);
  auto itr=
    upper_bound(rsk[c-'a'].begin(),rsk[c-'a'].end(),rsk[c-'a'][tmp]);
  if(itr==rsk[c-'a'].end()) return 0;
  if(df)print(itr-rsk[c-'a'].begin());
  return itr-rsk[c-'a'].begin();
}

int main(){
  string s,t; cin >>s >>t;
  int n=s.size();
  vector<vector<int>> rsk(26,vector<int>(s.size()+1,0));
  n=s.size();
  rep(i,n) rsk[s[i]-'a'][i+1]=1;
  rep(i,26)rep(j,n){
    rsk[i][j+1]+=rsk[i][j];
  }
  n=t.size();
  int tmp=0,m=0;
  rep(i,n){
    tmp=next(rsk,t[i],tmp);
    if(tmp==0){
      m++;
      tmp=next(rsk,t[i],tmp);
      if(tmp==0){
        if(df)print(t[i]);
        print(-1);
        return 0;
      }
    }
    
  }
  print((long int)m*s.size()+tmp);
}


Measured memory_bytes: 14068
# ABC 120 C

import re

S = input()

l0 = 0
l1 = 0

for i in range(len(S)):
    if S[i] == '0':
        l0 += 1
    elif S[i] == '1':
        l1 += 1

print(min(l0, l1) * 2)


Measured memory_bytes: 3316
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
    n <- readInt
    xs <- replicateM n $ do
        [x, y] <- readInts
        return $ y - x + 1
    print $ sum xs
------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  if (s.size() == 26) {
    int i;
    for (i = s.length()-2; i >= 0; i--)
      if (s[i] < s[i+1]) break;

    if (i < 0) {
      cout << -1 << endl;
      return 0;
    }

    char minl = s[i+1];
    for (int j = i + 2; j < s.length(); j++)
      if (s[i] < s[j] && minl > s[j]) minl = s[j];

    s[i] = minl;

    cout << s.substr(0, i+1) << endl;
  } else {
    bool occur[26];
    fill_n(occur, 26, false);
    for (auto c : s) occur[c-'a'] = true;
    int i;
    for (i = 0; i < 26; i++) if (!occur[i]) break;
    cout << s << (char)(i + 'a') << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool p[8][8];int n,m,a,b;
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){cin>>a>>b;a--;b--;p[a][b]=true;p[b][a]=true;}
	int G[8]={0,1,2,3,4,5,6,7};
	int cnt=0;
	do{
		if(G[0]!=0)continue;
		bool OK=true;
		for(int i=1;i<n;i++){
			if(p[G[i-1]][G[i]]==false)OK=false;
		}
		if(OK==true)cnt++;
	}while(next_permutation(G,G+n));
	cout<<cnt<<endl;
	return 0;
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

int main() {
    int N;
    cin >> N;
    set<string> S;
    REP(i, N) {
        string s;
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
}


Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int W, H; cin >> W >> H;
  vector<P> a(W + H);
  for (int i = 0; i < W; i++) {
    int p; cin >> p;
    a[i] = {p, 0};
  }
  for (int i = 0; i < H; i++) {
    int q; cin >> q;
    a[i + W] = {q, 1};
  }
  sort(begin(a), end(a));
  ll ans {};
  int cp { W + 1 }, cq { H + 1 };
  for (auto x : a) {
    ans += (ll)x.first * ( (!x.second) ? cq : cp );
    ( (x.second) ? cq : cp )--;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int k, s; cin >> k >> s;

	int count = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int u = s - i - j;
			if (0 <= u && u <= k) count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef complex<ld> Point;
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

void solve() {
	int a[5];
	rep(i, 5)cin >> a[i];
	int k; cin >> k;
	if (k >= a[4] - a[0]) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
}
int main() {
	solve();
	//stop
	return 0;
}


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

int N;
const int MAX_N = 100000;
int A[MAX_N];

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

int main() {
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    int a0 = A[0];
    for (int i = 1; i < N; i++){
        a0 = gcd(a0, A[i]);
    }
    cout << a0 << endl;
    return 0;    
}

Measured memory_bytes: 1144
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
	char p[200],p2[100],s[100];

	scanf("%s",p);
	strcpy(p2,p);
	strcat(p,p2);
	scanf("%s",s);

	if(strstr(p,s)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 540
url = "https://atcoder.jp/contests/abc043/tasks/arc059_a"

def main():

    all = int(input())
    num_li = list(map(int, input().split()))

    n = sum(num_li) // all + 1
    end = min(num_li)
    ans = 10000000
    for i in range(n, end - 1, -1):
        tmp = 0
        for v in num_li:
            if v == i:
                continue
            else:
                tmp += keisan(v, i)

        if tmp < ans:
            ans = tmp
    print(ans)

def keisan(v, x):
    return (v - x) ** 2

if __name__ == '__main__':
    main()




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S;
  int Q;
  cin>>S>>Q;
  vector<string> A(2,"");
  int f=0;
  for(int i=0;i<Q;i++){
    int T;
    cin>>T;
    if(T==1)
      f=1-f;
    else{
      int F;
      char C;
      cin>>F>>C;
      A[(f+F-1)%2]+=C;
    }
  }
  reverse(A[f].begin(),A[f].end());
  if(f==1)
    reverse(S.begin(),S.end());
  cout<<A[f]<<S<<A[1-f]<<endl;
}

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

int main() {	
	int a[105];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int count=0;
	int flag=1;
	while(flag){
		flag=0;
		for(int i=n-1;i>0;i--){
			if(a[i]<a[i-1]){
				int temp=a[i];
				a[i]=a[i-1];
				a[i-1]=temp;
				flag=1;
				count++;
			}
		}
	}
	
	for(int i=0;i<n;i++){
		if(i>0) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>

int main() {
	int n, i, max, cnt, temp;
	if (scanf("%d", &n) == 0) return 1;
	cnt = 0;
	max = 0;
	for (i = 0; i < n; i++) {
		if (scanf("%d", &temp) == 0) return 1;
		cnt += temp;
		if (temp > max) max = temp;
	}
	printf("%d", cnt - max / 2);
}

Measured memory_bytes: 128
#include <iostream>

int main() {
	std::string str;
  	std::cin >> str;
  	
  	int cnt1 = 0;
  	for (int i = 0, c = 0; i < str.size(); ++i, c ^= 1) {
    	if (str[i] - '0' == c) {
          ++cnt1;
        }
    }
  
  	int cnt2 = 0;
    for (int i = 0, c = 1; i < str.size(); ++i, c ^= 1) {
    	if (str[i] - '0' == c) {
          ++cnt2;
        }
    }
     
  	std::cout << std::min(cnt1, cnt2) << std::endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
	int n;
	cin>>n;
	ll a[n],b[n];
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	ll anst[100005];
	memset(anst,0,sizeof(anst));
	for(int i=0;i<n;i++){
		anst[a[i]-2]+=1;
		anst[b[i]-1]-=1;
	}
	ll ans=0;
	for(int i=1;i<n;i++){
		anst[i]+=anst[i-1];
	}

	for(int i=0;i<n;i++){
		if(anst[i]>=i+1){
//			ans = max(anst[i],ans);
			ans = i+1;
			//if(i+1>=n)break;
			//if(anst[i+1]<anst[i])ans-=(anst[i]-anst[i+1]);
		}
		//if(anst[ans]>ans)i=ans;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 5444
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n);
	vector<LL> a(n), dp(n + 1);
	cin >> a;
	
	dp[0] = 1000;
	inc(i, n) {
		incID(j, i, n) {
		incID(k, j, n) {
			setmax(dp[k + 1], dp[i] % a[j] + dp[i] / a[j] * a[k]);
		}
		}
	}
	OUT(dp[n]);
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    int n,k,s;cin>>n>>k>>s;
    REP(i,k)cout<<s<<" ";
    if(s==(int)1e9)REP(i,n-k)cout<<(int)1e9-1<<" ";
    else REP(i,n-k)cout<<(int)1e9<<" ";
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// https://atcoder.jp/contests/abc139/tasks/abc139_b
/*
	2 <= A <= 20
	1 <= B <= 20
*/

int main()
{
	int32_t a, b;
	cin >> a >> b;

	if (b == 1) {
		printf("0\n");
		return 0;
	}

	uint32_t result = 0;
	while (1) {
		result++;
		if (b <= a) { break; }
		b -= (a - 1);
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999
#define MAX_V 100010
#define MAX_E 2019

    /*Solve*/

int main(){
    int n,m;
    int food[35]={0};
    cin >> n >> m;
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int f;
            cin >> f;
            food[f]++;
        }
    }
    int res=0;
    rep(i,m+1){
        if(food[i]==n){
            res++;
        }
    }
    cout << res;
}

Measured memory_bytes: 256
from collections import Counter
from operator import mul
from functools import reduce


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
lst_s = ["".join(sorted(input())) for _ in range(N)]
lst_s.sort()

cnt_s = Counter(lst_s)

ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += cmb(v, 2)
print(ans)


Measured memory_bytes: 19960
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <stdbool.h>
long long N;
static long long dp[3100][3100];

// ���DP
// �~�j�}�b�N�X

long long
chmin2(long long  a, long long b) 
{
	 if (a > b){
		 //a = b; //	printf("%ld\n",*a);
		 return b; 
	 }
	 return a;
}

long long
chmax2(long long a, long long b) 
{
	 if (a < b){
		 //a = b; //	printf("%ld\n",*a);
		 return b; 
	 }
	 return a;
}

int 
main(){
	long long i,j,k;
	long long a[4000];
	scanf("%lld",&N);
	for(i=0;i<N;i++)
	{
		scanf("%lld",&a[i]);
	}
	
	#if 1
	long long len;
	for(len=1;len<=N;len++){
		for( i=0;i+len<= N;i++){
			j = i + len;
			
			if((N-len)%2==0)
			dp[i][j] = chmax2(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
			else
			dp[i][j] = chmin2(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
		}
    }
    #endif
	
	printf("%lld\n",dp[0][N]);

	
 return 0;
}

Measured memory_bytes: 73984
S_a = input()
S_b = input()
S_c = input()
a = []
b = []
c = []
for i in range(len(S_a)):
    a.append(S_a[i])
for j in range(len(S_b)):
    b.append(S_b[j])
for k in range(len(S_c)):
    c.append(S_c[k])
l = a
winner = 'A'
while len(l) > 0:
    x = l.pop(0)
    if x == 'a':
        l = a
        winner = 'A'
    elif x == 'b':
        l = b
        winner = 'B'
    else:
        l = c
        winner = 'C'
print(winner)

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

int main(){
	int n ;
	cin >> n;
	cout << pow(n, 3) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(n); 
    rep(i, 0, n) cin >> s[i];
    vector<string> t = s;   
    int ans = 0; 
    rep(i, 0, n){
        rep(j, 0, n){
            rep(k, 0, n){
                t[j][k] = s[(j + i) % n][k];
            }
        }
        bool g = true;
        rep(j, 0, n){
            rep(k, 0, n){
                if(t[j][k] != t[k][j]) g = false;
            }
        }
        if(g) ans += n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;
ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];
int main(){
	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}
	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}
	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<K;i++){
     sum+=p[i];
  }
  cout<<sum<<endl;
  return 0;  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,head[MAXN],sumE,deg[MAXN];
int64 up[MAXN],A[MAXN];
bool flag = 0;
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u,int fa) {
    if(deg[u] == 1) {up[u] = A[u];return;}
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs(v,u);
	    if(flag) return;
	}
    }
    int64 md = 0;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    md = max(up[v],md);
	    up[u] += up[v];
	}
    }
    if(up[u] == 0 && A[u] == 0) return;
    int64 k = min(up[u] / 2,up[u] - md);
    if(up[u] - k > A[u] || up[u] < A[u]) {flag = 1;return;}
    up[u] = A[u] - (up[u] - A[u]);
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(A[i]);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
	read(a);read(b);
	deg[a]++;deg[b]++;
	add(a,b);add(b,a);
    }
    if(N == 2) {
	if(A[1] == A[2]) puts("YES");
	else puts("NO");
	return;
    }
    int rt = 0;
    for(int i = 1 ; i <= N ; ++i) {
	if(deg[i] > 1) rt = i;
    }
    dfs(rt,0);
    if(flag == 1 || up[rt] != 0) puts("NO");
    else puts("YES");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  


void solve(){
	int n , m , k;
	re(n,m,k);
	vi a(n) , b(m);
	re(a,b);
	 partial_sum(begin(a), end(a), begin(a));
  partial_sum(begin(b), end(b), begin(b));
  int res = upper_bound(begin(b), end(b), k) - begin(b), c = 0;
  for (auto e : a) {
    if (e > k) break;
    res = max<int>(res, ++c + (upper_bound(begin(b), end(b), k - e) - begin(b)));
  }
  cout << res << '\n';
}


signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 6348
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, c;
    cin >> n >> c;
    vl x(n), v(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> v[i];
    }
    vvl pcal(2, vl(n + 1, 0));
    vvl psum(2, vl(n + 1, 0));
    pcal[0][0] = v[0] - x[0];
    psum[0][0] = max(0LL, pcal[0][0]);
    for (int i = 1; i < n; ++i) {
        pcal[0][i] = pcal[0][i - 1] + v[i] - (x[i] - x[i - 1]);
        psum[0][i] = max(psum[0][i - 1], pcal[0][i]);
    }
    pcal[1][n - 1] = v[n - 1] - (c - x[n - 1]);
    psum[1][n - 1] = max(0LL, pcal[1][n - 1]);
    for (int i = n - 2; i >= 0; --i) {
        pcal[1][i] = pcal[1][i + 1] + v[i] - (x[i + 1] - x[i]);
        psum[1][i] = max(psum[1][i + 1], pcal[1][i]);
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        chmax(ret, pcal[0][i]);
        chmax(ret, pcal[1][i]);
        if (i != n - 1) {
            chmax(ret, pcal[0][i] + psum[1][i + 1] - x[i]);
            chmax(ret, psum[0][i] + pcal[1][i + 1] - (c - x[i + 1]));
        }
    }
    cout << ret << "\n";
    return 0;
}

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

int main(){
  string S;
  cin >> S;

  string T = "ATCG";
  int ans = 0;
  for(int i = 0; i < S.size(); i++){
    int now = 0;
    for(int j = i; j < S.size(); j++){
      bool ok = false;
      for(int k = 0; k < T.size(); k++){
        if(S[j] == T[k]) ok = true;
      }
      if(ok){
        now++;
        ans = max(now,ans);
      }
      else{
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
vector<vector<int> > v;
void find_root(int n,vector<int> &parent){
	vector<vector<int> > p(n);
	for(int i=0;i<n;i++){
		int sz=v[i].size();
		for(int j=0;j<sz;j++)
		p[v[i][j]].push_back(i);
	}
	for(int i=0;i<n;i++){
		if(p[i].size()==0)
		parent.push_back(i);
	}
}
int dfs(int node,pair<int,int> vi[]){
	int lp_max=0;
	if(vi[node].first==0){
		vi[node].first=1;
		int sz=v[node].size();
		for(int i=0;i<sz;i++){
			int lp=dfs(v[node][i],vi);
			lp_max=max(lp+1,lp_max);
		}
		vi[node].second=lp_max;
	}
	return vi[node].second;
}
int main(){
	int n,e;cin>>n>>e;
	v.resize(n);
	for(int i=0;i<e;i++){
		int n1,n2;cin>>n1>>n2;
		v[n1-1].push_back(n2-1);
	}
	vector<int> parent;pair<int,int> vi[n];
	find_root(n,parent);
	int sz=parent.size(),maximum=0;
	for(int i=0;i<n;i++)
	vi[i].first=0;
	for(int i=0;i<sz;i++)
	maximum=max(maximum,dfs(parent[i],vi));
	cout<<maximum<<endl;
}

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

int main(){
  int64_t n,d;
  cin >> n >> d;
  vector<int>x(n);
  vector<int>y(n);
  for(int i=0;i<n;i++)
    cin >> x.at(i) >> y.at(i);
  int c=0;
  d*=d;
  for(int i=0;i<n;i++){
    if(pow(x.at(i),2)+pow(y.at(i),2)<=d)
      c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

long long int dp[31];

int main(){
	int n;
	while(cin>>n&&n){
		for(int i=0; i<=n; ++i){
			dp[i]=0;
		}
		dp[0]=1;
		for(int i=1; i<=n; ++i){
			if(i>=1){
				dp[i]+=dp[i-1];
			}
			if(i>=2){
				dp[i]+=dp[i-2];
			}
			if(i>=3){
				dp[i]+=dp[i-3];
			}
		}
		int ans=(((dp[n]+9)/10)+364)/365;
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160