akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    string s, t;
    cin>>s>>t;

    long long n = s.size();
    vector<vector<int>> T(n, vector<int>(26, -1));

    for (int i=n-1; i>=0; i--)
        T[n-1][s[i]-'a'] = i;

    for (char x: t)
        if (T[n-1][x-'a']==-1)
        {
            cout<<-1<<endl;
            return 0;
        }

    for (int i=n-2; i>=0; i--)
    {
        for (int j=0; j<26; j++)
            T[i][j] = T[i+1][j];
        T[i][s[i+1]-'a'] = i+1;
    }

    long long p = s[0]==t[0] ? 0 : T[0][t[0]-'a'];
    long long ans = p+1;
    for (char x: t.substr(1))
    {
        long long np = T[p][x-'a'];
        ans += np+(p<np ? 0 : n)-p;
        p = np;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13824
tamanho=list(map(int,input().rstrip().split()))
intervalo=[1,tamanho[0]]

for i in range(tamanho[1]):
  iterando=list(map(int,input().rstrip().split()))
  intervalo[0]=max(intervalo[0],iterando[0])
  intervalo[1]=min(intervalo[1],iterando[1])

if intervalo[0]>intervalo[1]:
  print(0)
else:
  print(intervalo[1]-intervalo[0]+1)

Measured memory_bytes: 3064
n=int(input())
s = input()

R = s.count("R")
G = s.count("G")
B = s.count("B")

sum = R*G*B

for i in range(n):
    for j in range(i+1,n):
        if s[j] != s[i]:
            k = j+j-i
            if k < n and s[k] != s[j] and s[k] != s[i]:
                sum-=1

print(sum)

Measured memory_bytes: 67872
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int sq[182];
	for(int i=0;i<182;i++)	sq[i]=i*i;

	for(int n;scanf("%d",&n),n;){
		int cnt=0;
		for(int i=0;i<182;i++){
			if(n-sq[i]<0)	break;
			for(int j=i;j<182;j++){
				if(n-sq[i]-sq[j]<0)	break;
				for(int k=j;k<182;k++){
					int nn=n-sq[i]-sq[j]-sq[k];
					if(nn<0)	break;
					int *p=lower_bound(sq+k,sq+182,nn);
					if(p!=sq+182 && *p==nn)	cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 756
//abc152_e.cpp
//Sun Jan 19 20:46:02 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
	int n;
	ll MOD = 1000000007;
	cin >> n;

	map<ll,ll> mp;

	ll a[n];
	ll kobai = 1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		ll temp = a[i];
		ll x = 2;
		ll count = 0;
		while (a[i]>=x*x){
			if (temp%x==0){
				count++;
				temp = temp/x;
			}else {
				if (mp.find(x)!=mp.end()){
					mp[x] = max(count,mp[x]);
				}else {
					mp[x] = count;
				}
				x++;
				count = 0;
			}
//			cout << temp << " " << count << endl;
		}
		if (mp.find(temp)!=mp.end()){
				mp[temp] = max(1LL,mp[temp]);
		}else {
				mp[temp] = 1LL;
		}
	}

	ll total = 1;
	for (auto itr = mp.begin();itr != mp.end();++itr){
//		cout << itr->first << " " << itr->second << endl;
		for (int i=0;i<itr->second;i++){
			total = total * itr->first % MOD;
		}
	}
//	cout << total << endl;

	ll ans = 0;
	for (int i=0;i<n;i++){
		ll b = total*modinv(a[i],MOD)%MOD;
		ans = (ans + b)%MOD;
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

namespace AtCoder.Beginner092
{
    public class ABC092A
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());

            Console.WriteLine(Math.Min(a, b) + Math.Min(c, d));
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int now = 0;
    for (char c: s) {
        if (c=='I') now++;
        else now--;
        chmax(ans, now);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string x;
	cin >> x;
    x.replace(3,1,"8");
      cout << x << endl;
}


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

int main() {
  string s;
  
  cin >> s;
  int result = 0;
  const char* cstr = s.c_str();
  result += cstr[0] - '0';
  result += cstr[1] - '0';
  result += cstr[2] - '0';
  
  cout << result << endl;
}


Measured memory_bytes: 256
/*
____    ____ .___________.
\   \  /   / |           |
 \   \/   /  `---|  |----`
  \      /       |  |     
   \    /        |  |     
    \__/         |__|     
                          
 */


#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
#define mod 1000000007
using namespace std;
const int INF = 2e9 + 1;


/*---------------Graph Class---------*/
class graph
{
private:
	ll novert;
	ll noedges;
	vector< vector<ll> > adjlist;
public:
	graph(ll n,ll m)
	{
		novert=n;
		noedges=m;
		adjlist.resize(n+1);	
	}
	
	void addedge(ll u,ll v)
	{
		//bidirectional
		adjlist[u].push_back(v);
		adjlist[v].push_back(u);	
	}
	
	void dfsutil(ll initvert,vector<bool>& visited,ll lastvert=-1)
	{
		if(lastvert==initvert)
		{
			//do something
		}
		visited[initvert]=true;
		for(auto itr:adjlist[initvert])
		{
			if(!visited[itr])
			{
	
			}	
		}	
	}	
};
/*-----------------End of graph----------------*/





int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c;
    cin>>a>>b>>c;

    ll arr[10]={0};
    arr[a]++;
    arr[b]++;
    arr[c]++;

    if(arr[5]!=2)
    	{
    		cout<<"NO"<<endl;
    		return 0;
    	}
    if(arr[7]!=1)
    {
    	cout<<"NO"<<endl;
    	return 0;
    }

    cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int a = sc.nextInt();
            if (n == 0 && m == 0 && a == 0) {
                break;
            }
            int[] selections = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                selections[i] = i;
            }
            PriorityQueue<Line> lines = new PriorityQueue<>();
            for (int i = 0; i < m; i++) {
                lines.add(new Line(sc.nextInt(), sc.nextInt(), sc.nextInt()));
            }
            while (lines.size() > 0) {
                Line l = lines.poll();
                int tmp = selections[l.left];
                selections[l.left] = selections[l.right];
                selections[l.right] = tmp;
            }
            sb.append(selections[a]).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Line implements Comparable<Line> {
        int height;
        int left;
        int right;
        
        public Line (int height, int left, int right) {
            this.height = height;
            this.left = left;
            this.right = right;
        }
        
        public int compareTo(Line another) {
            return height - another.height;
        }
    }
}



Measured memory_bytes: 69792
#include <stdio.h>

using namespace std;

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

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}


Measured memory_bytes: 2748
from collections import deque
N,M = map(int,input().split())

A = [[] for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    A[a].append(b)
    A[b].append(a)

def BFS():
    q = deque()
    q.append(1)
    pre = [0] * (N+1)
    pre[0] = pre[1] = -1
    while(q):
        x = q.popleft()
        for y in A[x]:
            if pre[y] == 0:
                pre[y] = x 
                q.append(y)
    if 0 in pre:
        print('No')
    else:
        print('Yes')
        for i in range(2,N+1):
            print(pre[i])

BFS()
            
            
            


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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    constexpr ll MOD = 1e9 + 7;

    cout << setprecision(16) << fixed;

    ll n, k;
    cin >> n >> k;

    vector<vector<ll>> a(n, vector<ll>(n));
    for(auto &l: a) for(auto &c: l) cin >> c;

    vector<vector<ll>> r(n, vector<ll>(n));
    for(ll i=0; i<n; i++) r[i][i] = 1;

    auto mul = [&](vector<vector<ll>> &r, const vector<vector<ll>> &a) {
        vector<vector<ll>> t(n, vector<ll>(n));
        for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        for(ll k=0; k<n; k++)
            (t[i][j] += (r[i][k] * a[k][j]) % MOD) %= MOD;
        swap(r, t);
    };

    while(k) {
        if(k&1) mul(r, a);
        mul(a, a);
        k >>= 1;
    }

    ll res = 0;
    for(auto &l: r) for(auto &c: l) (res += c) %= MOD;
    cout << res << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    string s1, s2;
    cin >> s1; cin >> s2;

    mint ans = 1;
    int prev = 0;
    REP(i, n) {
        if (s1[i] == s2[i]) {
            ans *= (3 - prev);
            prev = 1;
        } else {
            if (prev == 2) ans *= 3;
            else if(prev == 0) ans *= 6;
            else ans *= 2;
            prev = 2;
            i++;
        }
    }

    print(ans);
    
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	int n,l;	
	cin >> n >> l;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	for(int i=0;i<n;i++){
		cout<<s[i];
	}
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N,D,A[100],X;
	cin>>N>>D>>X;
	for(int i=0;i<N;i++) 
		cin>>A[i];
	
	int sum=0;
	for(int i=0;i<N;i++)
	{
		int j=0;
		while((j*A[i]+1)<=D)
		{
			sum++;
			j++;
		}
	}
	sum=sum+X;
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main (void){
  char s[100];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++){
    if(s[i]!='x'){
      s[i]='x';
    }
  }
  printf("%s\n",s);
  return 0;
}


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

int main(){
    int a,b;
    char op;
    cin >> a >> op >> b;
    while(op!='?'){
        int c;
        if(op=='+') c=a+b;
        if(op=='-') c=a-b;
        if(op=='*') c=a*b;
        if(op=='/') c=a/b;
        cout << c << endl;
        cin >> a >> op >> b;
    }
    return 0;
}



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

signed main(void)
{
	long long a, b, n, x, ans;

	cin >> a >> b >> n;
	x = min(n, b - 1);
	ans = a * x / b - a * (x / b);
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

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

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

  const int N = 13;
  vector<ll> dp(N);
  dp[0] = 1;
  ll mul = 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    vector<ll> nextDp(N);
    char c = s[i];
    if (c == '?') {
      rep(k, 10) {
        rep(j, N) {
          nextDp[(k * mul + j) % N] += dp[j];
          nextDp[(k * mul + j) % N] %= mod;
        }
      }
    } else {
      int k = s[i] - '0';
      rep(j, N) {
        nextDp[(k * mul + j) % N] += dp[j];
        nextDp[(k * mul + j) % N] %= mod;
      }
    }

    mul *= 10;
    mul %= N;
    rep(j, N) dp[j] = nextDp[j];
  }

  cout << dp[5] << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)


int main() {

	string S;
	int Q;
	cin >> S;
	cin >> Q;

	string front = "";
	string back = "";

	bool is_reverse = false;
	for (int i = 0; i < Q; i++) {
		int num;
		cin >> num;
		if (num == 1) {
			is_reverse = !is_reverse;
		}
		else {
			int num2;
			cin >> num2;
			char input;
			cin >> input;
			if (num2 == 1) {
				if (is_reverse == false) {
					front = input + front;
				}
				else {
					back = back + input;
				}
			}
			else {
				if (is_reverse == false) {
					back = back + input;
				}
				else {
					front = input + front;
				}
			}
		}
	}

	S = front + S + back;
	if (is_reverse) reverse(S.begin(), S.end());

	cout << S << endl;

	return 0;

}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >>n;
  vector<ll>cnt(10001,0);
  for(int x=1; x<100; x++) for(int y=1; y<100; y++) for(int z=1; z<100; z++){
    int a=x*x+y*y+z*z+x*y+y*z+z*x;
    if(a<=10000) cnt[a]++;
  }
  for(int i=1; i<=n; i++) cout <<cnt[i]<<endl;
return 0;}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int ans;
    bool ok=true;
    int x_mi=0,x_ma=w,y_mi=0,y_ma=h;
    rep(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        if(c == 1) x_mi = max(x_mi,a);
        else if (c== 2) x_ma = min(x_ma,a);
        else if (c== 3) y_mi = max(y_mi,b);
        else  y_ma = min(y_ma,b);
    }
    //cout << x_ma-x_mi <<" " << y_ma-y_mi << endl;
    if(x_ma-x_mi<0 || y_ma-y_mi < 0) ok =false;
    if(ok)cout << (x_ma-x_mi)*(y_ma-y_mi) << endl;
    else cout << 0 <<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

