akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

int p[200005];
vi g[200005];
bool r[200005];
int n;
int possible(int i){
  si tmp;
  for(vi::iterator itr=g[i].begin(); itr!= g[i].end(); itr++){
    tmp.insert(possible(*itr));
  }
  int c=0;
  while(true){
    if (tmp.find(c) == tmp.end()){
      break;
    }
    c++;
  }
  return c;
}
pii possible_ring(int i, int back){
  si tmp;
  bool z=true;
  int a=-1,b=-1,c=0,l;
  for(vi::iterator itr=g[i].begin(); itr!= g[i].end(); itr++){
    if(*itr == back)continue;
    tmp.insert(possible(*itr));
  }
  while(true){
    if (tmp.find(c) == tmp.end()){
      if(z){
        a = c;
        z = false;
      }else{
        b = c;
        return pii(a,b);
      }
    }
    c++;
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 1, n+1){
    ll q;
    cin >> q;
    p[i] = q;
    g[q].pb(i);
  }
  int c = 1,b;
  while(!r[c]){
    r[c] = true;
    b = c;
    c = p[c];
  }
  int cf = c;
  pii f = possible_ring(c, b);
  pii pp = f, np;
  b = c;
  c = p[c];
  while(true){
    int _a, _b;
    np = possible_ring(c, b);
    _a = (pp.first == np.first) ? np.second : np.first;
    _b = (pp.second == np.first) ? np.second : np.first;
    pp = pii(_a, _b);
    if(c == cf)break;
    b = c;
    c = p[c];
  }
  if(f.first == pp.first || f.second == pp.second){
    cout << "POSSIBLE"<<endl;
  }else{
    cout << "IMPOSSIBLE"<<endl;
  }
  return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  bool ok = true;
  for(int i=0;i<n;++i) {
    if(a[i] % 2) continue;
    if(!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
      ok = false;
      break;
    }
  }

  cout << (ok ? "APPROVED" : "DENIED") << endl;

}


Measured memory_bytes: 256
H,W=map(int,input().split())
tmp=[]

for i in range(H):
  l=input()
  if '#' in l:
    tmp.append(l)

ans=[]
for l in zip(*tmp):
  if '#' in l:
    ans.append(''.join(l))

for l in zip(*ans):
  print(''.join(l))

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

