akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

typedef vector<vector<int>> Graph;

int dfs(const Graph &g, const vector<bool> &bs,int node){
    if(node==0) return 1;
    if(bs[node]) return node+1;
    
    int par=g[node][0];
    return dfs(g,bs,par);
}

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

    int n,q;
    while(cin>>n>>q, n||q){
            Graph g(n);
        for(int i=1;i<n;i++){
            int par;cin>>par;par--;
            g[i].push_back(par);
        }
        ll res=0;
        vector<bool> bs(n,false);
        bs[0]=true;
        for(int i=0;i<q;i++){
            string s;int node;
            cin>>s>>node; node--;
            if(s=="M") bs[node]=true;
            else{
            res+=dfs(g,bs,node);
            }
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 8364
#include<bits/stdc++.h>
using namespace std;
#define inf 100000007
#define MOD 100000007
#define x first
#define y second
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define pb push_back
#define ubnd upper_bound
#define lbnd lower_bound
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 2e5 + 5;
ll n, k;
ll dp[N][55];
ll A[N], t;

int main()
{
 //   ios
//   freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
    ll i ,j ,k , m , ans=0, a,  c, d,b, p=0,z;
    cin>>n;
    a=0; b=0;
    for(i=1; i<=n; i++){
        cin>>t>>c>>d;
        z=t;
        t-=p;
        if(abs(a-c) + abs(b-d) > t){
            cout<<"No";
            return 0;
        }
        t= t-abs(a-c)-abs(b-d);
        if(t&1){
            cout<<"No";
            return 0;
        }
        p= z;
        a=c;
        b=d;
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i=0; i<n; i++)
 
using namespace std;
const double PI = acos(-1);
using Graph = vector<vector<int>>;
 
int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> seen(n, -1);
	ll i = 0;
	ll count = 0;
	while (seen[i] == -1) {
		seen[i] = count;
		count++;
		i = a[i] - 1;
	}
	ll c1 = seen[i];
	ll c2 = count - c1;

	if (k <= c1) {
		i = 0;
		while (k--) {
			i = a[i] - 1;
		}
		cout << i + 1 << endl;
		return 0;
	}
	else {
		k -= c1;
		k %= c2;
		while (k--) {
			i = a[i] - 1;
		} 
		cout << i + 1 << endl;
		return 0;
	}
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int d[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	int A[M];
	for(int i=0; i<M; i++){
		cin >> A[i];
	}
//dp[i]・・・i本のマッチ棒をちょうど使って作れる最大桁数，作れないなら-2
	int dp[N+1];
	dp[0] = 0;
	for(int i=1; i<N+1; i++){
		int max = -2;
		for(int j=0; j<M; j++){
			if(i >= d[A[j]]){
				if(max < dp[i - d[A[j]]]){
					max = dp[i - d[A[j]]];
				}
			}
		}
		if(max < 0){
			dp[i] = -2;
		}else{
			dp[i] = max + 1; 
		}
	}
	sort(A, A+M);
	int ans[dp[N]];
	int p = N;
	for(int i=0; i<dp[N]; i++){
		for(int j=M-1; j>=0; j--){
		  if(p >= d[A[j]]){
				if(dp[p] == dp[p-d[A[j]]] + 1){
					ans[i] = A[j];
					p -= d[A[j]];
					break;
				}
			}
		}
	} 
	for(int i=0; i<dp[N]; i++){
		cout << ans[i];
	}
    cout << endl;
	return 0;
}


Measured memory_bytes: 384
inputbox1 = input()
inputbox2 = input()

N = int(inputbox1)
box = list(inputbox2)
count = 0
if (N%2 == 1):
    print("No")
else:    
    harf = int(N/2)
    for i in range (0,harf):
        if box[i]==box[i+harf]:
            count = count + 1
    
    if count == harf:
        print("Yes")
    else:
        print("No")

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a <= 5) {
		cout << 0 << endl;
	}
	else {
		cout << b/2 << endl;
	}
	return 0;
}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

void solve() {
  Real a;
  Real b;
  cin >> a >> b;
  
  cout << (Bint)mp::floor(a * b) << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <ll> a(n);
    const int mod = 1e9 + 7;
    ll ans = 0;
    vector <int> cnt[2];
    for (int i = 0; i < 2; i++) {
        cnt[i].resize(60, 0);
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < 60; j++) {
            bool t = a[i] & (1ll << j);
            ll add = cnt[t ^ 1][j];
            ll mul = 1ll << j;
            mul %= mod;
            add *= mul;
            add %= mod;
            ans += add;
            ans %= mod;
        }
        for (int j = 0; j < 60; j++) {
            bool t = a[i] & (1ll << j);
            cnt[t][j]++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  int *p=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    scanf("%d",&p[i]);
  }

  int count=0;

  rep(i,N-2){
    if((p[i]<p[i+1] && p[i+1]<p[i+2]) || (p[i]>p[i+1] && p[i+1]>p[i+2])){
      count++;
    }
  }

  printf("%d\n", count);


  return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
A = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(M)]

li=[]

for i in range(N):
    li.append([A[i],1])

for i in range(M):
    li.append([S[i][1],S[i][0]])

#二次元配列のソート(リストの最初の要素で)
from operator import itemgetter
li.sort(key=itemgetter(0), reverse=True)

tmp=0
index=0
ans=0
while tmp <N:
    if li[index][1] >0:
        ans+=li[index][0]
        li[index][1] -=1
        tmp+=1
    else:
        index +=1

print(ans)

Measured memory_bytes: 106008
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
    int h,w;
    while (1) {
        cin>>h>>w;
        if(h==0 && w==0)break;

        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {

                if (i == 1 || i == h) {
                    cout << '#';
                    if (j == w)cout << endl;
                } else {
                    if (j == 1)cout << '#';
                    else if (j == w)cout << '#' << endl;
                    else cout << '.';
                }

            }
        }
        cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=5e3+5;
char s[maxn];
ll dp[maxn][3];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin>>n;
    cin>>(s+1);
    if(n<=3)
    {
        cout<<0<<'\n';
        return 0;
    }
    //ll tol=n*(n-1)*(n-2)/6;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        dp[i][j]=dp[i-1][j];
        if(s[i]=='R')
            dp[i][0]++;
        else if(s[i]=='G')
            dp[i][1]++;
        else
            dp[i][2]++;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(s[i]==s[j])
               continue;
                char x='R'+'G'+'B'-s[i]-s[j];
                if(x=='R')
                {
                    sum+=dp[n][0]-dp[j][0];
                    if(j+j-i<=n&&s[j+j-i]=='R')
                    {
                        sum--;
                    }
                }
                else if(x=='G')
                {
                    sum+=dp[n][1]-dp[j][1];
                    if(j+j-i<=n&&s[j+j-i]=='G')
                    {
                        sum--;
                    }
                }
                else
                {
                    sum+=dp[n][2]-dp[j][2];
                    if(j+j-i<=n&&s[j+j-i]=='B')
                    {
                        sum--;
                    }
                }

        }

    }
    cout<<sum<<'\n';


}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=888888;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,q,rt,cnt,ch[maxn][3],id[maxn],ans[maxn];
bool rev[maxn];
char s[maxn];
inline void setrev(int x){
	rev[x]^=1;
	swap(ch[x][1],ch[x][2]);
}
inline void pushdown(int x){
	if(rev[x]){
		if(ch[x][0]) setrev(ch[x][0]);
		if(ch[x][1]) setrev(ch[x][1]);
		if(ch[x][2]) setrev(ch[x][2]);
		rev[x]=false;
	}
}
void build(int &x,int dep,int cur,int pr){
	x=++cnt;
	if(dep==n){
		id[x]=cur;
		return;
	}
	build(ch[x][0],dep+1,cur,pr*3);
	build(ch[x][1],dep+1,cur+pr,pr*3);
	build(ch[x][2],dep+1,cur+pr*2,pr*3);
}
void add(int x,int dep){
	pushdown(x);
	if(dep==n) return;
	swap(ch[x][1],ch[x][2]);
	swap(ch[x][0],ch[x][1]);
	add(ch[x][0],dep+1);
}
void dfs(int x,int dep,int cur,int pr){
	pushdown(x);
	if(dep==n){
		ans[id[x]]=cur;
		return;
	}
	dfs(ch[x][0],dep+1,cur,pr*3);
	dfs(ch[x][1],dep+1,cur+pr,pr*3);
	dfs(ch[x][2],dep+1,cur+pr*2,pr*3);
}
int main(){
	n=read();
	build(rt,0,0,1);
	scanf("%s",s+1);
	q=strlen(s+1);
	FOR(i,1,q) if(s[i]=='S') setrev(rt);
	else add(rt,0);
	dfs(rt,0,0,1);
	m=1;
	FOR(i,1,n) m*=3;
	FOR(i,0,m-1) printf("%d ",ans[i]);
}

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

