akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1010;
const int MAXM = 10010;

struct tnode
{
    int x, y;
}a[MAXN];

int dp[MAXM * MAXM];

int main()
{
    int h, n;
    scanf("%d%d", &h, &n);
    double ma = 0;
    int nox, noy;
    for (int i = 1; i <= n; i ++)
    {
        scanf("%d%d", &a[i].x, &a[i].y);
        double z = (double) a[i].x / (double) a[i].y;
        if (z > ma)
        {
            ma = z;
            nox = a[i].x;
            noy = a[i].y;
        }
    }
    int tmp = h / nox;
    if (h % nox)
    {
        tmp ++;
    }
    int r = tmp * noy;
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i ++)
    {
        for (int j = a[i].y; j <= r; j ++)
        {
            if (dp[j - a[i].y] + a[i].x > dp[j])
            {
                dp[j] = dp[j - a[i].y] + a[i].x;
            }
        }
    }
    int ans = r;
    for (int i = 1; i <= r; i ++)
    {
        if (dp[i] >= h)
        {
            ans = i;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 391680
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  string s,t;
  cin>>s>>t;
  ll n=s.length();
  ll m=t.length();
  ll dp[n+1][m+1];
  memset(dp,0,sizeof(dp));
  for(ll i=1;i<=n;i++)
  {
    for(ll j=1;j<=m;j++)
    {
      if(s[i-1]==t[j-1])
        dp[i][j]=1+dp[i-1][j-1];
      else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  ll i=n,j=m;
  string ans="";
  while(j>0&&i>0)
  {
    if(s[i-1]==t[j-1])
    {
      ans=ans+s[i-1];
      i--;j--;
    }
    else if(dp[i-1][j]>=dp[i][j-1])
      i--;
    else
      j--;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans;
  return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    string S,T;
    getline(cin,S);
    getline(cin,T);

     if(S.substr(0,S.length())==(T.substr(0,(T.length()-1))))
   {
       cout << "Yes";
   }
   else
       cout<<"No";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int _maxi;
int _num;
int _multi;

void CParseIn () {
    cin >> _maxi >> _num >> _multi;
}

void CoreCWriteOut () {
    bool flag;
    for (int i = 1; i < _num + 1; i++) {
        cout << _multi << " ";
    }
    
    if (_multi < 1000000000) {
        flag = false;
    }
    
    else {
        flag = true;
    }
    
    for (int i = _num + 1; i < _maxi + 1; i++) {
        if (flag) {
            cout << "1 ";
            continue;
        }
        cout << "1000000000 ";
    }
}

int main () {
    
    CParseIn();
    CoreCWriteOut();
    
    return 0;
}

Measured memory_bytes: 1280
a, b = map(int, input().split())
ans = 0
if a%2 == 1:
  ans = ans^a
  a += 1
if b%2 == 0:
  ans = ans^b
  b -= 1
if (b-a+1)%4 != 0:
  ans = ans^1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
ll solve(ll cc)
{
    if(cc==1) return 1;
    return 2*solve(cc/2)+1;
}
int main()
{
    ll h;
    cin>>h;
    cout<<solve(h)<<'\n';
}

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

const int M = 10, Y = 1000;
int sdays[M + 1], ldays[M + 1];

int main(){
	int n, y, m, d, c;
	fill(sdays, sdays + M + 1, 20);
	fill(ldays, ldays + M + 1, 20);
	for(int i = 1;i <= M;++i){
		if(i % 2 == 0){
			sdays[i]--;
		}
	}

	cin >> n;

	for(int i = 0;i < n;++i){
		c = 0;
		cin >> y >> m >> d;
		int* p = y % 3 == 0 ? ldays : sdays;
		c += p[m] - d + 1;
		for(int j = m + 1;j <= M;++j){
			c += p[j];
		}
		for(int j = y + 1;j < Y;++j){
			p = j % 3 == 0 ? ldays : sdays;
			c += accumulate(p + 1, p + M + 1, 0);
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int n,k,q;
int main()
{
	while (cin>>n>>k>>q)
	{
//		for (int i=1;i<=n;i++)
//			a[i]=k;
		memset(a,0,sizeof(a));
		int ai;
		for (int i=0;i<q;i++)
		{
			scanf("%d",&ai);
//			for (int j=1;j<=n;j++)
//			{
//				if(j!=ai)
//					a[j]--;
//				else 
//					continue;	
//			}
			a[ai]++;	
		}
		for (int j=1;j<=n;j++)
			if (a[j]<q-k+1)
				printf("No\n");
			else
				printf("Yes\n");
				
	}
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define REP(i, a, b, c) for(int i = a; i <= b; i+=c)
#define pb push_back
#define int long long int
#define MOD 1000000007
using namespace std;

vector<int> edge[100001];
int dp[100001];

int solve(int src) {
  if (edge[src].size() == 0)
    return 0;
  if (dp[src] != -1)
    return dp[src];
  int res = 0;
  for (auto m : edge[src])
  {
    res = max(res, solve(m));
  }
  return dp[src] = 1 + res;
}

int32_t main()
{
  ios :: sync_with_stdio(false); cin.tie(0);
  int t = 1;
  memset(dp, -1, sizeof(dp));
  for (int i9 = 1; i9 <= t; i9++)
  {
    int n, m;
    cin >> n >> m;
    while (m--) {
      int x, y;
      cin >> x >> y;
      edge[x].pb(y);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
      ans = max(ans, solve(i));
    cout << ans << endl;
  }
}



Measured memory_bytes: 11812
#include <stdio.h>

#define tmnmx long
tmnmx abs(tmnmx p){
  return(p<0?-p:p);
}

int main(){
  long a,b,v,w,t;
  scanf("%ld",&a);
  scanf("%ld",&v);
  scanf("%ld",&b);
  scanf("%ld",&w);
  scanf("%ld",&t);
  
  if(abs(a-b)<=(v-w)*t){
    printf("YES");
  }else{
    printf("NO");
  }
  return(0);
}

Measured memory_bytes: 1736
a,b,c=input(),input(),input()
string=[a,b,c]
ans=["A","B","C"]
s=[0,0,0]
ban=0
while s[ban]!=len(string[ban]):
    temp=s[ban]
    s[ban]+=1
    if string[ban][temp]=="a": ban=0
    elif string[ban][temp]=="b": ban=1
    else: ban=2
print(ans[ban])

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
struct CP {
	int x;
	int y;
	int c;
	bool operator<(const CP& cp)const
	{
		return x != cp.x ? x < cp.x : y < cp.y;
	}
	bool operator<=(const CP& cp)const
	{
		return x != cp.x ? x <= cp.x : y <= cp.y;
	}
	bool operator>(const CP& cp)const
	{
		return x != cp.x ? x > cp.x : y > cp.y;
	}
	bool operator>=(const CP& cp)const
	{
		return x != cp.x ? x >= cp.x : y >= cp.y;
	}
	bool operator==(const CP& cp)const
	{
		return x == cp.x&&y == cp.y&&c == cp.c;
	}
	bool operator!=(const CP& cp)const
	{
		return x != cp.x||y != cp.y||c != cp.c;
	}
};

vector<CP> cps;

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

	int x, y;
	cin >> N;
	rep(i, 0, N)
	{
		cin >> x >> y;
		cps.push_back({ x,y,0 });
	}
	rep(i, 0, N)
	{
		cin >> x >> y;
		cps.push_back({ x,y,1 });
	}

	sort(all(cps));

	set<CP> cpset;

	int ans = 0;
	for (auto cp : cps)
	{
		if (cp.c == 0)
		{
			cpset.insert(cp);
		}
		else
		{
			auto it = cpset.begin();
			auto mit = cpset.end();
			int maxy = -1;
			while (it != cpset.end())
			{
				if (it->y<cp.y&&it->y>maxy)
				{
					maxy = it->y;
					mit = it;
				}
				it++;
			}
			if (maxy != -1)
			{
				ans++;
				cpset.erase(mit);
			}
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll m;
  cin>>m;
  vector<ll> d(m),c(m);
  ll csum=0,dsum=0;
  for(int i=0;i<m;i++){
    cin>>d[i]>>c[i];
    csum+=c[i];
    dsum+=d[i]*c[i];
  }
  //  cout<<dsum<<endl;
  cout<<csum-1LL+((dsum-1LL)/9LL)<<endl;
}


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

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll result = 0;
    if(A >= K)
    {
        result = K;
    }
    else
    {
        result += A;
        K -= A;

        if(B >= K)
        {
        }
        else
        {
            K -= B;
            result -= K;
        }
    }
    OUTX(result);
    


    return 0;
}


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

int main(){
    // input
    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> r(100010);
    vector<ll> p(m), y(m);
    rep(i, 0, m){
        cin >> p[i] >> y[i];
        r[p[i]].push_back(y[i]);
    }
    
    map<ll, bool> seen;
    vector<map<ll, ll>> o(100010); 
    for(auto t : p){
        if(seen[t]) continue;
        seen[t] = true;
        sort(r[t].begin(), r[t].end());
        rep(i, 0, r[t].size()){
            o[t][r[t][i]] = i+1;  
        }
    }

    rep(i, 0, m){
        string s = to_string(p[i]);
        ll lm = s.size();
        rep(j, 0, 6-lm){
            s = "0" + s;
        }
        ll ty = o[p[i]][y[i]];
        string ss = to_string(ty);
        lm = ss.size();
        rep(j, 0, 6-lm){
            ss = "0" + ss;
        }
        cout << s + ss << endl;
    }

    return 0;
}

Measured memory_bytes: 25728
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        Console.WriteLine(((int.Parse(Console.ReadLine()) + 110) / 111) * 111);
    }
}



Measured memory_bytes: 11092
class Main
{
    public static void main(String[] args)
    {
	for (int i=1;i<=9;i++)
	    {
		for(int j=1;j<=9;j++)
		    {
		System.out.println( +i+"x"+j+"="+(i*j));
		    }
	    }
    }
    
}

Measured memory_bytes: 9340
#include<iostream>
using namespace std;
int a[101],n;
unsigned long long tot;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			tot+=a[i]*a[j];
		}
	}
	cout<<tot;
}

Measured memory_bytes: 256
"use strict";
const main = arg => {
  let Info = arg.split("\n");
  let Num = Info.shift();
  // .map(x => x*1)については型変換の常套句
  let personInfo = Info.map(i => i.split(" ").map(x => x*1));
  let infoMap = new Map();
  let As = [];
  
  // 情報をそれぞれの値に格納する（別にmapでなくてもよかった）
  personInfo.forEach((x) => {
  	infoMap.set(x[0],x[1]); 
    As.push(x[0]);
  })
  // 一番最下位に近い人とその人の下に何人いるかの可能性だけ探ればいい
  let Amax = Math.max(...As);
  let ans = Amax + infoMap.get(Amax);
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 74276
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    while(getline(cin,S)){
        if(S == ".") break;
        string T = "";
        for(int i=0; i<S.size(); i++){
            if(S[i] == '(' or S[i] == ')' or S[i] == '[' or S[i] == ']') T += S[i];
        }
        bool ok = true;
        while(ok){
            if(T.size() == 0) break;
            ok = false;
            for(int i=0; i<T.size()-1; i++){
                if((T[i] == '(' and T[i+1] == ')') or(T[i] == '[' and T[i+1] == ']')){
                    ok = true;
                    T.erase(i,2);
                    break;
                }
            }
        }
        if(T.size() == 0){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3244
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	ll n,sunuke=0,arai=0,ans=9999999999;
    cin >> n;
    ll a[n];
    rep(i,n){
        cin >> a[i];
        arai+=a[i];
    }
    rep(i,n-1){
        sunuke+=a[i];
        arai-=a[i];
        ans=(ans>abs(sunuke-arai)?abs(sunuke-arai):ans);
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    vector<int> ABC(3);

    REP0(i, 3)
    {
        cin >> ABC[i];
    }

    sort(ABC.begin(), ABC.end());

    int delta1 = ABC[2] - ABC[1];

    ABC[0] += delta1;

    int delta2 = ABC[2] - ABC[0];

    cout << delta1 + (delta2 + 1) / 2 + (delta2 % 2) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
int f[1005][20];
int p[1005][20];
int b[2000];
int sum[1000];
int ji = 0;
ll ans;
int n;
void dfs(int cur)
{
    memset(sum, 0, sizeof(sum));
    for(int i = 0; i < 10; i++)
    {
        if(cur&(1<<i))
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= 10; k++)
            if(f[j][k] == 1 && k == i+1)sum[j]++;
        }
    }
    ll sum1 = 0;
    for(int i = 1; i <= n; i++)
    {
        sum1 += p[i][sum[i]];
    }
    ans = max(ans, sum1);
}
int main()
{
    scanf("%d", &n);
    FOR(i,1,n)
    FOR(j,1,10)
    cin >> f[i][j];
    FOR(i,1,n)
    FOR(j,0,10)
    cin >> p[i][j];
    memset(b, 0, sizeof(b));
    ans = -INF;
    for(int i = 1; i < (1<<10); i++)
    dfs(i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

const int mx = 1e5+123;
ll dp[102][mx];
int n, w[mx], v[mx], W;

ll solve ( int i, int j )
{
    if ( i > n ) return 0;

    if ( dp[i][j] != -1 ) return dp[i][j];

    ll ret1 = 0, ret2 = 0;

    if ( w[i] + j <= W ) ret1 = v[i] + solve ( i+1, w[i] + j );
    ret2 = solve ( i+1, j );

    return dp[i][j] = max ( ret1, ret2 );
}

int main()
{
    optimize();

    cin >> n >> W;
    for ( int i= 1; i <= n; i++ ) cin >> w[i] >> v[i];

    mem ( dp, -1 );
    cout << solve( 1, 0 ) << endl;

    return 0;
}


















Measured memory_bytes: 83396
#include <iostream>
using namespace std;
int main () {
    int h,w,c1=0,c2=0,c=0;
    char a[110][110];
    cin >> h >> w;
    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            if (a[i][j]=='.')
            {
                for (int k=1;k<=h;k++)
                {
                    if (a[k][j]=='#')
                    {
                        c1=1;
                    }
                }
                if (c1==0)
                {
                    for (int k=1;k<=h;k++)
                    {
                        a[k][j]='?';
                    }
                    c1=0;
                }
                c1=0;
                for (int k=1;k<=w;k++)
                {
                    if (a[i][k]=='#')
                    {
                        c2=1;
                    }
                }
                if (c2==0)
                {
                    for (int k=1;k<=w;k++)
                    {
                        a[i][k]='?';
                    }
                }
                c2=0;
            }
        }
    }
    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            if (a[i][j]!='?')
            {
                cout << a[i][j];
                c=1;
            }
        }
        if (c==1)
        {
            cout << endl;
        }
        c=0;
    }
    return 0;
}

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<=b)
    {
        cout<<a*c<<endl;
        return 0;
    }
    else
    {
        cout<<(b*c)+((a-b)*d)<<endl;
    }
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
s=[input() for _ in range(n)]
d={"M":0,"A":0,"R":0,"C":0,"H":0}
l=itertools.combinations(["M","A","R","C","H"],3)
for i in range(n):
    if s[i][0] in d:
        d[s[i][0]]+=1
ans=0
for i in l:
    a,b,c=i
    ans+=d[a]*d[b]*d[c]
print(ans)

Measured memory_bytes: 83944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        double N=cin.nextDouble();
        double ans=(N/2)/N;
        if(N%2!=0) ans=((N-1)/2+1)/N;
        Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
import sys
a=sys.stdin.readline()
res = [int(i) for i in a.split() if i.isdigit()] 
P,Q,R = [res[i] for i in (0,1,2)]
if (P>=1 and P<=100) and (Q>=1 and Q<=100) and (R>=1 and R<=100):
    t1=P+Q
    t2=Q+R
    t3=P+R
    L=[t1,t2,t3]
    L.sort()
    st=L[0]
    print(st)
else:
	print("Error")

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

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

        int mod = (int)1e9 + 7;

        long count = 0;
        for (int i=0; i<n-1; i++){
            for (int j=i+1; j<n; j++){
                if (arr[i]>arr[j]) count++;
            }
        }

        long count1 = 0;
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                if (arr[i]>arr[j]) count1++;
            }
        }

        long ans = (count*k)%mod;
        ans = (ans + ((count1%mod)*(((long)k*(long)(k-1))/2%mod))%mod)%mod;
        System.out.println(ans);

    }
}