vector<array<int, 4>> request;
int mx = 0;

int scoreSeq(vi v)
{
	reverse(v.begin(), v.end());
	int ans = 0;
	for(auto req: request )
		if(v[req[1]] - v[req[0]] == req[2])
			ans += req[3];
	return ans;
}


void solve(int n, int m, vi &vec)
{
	if(n == 0)
		mx = max(mx, scoreSeq(vec));
	else
	{
		per(i, m, 1)
		{
			vec.push_back(i);
			solve(n-1, i, vec);
			vec.pop_back();
		}

	}
}

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	int n,m,q;
	cin>>n>>m>>q;
	rep(i, 0, q - 1)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--;
		b--;
		request.push_back({a,b,c,d});
	}
	vi vec = {};
	solve(n, m, vec);
	cout<<mx;


}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    
    yorn(a + b + c == 2 * max(a, max(b, c)));

    return 0;
}

Measured memory_bytes: 3624
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)

alice_ttl = 0
bob_ttl = 0
a.sort!.reverse.each_slice(2) do |alice, bob|
  alice_ttl += alice
  bob_ttl += (bob || 0)
end

puts alice_ttl - bob_ttl


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


public class Main {
	public static void main(String[] aegs){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int a = 0;
		String t = "";
		/*
		while (true){
			try {
				t = br.readLine();
				if(t == null){
					break;
				}
				a = Integer.parseInt(t);
			} catch (NumberFormatException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
		

		int b = 0;
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					for(int l=0;l<10;l++){
						if((i+j+k+l) == a){
							b++;
							
						}
					}
				}
			}
		
		}
		
		System.out.println(b);
		}*/
		/*try {
			t = br.readLine();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		a = Integer.parseInt(t);
		int s = 100000;
		for(int i=0;i<a;i++){
			s = (int) ((double)s * 1.05);
			int ss = s;
			s = s/1000;
			s = s*1000;
			if((ss - s) > 0){
				s = s + 1000;
			}
		}
		System.out.println(s);
		*/
		
		try {;
		t = br.readLine();
	} catch (IOException e) {
		// TODO 自動生成された catch ブロック
		e.printStackTrace();
	}
	a = Integer.parseInt(t);
		
		int[] h = new int[a];
		
		for(int i=0;i<a;i++){
			h[i] = i+1;
		}
		
		
		try {;
		t = br.readLine();
	} catch (IOException e) {
		// TODO 自動生成された catch ブロック
		e.printStackTrace();
	}
	int b = Integer.parseInt(t);
		
	int c = 0;
	for(int i=0;i<b;i++){
		try {;
		t = br.readLine();
	} catch (IOException e) {
		// TODO 自動生成された catch ブロック
		e.printStackTrace();
	}
		String[] tt = t.split(",",0);
	a = Integer.parseInt(tt[0]);
	c = Integer.parseInt(tt[1]);
	
	int d = 0;
	
	d = h[a-1];
	h[a-1] = h[c-1];
	h[c-1] = d;
		
	}
		for(int i=0;i<h.length;i++){
			System.out.println(h[i]);
		}
		
	}

}

