akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,m,ans,a[52],b[52];
vector <int> v[52];
bool vis[52];
void dfs (int x)
{
    vis[x]=true;
    for (int i=0;i<v[x].size();i++)
    {
        if (!vis[v[x][i]])
            dfs(v[x][i]);
    }
}
int main()
{
    cin >>n>>m;
    for (int i=0;i<m;i++)
    {
        cin >>a[i]>>b[i];
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    for (int i=0;i<m;i++)
    {
        memset(vis,0,sizeof vis);
        bool yes=false;
        int n1=a[i];
        int n2=b[i];
        v[n1].erase(find(v[n1].begin(),v[n1].end(),n2));
        v[n2].erase(find(v[n2].begin(),v[n2].end(),n1));
        for (int j=1;j<=n;j++)
        {
            if (!vis[j])
            {
                if (yes)
                {
                    ans++;
                    break;
                }
                yes=true;
                dfs (j);
            }
        }
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>

using namespace std;


void Solution()
{
    int n;
    
    string type;
    char comma;
    
    int a = 0;
    int b = 0;
    int ab = 0;
    int o = 0; //for counting the blood types
    
    
    while (cin>>n>>comma>>type)
    {
        if(type == "A")
        {
            a++;
        }
        else if(type == "B")
        {
            b++;
        }
        else if(type == "O")
        {
            o++;
        }
        else
        {
            ab++;
        }
    }
    
    cout<<a<<endl;
    cout<<b<<endl;
    cout<<ab<<endl;
    cout<<o<<endl;
}

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

Measured memory_bytes: 1208
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  long long s;cin>>s;
  cout << 0 << " " << 0 << " " << 1 << " " << 1000000000 << " " << (s-1)/1000000000+1 << " " << ((s-1)/1000000000+1)*1000000000-s << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define N 2<<15

char prime[N];

void make(){

  for(int i = 0; i < N; i++) prime[i] = '1';
  prime[0] = '0';
  prime[1] = '0';

  for(int i = 2; i*i < N; i++){
    if(prime[i] == '1'){
      for(int j = i*2; j < N; j+=i){
	prime[j] = '0';
      }
    }
  }

}

int main(){

  make();

  int in;

  while(cin >> in){
    if(in == 0) break;

    int sum = 0;

    for(int i = 2; i <= in/2; i++){
      if(prime[i] == '1' && prime[in-i] == '1') sum++;
    }

    cout << sum << endl;

  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define F first
#define S second
#define PB push_back
#define M 998244353
ll k,n,ka[100005],o[100005];
ll pw(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%M;
        x=x*x%M;
        y>>=1;
    }
    return res;
}
ll cm(ll x,ll y){
    if(x==0||y==0)return 1;
    return ka[x]*o[y]%M*o[x-y]%M;
}
vector<ll>ans;
int main(void){
    cin>>k>>n;
    ka[0]=1;
    o[0]=1;
    if(k<=1){
        cout<<0<<endl;
        return 0;
    }
    if(n<=1){
        for(int i=0;i<k*2-1;i++){
            cout<<0<<endl;
        }
        return 0;
    }
    for(ll i=1;i<=n+k;i++){
        ka[i]=ka[i-1]*i%M;
        o[i]=pw(ka[i],M-2);
    }
    for(ll i=0;i<(k+1)/2;i++){
        ll s=0;
        for(ll j=0;j<=i&&j<=n;j++){
            s=(s+(cm(n+k-i-j-2,n-j)+cm(n+k-i-j-3,n-j-1))%M*cm(i,j)%M)%M;
        }
        ans.PB(s);
    }
    if(ans.size()==0){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<ans.size()-1;i++){
        cout<<ans[i]<<endl<<ans[i]<<endl;
    }
    cout<<ans[ans.size()-1]<<endl;
    if(k%2==0)cout<<ans[ans.size()-1]<<endl<<ans[ans.size()-1]<<endl;
    for(int i=ans.size()-2;i>=0;i--){
        cout<<ans[i]<<endl<<ans[i]<<endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 200005;

int n, a[MAXN], b[MAXN];
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    REP1 (i, n) {
        cin >> a[i];
    }

    vector<int> ans;
    for (int i=n; i>=1; i--) {
        int j = i, sum = 0;
        while (j <= n) {
            sum += b[j];
            j += i;
        }
        if ((sum&1) ^ a[i]) {
            b[i] = true;
            ans.eb(i);
        }
    }

    sort(ALL(ans));
    cout << SZ(ans) << endl;
    REP (i, SZ(ans)) {
        cout << ans[i] << " \n"[i==SZ(ans)-1];
    }
    return 0;
}


Measured memory_bytes: 2936
import java.awt.print.Printable;
import java.util.Scanner;
import javax.sound.midi.SysexMessage;
  
public class Main{      
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String strs[] = new String[100];
        int count2=0;
        while(true){
            String str = sc.next();
            //System.out.println("Str is "+str);
            if(str.equals("-"))
                {
                    for(int j=0;j<count2;j++){
                        System.out.println(strs[j]);
                    }
                    sc.close();
                    break;
                }
            int num = sc.nextInt();
            //System.out.println("Num is "+num);
            for(int i=0;i<num;i++)
            {
                int count=sc.nextInt();
                String str1=str.substring(0,count);
                String str2=str.substring(count,str.length());
                str = str2 + str1;
                //System.out.println("I is "+i+" str is "+str);
            }
            strs[count2]=str;
            count2++;
        }  
    }   
}


Measured memory_bytes: 26404
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    string S;
    cin >> S;
    int ans = INF;
    for(char i = 'a'; i <= 'z'; i++) {
        bool flag = false;
        for(int j = 0; j < S.size(); j++) {
            if(S[j] == i) {
                flag = true;
            }
        }
        if(flag) {
            int cnt = 0;
            string T = S;
            while(true) {
                bool ok = false;
                string R = T;
                for(int k = 0; k < R.size(); k++) {
                    if(R[k] != i) {
                        ok = true;
                    }
                }
                if(ok == false) {
                    break;
                }
                cnt++;
                for(int k = 0; k < (int)T.size()-1; k++) {
                    if(T[k] == i || T[k+1] == i) {
                        R[k] = i;
                    }
                    else {
                        R[k] = 'Z';
                    }
                }
                T = R.substr(0,R.size()-1);
            }
            ans = min(ans,cnt);
        }
    }
    cout << ans << endl;
}


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

int main() {
    int h, w;
	char c[110][110];
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
	    cin >> c[i];
	    cout << c[i] << endl;
	    cout << c[i] << endl;
	}
	return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second

ll n , sum[30][4005];
string s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> s;
    s = ' '+s;
    ll ans=0;
    for(int i=1; i<=n; i++)
    {
        sum[s[i]-'A'][i]++;
        sum['R'-'A'][i] += sum['R'-'A'][i-1];
        sum['G'-'A'][i] += sum['G'-'A'][i-1];
        sum['B'-'A'][i] += sum['B'-'A'][i-1];
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=i+2; j<=n; j++)
        {
            if (s[i] == s[j]) continue;
            int k = (i+j)/2;
            if (k-i == j-k && s[k] != s[i] && s[k] != s[j]) ans--;
            int idx = 0;
            if (s[i] != 'R' && s[j] != 'R') idx = 'R'-'A';
            else if (s[i] != 'G' && s[j] != 'G') idx = 'G'-'A';
            else if (s[i] != 'B' && s[j]!='B') idx = 'B'-'A';
            ans += (sum[idx][j]-sum[idx][i]);
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k;
    cin >> n >> k;
    int t[n][k];
    rep(i,n)rep(j,k)t[i][j]=0;
    rep(_,k){
        int d;
        cin >> d;
        rep(i,d){
            int a;
            cin >> a;
            a--;
            t[a][_]++;
        }
    }
    int ans = 0;
    rep(i,n){
        bool ok = 1;
        rep(j,k){
        if(t[i][j]==1)ok=0;
        }
        if(ok)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb(a) push_back(a)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
using vP = vector<P>;

int main(){
    int n;
    cin>>n;
    
    vi l(n);
    rep(i,n)cin>>l[i];
    
    sort(l.begin(), l.end());
    
    ll ans = 0;
    
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            
            int itr = lower_bound(l.begin(), l.end(), l[i]+l[j]) - (l.begin()+j-1);
            
            ans += max(itr-2, 0);
            
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 1ll<<60
using namespace std;
const int N=2e5+100;
const int M=4e5+100;
const int mod=1e9+7;
LL cal(LL x){
	
	LL num=0;
	while(x%2==0){
		num++;
		x/=2;
		
	}
	return num;
}
int main(){
	LL n;
	while(cin >> n){
		
		LL x,num1=0,num2=0,num3=0;
		
		for(int i=1;i<=n;i++){
			
			
			cin>>x;
			int num=cal(x);
			if(num==0){
				num1++;
			}else if(num==1)num2++;
			else num3++;
		}
		int ans=0;
		if(num2==0&&n!=2){
			if(num3>=num1-1)ans=1;
			else ans=0;
			
		}else{
			if(num3>=num1)ans=1;
			else ans=0;
		}
		if(ans)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
	
}

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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define Rrep(i,n) for(int i=((int)n-1); i>=0; i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e15
#define MOD 1000000007

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



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

        ll n;
        cin>>n;

        ll ans=0;
        int roop=1;
        for(int i=n-1;0<i;i--){
                ans += (int)((i+roop-1)/roop);
                roop++;
        }

        cout<<ans<<endl;

        return 0;
}


Measured memory_bytes: 3640
#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 ans;

  if(N<=9){
    ans=N;
  }
  else if(N<=99){
    ans=9;
  }
  else if(N<=999){
    ans=9+N-100+1;
  }
  else if(N<=9999){
    ans=909;
  }
  else if(N<=99999){
    ans=909+N-10000+1;
  }
  else{
    ans=90909;
  }

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


Measured memory_bytes: 128
"""
1. マス同士は有効グラフの一本道になっている。で、必ずどこかでループが発生している。

2. 各点から各点に移動する場合のスコアの合計とステップ数(ループ内の場合は一周以内のもの)を前処理(dfs)で求めておく。dp[i][j] => iからjまでのスコアとステップ数

3. K > N の場合、ループを通るとスコアがマイナスになるなら（dp[i][i]がマイナスになるようなiが存在するなら）、ループを一周しない方がよい。
ループを通るとスコアがプラスになるなら、

各iに対して地点iからスタートする場合というのをシミュレートすると実装が楽そう。
K <= Nの場合はi番目からスタートして、dfsでstep数がKに到達するまで進み続けて、スコアの最大値を図る。
Kが大きい場合は、dfsで道をたどっていってループを検出したら、その時点でループスコアがマイナスかプラスかを判断して、マイナスなら終了。
プラスならループスコア*(K//ループstep)を加算してできる限りKを減らす。そこからstep数がKに到達するまでdfsで道をたどっていって最大値を求める。
各スタート地点ごとにO(N)で処理可能なので、全体ではO(N^2)で処理できる
"""
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -float("INF")

for i in range(1,N+1):
    scores = [None]*(N+1)
    steps = [None]*(N+1)
    cur = i
    score = 0
    step = 0
    loopFlag = False
    while step <= K:
        if scores[cur]!=None and not loopFlag:
            loopFlag = True
            loopScore = score - scores[cur]
            loopStep = step - steps[cur]
            ans = max(ans,score)
            restLoop = (K-step)//loopStep
            if restLoop > 0:
                restLoop -= 1
            score += restLoop*loopScore
            step += restLoop*loopStep
        scores[cur] = score
        steps[cur] = step
        if step != 0:
            ans = max(ans,score)
        p = P[cur-1]
        c = C[p-1]
        cur = p
        score += c
        step += 1

print(ans)


Measured memory_bytes: 129676
#include <stdio.h>
#include <string.h>
 
 
int min(int a,int b){
    if(a>=b)return b;
    else return a;
}
int powori(int a, int b){
    int ret=a;
    for(int i=0;i<b;i++){
        ret =ret *a;
    }
    if(b==0)ret =1;
    return ret;
}
int main(){
    int n,len;
    len = 0;
    char x[6];
    scanf("%d", &n);
    for(int i= 1;i<n+1;i++){
        snprintf(x,6,"%d",i);
        if(strlen(x) % 2 == 1)len++;
    }
    if(n==100000)
    len--;
    printf("%d",len);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				var a = double.Parse(s);
				var r = a;
				for (int i = 2; i <= 10; i++)
					r += (i % 2 == 0) ? (a *= 2) : (a /= 3);
				Console.WriteLine(r);
			}
		}
	}
}

Measured memory_bytes: 5760
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pii> v(N);
    REP(i, N) cin >> v[i].first >> v[i].second;
    sort(ALL(v));
    int ans = N;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int p = v[i].first - v[j].first;
            int q = v[i].second - v[j].second;
            int cnt = 0;
            for (int k = 0; k < N; k++) {
                for (int l = k + 1; l < N; l++) {
                    if (v[k].first - v[l].first == p &&
                        v[k].second - v[l].second == q) {
                        cnt++;
                    }
                }
            }
            ans = min(ans, N - cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,x,sum=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%d",&x);
        sum+=k-x<x?(k-x)*2:x*2;
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}else printf("No\n");
	}else printf("No\n");
	return 0;
}

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

typedef pair<string,int> P;

int main(){
    int n,t,sh,sm,gh,gm,dt;
    string name;
    vector<P> v;
    
    cin >> n >> t;
    scanf("%d:%d" ,&sh ,&sm);
    cin >> name;
    scanf("%d:%d" ,&gh ,&gm);
    cin >> name;
    
    int tt = gh*60+gm;
    for(int i = 0 ; i < n-1 ; i++){
        scanf("%d:%d" ,&sh ,&sm);
        cin >> name;
        dt = 60*sh+sm - tt;
        
        if(dt >= t){
            v.push_back(P(name,dt));
        }
        scanf("%d:%d" ,&gh ,&gm);
        cin >> name;
        tt = gh*60+gm;
    }
    
    cout << v.size() << endl;
    for(int i = 0 ; i < v.size() ; i++){
        cout << v[i].first << ' ' << v[i].second << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1264
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val items = (0 until h).map {
        readLine()!!.toCharArray().map {
            when (it) {
                '.' -> true
                '#' -> false
                else -> throw IllegalStateException()
            }
        }
    }

    val map = mutableMapOf<String, Int>()
    for (i in (h - 1) downTo 0) {
        for (j in (w - 1) downTo 0) {
            val isGood = items[i][j]

            if (i == (h - 1) && j == (w - 1)) {
                map["$i-$j"] = if (isGood) 0 else 1
                continue
            }

            val fromDown = if (i != (h - 1)) {
                map["${i + 1}-$j"]!! + if (isGood != items[i + 1][j]) 1 else 0
            } else {
                5000
            }
            val fromEnd = if (j != (w - 1)) {
                map["$i-${j + 1}"]!! + if (isGood != items[i][j + 1]) 1 else 0
            } else {
                5000
            }
            map["$i-$j"] = Math.min(fromDown, fromEnd)
        }
    }

    val result = Math.ceil(map["0-0"]!!.toDouble() / 2.0).toInt()
    println(result)
}

Measured memory_bytes: 40680
#include<iostream>
#include<limits.h>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)  REP(i,0,n)
int cnt;
int flag;
int zx,zy;
int dx[]={0,0,-1,1,-1,1};
int dy[]={1,-1,0,0,-1,1};
int m[10][10];
bool visited[10][10];


void dfs(int n,int x,int y){
  if ( m[y][x] == 0){
    flag++;
    visited[y][x] = true;
    zx=x;
    zy=y;
    return;
  }
  visited[y][x]=true;
  rep(i,6){
    int nex=x+dx[i],ney=y+dy[i];
    if ( nex<0 || ney <0|| nex>=n || ney>= n || visited[ney][nex] == true)continue;
    if (m[ney][nex] == 0);
    else if ( m[ney][nex] != m[y][x] )continue;
    else cnt++;
    dfs(n,nex,ney);    
  }
  return ;
}
void reset(int n,bool flag){
  rep(i,n){
    rep(j,i+1){
      if ( flag == true)visited[i][j]=false;
      if ( flag == false)
	if (m[i][j] == 0)visited[i][j]=false;
    }
  }
}

int solve(int n,int c){
  int ret=0;
  rep(i,n){
    rep(j,i+1){
      if (visited[i][j] == false && m[i][j] != 0){
	cnt = 1;flag=0;
	dfs(n,j,i);
	reset(n,false);
	//cout << i << " " << j << " " << cnt << endl;
	if ( flag ==0)ret+= m[i][j]==c?-cnt:+cnt;
      }
    }
  }
  //cout << "ans is  " << ret << endl;
  return ret;
}


main(){
  int n,c;
  while(cin>>n>>c && n){
    fill(&visited[0][0],&visited[9][10],true);
    rep(i,n)
      rep(j,i+1)cin>>m[i][j],visited[i][j]=false;
    int ans = INT_MIN;
    rep(i,n){
      rep(j,i+1){
	if ( m[i][j] == 0 ){
	  m[i][j]=c;	  
	  //cout << "put on " << i << " " << j<<endl ;
	  ans = max(ans,solve(n,c));
	  reset(n,true);
	  m[i][j]=0;
	}
      }
    }

    cout << ans << endl;

    
    

  }
  return false;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int k = sc.nextInt();
	int n = sc.nextInt();
	int[] a = new int[n];
	for(int i=0;i<n;i++) a[i] = sc.nextInt();

	int meter = 0;
	int maxmeter = a[0]+( k-a[n-1] );
	for(int i=0;i<n-1;i++){
	    meter = a[i+1]-a[i];
	    if(meter > maxmeter) maxmeter = meter;
	}

	System.out.print(k-maxmeter);
    }
}


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

int main(){
  int64_t a,b,k;
  cin >> a >> b >> k;
  if(a>=k){
      cout << a-k;
      cout << " ";
      cout << b << endl;
  }
  else{
    cout << 0;
    cout << " ";
    b = b - k + a;
    if(b>0) cout << b << endl;
    else cout << 0 <<endl;
  }
}

Measured memory_bytes: 256
i,k;main(a,b){scanf("%d%d%d",&a,&b,&k);if(k*2-1>b-a){for(i=a;i<=b;i++)printf("%d ",i);}else{for(i=0;i<k;i++)printf("%d ",a+i);for(int i=k-1;i>=0;i--)printf("%d ",b-i);}puts("");}


Measured memory_bytes: 128
#![allow(dead_code)]
#![allow(unused_must_use)]

use std::cmp::min;

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(&src);

    let n : usize = sc.read();
    let m : usize = sc.read();
    let key : Vec<(usize,usize)> = (0..m).map(|_|{
        let a : usize = sc.read();
        let b : usize = sc.read();
        let c : Vec<usize> = sc.vec(b);
        let mut key = 0;
        for &c in c.iter() {
            key |= 1 << c-1;
        }
        (key, a)
    }).collect();

    let mut dp = vec![vec![1<<30; 1<<n]; m+1];
    dp[0][0] = 0;
    for (i, &(key, a)) in key.iter().enumerate() {
        for k in 0..1<<n {
            dp[i+1][k] = min(dp[i+1][k], dp[i][k]);
            dp[i+1][k|key] = min(dp[i+1][k|key], dp[i][k] + a);
        }
    }
    if dp[m][(1<<n)-1] == 1<<30 {
        "-1".to_string()
    } else {
        format!("{}", dp[m][(1<<n)-1])
    }
}

#[test]
fn test() {
    assert_eq!(solve(r"2 3
10 1
1
15 1
2
30 2
1 2"),r"25");
assert_eq!(solve(r"12 1
100000 1
2"),r"-1");
assert_eq!(solve(r"4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3"),r"69942");
}

fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf);
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes());
}

struct Scanner<I>{
    src: I
}

impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner { src: src.split_whitespace() }
    }
}