bool isEvenTuple(ll a, ll b, ll c) {
	return (a%2==0) && (b%2==0) && (c%2==0);
} 

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (isEvenTuple(a,b,c) && a==b && b==c) {
		cout << -1 << endl;
		return 0;
	}
	while (true)
	{
		if (!isEvenTuple(a, b, c)) break;
		ll x = a/2, y = b/2, z = c/2;
		a = y+z, b = z+x, c = x+y;
		ans++; 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(int i=a;i<b;i++)
#define f0(a,b) for(int i=a;i<b;i++)
#define fn(b,a) for(int i=b;i>a;i--)
#define dbg(x); cout<<"\n"<<#x<<": "<<x;
#define ret return
#define ub upper_bound
#define lb lower_bound
#define psb push_back
#define psf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define sq(a) (a)*(a)
#define fs first
#define sc second
#define el "\n"
#define brk break
#define cont continue
#define all(a) a.begin(),a.end()
#define E9 1000000007
#define E5 100007
#define INF 1e18+7
typedef long long int lli;  //  1e-18 to 1e18
typedef vector<int> vi;
typedef multiset<int> msi;
typedef set<int> si;
typedef string str;
typedef priority_queue<int> pqi;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef vector<long long int> vll;
typedef pair<long long int,long long int> pll;
typedef vector<vector<long long int>> vvll;
typedef long double ld;
void readVec(vi &a,int n){
    a.resize(n);
    f0(0,n) cin>>a[i];
}
void writeVec(vi &a){
	for(int x:a) cout<<x<<" ";
	cout<<el;
}
//----------------------------------------
void solve(){
    int x,y;
    cin>>x>>y;
    si s;
    f0(0,x+1){
        s.insert(2*i+4*(x-i));
    }
    if(!s.count(y)) cout<<"No"<<el;
    else cout<<"Yes"<<el;
}
int main(){
    fastIO();
    int t(1);
    // cin>>t;
    while(t--) solve();
    ret 0; 
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
string S = "MARCH";
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> A(N);
	int res = 0;
	map<char, int> mp;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mp[A[i][0]]++;
	}
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < i; j++) {
			for (int k = 0; k < j; k++) {
				res = res + mp[S[i]] * mp[S[j]] * mp[S[k]];
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second

const ll INFL = 1LL << 60;//10^18 = 2^60
//ll MOD = 998244353;

int N, M;
char mp[1010][1010];

int main(){
  int A, B;
  cin >> N >> M >> A >> B;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      mp[i][j] = '.';
    }
  }
  if(N % 2){
    for(int j = 0; j < M-1; j += 2){
      if(A == 0) break;
      A--;
      mp[N-1][j] = '<';
      mp[N-1][j+1] = '>';
    }
  }
  if(M % 2){
    for(int i = 0; i < N-1; i += 2){
      if(B == 0) break;
      B--;
      mp[i][M-1] = '^';
      mp[i+1][M-1] = 'v';
    }
  }
  if(N % 2 && M % 2){
    if(mp[N-1][M-2] == '>'){
      mp[N-1][M-1] = '>';
      mp[N-1][M-2] = '<';
      mp[N-1][M-3] = '.';
    }
  }

  for(int i = 0; i < N-1; i += 2){
    for(int j = 0; j < M-1; j += 2){
      if(A >= 2){
        A -= 2;
        mp[i][j] = '<';
        mp[i][j+1] = '>';
        mp[i+1][j] = '<';
        mp[i+1][j+1] = '>';
      }else if(B >= 2){
        B -= 2;
        mp[i][j] = '^';
        mp[i+1][j] = 'v';
        mp[i][j+1] = '^';
        mp[i+1][j+1] = 'v';
      }
    }
  }



  for(int i = N-1; i >= 1; i--){
    if(B == 0) break;
    for(int j = 0; j < M; j++){
      if(B == 0) break;
      if(mp[i-1][j] == '.' && mp[i][j] == '.'){
        mp[i-1][j] = '^';
        mp[i][j] = 'v';
        B--;
      }
    }
  }

  for(int i = 0; i < N; i++){
    if(A == 0) break;
    for(int j = 0; j < M-1; j++){
      if(A == 0) break;
      if(mp[i][j] == '.' && mp[i][j+1] == '.'){
        mp[i][j] = '<';
        mp[i][j+1] = '>';
        A--;
      }
    }
  }

  if(A || B){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < M; j++){
        cout << mp[i][j];
      }
      cout << endl;
    }
  }
}


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