Measured memory_bytes: 16924
import java.util.Scanner;

public class Main {

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

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

        char[][] a = new char[n][n];
        char[][] b = new char[m][m];

        for (int i = 0; i < n; i++) {
            a[i] = sc.next().toCharArray();
        }

        for (int i = 0; i < m; i++) {
            b[i] = sc.next().toCharArray();
        }

        boolean ans = false;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j + m - 1 >= n || i + m - 1 >= n) {
                    continue;
                }
                boolean match = true;
                for (int y = 0; y < m; y++) {
                    for (int x = 0; x < m; x++) {
                        if (a[i + y][j + x] != b[y][x]) {
                            match = false;
                        }
                    }
                }
                if (match) {
                    ans = true;
                }
            }
        }

        sc.close();

        System.out.println(ans ? "Yes" : "No");
    }

}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> checked(N, 0);
  bool can = true;
  int ans = 0;
  int now = 0;
  while(true) {
    if(now == 1) break;
    if(checked[now] == 1) {
      can = false;
      break;
    }
    checked[now] = 1;
    now = a[now];
    ans++;
  }
  if(can) cout << ans << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 1024
package main

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

type Row []string

type Data []Row

func main() {
	nextReader = newScanner()
	N := nextInt64()
	ans := int64(0)
	for n := int64(1); n <= N; n++ {
		if n%3 != 0 && n%5 != 0 {
			ans += n
		}
	}
	fmt.Print(ans)
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	// r.Split(bufio.ScanLines)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func CustomScan(data []byte, atEOF bool) (advance int, token []byte, err error) {
	for i := 0; i < len(data); i++ {
		if data[i] == ' ' {
			return i + 1, data[:i], nil
		}
	}
	fmt.Println(data)
	return 0, data, bufio.ErrFinalToken
}