Measured memory_bytes: 26084
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String first = sc.next();
        String second = sc.next();
        String third = sc.next();

        String[] splitFirst = first.split("", 0);
        String[] splitSecond = second.split("", 0);
        String[] splitThird = third.split("", 0);

        System.out.println(splitFirst[0] + splitSecond[0] + splitThird[0]);
    }
}

Measured memory_bytes: 23764
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int ans = T.Length;
            int num = 0;

            #region 自作
#if mine
            for (int i = T.Length; i > 0 ; i--)
            {
                for (int j = 0; j < T.Length - i + 1; j++)
                {
                    num = S.IndexOf(T.Substring(j, i));
                    while (num != -1)
                    {
                        if (S.Length - j >= T.Length
                            && j <= num)
                        {
                            ans = T.Length - i;
                            Console.WriteLine($"{ans}");
                            return;
                        }
                        num = S.IndexOf(T.Substring(j, i), num+1);
                    }
                }
            }

            ans = T.Length;
            Console.WriteLine($"{ans}");
            return;
#endif
            #endregion

            #region 解説を参考
            int diff = 0;
            for (int i = 0; i <= S.Length - T.Length; i++)
            {
                diff = 0;
                for (int j = 0; j < T.Length; j++)
                {
                    if(S[i+j] != T[j])
                    {
                        diff++;
                    }
                }
                ans = Math.Min(ans, diff);
            }

            Console.WriteLine($"{ans}");
            return;

            #endregion
        }
    }
}