int main() {

  int n,total = 0;
  cin >> n;
  
  vector<int> v(n),c(n);
  for ( int i = 0; i < n; i++){
    cin >> v[i];
  }
  for ( int i = 0; i < n; i++){
    cin >> c[i];
  }
  
  for ( int i = 0; i < n; i++){
    if ( v[i] - c[i] > 0 ){
      total += v[i] - c[i];
    }
  }
  
  cout << total << endl;  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int main(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,s.size()){
        int tmp = s[i] - 'A';
        tmp = (tmp + n)%26;
        s[i] = 'A' + tmp; 
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n;
vi ama(224);

int main(){
  ll ans=0;
  string s;
  cin>>s;
  n=s.length();
  vi ama(224);
  ama[0]=1;
  for(ll i=1;i<224;i++){
    ama[i]=ama[i-1]*10%2019;
  }
  vi si(n);
  for(ll i=0;i<n;i++){
    si[n-1-i]=s[i]-48;
  }
  
  for(ll k=0;k<224;k++){
      vi nums(2019);
      ll gk=0;
      nums[0]=1;
      ll offset=0;
      for(ll i=0;i+k<n;i++){
        gk+=ama[i%224]*si[i+k]%2019;
        gk%=2019;
        //何個あるか
        ans+=nums[(2019*2-offset-gk)%2019];

        if (i%224==223){
          //初期化
          /*
          for(ll j=0;j<2019;j++){
            nums2[(j+gk)%2019]=nums[j];
          }
          for(ll j=0;j<2019;j++){
            nums[j]=nums2[j];
          }
          */
          //ここでnums[0]の数値がnums[0+gk]に移動する操作をする
          //してないので本当のnums[i]は今はnums[i-gk]にある
          offset+=gk;
          offset%=2019;
          nums[(2019-offset)%2019]++;//本当はnums[0]++をしたい
          //nums[0]++;
          gk=0;
        }
      }
  }

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5132
#include<stdio.h>
#include<stdlib.h>
int N[100000];
int N2[100000];
int n;


int cmp(const void *x, const void *y){
  return *(int*)x - *(int*)y;
}

int main(){
  int ans = 0;
  int i,j;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&N[i]);
    N2[i] = N[i];
  }
  qsort(N2,n,sizeof(int),cmp);
  for(i = 0; i < n; i++){
    int l = 0,r = n-1,k;
    
    while(l <= r){
      k = (l+r)/2;
      if(N2[k] == N[i])break;
      else if(N2[k] > N[i])r = k-1;
      else l = k+1;
    }
   
    if(i % 2 != k % 2)ans++;
  }
      

  printf("%d\n",ans/2);
  return 0;
}
  
  


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

ll MOD = 1e9 + 7;
int const MAXN = 1e5 + 3;
ll n,k;

vi g[MAXN];

vi levels[MAXN];

ll dfs(int node, ll colors, int parent){
	ll val = 1;
	ll c = colors;
	for(int i=0;i<g[node].size();++i){
		int next = g[node][i];
		if(next!=parent){
			val *= (c--)*dfs(next,max(colors-1,k-2),node)%MOD;
			val %= MOD;
		}
	}
	return val;
}

int main(){
	cin >> n >> k;
	int a,b;
	for(int i=0;i<n-1;++i){
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout << k*dfs(1,k-1,-1)%MOD << endl;
}

Measured memory_bytes: 15104
from fractions import gcd
def lcm(x,y):return x*y//gcd(x,y)

a,b,c,d = map(int,input().split())
total =b-a+1##総数
cnum= b//c-(a-1)//c##cの倍数
dnum =b//d-(a-1)//d##dの倍数
m = lcm(c,d)
mnum = b//m -(a-1)//m##最小公倍数の倍数

print(total-(cnum+dnum-mnum))

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

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

	if(a%k==0)
	{
		cout<<"OK"<<endl;
	}
	else
	{
		int r=a/k;
		if((r+1)*k<=b)
			cout<<"OK"<<endl;
		else
			cout<<"NG"<<endl;
	}

	return 0;
}

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

int main()
{
	int n,ans =0; 
	string str; 
	cin>>n>>str; 
	for (int i=0; i<n-2; i++){
		if(str[i]=='A')
		{
			if(str[i+1]=='B'){
			    if(str[i+2]== 'C'){
			    	  ans++;
			    	  i+=2;
				}	
			}
		}
	}
	cout<<ans;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

vector<ll> G[100005];
ll dp[100005];

ll rec(ll x){
	if(dp[x]==-1){
		if(sz(G[x])==0) dp[x]=0;
		else rep(i,sz(G[x])) chmax(dp[x],rec(G[x][i])+1);
		
		return dp[x];
	}
	else return dp[x];
}

int main(){
	rep1(i,100000) dp[i]=-1;
	ll N,M; cin>>N>>M;
	rep(i,M){
		ll A,B; cin>>A>>B;
		G[A].pb(B);
	}
	ll ans=0;
	rep1(i,N){
		chmax(ans,rec(i));
	}
	cout<<ans; 
}

Measured memory_bytes: 8576
#include<stdio.h>
long long gcd(long long a,long long b){
  if(a%b==0) return b;
  return gcd(b,a%b);
}
int main(void){
  int n,i;
  long long ans,t;
  
  scanf("%d%lld",&n,&ans);
  for(i=0;i<n-1;i++){
    scanf("%lld",&t);
    ans=ans/gcd(ans,t)*t;
  }
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 main()
 {
 	int n, m, x, i, p=0, br=0;
 	scanf("%d%d%d", &n, &m, &x);
 	int A[m];
	 for(i=0;i<m;i++)
{
 	scanf("%d", &A[i]);
if (A[i]<x)
br=br+1;
else if (A[i]>x)
p=p+1;
}
 if (p>br)
 printf("%d", br);
 else 
 printf("%d", p);
 return 0;
}

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

int main(void)
{
    int n; cin >> n;
    vector<long long> a(n), cnt(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    long long all = 0;
    for (int i = 0; i < n + 1; i++) all += cnt[i] * (cnt[i] - 1) / 2;
    long long ans;
    for (int i = 0; i < n; i++)
    {
        ans = all - (cnt[a[i]] - 1);
        cout << ans << endl;
    }
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n){
    cin >> a[i];
    a[i] -= i+1;
  } 
  sort(ALL(a));
  ll b = (n%2) ? a[n/2] : (a[(n-1)/2] + a[n/2])/2;
  ll ans = 0;
  REP(i, n) ans += labs(a[i]-b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

string nth(set<string> &st, int n) {
  int i = 0;
  each(x, st) {
    if (i++ == n) {
      return x;
    }
  }
  return "";
}

void solve() {
  VAR(string, s);
  VAR(int, K);
  set<string> st;

  int sl = s.length();
  rep(i, 0, sl) {
    if ((int)st.size() >= K) {
      auto ss = nth(st, K - 1);
      if (s.substr(i, ss.size()) >= ss) {
        continue;
      }
    }
    rep(j, 1, sl + 1 - i) {
      st.insert(s.substr(i, j));
    }
  }
  print(nth(st, K - 1));
}


Measured memory_bytes: 181632
#include <stdio.h>

int main(void)
{
	char str[100];
	char str2[100];
	int a, b, c, ans;
	
	ans = 0;
	while (scanf("%s", str) != EOF){
		a = 0;
		b = 0;
		c = 0;
		while (str[a] != '\0') {
			a++;
		}
		a -= 1;
		while (a != -1) {
			str2[b] = str[a];
			if (str[b] == str2[b]) {
				c++;
			}
			b++;
			a--;
		}
		if (c == b) {
			ans++;
		}
	}
	
	printf("%d\n", ans);
	
	return (0);
}		

Measured memory_bytes: 540
n = int(input())
T_point = H_point = 0
for _ in range(n):
    T_card,H_card = [x for x in input().split()]
    if T_card > H_card:
        T_point += 3
    elif T_card < H_card:
        H_point += 3
    else:
        T_point += 1
        H_point += 1
print(T_point,H_point)



Measured memory_bytes: 5604
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in a,b;
  cin>>a>>b;
  if(a<=0 && b>=0){
    cout<<"Zero"<<endl;
    return 0;
  }
  if(a>0 || (b-a+1)%2==0){
    cout<<"Positive"<<endl;
    return 0;
  }
  cout<<"Negative"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; ans %= m;
    a *= a; a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

///////////////////////////////////

int main(){
  lint l,r,d; cin >> l >> r >> d;
  lint cnt = 0;
  for(lint i=l; i<=r; i++){
    cnt += (i%d==0);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

int n;
string s[100];

int expr(int &i){
    char c = s[i][s[i].size()-1];
    if(isdigit(c)){
        ++i;
        return c - '0';
    }
    else if(c == '+'){
        int ret = 0, level = s[i].size();
        ++i;
        while(i < n && s[i].size() == level + 1){
            ret += expr(i);
        }
        return ret;
    }
    else{
        int ret = 1, level = s[i].size();
        ++i;
        while(i < n && s[i].size() == level + 1){
            ret *= expr(i);
        }
        return ret;
    }
}

int main(){
    while(scanf("%d", &n) && n){
        rep(i, n) cin >> s[i];
        int idx = 0;
        printf("%d\n", expr(idx));
    }
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int h, w;
  cin >> h >> w;
  char a[h][w];
  REP(i, h){
    REP(j, w) cin >>a[i][j];
  }
  REP(i, h + 2){
    REP(j, w + 2){
      if(i == 0 || i == h + 1 || j == 0 || j == w + 1) cout << "#";
      else cout << a[i - 1][j - 1];
    }
    cout << endl;
  }

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

typedef unsigned long long ULL;

ULL gcd(ULL x, ULL y) {
    while (1) {
	if (x) y %= x; else return y;
	if (y) x %= y; else return x;
    }
}

ULL lcm(ULL x, ULL y) { return x/gcd(x, y)*y; }

// xs + yt = gcd(x, y), xu + yv = 0
// abs(s) < abs(y / gcd(x, y));
// abs(t) < abs(x / gcd(x, y));
LL extgcd(LL x, LL y, LL&s, LL&t) {
    assert(x >= 0 && y >= 0);
    for (LL u=t=1, v=s=0; x; ) {
	LL q = y / x;
	swap(s -= q * u, u);
	swap(t -= q * v, v);
	swap(y -= q * x, x);
    }
    return y;
}

LL inv_mod(LL a, LL mod) {
    LL x, y;
    if (extgcd(a, mod, x, y) == 1) return (x + mod) % mod;
    return 0; // unsolvable
}

LL ans;
LL N;

void update(LL K) {

    LL a = K, b = K+1, n = N;
    if (a % 2 == 0) a /= 2;
    else b /= 2;
    n /= gcd(a, n);
    n /= gcd(b, n);

    if (n == 1) {
	amin(ans, K);
    } else {
	eprintf("%lld !\n", K);
    }
}

LL safe_mul(LL x, LL y, const LL mod) {
    if (y == 0) return 0;
    if (y == 1) return x % mod;
    x %= mod;
    y %= mod;
    LL r = 0;
    for (;y; y>>=1) {
	if (y&1) {
	    r += x;
	    if (r >= mod) r -= mod;
	}
	x += x;
	if (x >= mod) x -= mod;
    }

    return r;
}

void solve(LL p) {
    LL q = N / p;

    if (gcd(2*p, q) == 1) {
	LL x;
	if (q == 1) {
	    x = 1;
	} else {
	    LL inv_p = inv_mod(2*p % q, q);
	    x = safe_mul(q-1, inv_p, q);
	}
	update(2*x*p);
    }
    if (gcd(2*q, p) == 1) {
	LL y;
	if (p == 1) {
	    y = 1;
	} else {
	    y = inv_mod(2*q % p, p);
	}
	update(2*y*q-1);
    }
}

void MAIN() {
    scanf("%lld", &N);
    ans = 2*N;

    if (N % 2 == 1) {
	amin(ans, N);
    }

    for (LL i=1; i*i<=N; i++) if (N % i == 0) {
	solve(i);
	if (i*i != N) solve(N/i);
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,a,b,c;

int l[10];

int INF = pow(10,9);


int dfs(int ret,int alen,int blen,int clen){
  if(ret==n){
    if(min({alen,blen,clen})>0) {
      // if(abs(alen-a) + abs(blen-b) + abs(clen-c)<300) cout << alen << " " << blen << " " << clen << endl;
      return abs(alen-a) + abs(blen-b) + abs(clen-c) - 30;
    }
    else return INF;
  }

  int pat0 = dfs(ret+1, alen, blen, clen);
  int pat1 = dfs(ret+1, alen+l[ret], blen, clen) + 10;
  int pat2 = dfs(ret+1, alen, blen+l[ret], clen) + 10;
  int pat3 = dfs(ret+1, alen, blen, clen+l[ret]) + 10;
  return min({pat0,pat1,pat2,pat3});
}


int main() {
  cin >> n >> a >> b >> c;
  FOR(i,0,n-1) {
    cin >> l[i];
    // cout << i << " " << l[i] << endl;
  }

  cout << dfs(0,0,0,0) << endl;
  
}



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


ll binpow(ll a, ll b)
{
	if(b==0)
		return 1;
	if(b%2==0)
	{
		return (binpow(a,b/2)*binpow(a,b/2))%modulo;
	}
	else
	{
		return (((binpow(a,b/2)*binpow(a,b/2))%modulo)*a)%modulo;
	}
}

ll factorial(ll n)
{
	ll temp=1;
	for(ll i=n;i>=1;--i)
	{
		temp=(temp*i)%modulo;
	}
	return temp;
}

ll factorial1(ll n,ll p)
{
	ll temp=1;
	for(ll i=n;i>=(p+1);--i)
	{
		temp=(temp*i)%modulo;
	}
	return temp;
}

ll moduloinverse(ll n)
{
	///cout<<"dvsd"<<endl;
	ll p =modulo-2;
	return binpow(n,p)%modulo;
}
ll com(ll n, ll r)
{
	if(r==0)
		return 1;
	ll temp1=std::max(r,n-r);
	ll temp2=std::min(r,n-r);
	ll a=factorial1(n,temp1);
	ll b=factorial(temp2);
	//cout<<a<<" "<<b<<endl;
	return (a*moduloinverse(b))%modulo;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    ll ans=0;
    ll temp=std::min(k,n-1);
    ll first=(com(n,0)*com(n-1,0))%modulo;
    ans=first;
    for(ll i=0;i<=temp-1;++i)
    {
    	ll v=((n-i)*(n-i-1))%modulo;
    	v=(v*first)%modulo;
    	ll u=((i+1)*(i+1))%modulo;
    	v=(v*moduloinverse(u))%modulo;
    	ans=(ans+v)%modulo;
    	first=v;
    	//cout<<first<<" ";
    	
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define fi first
#define se second

ll oe_solve(std::vector<ll> &a, bool minus){
	ll ans = 0, sum = 0;
	if(minus){
		sum = -1;
		if(a[0]>=0) ans += a[0]+1;
		else sum = a[0];
	}else{
		sum = 1;
		if(a[0]<=0) ans -= a[0]-1;
		else sum = a[0];
	}
	REP(i, 1, a.size()){
		if(sum>0){
			sum += a[i];
			if(sum>=0){
				ans += sum+1;
				sum = -1;
			}
		}else{
			sum +=a[i];
			if(sum<=0){
				ans -= sum-1;
				sum = 1;
			}
		}
	}
	return ans;
}


int main(){
	int n;
	scanf("%d", &n);
	std::vector<ll> a(n, 0);
	REP(i, 0, n) scanf("%ld", &a[i]);
	printf("%ld\n", std::min(oe_solve(a, true), oe_solve(a, false)));
	return 0;
}



Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

bool check(ll i, ll j) {
    ll d1 = j % 10;
    ll d10 = j / 10;
    return (d1 >= 2) && (d10 >= 2) && (d1 * d10 == i);
}

signed main() {
    ll M, D;
    cin >> M >> D;
    ll ans = 0;
    FOR(i, 1, M + 1) {
        FOR(j, 1, D + 1) {
            if (check(i, j)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include<stdio.h>

void tri(int x, int y, int z)
{
    if((x == y + z) || (y == z + x) || (z == x + y)) {
        printf("YES\n");
    }else {
        printf("NO\n");
    }    
}

int main(void)
{
    int a, b, c, num;

    scanf("%d", &num);

    for(int i = 0; i < num; i++) {
        scanf("%d %d %d", &a, &b, &c);
        tri(a*a, b*b, c*c);
    }

    return 0;
}

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

void solve(long long a, long long b)
{
    long long height = b - a;
    long long sum = 0;
    for (int i = 0; i < height; i++)
    {
        sum += i;
    }

    cout << sum - a << endl;
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
 
const int MAXN = 1e5+3;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int N,u,v;
int par[MAXN], depth[MAXN], h[MAXN];
//vector<pii> child[MAXN];
vector<int> edge[MAXN];

void dfs(int u, int p) {
    par[u] = p;
    //depth[u] = 1;
    for(int v: edge[u]) {
        if(v == p) continue;
        h[v] = h[u]+1;
        dfs(v,u);
        mmax(depth[u], depth[v]+1);
    }
}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> u >> v;
    fori(i,N-1) {
        int a,b;
        cin >> a >> b;
        edge[a].pb(b);
        edge[b].pb(a);
    }

    dfs(v,0);
    int ans = depth[u]+h[u]-1;
    int k = h[u];
    while(k > 2) {
        k -= 2;
        u = par[u];
        mmax(ans, depth[u]+h[u]-1);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12032
<?php
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$as = [];
$parent = [];
for ($i=1; $i <= $n; $i++) { 
	$as[$i] = false;
	$parent[$i] = $i;
}

for ($i=0; $i < $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$x = (int)$input[0];
	$y = (int)$input[1];
	// $z = (int)$input[2];
	// $as[$x] = true;
	// $as[$y] = true;
	if (getParent($y) < getParent($x)) {
		$parent[getParent($x)] = getParent($y);
	}else{
		$parent[getParent($y)] = getParent($x);
	}
}
// foreach ($parent as $key => $value) {
// 	echo $key . ': ' . $value . PHP_EOL;
// }

// $undefined = 0;
$groupHead = [];
for ($i=1; $i <= $n; $i++) { 
	$groupHead[getParent($i)] = true;
}
echo count($groupHead);




function getParent($num){
	global $parent;
	if ($parent[$num] === $num) {
		return $num;
	}else{
		$parent[$num] = getParent($parent[$num]);
		return $parent[$num];
	}
}

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

int main(){
  ll h,w,ans;
  cin >> h >> w;
  if (h == 1 || w ==1) ans = 1;
  else if((h*w)%2 == 0) ans = h*w/2;
  else ans =h*w/2+1;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
H,W=map(int,input().split())
a=[]
for i in range(H):
    a.append(str(input()))

cnt=0
while cnt<H:
    if a[cnt]=='.'*W:
        H-=1
        del a[cnt]
    else:
        cnt+=1

cnt=0
while cnt<W:
    for s in a:
        if s[cnt]=='#':
            cnt+=1
            break
        elif s==a[H-1]:
            W-=1
            for i in range(H):
                a[i]=a[i][:cnt]+a[i][cnt+1:]

            
for s in a:
    print(s)

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, X;
	cin >> n >> X;
	vector<ll> x(n);
	rep(i, n) {
		int a; cin >> a;
		x[i] = abs(X - a);
	}
	ll ans = x[0];
	for (int i = 1; i < n;++i) {
		ans = gcd(ans, x[i]);
	}
	//rep(i, n) cout << x[i] << ' ';
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string T;
        cin>>T;
        rep(i,Size(T)){
            if(T[i]=='?')T[i]='D';
        }
        cout<<T<<endl;
    }

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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000
#define N cout<<"No\n"
#define Y cout<<"Yes\n"

int main()
{
    ll A,B,n,i,j,bcn=0,cn=0;
    string s;
    cin>>n>>A>>B;
    cin>>s;
    fr(i,n)
    {
        if(s[i]=='c') N;
        else if(s[i]=='a')
        {
            if(cn<A+B) {
                Y;
                cn++;
            }
            else N;
        }
        else
        {
            if(cn<A+B&&bcn<B)
            {
                Y;
                bcn++;
                cn++;
            }
            else N;
        }
    }

    return 0;
}




Measured memory_bytes: 3712
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.split(" ").map { it.toInt() }
    val total = s.reduce {a, b -> a + b }
    var min = total
    for (i in 0 until n) {
        val first = s.subList(0,i+1).reduce{a,b -> a+b}
        if (min > Math.abs((total - first) - first)) min = Math.abs((total - first) - first)
    }
    println(min)
}


Measured memory_bytes: 37908
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;
//vector<ll>a;
int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,c,res,c1,x,y,c2;
    sf1(t)
    co<<t*t*t;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
//typedef long long float;
#define int long long
typedef pair<int, int> pii;
//#define float unsigned long long
typedef pair<int, int> pii;
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 
#define pi pair<int,int> 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y) 
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD2;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b) 
{
	return (long long) a * b % MOD2;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 


int32_t main()
{
    FAST
    cout << fixed << setprecision(2);
 
    
    int n;
    cin>>n;
    int div=n/500;
    int rem=n%500;
    int div2=rem/5;
    int tot=(div*1000)+(div2*5);
    cout<<tot<<endl;


    return 0;
}


//    1 2 1 2 1 2 1 2 1

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
int dgts2(int n){return (n?dgts2(n>>1)+1:0);}
int dgts(int n, int k){return (n?dgts(n/k,k)+1:0);}
inline int v2(int n){return __builtin_ctzll(n);}
 
const int maxn=5005;
//i_am_noob
int n,a,b;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> a >> b;
	print1(n/(a+b)*a+min(n%(a+b),a));
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}
ll inv_mod(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int n, m;
int ans;
/*signed*/int main(void) {
    cin >> n >> m;
    vector<int> x(m);
    vector<int> kaisa(m - 1);
    rep(i, m) cin >> x[i];
    sort(x.begin(), x.end());
    rep(i, m - 1) kaisa[i] = x[i + 1] - x[i];
    sort(kaisa.begin(), kaisa.end());
    rep(i, m - n) ans += kaisa[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x;

    int y,z;
    //string r;
    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
struct S
{
    int x,y;
};
vector<P> v[100333];
//bitset<4001000> bit;
int a,c,i,b,k,d,n,m,e=1987654321;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[200200];
int o[152202];
long long j[5][200100];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z[5][100100],mod=1000000007;
P u[2222];
//int j[31][11111];

stack<S> s;
queue<int> q;


//deque<int> de;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<string,int > p;
//list<int> l;
string r,r1,r2;
//char r[33][33];

bool as(int a,int b)
{
    return a>b;
}

long long f(int i,int n)
{
    if(l[i]==n) return 1;
    if(z[i][n]) return z[i][n];
    long long x=0;
    for(int h=0;h<v[n].size();h++)
    {
        //printf("@%d %d %d %d %d\n",n,v[n][h].x,j[i][n],j[i][v[n][h].x],v[n][h].y);
        if(j[i][n]==j[i][v[n][h].x]+v[n][h].y)
        {

            x+=f(i,v[n][h].x),x%=mod;
        }
    }
    return z[i][n]=x;
}

int main()
{
    //memset(z,-1,sizeof(z));
    scanf("%d %d %d %d",&a,&b,&l[1],&l[2]);
    for(int t=1;t<=b;t++)
    {
        //n=t;
        //m=t+1;
        //i=1;
        scanf("%d %d %d",&n,&m,&i);
        v[n].push_back({m,i});
        v[m].push_back({n,i});
    }
    memset(j,-1,sizeof(j));
    for(int u=1;u<=2;u++)
    {
        j[u][l[u]]=0;
        q.push(l[u]);
        for(;q.size();q.pop())
        for(int h=0;h<v[q.front()].size();h++)
        if(j[u][v[q.front()][h].x]<0||j[u][v[q.front()][h].x]>j[u][q.front()]+v[q.front()][h].y)
        {
            j[u][v[q.front()][h].x]=j[u][q.front()]+v[q.front()][h].y;
            q.push(v[q.front()][h].x);
        }
    }
    y=f(1,l[2]);
    x=y*y%mod;
    for(int t=1;t<=a;t++)
        if(j[1][t]==j[2][t]&&j[2][t]*2==j[1][l[2]])
        //if(t!=l[1]&&t!=l[2])
        x-=f(1,t)*f(1,t)%mod*f(2,t)%mod*f(2,t)%mod,x+=mod,x%=mod;
    for(int t=1;t<=a;t++)
        for(int h=0;h<v[t].size();h++)
        //if(t>v[t][h].x)
        if(v[t][h].y+j[1][t]+j[2][v[t][h].x]==j[1][l[2]]&&max(j[1][t],j[2][v[t][h].x])<min(j[1][t],j[2][v[t][h].x])+v[t][h].y)
            x-=f(1,t)*f(1,t)%mod*f(2,v[t][h].x)%mod*f(2,v[t][h].x)%mod,x+=mod,x%=mod;
    //for(int t=1;t<=a;t++)
    printf("%lld ",x);
}


Measured memory_bytes: 34176
#include <stdio.h> 

int main(void)
{	
	int a,b;
	char op;

	scanf("%d %c %d", &a, &op, &b);

	while(op != '?')
	{
		if(op=='+')
		{
			printf("%d\n", a+b);
		}
		else if(op=='-')
		{
			printf("%d\n", a-b);
		}
		else if(op=='*')
		{
			printf("%d\n", a*b);
		}
		else if(op=='/')
		{
			printf("%d\n", a/b);
		}

		scanf("%d %c %d", &a, &op, &b);
	}

	return 0;
}

Measured memory_bytes: 600