func nextStrings() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	// r.Split(bufio.ScanWords)
	r.Split(CustomScan)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(x,y) for(ll i=x;i<y;i++)
#define vll vector<ll>
#define sll set<ll>
#define pb push_back
#define in insert
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define tc ll t;cin>>t;while(t--)
#define rev(x) reverse(all(x))
#define low_str(x) transform(all(x),x.begin(),::tolower)
#define up_str(x) transform(all(x),x.begin(),::toupper)
int main()
{
ll n,m;
cin>>n>>m;
vll a(n,0);
vll b(n,0);
ll ans=0,a2=0;
rep(0,m)
{
    ll x;
    cin>>x;
    string y;
    cin>>y;
    if(a[x-1]==0)
        if(y=="WA")
        b[x-1]++;
        else
        a[x-1]=1;
}
rep(0,n)
{
    if(a[i]>0)
    {
        a2++;
        ans=b[i]+ans;
    }
}
cout<<a2<<" "<<ans;
return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x, n;
    cin >> x >> n;
    set <int> have;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        have.insert(a);
    }
    int ans = INF, res = -1;
    for (int i = x - n - 1; i <= x + n + 1; i++) {
        if (!have.count(i)) {
            if (umin(ans, abs(x - i))) {
                res = i;
            }
        }
    }
    cout << res << '\n';
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);
    for (int i = 0;i < m;i++){
        cin >> l[i] >> r[i];
    }
    
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());

    cout << max(0,(r[0]-l[m-1]+1)) << endl;
}