using namespace std;

int main()
{
	int t;
   t=1;
	while(t--)
	{
	
	double n,a,b,c;
	
	cin>>n;
	
  int yy= 1000*ceil(n/1000)-n;
  
  cout<<yy<<endl;
	
	
	}



}


Measured memory_bytes: 3720
n = int(input())
s = input()
t = input()

ans = 0
for i in range(n):
    curr_s = s[i:]
    cnt = 0
    for j in range(n-i):
        if t[j] == curr_s[j]: cnt += 1
        else: break
    ans = max(ans,cnt)

ans = n*2 - ans
print(ans)

Measured memory_bytes: 63416
#include<bits/stdc++.h>
using namespace std;
#define int         unsigned long long
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			emplace_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
int n,m;
vi adj[(ll)1e5+1];
int  dp[(ll)1e5+1],dp1[(ll)1e5+1];
inline void dfs1(int s,int e)
{
	int ans=1;
	for(int i:adj[s])
	{
		if(i!=e)
		{
			dfs1(i,s);
			ans=(ans*(1+dp[i])%m)%m;
		}
	}
	dp[s]=ans;
}
void dfs(int s,int e)
{
	int temp1[sz(adj[s])+2],temp2[sz(adj[s])+2],u=1;
	rep(i,0,sz(adj[s])+1)
	temp1[i]=1;
	rep(i,0,sz(adj[s])+2)
	temp2[i]=1;
	for(int i:adj[s])
		if(i!=e)
			temp1[u]=temp2[u++]=(1+dp[i])%m;
	
	rep(i,1,u)
		temp1[i]=(temp1[i]*temp1[i-1])%m;
	rep(i,u,1)
		temp2[i]=(temp2[i+1]*temp2[i])%m;
	u=1;

	for(int i:adj[s])
		if(i!=e)
		{
			dp1[i]=(((temp1[u-1]*temp2[u+1])%m)*(1+dp1[s])%m)%m;
			u++;
			dfs(i,s);
		}
	
}
signed main(void)
{ios
	cin>>n>>m;
	rep(i,1,n)
	{
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dp1[1]=0;
	dfs1(1,0);
	dfs(1,0);
	rep(i,1,n+1)
	{
		cout<<(dp[i]*(1+dp1[i]))%m<<"\n";
	}
}

Measured memory_bytes: 22016
# 解説YouTubeをもとに
# https://atcoder.jp/contests/agc036/submissions/6943945 参考
S = int(input())
x1, y1, x2, y2 = 0, 0, 10**9, 1
if S==10**18:
  print(x1, y1, x2, y2, 0, x2)
else:
  y3 = S//x2 + 1
  x3 = x2*y3 - S
  print(x1, y1, x2, y2, x3, y3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// #include <limits>
//auto std::numeric_limits<float>::infinity() { return __builtin_huge_valf(); }
using namespace std;

int main()
{
    //A
    /*
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB")
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
        */
    //B

    long long N, A, B, C;
    cin >> N >> A >> B;
    if (N <= A)
        cout << N << endl;
    else if (A == 0)
        cout << 0 << endl;
    else
    {
        C = N % (A + B);
        cout << N / (A + B) * A + min(C, A);
    }

    //C
    /*
    int A, B;
    cin >> A >> B;
    float c;
    c = A / 0.08;
    if ((int)(10 * c) % 10 == 0)
    {
        if (floor(c * 0.1) == B)
        {
            cout << (int)c << endl;
        }
        else
            cout << -1 << endl;
    }
    else
    {
        if (floor((c + 1) * 0.1) == B)
            cout << (int)c << endl;
        else
            cout << -1 << endl;
    }
    */
    //Cやり直し
    /*
    int A, B;
    cin >> A >> B;
    for (int i = 1; i <= 1009; i++)
    {
        if (int(i * 0.08) == A && int(i * 0.1) == B)//intの対象を()でくくるように
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    */
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    r = 1
    rr = 0
    x = a[0]
    for l in range(n):
        while True:
            if r == n:
                break
            if (x & a[r]) > 0:
                break
            x += a[r]
            r += 1
        x -= a[l]
        rr += r - l

    return rr




print(main())



Measured memory_bytes: 27068
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define kakkei vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{return f<p.f;};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
ten shaei(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return l.p1+a*a.naiseki(p-l.p1)/a.abs2();
}
ten hansha(ten p,chokusen l){return shaei(p,l)*2-p;}
ld tenchoku(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return abs(a.gaiseki(p-l.p1))/a.abs();
}
ld tensen(ten p,senbun s){
	if((p-s.p1).naiseki(s.p2-s.p1)<0)return (p-s.p1).abs();
	if((p-s.p2).naiseki(s.p1-s.p2)<0)return (p-s.p2).abs();
	return tenchoku(p,s);
}
ll ccw(ten p0,ten p1,ten p2){
	v2 a=p1-p0,b=p2-p0;
	if(a.gaiseki(b)>MIN)return -1;//012反時計回り
	if(a.gaiseki(b)<-MIN)return 1;//012時計回り
	if(a.naiseki(b)<-MIN)return -2;//102
	if(a.abs2()<b.abs2())return 2;//012
	return 0;//021
}
bool majiwaru(senbun s,senbun t){return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2)<=0&&ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2)<=0;}
ld sensen(senbun s,senbun t){
	if(majiwaru(s,t))return 0;
	return min({tensen(s.p1,t),tensen(s.p2,t),tensen(t.p1,s),tensen(t.p2,s)});
}
void solve(){
	ll n;cin>>n;
	rep(i,0,n){
		senbun s1,s2;
		ld a,b,c,d;
		cin>>a>>b>>c>>d;
		s1={{a,b},{c,d}};
		cin>>a>>b>>c>>d;
		s2={{a,b},{c,d}};
		cout<<majiwaru(s1,s2)<<kai;
	}
}


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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;

void solve();

int main(void){
    string S;
    cin >> S;
    char order[] = {'A', 'K', 'I', 'H', 'A', 'B', 'A', 'R', 'A'};
    int index = 0;
    rep(i, S.length()){
        if(S[i] != order[index]){
            if(order[index++] == 'A'){i--; continue;}
            else{
                cout << "NO" << endl;
                return 0;
            }
        }
        index++;
    }
    if(index >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);

  int i;
  double x[n];
  char u[n][5];
  for(i=0;i<n;i++)
    scanf("%lf%s",&x[i],u[i]);

  double ans=0;
  for(i=0;i<n;i++){
    if(u[i][0]=='J')
      ans += x[i];

    else
      ans += x[i]*380000;
  }

  printf("%lf\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n;
		double money = 100000;

		str=br.readLine();
		n=Integer.parseInt(str);
		
		while(n>0){
			money = money*1.05;
			money = (Math.ceil(money/1000))*1000;
			n--;
		}
		System.out.println((int)money);
	}

}

Measured memory_bytes: 24064
n = int(input())
c = list(map(int, input().split()))

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)