Measured memory_bytes: 25872
#include <iostream>
using namespace std;
struct T{
    int parent,left,right;
};
void maketree(T tree[]){
    int node,l,r;
    cin>>node>>l>>r;
    tree[node].left=l;
    tree[node].right=r;
    tree[l].parent=node;
    tree[r].parent=node;
}
void Preorder(int x,T tree[]){
    if(x!=-1){
        cout<<" "<<x;
        Preorder(tree[x].left,tree);
        Preorder(tree[x].right,tree);
    }
}
void Inorder(int x,T tree[]){
    if(x!=-1){
        Inorder(tree[x].left,tree);
        cout<<" "<<x;
        Inorder(tree[x].right,tree);
    }
}
void Postorder(int x,T tree[]){
    if(x!=-1){
        Postorder(tree[x].left,tree);
        Postorder(tree[x].right,tree);
        cout<<" "<<x;
    }
}
int main(){
    int n,x=0;
    T tree[10000];
    cin>>n;
    for(int i=0;i<n;i++){
        tree[i].parent=-1;
        tree[i].left=-1;
        tree[i].right=-1;
    }
    for(int i=0;i<n;i++){
        maketree(tree);
    }
    while(tree[x].parent!=-1){
        x=tree[x].parent;
    }
    cout<<"Preorder"<<endl;
    Preorder(x,tree);
    cout<<endl<<"Inorder"<<endl;;
    Inorder(x,tree);
    cout<<endl<<"Postorder"<<endl;
    Postorder(x,tree);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    char s[10];
    scanf("%s",&s);
    int tmp={0};
    int min=1000000;
    for(int i=0;i<strlen(s);i++){
        tmp*=10;
        tmp+=s[i]-'0';
        tmp%=1000;
        if(abs(tmp-753)<min) min=abs(tmp-753); 
    }
    printf("%d\n",min);
}

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