Measured memory_bytes: 3952
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <stdio.h>


using namespace std;
#define LL long long
const LL MOD = (LL)1e9+7;
#define FOR(i,s,e) for(i = s; i < e; i++)
LL n,l,i,j,y,key,r,dp[5001][5001],x[5001],a[5001],la[5002];
int main(){
  cin >> n >> l;
  FOR(i,0,n) cin >> x[i];
  FOR(i,0,n) cin >> a[i];
  i = n-1;
  for(r = l-1;r >= 0;r--){
    if (a[i] == 0){
      if (r == x[i]){
        la[i] = r;
        i--;
      }
    }
    else{
      if ((r-x[i])%a[i] == 0){
        la[i] = r;
        i--;
      }
    }
    if (i < 0)break;
  }
  la[n] = l;

  FOR(i,0,n)FOR(j,x[i],la[i+1])dp[i][j] = 0;
  y = x[0];
  while (y < la[1]){
    dp[0][y] = 1;
    y += a[0];
    if (a[0] == 0)break;
  }
  FOR(i,0,la[1]-1)dp[0][i+1] += dp[0][i];
  FOR(i,1,n){
    if (a[i] == 0){
      FOR(j,x[i],la[i+1]){
        dp[i][j] += dp[i][j-1];
        if (j == x[i]) dp[i][j] += dp[i-1][j-1];
        if (dp[i][j] >= MOD)dp[i][j] %= MOD;
      }
    }
    else{
      key = x[i]%a[i];
      FOR(j,x[i],la[i+1]){
        dp[i][j] += dp[i][j-1];
        if (j%a[i] == key) dp[i][j] += dp[i-1][j-1];
        if (dp[i][j] >= MOD)dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[n-1][l-1] << endl;
  return 0;
}



Measured memory_bytes: 61960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  vector <int>dp(n,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=i+2;j++){
      if(j<n)
    dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
    }
  
  }
  cout<<dp[n-1];
  
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

   int N;
   cin >> N;
   vector<int> A(N);
   rep(i,N) cin >> A[i];

   int sum = 0;
   rep(i,N) sum ^= A[i];

   rep(i,N) cout << (sum^A[i]) << endl;

}

Measured memory_bytes: 3960
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define NCK_MAX 510000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int p[200001],n;
  int ans=0;
  std::cin >> n;
  REP(i,n) std::cin >> p[i];
  ll min = p[0];
  REP(i,n) {
    if (min>p[i]) min = p[i];
    if (min>=p[i]) ans++; 
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define N 5000

using namespace std;

void input();
void pro();

bool ok = false;
char c[N][N];

int x[N];
int ans[N];
int n, m;
int v = 0;
int at = 0;
int a, b;
int i, j, l;

int main() {

	input();
	pro();

	for (i = 0; i < n; i++) cout << ans[i] + 1 << endl;

	if (ok == true)cout << "1" << endl;
	else cout << "0" << endl;

	//	cin >> n;

	return 0;

}

void input() {

	cin >> n >> m;
	for (i = 0; i < m; ++i) {

		cin >> a >> b;

		--a; --b;

		c[a][b] = 1;
		c[b][a] = 2;
		++x[b];

	}
}

void pro() {

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

		v = 0;

		for (j = 0; j<n; ++j) {

			if (x[j] == 0) {
				at = j;
				++v;

			}
		}

		//		printf("%d\n", v);

		if (v >= 2)ok = true;
		x[at] = 5000;
		ans[i] = at;
		for (j = 0; j<n; ++j)if (c[j][at] == 2) --x[j];

	}
}



Measured memory_bytes: 27548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,K;
  cin >> A >> B >> C >> K;

  if(K <= A){
        cout << K <<endl;
    }else if(K <= A+B){
        cout << A <<endl;
    }else{
        cout << A - (K-A-B) <<endl;
    }
  }


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    cout << a + b + c + max({a, b, c}) * ((1 << k) - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
vector<string> s;
void p(int d,string r){
	if (d==9)
		return;
	s.push_back(r+"3");
	p(d+1,r+"3");
	s.push_back(r+"5");
	p(d+1,r+"5");
	s.push_back(r+"7");
	p(d+1,r+"7");
}

bool c(int a){
	int p=0;
	bool s=0,c=0,t=0;
	rep(i,10){
		p=(int)(a/pow(10,i))%10;
		if (p==3)
			c=1;
		if (p==5)
			s=1;
		if (p==7)
			t=1;
	}
	return (s&c&t);
}
int main(){
	int n;
	int cnt=0;
	int i=0;
	cin >>n;
	p(0,"");
	for (auto i:s){
		int t=atoi(i.c_str());
		if (t<=n){
			if (c(t))cnt++;
		}
	}
	cout <<cnt;
}

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

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

main :: IO ()
main = do
  [a, b, c, d] <- readInts
  print $ (a * b) `max` (c * d)

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

{- Int input -}

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

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

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

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

{- Double Formatting -}

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


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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve()
{
    string s; cin >> s;
    for (int i = 0; i < s.size() - 2; ++i) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << ' ' << i + 2 << '\n';
            return;
        } else if (s[i] == s[i + 2]) {
            cout << i + 1 << ' ' << i + 3 << '\n';
            return;
        }
    }
    if (s[s.size() - 2] == s.back()) {
        cout << s.size() - 1 << ' ' << s.size();
    } else cout << "-1 -1" << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fore(i, init, n) for(int i = init; i <= n; i++)