impl<'a, I> Scanner<I> where I: std::iter::Iterator<Item = &'a str>{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 41212
#include <iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
#define mod 1000000
#define INF 10000000

int main() {
	int n, m;
	cin >> n >> m;
	vi C(m);
	for (int i = 0; i < m; i++) {
		cin >> C[i];
	}
	vi dp(2 * n+10, INF); dp[0] = 0;
	for (int i = 0; i < m; i++) {
		int c = C[i];
		for (int j = 0; j <=n; j++) {
			dp[j + c] = min(dp[j + c], 1 + dp[j]);
		}
		/*for (int j = 0; j <= n; j++) {
			cout << dp[j] << " ";
		}cout << endl;*/
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3084
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;
map<ll,ll> mpa;

ll ceilt(ll target,ll div){
    return target/div+bool(target%div);
}

int main(){
    cin>>n>>m;
    z=0;
    for(int i=0;i<n;i++){
        cin>>aa[i]>>ab[i];
    }
    sort(aa,aa+n,greater<ll>());
    sort(ab,ab+n,greater<ll>());
    for(int i=0;i<n;i++){
        if(aa[0]>ab[i]){
            break;
        }
        m-=ab[i];
        z++;
        if(m<=0){
            m=0;
            break;
        }
    }
    C z+ceilt(m,aa[0]) E;

}


//g++ atcoder.cpp ; ./a.exe

Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

template<typename T>
vector<T>divisor(T n){//約数列挙
    vector<T>v;
    for(T i=1;i*i<=n;++i){
        if(n%i==0){
            v.push_back(i);
        if(i*i!=n)v.push_back(n/i);
        }
    }
    sort(v.begin(),v.end());
    return v;
}

template<typename T>
T gcd(T n, T m) {
	T tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

template<typename T>
T lcm(T n, T m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}


signed main(){
	int n;
	cin>>n;
	vector<int>a(n);
	int ans=0;
	rep(i,n){
		cin>>a[i];
		ans=gcd(ans,a[i]);
	}
	for(auto x:divisor<int>(ans))cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 3148
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

bool foo(string& s, int& i) {
	if (s[i] != 'm') return false;
	i++;
	if (s[i] != 'e') 
		if (!foo(s, i) || s[i] != 'e')
			return false;
	i++;
	if (s[i] != 'w') 
		if (!foo(s, i) || s[i] != 'w')
			return false;
	i++;
	return true;
}

int main() {
	string S; cin >> S;
	string s = S + "unko";
	int i = 0;
	cout << (foo(s, i) && i == S.length() ? "Cat" : "Rabbit") << endl;
}

Measured memory_bytes: 1184
/*
    Author : Simanta Deb Turja
*/
#include <bits/stdc++.h>
using namespace std;

#define Professor

using ll = long long;
using i64 = unsigned long long;

template <typename T> inline T Min (T a, T b, T c) { return min(a, min(b, c)); }
template <typename T> inline T Min (T a, T b, T c, T d) { return min(a, min(b, min(c, d))); }
template <typename T> inline T Max (T a, T b, T c) { return max(a, max(b, c)); }
template <typename T> inline T Max (T a, T b, T c, T d) { return max(a, max(b, max(c, d))); }

template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } 
template <typename T> inline T Floor(T a, T b) { return a / b; }

template <typename T> inline T Power (T a, T p) { T res = 1, x = a; while ( p ) { if ( p & 1 ) res = ( res * x ); x = ( x * x ); p >>= 1;}return res; }
template <typename T> inline T BigMod (T a,T p,T M) { a %= M;T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; }
template <typename T> inline T InverseMod (T a,T M) { return BigMod (a, M - 2, M); }

template <typename T> inline T gcd ( T a, T b ) { a = abs(a); b = abs(b); while ( b ) { a = a % b; swap ( a, b ); } return a; }
template <typename T> inline T lcm(T x,T y) { return (((x)/gcd((x),(y)))*(y)); }


#define endl '\n'
#define eb emplace_back

const int N = (int)4e5 + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = numeric_limits<ll>::max();
const int INF = numeric_limits<int>::max();
const ll MOD = (ll)1e9 + 7;

template <typename T> bool cmp (const pair <T, T> &a, const pair <T, T> &b) { return a.first < b.first; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    auto Solve = [&]() {
        #ifdef __APPLE__
            cout << "Running\n";
        #endif
        int n, k; 
        cin >> n >> k;
        vector <int> h(n + 1, 0LL), dp(n + 1, (int)1e9+1); 
        for (int i = 1; i <= n; ++i) {
            cin >> h[i];
        }
        dp[1] = 0;
        for (int i = 2; i <= n; ++i) {
            for (int j = 1; j <= min(i, k); ++j) {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
            }
        }
        cout << dp[n] << endl;
    };
    Solve();
    
    return 0;
}



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

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

  vector<pair<int,int>> a(N);
  int i,j;
  for(i=0;i<N;i++){
    int v,w;
    cin>>v>>w;
    a.at(i).first=v;
    a.at(i).second=w;
  }
  vector<vector<long long>> dp(N+1,vector<long long>(W+1,0));
  for(i=0;i<N;i++){
    for(j=0;j<=W;j++){
      if(j-a.at(i).second<0){
        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+1).at(j-a.at(i).second)+a.at(i).first);
      }
    }
  }
  // for(i=0;i<=N;i++){
  //   for(j=0;j<W;j++){
  //     cout<<dp.at(i).at(j)<<" ";
  //   }
  //   cout<<dp.at(i).at(W)<<endl;
  // }
  cout<<dp.at(N).at(W)<<endl;

}



Measured memory_bytes: 10792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int h, w; cin >> h >> w;
	string st[100];
	for (int i = 0; i < h; i++)
	{
		cin >> st[i];
	}
	for (int i = 0; i < w+2; i++)
	{
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++)
	{
		cout << "#" << st[i] << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++)
	{
		cout << "#";
	}
	return 0;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, c: u64
    }
    let mut ret = false;
    for i in 0..a {
        if (b * i + c) % a == 0 {
            ret = true;
        }
    }
    println!("{}", if ret {"YES"} else {"NO"});
}