struct node {
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x) {}

Node treeMaximum(Node x) {}

Node treeSearch(Node u, int k) {
  Node x = u;
  while (x != NIL) {
    if (x->key == k)
      return x;
    if (k < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  return NIL;
}

Node treeSuccessor(Node x) {}

int numChildren(Node x) {
  int n = 0;
  if (x->left != NIL)
    n++;
  if (x->right != NIL)
    n++;
  return n;
}

Node mostLeft(Node u) {
  Node x = u;
  while (x->left) {
    x = x->left;
  }
  return x;
}

bool isLeftChild(Node u) {
    return u->parent->left == u;
}


void treeDelete(Node z) {
  Node next;
  switch (numChildren(z)) {
  case 0:
    if (isLeftChild(z)) {
      z->parent->left = NIL;
    } else {
      z->parent->right = NIL;
    }
    free(z);
    break;
  case 1:
    next = z->left ? z->left : z->right;
    next->parent = z->parent;
    if (isLeftChild(z)) {
      z->parent->left = next;
    } else {
      z->parent->right = next;
    }
    free(z);
    break;
  case 2:
    next = mostLeft(z->right);
    z->key = next->key;
    treeDelete(next);
    break;
  }
}

void insert(int k) {
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NIL) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void inorder(Node u) {
  if (u == NIL)
    return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u) {
  if (u == NIL)
    return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s", com);
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NIL)
        printf("yes\n");
      else
        printf("no\n");
    } else if (com[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    } else if (com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0] == 'd') {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 21372
n = int(input())
As =list(map(int,input().split()))

sum = 0
step =0


for i in range(n):
    try:
        if As[i] > As[i + 1]:
            step = As[i] - As[i + 1]
            As[i + 1] += step
            sum += step 
    except IndexError:
        continue



print(sum)

Measured memory_bytes: 32188
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long
vector<vector<ll>> dp;
vector<ll> w, v;
ll N, W;

void solve()
{
    cin >> N >> W;
    dp = vector<vector<ll>>(N + 1, vector<ll>(W + 1, 0));
    w = vector<ll>(N);
    v = vector<ll>(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> w.at(i) >> v.at(i);
    }

    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j <= W; j++)
        {
            if (w.at(i) > j)
            {
                dp.at(i + 1).at(j) = dp.at(i).at(j);
            }
            else
            {
                dp.at(i + 1).at(j) = max(dp.at(i).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
            }
        }
    }
    cout << dp.at(N).at(W) << endl;

    // for (auto aa : dp)
    // {
    //     for (auto bb : aa)
    //     {
    //         cout << bb << " ";
    //     }
    //     cout << endl;
    // }

    return;
}

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


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

using namespace std;

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

    int ans = 0;
    if (A > B) {
        ans = A;
        A--;
    } else {
        ans = B;
        B--;
    }
    if (A > B) {
        ans += A;
        A--;
    } else {
        ans += B;
        B--;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
int main() {
	int n; cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long nowmoney = 1000;
	for (int i = 0; i < n - 1; i++) {
		long long t = 0;
		if (a[i] < a[i + 1]) {
			t = nowmoney / a[i];
		}
		nowmoney += (a[i + 1] - a[i])*t;
	}
	cout << nowmoney << endl;
	return 0;
}


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


int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a+b > c+d) cout << "Left" << endl;
    else if (a+b == c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}

Measured memory_bytes: 256
def tree(s,pls):
	dep[s] += pls
	pls += 1
	#print()
	#print(main[int(order.index(s))])
	for r in range(1,len(main[s])):
		#print(lis)
		tree(main[s][r],pls)

n = int(input())
main = [[-1] * 1 for i in range(n)]
for i in range(n):
	a = input().split()
	for j in range(2,int(a[1])+2):
		main[int(a[j])][0] = int(a[0])
		main[int(a[0])].append(int(a[j]))
	#print(main)

dep = [-1] * n



for i in range(n):
	if main[i][0] == -1:
		tree(int(i),1)
		break

for i in range(n):
	print("node " + str(i) + ": parent = " + str(main[i][0]) +", depth = " + str(dep[i]) + ", " ,end='')
	if main[i][0] == -1:
		print("root, ",end='')
	elif len(main[i]) == 1:
		print("leaf, []")
		continue
	else:
		print("internal node, ",end='')
	print(main[i][1:])


"""
print(main)
print(dep)
"""


Measured memory_bytes: 24232
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 100005;
#ifndef LOCAL
#define cerr if(0)cout
#endif
int n; 
vector <int> V[MAXN];
int dp[MAXN][2];
//0-> white
//1-> black
ll dfs(int x, int p, int color) {
	if(dp[x][color]!=-1)return dp[x][color];
	dp[x][color] = 1;
	if(V[x].size()==1&&p!=-1)return 1;
	if(color == 0) {
		for(auto v:V[x]) if(v!=p){
			dp[x][0]*=(dfs(v,x,0) + dfs(v,x,1));
			dp[x][color]%=MOD;
		}
		return dp[x][color];
	} else {
		for(auto v:V[x]) if(v!=p){
			dp[x][color]*=dfs(v,x,0);
			dp[x][color]%=MOD;
		}
		return dp[x][color];
	}
}

		

int32_t main() 
{
	IAMSPEED
	memset(dp,-1,sizeof dp);
	cin >> n;
	FOR(i,1,n-1) {
		int x,y; cin >> x >> y;
		V[x].pb(y);
		V[y].pb(x);
	}
	if(n==1) {
		cout << 2;
		exit(0);
	}
	
	cout << (dfs(1,-1,0) + dfs(1,-1,1)) %MOD;
}



Measured memory_bytes: 17552
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
int main(){
	int n;
	int rN,lN,rSum=0,lSum=0;
	int A[100];

	int t,ans=1000000000;

	scanf("%d",&n);

	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
	}


	for(int i=0;i<n-1;i++){
		t=i;
		lSum=rSum=0;
		//printf("t=%d\n",t);
		for(int j=0;j<n;j++){
			if(j<=t){
				//printf("L[%d,%d]\n",lSum,rSum);
				lSum+=A[j];
			}else{
				//printf("R[%d,%d]\n",lSum,rSum);
				rSum+=A[j];
			}
		}
		//printf("end[%d,%d]\n",lSum,rSum);
		if(ans>abs(lSum-rSum))ans=abs(lSum-rSum);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int a, b;
    cin >> a >> b;
    if (a == 1) a += 13;
    if (b == 1) b += 13;
    if (a < b) {
        cout << "Bob" << endl;
    } else if (a > b) {
        cout << "Alice" << endl;
    } else {
        cout << "Draw" << endl;
    }
}


Measured memory_bytes: 3644
#include<stdio.h>

int  scan_sentence(char * str, int length_max);
void count_alphabet(char * str, int * num_check, int length);
void print_result(int * num_check);

int main(){

	int length;
	char str[1200];
	int num_check[26];
	int i;
	
	for(i = 0;i < 1200;i++){
		str[i] = 0;
	}
	for(i = 0;i < 26;i++){
		num_check[i] = 0;
	}
	
	length = scan_sentence(str, 1200);
	
	count_alphabet(str, num_check, length);
	
	for(i = 0;i < 26;i++){
		printf("%c : %d\n", (i + 97), *(num_check + i));
	}
	
	return 0;
}

/* 関数名：文字列入力 */
/* 概要：文字列を入力する。その長さを返す */
/* 引数：文字列を格納する配列の先頭アドレス、その配列の大きさ */
/* 戻り値：入力された文字列の長さ */
int scan_sentence(char * str, int length_max)
{
	int count_text = 0;
	int i;

	for(i = 0;i < length_max;i++){
		scanf("%c", str + i);
		if(*(str + i) == EOF){
			break;
		}
		count_text++;
	}

	return count_text;
}

/* 関数名：アルファベットカウント */
/* 概要：渡された文字列に各アルファベットが何文字含まれるか調べる */
/* 引数：文字列が格納された配列の先頭アドレス、アルファベットの数を記録する配列の先頭アドレス、文字列の長さ */
/* 戻り値：なし */
void count_alphabet(char * str, int * num_check, int length)
{
	int i;
	char alphabet;
	for(i = 0;i < length;i++){
		if(((65 <= *(str + i)) && (*(str + i) <= 90)) || ((97 <= *(str + i)) && (*(str + i) <= 122))){
			alphabet = *(str + i) & 0x1F;
			*(num_check + (alphabet - 1)) += 1;
		}
	}
}

void print_result(int * num_check)
{
	int i;

}


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

#define mod 1000000007

typedef long long ll;

ll N;
ll dp[100][5] = {0};

int main()
{
    scanf("%lld",&N);
    dp[61][0] = 1;
    for(int i = 60; i >= 0; i--)
    {
        ll mem = (N >> i) & 1;
        dp[i][2] += dp[i + 1][2] * 3;
        if(mem)
        {
            dp[i][2] += dp[i + 1][1] * 2;
            dp[i][1] += dp[i + 1][1];
            dp[i][1] += dp[i + 1][0];
            dp[i][0] += dp[i + 1][0];
        }
        else
        {
            dp[i][2] += dp[i + 1][1];
            dp[i][1] += dp[i + 1][1];
            dp[i][0] += dp[i + 1][1];
            dp[i][0] += dp[i + 1][0];
        }
        dp[i][0] %= mod;
        dp[i][1] %= mod;
        dp[i][2] %= mod;
    }
    printf("%lld\n",(dp[0][0] + dp[0][1] + dp[0][2]) % mod);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,b,e,q;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>q;
    for(long long i=0;i<q;i++){
        cin>>b>>m>>e;
        swap_ranges(a+b,a+m,a+e);
    }
    for(long long i=0;i<n-1;i++){
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	vector<int> b(N);
	vector<int> s(N);
	for(int i=0; i<N; i++){
		cin>>a[i];
	}
	for(int i=0; i<N; i++){
		cin>>b[i];
	}
	
	for(int i=0; i<N; i++){
		int A=0,B=0;
		for(int j=0; j<i+1; j++){
			A+=a[j];
		}
		for(int j=i; j<N; j++){
			B+=b[j];
		}
		s[i]=A+B;
	}
	int ans=0;
	for(int i=0; i<N; i++){
		if(ans<=s[i]){
			ans=s[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, err := strconv.Atoi(input())
	if err != nil {
		log.Fatal(err)
	}

	a := make([]int, n)
	for i, _ := range a {
		a[i], err = strconv.Atoi(input())
		if err != nil {
			log.Fatal(err)
		}
		if a[i] % 2 == 1 {
			fmt.Println(0)
			return
		}
	}

	count := 0
	for ; ; count++ {
		for i, v := range a {
			if v % 2 == 1 {
				fmt.Println(count)
				return
			}
			a[i] = v / 2
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        Integer[] m = new Integer[n];
        Arrays.setAll(m, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int sum = Arrays.stream(m).mapToInt(i -> i).sum();
        int min = Arrays.stream(m).mapToInt(i -> i).min().getAsInt();
        int result = n + (x - sum) / min;

        // 出力
        System.out.println(result);
    }
}


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

constexpr int MAXN = 2e5 + 10;

int n;
long long x[MAXN], y[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld", x + i, y + i);
		if (x[i] < y[i]) swap(x[i], y[i]);
	}
	x[0] = LLONG_MIN;
	y[0] = LLONG_MAX;
	int max_pos = 0, min_pos = 0;
	for (int i = 1; i <= n; ++i) {
		if (x[max_pos] < x[i]) max_pos = i;
		if (y[min_pos] > y[i]) min_pos = i;
		if (y[min_pos] == y[i] && min_pos == max_pos)
			min_pos = i;
	}
	long long ans = LLONG_MAX;
	{ // case 1 : rmax == max, bmin == min
		long long rmax = x[max_pos], rmin = LLONG_MAX;
		long long bmin = y[min_pos], bmax = LLONG_MIN;
		for (int i = 1; i <= n; ++i) {
			rmin = min(rmin, x[i]);
			bmax = max(bmax, y[i]);
		}
		ans = min(ans, (rmax - rmin) * (bmax - bmin));
	}
	
	if (max_pos != min_pos) { // case2 : rmax == max, rmin == min
		long long rdiff = x[max_pos] - y[min_pos];
		set<pair<long long, long long> > sets;
		for (int i = 1; i <= n; ++i)
			sets.insert(make_pair(x[i], i));
		for (;;) {
			long long bdiff = sets.rbegin()->first - sets.begin()->first;
			ans = min(ans, rdiff * bdiff);
			pair<long long, long long> temp = *sets.rbegin();
			sets.erase(*sets.rbegin());
			if (temp.second == -1) break;
			sets.insert(make_pair(y[temp.second], -1));
		}
	}
	printf("%lld\n", ans);
}

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

int main(){
    long long x; cin >> x;
    long long mi, mi2;
    for (int i = 1; i < 40000; i++)
    {
        if (x%i==0)
        {
            long long y = x/i;
            long long start = sqrt(sqrt(y));
            for (long long j = start; j > 0; j--)
            {
                mi = j-i;
                mi2=mi*mi;
                if (j*j*j*j + j*j*j*mi + j*j*mi2 + j*mi*mi2 + mi2*mi2 == y)
                {
                    printf("%lld %lld\n",j, mi);
                    return 0;
                }
                
            }
            
        }
        
    }
    
}

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

int main()
{
	int i,ans1,ans2,expected,n;
	string s;

	cin >> s;
	ans1 = 0;
	for(i=0; i<s.size(); i++)
	{
		expected = i%2;
		if(s[i] != ('0'+expected))
			ans1++;
	}
	ans2 = 0;
	for(i=0; i<s.size(); i++)
	{
		expected = (i+1)%2;
		if(s[i] != ('0'+expected))
			ans2++;
	}
	// cout << ans1 << " " << ans2 << endl;
	cout << min(ans1, ans2) << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  int Ans=0;
  for(int i=0; i<N; i++){
    cin >> V.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> C.at(i);
  }
  for(int i=0; i<N; i++){
    if(V.at(i)>C.at(i)){
      Ans+=V.at(i)-C.at(i);
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
a = []
a.append(w[0])
now = w[0]
ans = True
for i in w[1:]:
    if i not in a and now[-1] == i[0]:
        now = i
        a.append(i)
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")

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

int main(){
  int n;  cin >> n;
  vector<int> b(n), ans(n);
  for(int i=0; i<n; i++)  cin >> b[i];
  bool all_done = true;
  int point = -1, cnt = 0;
  for(int j=0; j<n; j++){
    point = -1, cnt = 0;
    for(int i=0; i<n; i++)
      if(b[i] != -1)
        if(b[i] == ++cnt)  point = i;
    if(point == -1){
      all_done = false;
      break;
    }else{
      ans[j] = b[point];
      b[point] = -1;
    }
  }
  if(all_done){
    for(int i=n-1; i>=0; i--)
      cout << ans[i] << endl;
  }else{ 
    cout << "-1" << endl;
  }
  return 0;
}

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

int main(void){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx, dy;
    dx = tx-sx;
    dy = ty-sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy+1, 'U') << string(dx+1, 'R') << 'D';
    cout << 'R' << string(dy+1, 'D') << string(dx+1, 'L') << 'U';
    cout << endl;
    return 0;
}


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

int N;
ll dp[3300][3300];
int a[3300];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int w = 1; w <= N; w++) {
		for (int l = 0; w + l <= N; l++) {
			int r = l + w;
			if (w % 2 == N % 2) dp[l][r] = max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r - 1]);
			else dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1]);
		}
	}
	cout << dp[0][N] << '\n';
	return 0;
}

Measured memory_bytes: 78080