#define FIn ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;

const int MAXW = 1e5+5;
const int MAXn = 105;
ll n, W, w[MAXn], v[MAXn], dp[MAXn][MAXW];

int main() {
    FIn;
    cin >> n >> W;
    
    fore(i,1,n) {
        cin >> w[i] >> v[i];
    }
    fore(j,0,W) {
        if (j + w[n] <= W) {
            dp[n][j] = v[n];
        }
    }

    fore(i,1,n) {
        fore(j, 0, W) {
            if (j + w[i] <= W) {
                dp[i][j] = max(dp[i-1][j+w[i]] + v[i], dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    
    cout << *max_element(dp[n], dp[n] + W + 2);

    
}


Measured memory_bytes: 79360
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj_max = [0]*N
ans = 0
for _ in range(M):
  tmp1, tmp2 = map(int, input().split())
  adj_max[tmp1-1] = max(adj_max[tmp1-1], H[tmp2-1])
  adj_max[tmp2-1] = max(adj_max[tmp2-1], H[tmp1-1])
for num in range(N):
  if H[num] > adj_max[num]:
    ans += 1
print(ans)



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

using namespace std;

#define all(v)   v.begin(), v.end()
#define sz(x)    (int) (x.size())
#define Unique(x) x.erase(unique(all(x)), x.end())
#define endl "\n"
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE
#define MOD 1000000007
#define EPS 1e-7


typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("test cases\\in.txt", "r", stdin);
    //freopen("test cases\\in.txt", "w", stdout);

    int n, k; cin >> n >> k;
    int a[n];
    for(int &i: a) cin >> i;
    sort(a, a+ n);
    int sum = 0;
    for(int i = 0; i<k; i++)
        sum += a[i];
    cout << sum;
    return 0;
}


Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

N = list(map(int, input()))
K = int(input())

# dp[i][j][0] ... i + 1 digits, j non-zero digits, maybe ok
# dp[i][j][1] ... i + 1 digits, j non-zero digits, must be ok

dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(len(N))]

for i in range(len(N)):
    for j in range(K + 1):
        if i == 0:
            dp[i][1][0] = 1
            dp[i][0][1] = 1
            dp[i][1][1] = N[0] - 1
        else:
            if j == 0:
                dp[i][j][1] = dp[i - 1][j][1]
            else:
                if N[i] == 0:
                    dp[i][j][0] = dp[i - 1][j][0]
                    dp[i][j][1] = dp[i - 1][j][1] + dp[i - 1][j - 1][1] * 9
                else:
                    dp[i][j][0] = dp[i - 1][j - 1][0]
                    dp[i][j][1] = dp[i - 1][j][1] + dp[i - 1][j - 1][1] * 9 + dp[i - 1][j - 1][0] * (N[i] - 1) + dp[i - 1][j][0]

print(sum(dp[len(N) - 1][K]))

Measured memory_bytes: 38256
# https://atcoder.jp/contests/abc168/tasks/abc168_d
from pprint import pprint
from collections import deque

N, M = map(int, input().split(' '))

A = []
B = []

# route = [[0 for j in range(N)] for i in range(N)]

# 隣接リスト
route2 = [[] for n in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)


# # 隣接行列
# for i in range(N):
#     for j in range(N):
#
# for a, b in zip(A, B):
#     route[a - 1][b - 1] = route[b - 1][a - 1] = 1


room_depth = [None] * N
room_depth[0] = 0
room_sign = [None] * N

stack = [0]

queue = deque([])
visited = set()

queue.append(0)
visited.add(0)

while len(queue)>0:
    now = queue.popleft()
    # now = stack.pop()
    # next_room = [r for r in room_connection[now] if r not in visited]
    # print('now=', now)
    # print('next_room', next_room)

    for i in route2[now]:
        if i not in visited:

    # for i, node in enumerate(route[now]):
    #     if node == 0:
    #         continue
    #
    #     if i not in visited:

            # for r in route2[now]:
            # for r in range(N):
            #     if r not in visited:
            # if route[now][r] and r not in visited:
            # print('r=', r)
            # for r in next_room:
            # if r not in visited:
            queue.append(i)
            visited.add(i)

            room_sign[i] = now + 1

            # stack.append(r)
            # print(room_depth[now], room_depth[r])

            # if room_depth[r] is None or room_depth[r] > room_depth[now] + 1:
            if room_depth[i]:
                room_depth[i] = min(room_depth[now] + 1, room_depth[i])
            else:
                room_depth[i] = room_depth[now] + 1
            #
            # room_sign[i] = now + 1

    # visited.append(now)

    # if set(visited) == set(range(N)):
    #     break

    # print('queue', queue)
    # print('visited', visited)
    # print('depth', room_depth)
    # print('stack', stack)
    # print('sign', room_sign)
    # print('-----')

print('Yes')
for s in room_sign[1:]:
    print(s)


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

class MainClass {
  public static void Main (string[] args) {
	  // 入力
    var N = int.Parse(Console.ReadLine());
    var list = new List<double>();
    var numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

    //処理
    for(var i = numbers.Min(); i <= numbers.Max(); i++){ 
      list.Add(numbers.Select(x => Math.Pow((x - i), 2)).Sum());
    }

    //出力
    Console.WriteLine(list.Min());
  }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a = 0, b = 0;
		int num = 0;
		for(int i = 0;i < s.length(); i++) {
			if((s.charAt(i)) == ('1')){
				a++;
			}else {
				b++;
			}
		}
		if(a == b) {
			num = s.length();
		}else if(a<b) {
			num = b-a;
			num = s.length() - num;
		}else {
			num = a-b;
			num = s.length() - num;
		}
		System.out.println(num);
	}

}


Measured memory_bytes: 39568
#include <bits/stdc++.h>
using namespace std;
int vec[200004],vv[200004];
int main() {
  int N;
  cin >> N;
  for (int X=0; X<N-1; X++){
    cin >> vec[X];
    vv[vec[X]-1]+=1;
  }
  for (int X=0; X<N; X++){
    cout << vv[X] << endl;
  }
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
string t;
void bitdfs(int n, string s){
    if(s.size()==n){
        //cout<<s<<endl;
        int cal=t[0]-'0';
        int now = 0;
        rep(i,t.size()){
            if(i==0) continue;
            if(s[now] == '+') cal+=t[i]-'0';
            else cal -=t[i]-'0';
            now++;
        }
        //cout<<cal<<endl;
        if(cal == 7) {cout<<t[0]<<s[0]<<t[1]<<s[1]<<t[2]<<s[2]<<t[3]<<"=7"<<endl; exit(0);}
        return ;
    }
    bitdfs(n, s+"+");
    bitdfs(n, s+"-");
    return ;
}
signed main(void){
    cin>>t;
    bitdfs(3,"");
}


Measured memory_bytes: 764
#include<stdio.h>

int card[4][14];

int main(void){
    int n,i,j;
    char a;

    scanf("%d",&n);


    for(i = 0;i < n;i++){
       scanf(" %c %d",&a,&j);
       if(a == 'S')
           card[0][j] = 1;
       else if(a == 'H')
           card[1][j] = 1;
       else if(a == 'C')
           card[2][j] = 1;
       else
           card[3][j] = 1;
    }
    for(i = 0;i < 4;i++){
        if(i == 0)
            a = 'S';
        else if(i == 1)
            a = 'H';
        else if(i == 2)
            a = 'C';
        else
            a = 'D';

        for(j = 1;j <= 13;j++)
            if(card[i][j] == 0)
                printf("%c %d\n",a,j);
    }

    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void)
{
int i,j;
	int a[5] = {0};
scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);

for(i = 0; i < 4; i++)
	for(j = 4; j > i; j--)
		if(a[j] > a[j-1]) {
			int temp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = temp;
		}

printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);

return 0;
}

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    X=[(a,b) for a,b in zip(A,B)]
    X.sort(lambda x:x[1])

    # B を先に昇順ソートしておき、それに応じて A の順序を定める
    A=[X[i][0] for i in range(n)]
    B=[X[i][1] for i in range(n)]
    # Aのソート結果のインデックスを保持する
    C=[(a,i) for i,a in enumerate(A)]
    C.sort()

    # 最適な場合でも不可能なときはNo
    if(any(C[i][0]>B[i] for i in range(n))):
        print("No")
        return

    # 自由度が1つ以上あればYes
    if(any(C[i+1][0]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    # この時点で A に値の重複は無いので、A のソートのサイクルを見る
    I=[C[i][1] for i in range(n)]
    x=0
    cnt=0
    while(True):
        cnt+=1
        x=I[x]
        if(x==0): break

    # サイクルが1つの場合は不可能、それ以外は可能
    if(cnt<n):
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 84824
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }
#define p   200005




void solve()
{  
   int x;
    cin>>x;
    int ans=0;
    ans+=(x/500)*1000;
    x-=(x/500)*500;
    ans+=(x/5)*5;
    cout<<ans;

   
 }

  

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












Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;
int main() {
	ll i, o, j, l;
	scanf("%lld %lld %*lld %lld %lld", &i, &o, &j, &l);
	
	ll r = i % 2 + j % 2 + l % 2; // reminder sum
	ll k = i + o + j + l - r;
	
	ll even;
	switch (r)
	{
	case 3:
		k += 3;
		break;
	
	case 2: // odd * 2, even * 1
		if (i % 2 == 0)
		{
			even = i;
		}
		else if (j % 2 == 0)
		{
			even = j;
		}
		else
		{
			even = l;
		}
		if (even > 0)
		{
			k += 1;
		}
		
		break;
	
	default:
		break;
	}
	printf("%lld", k);
	
	return 0;
}

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

int main(void) {
  int64_t H, W;
  cin >> H >> W;

  // pattern0 & pattern1
  int64_t min0 = INT64_MAX;
  for (int64_t i = 1; i < (H-1); i++) {
    int64_t B0 = (H - i) / 2;
    int64_t C0 = H - i - B0;
    int64_t minA = min({i, B0, C0}) * W;
    int64_t maxA = max({i, B0, C0}) * W;
    min0 = min(min0, (maxA - minA));
  }

  for (int64_t i = 1; i < H; i++) {
      int64_t B1 = W / 2;
      int64_t C1 = W - B1;
      int64_t minB = min({i * W, B1 * (H - i), C1 * (H - i)});
      int64_t maxB = max({i * W, B1 * (H - i), C1 * (H - i)});
      min0 = min(min0, (maxB - minB));
  }

  // pattern2 & pattern3
  for (int64_t i = 1; i < (W-1); i++) {
    int64_t B0 = (W - i) / 2;
    int64_t C0 = W - i - B0;
    int64_t minA = min({i, B0, C0}) * H;
    int64_t maxA = max({i, B0, C0}) * H;
    min0 = min(min0, (maxA - minA));
  }

  for (int64_t i = 1; i < W; i++) {
      int64_t B1 = H / 2;
      int64_t C1 = H - B1;
      int64_t minB = min({i * H, B1 * (W - i), C1 * (W - i)});
      int64_t maxB = max({i * H, B1 * (W - i), C1 * (W - i)});
      min0 = min(min0, (maxB - minB));
  }
  cout << min0 << endl;
  return 0;
}

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

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

using ll = long long;
using P = pair<int, int>;

const ll INF=1e9;
const ll MOD=1e9+7;

int main(int, char**)
{
    string t;
    cin >> t;
    rep(i,t.size()) {
        if (t[i] == '?') t[i] = 'D';
    }

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 3752