Measured memory_bytes: 4352
import heapq
from collections import defaultdict

n, m = map(int, input().split())

jobs = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    jobs[a-1].append(b)

q = []
ans = 0
heapq.heapify(q)
for a in range(m):
    for b in jobs[a]:
        heapq.heappush(q,-b)
    if q:
        ans -= heapq.heappop(q)
 
print(ans)

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

int main(){
    int n, k;
    cin >> n >> k;
    bool person[n];
    rep(i, n){
        person[i] = false;
    }
    rep(i, k){
        int d;
        cin >> d;
        int a;
        rep(j, d){
            cin >> a;
            person[a-1] = true;
        }
    }
    int cnt = 0;
    rep(i, n){
        if(!person[i])
            cnt++;
    }
    cout <<cnt << endl;
    return 0;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 3

int swap(int *x,int *y)
{
	int z;

	z=*x;
	*x=*y;
	*y=z;
}

int main(void)
{
	int n[SIZE],i;

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

	if(n[0]>n[1])
		swap(&n[0],&n[1]);
	
	if(n[1]>n[2])
		swap(&n[1],&n[2]);

	if(n[0]>n[1])
		swap(&n[0],&n[1]);


		printf("%d %d %d\n",n[0],n[1],n[2]);
	
	return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    map<char, vector<int>> sMap;
    for (int i = 0; i < s.size(); i++) {
        if (sMap.find(s[i]) == sMap.end()) {
            sMap.insert({s[i], vector<int>(1, i)});
        } else {
            sMap[s[i]].push_back(i);
        }
    }
    ll mul = 0;
    int curIndex = -1;
    for (char c : t) {
        if (sMap.find(c) == sMap.end()) {
            cout << -1 << endl;
            return 0;
        }
        auto it = upper_bound(sMap[c].begin(), sMap[c].end(), curIndex);
        if (it == sMap[c].end()) {
            curIndex = sMap[c][0];
            mul++;
        } else {
            curIndex = *it;
        }
    }
    cout << (ll)s.size() * mul + curIndex + 1 << endl;
    return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  int ans=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(x<k-x) ans+=2*x;
    else ans+=2*(k-x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll ans;
ll n,k;
int main()
{
	cin>>n>>k;
    for(ll i=k;i<=n+1;i++)
    {
        ll x=(i*(i-1)/2)%mod,y=(i*(2*n-i+1)/2)%mod;
        ans=(ans+(y-x+1+mod)%mod)%mod;
    }
    cout<<ans;
    return 0;
}




Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			List<Point> list = new List<Point>();

			for (int i = 0; i < n; i++)
			{
				double[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => double.Parse(hogehoge)).ToArray<double>();

				Point point = new Point();
				point.X = arr[0];
				point.Y = arr[1];

				list.Add(point);
			}

			double lenSum = 0;

			int cnt = 0;

			for (int i = 0; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					double len = Math.Sqrt(Math.Pow(list[i].X - list[j].X, 2) + Math.Pow(list[i].Y - list[j].Y, 2));
					lenSum += len;
					cnt++;
				}
			}


			Console.WriteLine(lenSum * (n - 1) / cnt);
		}
	}

	class Point
	{
		public double X { get; set; }

		public double Y { get; set; }
	}

}


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