Measured memory_bytes: 27108
//my vegetable has exploded. :(
#include<bits/stdc++.h>
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MM(x,y) memset(x,y,sizeof(x))
#define MCPY(a,b) memcpy(a,b,sizeof(b))
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define fi first
#define se second
using namespace std;
#define int long long
inline int quickpow(int m,int n,int p){int b=1;while(n){if(n&1)b=b*m%p;n=n>>1;m=m*m%p;}return b;}
inline int getinv(int x,int p){return quickpow(x,p-2,p);}
inline int read(void){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){f=ch=='-'?-1:1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x * f;
}
bitset<4000010>f;
int n,k,ret = 0;
///------------------head------------------
signed main(signed argc, char *argv[]){
    n=read();
    f[0] = 1;
    while(n--){
        int x = read();
        f=f|(f<<x);
        ret += x;
    }
    for (k = (ret+1)>>1; !f[k]; ++k);
    printf("%lld\n",k);
    return 0;
}

/* Examples: */
/*

*/

/*

*/


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

int main() {
    int i,j,n; 
    string a[100], b[100];
	cin >> n;
	for(i=0; i<n; i++) cin >> a[i], b[i] = a[i];
	for(i=0; i<n; i++) {
		for(j=n-1;j>i; j--) {
			if(b[j-1][1] > b[j][1]) {swap(b[j-1], b[j]);}
		}
	}
	for(i=0;i<n; i++) cout << (i? " " : "") << b[i]; cout << endl;
	cout << "Stable" << endl;
	for(i=0; i<n; i++) {int r = i;
		for(j=i+1; j<n; j++) {if(a[j][1] < a[r][1]) r = j;}
		swap(a[i], a[r]);
	}
	for(i=0; i<n; i++) cout << (i ? " " : "") << a[i]; cout << endl;
	cout << (equal(a, a + n, b) ? "Stable" : "Not stable") << endl;
}



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