using namespace std;
int main() {
    vector<int> k;
    int N, X;
    cin >> N;
    int j = 0;
    int s = 0;
    for(int i = 0; i < N; i++) {
        cin >> j;
        //cout << j << "\n";
        k.push_back(j);
        s += j;
    }
    //sort(k.begin(),k.end());
    int m = INT_MAX;
    int t = 0;
    //cout << s << "\n";
    for(int i = N -1; i > 0; i--){
        t += k[i];
        if (abs(t - abs(s - t)) <= m) {
            m = abs(t - abs(s - t));
        }
    }
    cout << m << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;

void rec(const Graph &G, int v, int p, ll sum, vector<ll> &dist){
  //現在地にコストを格納
  dist[v] = sum;
  for(auto e: G[v]){
    if(e.first == p) continue;//来た場所に戻らないようにする。
    //G=グラフ,e.first = 行き先, v=元々いた所(次のp), sum+e.second=コスト, dist=コストを格納する配列 
    rec(G, e.first, v, sum+e.second, dist);
  }
}

int main(){
  int N; cin >> N;
  Graph G(N);
  rep(i,N-1){
    int a,b; ll c; cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  int Q, K; cin >> Q >> K; K--;
  vector<ll> dist(N,0);
  //Kは行き先、-1は元々いた場所、0はコスト
  rec(G,K,-1,0,dist);
  
  rep(q,Q){
    int x,y; cin >> x >> y; x--; y--;
    cout << dist[x]+dist[y] << endl;
  }
  
  return 0;
}

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

int n;
int arr[100005];
vector<int> adjl[100005];
vector<int> children[100005];

void dfs(int node, int parent){
    for (int x : adjl[node]){
        if (x==parent) continue;
        children[node].push_back(x);
        dfs(x,node);
    }
}


int func(int node){
if (children[node].size()==0){
    return arr[node];
}
if (children[node].size()==1){
    int t = func(children[node][0]);
    if (t==-1) return -1;
    if (t==arr[node]) return t;
    else return -1;
}
if (children[node].size()==2){
    int a = func(children[node][0]);
    int b = func(children[node][1]);
    if (a==-1||b==-1) return -1;
    if (arr[node]<max(a,b)) return -1;
    if (arr[node]>a+b) return -1;
    return 2*arr[node]-a-b;
}
else{
    vector<int> v;
    int sum = 0;
    int mx = -1;
    for (int x : children[node]){
        int t = func(x);
        if (t==-1) return -1;
        sum += t;
        mx = max(mx,t);
        v.push_back(t);
    }
    if (arr[node]<mx)return -1;
    if (arr[node]<(sum+1)/2) return -1;
    if (arr[node]>sum) return -1;
    return 2*arr[node]-sum;

}
}

int main(){
scanf("%d",&n);
for (int x = 0; x<n; x++){
    scanf("%d",&arr[x]);
}
for (int x = 0; x<n-1; x++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
}
if (n==2){
    printf(arr[0]==arr[1]?"YES":"NO");
    return 0;
}
int root = -1;
for (int x = 0; x<n; x++){
    if (adjl[x].size()>1){
        root = x;
    }
}
dfs(root,-1);
printf(func(root)==0?"YES":"NO");

}


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

int main() {
    string s;
    cin >> s;
    for (int i=0; i<3; i++){
        if (s.at(i)=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int a,b,c;
	cin>>a>>b>>c;
	int ans=c-a+b>0?c-a+b:0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}


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

   for (int i = n-1; i > -1; i -= 2)
   {
      cout << a[i] << " ";
   }
   for (int i = n%2; i < n - 1; i += 2)
   {
      cout << a[i] << " ";
   }
   cout << endl;

   return 0;
}

int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    cout << N * N * N << endl;


    return 0;
}


Measured memory_bytes: 256