int n;
vector<string> s;

bool ok(int x, int y) {
	rep(i, n) {
		rep(j, i) {
			if(s[(x + i) % n][(y + j) % n] != s[(x + j) % n][(y + i) % n]) {
				return false;
			}
		}
	}
	return true;
}

signed main() {
	cin >> n;
	rep(i, n) {
		string w;
		cin >> w;
		s.push_back(w);
	}
	int ans = 0;
	rep(i, n) {
		if(ok(i, 0)) {
			ans += n - i;
		}
	}
	for(int i = 1; i < n; i++) {
		if(ok(0, i)) {
			ans += n - i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int gcd(a, b){
	if (a < b){ return gcd(b, a); }
	unsigned r;
	while ((r = a%b)){
		a = b;
		b = r;
	}

	return b;
}

int main(){
	int w, h, c;
	int total = 0;
	int g;

	scanf("%d %d %d", &w, &h, &c);

	g = gcd(w, h);
	total = (w / g) * (h / g) * c;
	printf("%d\n", total);

}


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

int main() {
	int Height[20];

	for(int i=0; i<10; ++i) cin >> Height[i];

	for(int i=0; i<9; ++i) {
		for(int j=i; j<10; ++j) {
			if(Height[i] < Height[j]) {
				int tmp;
				tmp= Height[i];
				Height[i]= Height[j];
				Height[j]= tmp;
			}
		}
	}

	for(int i=0; i<3; ++i) printf("%d\n", Height[i]);

	return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);
    for (auto &a : A) cin >> a;
    for (auto &b : B) cin >> b;
    for (auto &c : C) cin >> c;
    int ans = accumulate(B.begin(), B.end(), 0);
    for (int i = 0; i < N-1; ++i) {
        if (A[i]+1 == A[i+1]) ans += C[A[i]-1];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
main = do
  nn <- (read :: String -> Int) <$> getLine
  input <- map (map (read :: String -> Int) . words) . lines <$> getContents
  let n = [0,1]
      joi = tail [[a,b,c,d,e,f,g,h,i,j] | a <- n, b <- n, c <- n, d <- n, e <- n, f <- n, g <- n, h <- n, i <- n, j <- n]
      ff = take nn input
      pp = drop nn input
  putStrLn . show . maximum $ map (\x -> solve' pp (solve ff x)) joi

solve :: [[Int]] -> [Int] -> [Int]
solve ff joi = map (sum . zipWith (\x y -> if x == y && x == 1 then 1 else 0) joi) ff

solve' :: [[Int]] -> [Int] -> Int
solve' pp cc = sum $ zipWith (!!) pp cc


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc178/abc178_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  cout << (N ? 0 : 1) << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
    int a,b,c;
    char op;
    while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
        c=a+b;
        printf("%d\n",c);
    }
    else if(op=='-'){
        c=a-b;
        printf("%d\n",c);
    }
    else if(op=='*'){
        c=a*b;
        printf("%d\n",c);
    }
    else if(op=='/'){
        c=a/b;
        printf("%d\n",c);
    }
    if(op=='?'){
        break;
    }
}
    return 0;
}


Measured memory_bytes: 2104
import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO Int
readInt = fst . fromJust . BS.readInt <$> BS.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n readInts

readInteger :: IO Integer
readInteger = fst . fromJust . BS.readInteger <$> BS.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n readIntegers

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n <$> readStrings

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

divCeiling x n | b == 0    = a
               | otherwise = a + 1
  where (a, b) = x `divMod` n

main = do
  c<-getChar
  putChar $ succ c
  putStrLn ""


Measured memory_bytes: 380
n = int(input())
h_arr = [0] + [int(i) for i in input().split()]

cost = [0] * (n + 1)
cost[1] = 0
cost[2] = abs(h_arr[2] - h_arr[1])

for i in range(3, n + 1):
    by_one_step = cost[i - 1] + abs(h_arr[i] - h_arr[i - 1])
    by_two_step = cost[i - 2] + abs(h_arr[i] - h_arr[i - 2])
    cost[i] = min(by_one_step, by_two_step)

print(cost[n])


Measured memory_bytes: 13980
#include <stdio.h>

int main(void) {
	char ch1[] = "#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.";
	char ch2[] = ".#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.";
	int h, w;
	register int i;
	char *c[2];
	c[0] = ch1;
	c[1] = ch2;
	while (1) {
		scanf("%d %d", &h, &w);
		if ((h == 0) && (w == 0)) {
			break;
		}
		i = 0;
		ch1[w] = 0;
		ch2[w] = 0;
		while (h--) {
			printf("%s\n", c[i]);
			i = 1 - i;
		}
		ch1[w] = ch1[w + 2];
		ch2[w] = ch2[w + 2];
		putchar('\n');
	}
	
	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>

#define N_MAX 1000
char person[N_MAX];
int n_person;
int interval;
//get last person
int getlast(void)
{
    //init all vartex
    int i,j;
    for(i=0;i<n_person;i++){
        person[i]=1;
    }
    //until no one is there
    i=0, j=interval-1;//i: number  j: cnt of interval
    int n=n_person; //num of existing person
    while(1){
        //there is a person
        if(person[i]){
            if(j==0){
                person[i]=0;
                n--;
                if(n==0){ return i+1; } 
            }
            j=(j==0)?interval-1:j-1;
        }
        //i=0...n_person-1
        i=(i==n_person-1)?0:i+1;
    }
}


//#define DEBUG
int main(void)
{
    FILE* fp;
#ifdef DEBUG
    fp=fopen("input.txt","r");
#else
    fp=stdin;
#endif
    
    while(1)
    {
        int n,m; //num of everybody, num of interval
        fscanf(fp,"%d %d\n",&n,&m);
        if(n==0 && m==0){ break; } //exit
        n_person=n; interval=m;
        printf("%d\n",getlast());
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int d[3000][3000]={0};
int l[3000];
int main(){
  int n,m,k,min,mi,a,b,c,max,i,j;
  double D;
  scanf("%d %d %d",&n,&m,&k);
  for(i=0;i<n;i++)l[i]=2100000000;
  while(m--){
    scanf("%d %d %d",&a,&b,&c);
    a--;
    b--;
    d[a][b]=d[b][a]=c;
  }//return 0;
  while(k--){
    char f[3000]={0};
    scanf("%d",&a);
    a--;
    l[mi=a]=0;
    for(i=0;i<n;i++){
      f[mi]=2;
      for(j=0;j<n;j++){
	if(d[mi][j]==0||f[j]==2)continue;
	if(l[j]>l[mi]+d[mi][j]){
	  l[j]=l[mi]+d[mi][j];
	  f[j]=1;
	}
      }
      min=2100000000;
      for(j=0;j<n;j++){
	if(f[j]!=1)continue;
	if(min>l[j])min=l[mi=j];
      }
      if(min==2100000000)break;
    }
  }
  for(i=max=0;i<n;i++){//printf("%d %d\n",i+1,l[i]);
    for(j=0;j<n;j++){
      if(i==j)continue;//printf("%d %d\n",l[i],l[mi]);
      D=(d[i][j]+l[i]+l[j])/2.0+0.5;//printf("%f\n",D);
      if(max<D)max=D;
    }
  }
  printf("%d\n",max);
  return 0;
}
 

Measured memory_bytes: 35768
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

	ll N;
	cin >> N;

	vector<ll> A(N);
	vector<ll> B(N);

	for (ll i = 0; i < N; ++i)
	{
		cin >> A[i] >> B[i];
	}

	vector<pair<ll, ll>> kachi(N);
	// B_kachi = -A_kachi
	for (ll i = 0; i < N; ++i)
	{
		kachi[i].first = A[i] + B[i];
		kachi[i].second = i;
	}

	sort(kachi.begin(), kachi.end(), [](const pair<ll, ll>& l, const pair<ll, ll>& r) { return l.first < r.first; });

	//for (ll i = 0; i < N; ++i)
	//{
	//	cout << kachi[i].first << endl;
	//}

	ll point = 0;

	auto itr = kachi.rbegin();
	while(true)
	{
		auto i = itr->second;
		point += A[i];

		++itr;
		if (itr == kachi.rend()) break;

		auto j = itr->second;
		point -= B[j];

		++itr;
		if (itr == kachi.rend()) break;
	}

	cout << point << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll h, w; cin >> h >> w;
  vector<string> s(h);
  REP(i, h) cin >> s[i];

  REP(i, 2*h){
    cout << s[i/2] << endl;
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define ff first
#define ss second

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

const int N = 2e5 + 5;

long long BIT[N], a[N];
int h[N];

int n;

void add(int l, long long sum){
  for(; l <= n; l += (l & (-l))){
    BIT[l] = max(BIT[l], sum);
  }
}

long long get(int l){
  long long sum = 0;
  for(; l > 0; l -= (l & (-l))){
    sum = max(sum, BIT[l]);
  }
  return sum;
}

void solve(){
  int i, j, k;
  cin >> n;
  for(i = 1; i <= n; i++){
    cin >> h[i];
  }
  for(i = 1; i <= n; i++){
    cin >> a[i];
  }
  long long ans = 0;
  for(i = 1; i <= n; i++){
    long long maxPref = get(h[i] - 1);
    ans = max(ans, maxPref + a[i]);
    add(h[i], maxPref + a[i]);
  }
  cout << ans << '\n';
}

int main(){
  fastio

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 4224
import java.util.Scanner;


class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int h, w;
		h = scan.nextInt();
		w = scan.nextInt();
		String s;
		char X[][] = new char[h+2][w+2];
		for(int i = 0; i < h+2; i++)
			for(int j = 0; j < w+2; j++)
				X[i][j] = '.';
		
		for(int i = 1; i <= h; i++){
			s = scan.next();
			for(int j = 1; j <= w ; j++)
				X[i][j] = s.charAt(j-1);
		}
		scan.close();

		char Y[][] = new char[h+2][w+2];
		for(int i = 0; i < h+2; i++)
			for(int j = 0; j < w+2; j++)
				Y[i][j] = '.';

		Boolean flag = true;
		
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				if(X[i][j]=='#')
					if(!drawing(i,j,X,Y)){
						flag = false;
					}
			}
		}
		
		System.out.print(flag?"Yes":"No");
	}

	static Boolean drawing(int x, int y, char ArrayX[][], char ArrayY[][]){
		if(ArrayX[x][y-1] == '#'){
			ArrayY[x][y] = '#';
			ArrayY[x][y-1] = '#';
			return true;
		}
		else if(ArrayX[x][y+1] == '#'){
			ArrayY[x][y] = '#';
			ArrayY[x][y+1] = '#';
			return true;
		}
		else if(ArrayX[x-1][y] == '#'){
			ArrayY[x][y] = '#';
			ArrayY[x-1][y] = '#';
			return true;
		}
		else if(ArrayX[x+1][y] == '#'){
			ArrayY[x][y] = '#';
			ArrayY[x+1][y] = '#';
			return true;
		}
		else return false;
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <numeric>
#include <cassert>

const int MAXINT = 10000000;

// typedef std::vector<std::vector<int> > mat_int;
// typedef std::vector<std::vector<bool> > mat_bool;

void dfs(std::vector<std::vector<int> >& adj_list, std::vector<int>& d, std::vector<int>& f, int& time, int root = 0 ){
  assert(d[root] > time);
  {
    // std::cout << root << ", " << time << std::endl;
    d[root] = time;
    for(int const& v: adj_list[root]){
      if(d[v] > time){
        time++;
        // std::cout << "call: " << root+1 << " " << v+1 << std::endl;
        dfs(adj_list, d, f, time, v);
      }
    }
    time++;
    // std::cout << "done: " << std::endl;
    f[root] = time;
  }

}


int main(int argc, char const *argv[]) {
  int n; // .. 100
  std::cin >> n;
  // mat_bool adj(n, std::vector<bool>(n));
  // mat_int d(n, std::vector<int>(n)), f(n, std::vector<int>(n));
  std::vector<std::vector<int> > adj_list(n);
  std::vector<int> d(n, MAXINT), f(n, MAXINT);

  for(int q=0; q<n; ++q){
    int i_plus_1, k;
    std::cin >> i_plus_1;
    std::cin >> k;
    for(int p=0; p<k; ++p){
      int j_plus_1;
      std::cin >> j_plus_1;
      // adj[i_plus_1-1][j_plus_1-1] = true;
      adj_list[i_plus_1 - 1].push_back(j_plus_1-1);
    }
  }

  int t = 0;
  // dfs(adj_list, d, f, t);
  for(int i=0; i<n; ++i){
    if(d[i] == MAXINT){
      ++t;
      dfs(adj_list, d, f, t, i);
    }
  }


  for(int i=0; i<n; ++i){

    // if(d[i] < MAXINT){
      std::cout << (i+1)
        << " " << d[i]
        << " " << f[i]
        << std::endl;
    // }
    // else{
    //   std::cout << (i+1)
    //     << " " << d[i]
    //     << " " << f[i]
    //     << std::endl;
    // }


  }


  // for(auto it = adj_list.begin(); it != adj_list.end(); ++it){
  //   std::cout << ": ";
  //   for(auto jt = (*it).begin(); jt != (*it).end(); ++jt){
  //     std::cout << (*jt) << ' ';
  //   }
  //   std::cout << std::endl;
  // }

  return 0;
}

Measured memory_bytes: 3160
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

template<class U, class T>
void amax(U &a, T b) { if (a < b) a = b; }

const int N = 101;
int sum[N][N];
int GetSum(int left, int right, int top, int bottom) { //[left, right], [top, bottom]
        int res = sum[bottom][right];
        if (left > 0) res -= sum[bottom][left - 1];
        if (top > 0) res -= sum[top - 1][right];
        if (left > 0 && top > 0) res += sum[top - 1][left - 1];
        return res;
}
void init(const vector<vector<int>> &s, int h, int w) {
        for (int y = 0; y < h; y ++) {
                for (int x = 0; x < w; x ++) {
                        sum[y][x] = s[y][x];
                        if (y > 0) sum[y][x] += sum[y - 1][x];
                        if (x > 0) sum[y][x] += sum[y][x - 1];
                        if (y > 0 && x > 0) sum[y][x] -= sum[y - 1][x - 1];
                }
        }
}

short dp[101][101][101][101];

int main() {
        int h, w;
        scanf("%d%d", &h, &w);
        vector<string> s(h);
        vector<vector<int>> ss(h, vector<int> (w, 0));
        int y, x;
        for (int i = 0; i < h; i ++) {
                cin >> s[i];
                for (int j = 0; j < w; j ++) {
                        if (s[i][j] == 'E') y = i, x = j;
                        if (s[i][j] == 'o') ss[i][j] = 1;
                }
        }
        init(ss, h, w);
        int left = x, right = w - x - 1, up = y, down = h - y - 1;
        for (int i = 0; i < 101; i ++) for (int j = 0; j < 101; j ++) for (int k = 0; k < 101; k ++) for (int l = 0; l < 101; l ++) dp[i][j][k][l] = -10000;
        dp[0][0][0][0] = 0;
        short ans = 0;
        for (int l = 0; l <= left; l ++) for (int r = 0; r <= right; r ++) for (int u = 0; u <= up; u ++) for (int d = 0; d <= down; d ++) {
                int lx = r, rx = w - l, uy = d, dy = h - u;
                short now = dp[l][r][u][d];
                if (x - l - 1 >= lx) amax(dp[l + 1][r][u][d], now + GetSum(x - l - 1, x - l - 1, max(y - u, uy), min(y + d, dy - 1)));
                if (x + r + 1 < rx) amax(dp[l][r + 1][u][d], now + GetSum(x + r + 1, x + r + 1, max(y - u, uy), min(y + d, dy - 1))); 
                if (y - u - 1 >= uy) amax(dp[l][r][u + 1][d], now + GetSum(max(x - l, lx), min(x + r, rx - 1), y - u - 1, y - u - 1));
                if (y + d + 1 < dy) amax(dp[l][r][u][d + 1], now + GetSum(max(x - l, lx), min(x + r, rx - 1), y + d + 1, y + d + 1));
                amax(ans, dp[l][r][u][d]);
        }
        printf("%d\n", (int) ans);
}


Measured memory_bytes: 203648
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef pair<int, pair<int, int>> Next;
typedef map<int, vector<pair<int, int>>> Edge;

#define INF 100000000

int main(void){

    int N, M;
    cin >> N >> M;
    int a[M], b[M], c[M];
    Edge e;
    set<pair<int, int>> cand;
    REP(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        e[a[i]].push_back(MP(b[i], c[i])); e[b[i]].push_back(MP(a[i], c[i]));
        cand.insert(MP(min(a[i], b[i]), max(a[i], b[i])));
    }

    REP(i, N){
        VI done(N, 0);
        VI dist(N, INF);
        set<Next> nex;
        for(auto n : e[i]){
            nex.insert(MP(n.second, MP(i, n.first)));
        }
        done[i] = 1; dist[i] = 0;
        while(!nex.empty()){
            auto top = nex.begin();
            auto node = *top;
            nex.erase(node);
            int from = node.second.first, to = node.second.second, d = node.first;

            if(chmin(dist[to], dist[from]+d) || dist[to] == dist[from]+d){
                cand.erase(MP(min(from, to), max(from, to)));
                for(auto n : e[to]){
                    nex.insert(MP(n.second, MP(to, n.first)));
                }
            }
        }
    }
    
    cout << cand.size() << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define db long double
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000005
 
using namespace std;

vector<ll> g[100001];
ll dp[100001],vis[100001];

void dfs(ll node,ll par)
{
	vis[node]=1;
	for(auto x:g[node])
	{
		if(x!=par && !vis[x])
			dfs(x,node);
		dp[node]=max(dp[node],dp[x]+1);
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tests=1,t=1;
    // cin>>tests;
    while(tests--)
    {	
    	ll i,j,n,m;
    	cin>>n>>m;
    	rep(i,1,m)
    	{
    		ll u,v;
    		cin>>u>>v;
    		g[u].pb(v);
    	}

    	rep(i,1,n)
    	{
    		if(!vis[i])
    			dfs(i,0);
    	}
    	ll ans=0;
    	rep(i,1,n) ans=max(ans,dp[i]);
    	cout<<ans;


    }
    	return 0;
    
}

Measured memory_bytes: 13320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 200000 + 5;
int a[N],b[N],vis[N];

int main(){
	int n;
	ll k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	int z = 1,t = 2,f;
	vis[1] = 1,b[1] = 1;
	while(1){
		z = a[z];
		vis[t] = z;
		if(b[z] != 0){
			f = b[z];
			break;
		}
		b[z] = t;
		t++;
	}
	t -= f;
	f--;
	if(k <= f)
		cout << vis[k+1] << endl;
	else{
		k -= f;
		cout << vis[k%t+f+1] << endl;
	} 
	return 0;
}

Measured memory_bytes: 5932
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 

int main(){
    string t,s;
    cin>>s>>t;
    cout<<t+s;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;

int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return s + n;
}
int main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (S * T >= D) {
        cout << "Yes";
    }
    else
        cout << "No";
}


Measured memory_bytes: 3632