akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D,A=26;
  scanf("%d",&D);
  vector<int> C(A);
  for(int i=0;i<A;i++){
    scanf("%d",&C[i]);
  }
  vector<vector<int>> S(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      scanf("%d",&S[i][j]);
    }
  }
  vector<int> X(A,0);
  vector<int> XX(A,0);
  vector<vector<pair<int,int>>> Q(D,vector<pair<int,int>>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      X[j]+=C[j];
      XX[j]+=X[j];
      Q[i][j]=make_pair(-S[i][j]-X[j],j);
    }
    sort(Q[i].begin(),Q[i].end());
    XX[Q[i][0].second]-=X[Q[i][0].second];
    X[Q[i][0].second]=0;
  }
  vector<vector<int>> P(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      P[i][j]=Q[i][j].second;
    }
  }
  int SC=0,SC2;
  for(int i=0;i<D;i++){
    SC+=S[i][P[i][0]];
  }
  vector<int> Y;
  vector<int> YY;
  int Z;
  int SX,SY;
  for(int l=0;l<123;l++){
    for(int k=0;k<25;k++){
      for(int i=0;i<D;i++){
        SC2=SC;
        YY=XX;
        Y=X;
        SC2-=S[i][P[i][0]];
        SC2+=S[i][P[i][k+1]];
        for(int j=0;j<26;j++){
          Y[j]=0;
        }
        YY[P[i][0]]=0;
        YY[P[i][k+1]]=0;
        for(int j=0;j<D;j++){
          if(i==j){
            Z=P[j][k+1];
          }else{
            Z=P[j][0];
          }
          Y[P[i][0]]+=C[P[i][0]];
          Y[P[i][k+1]]+=C[P[i][k+1]];
          Y[Z]=0;
          YY[P[i][0]]+=Y[P[i][0]];
          YY[P[i][k+1]]+=Y[P[i][k+1]];
        }
        SX=0;
        SY=0;
        for(int j=0;j<D;j++){
          SX+=XX[j];
          SY+=YY[j];
        }if(SC2-SY>SC2-SX){
          P[i].insert(P[i].begin(),P[i][k+1]);
          P[i].erase(P[i].begin()+k+2,P[i].begin()+k+3);
          XX=YY;
          SC=SC2;
        }
      }
    }
  }
  for(int i=0;i<D;i++){
    cout<<P[i][0]+1<<"\n";
  }
}

Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N; cin >> N;
    int sum = 0;
    int M = N;
    while (N) sum += N % 10, N /= 10;
    cout << (M % sum == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int maxn = 2e5 + 7;
const int INF = 0x3f3f3f3f;

int dp[10][10];

int solve(int x) {
    int ans = 0;
    while(x) {
        ans = x % 10;
        x /= 10;
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
        dp[solve(i)][i%10]++;
    }
    int ans = 0;
    for(int i = 0 ; i < 10 ; i++) {
        for(int j = 0 ; j < 10 ; j++) {
            ans += dp[i][j] * dp[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();

            bool B = false;

            if (s[0] == 'B')
            {
                B = true;
            }
            else
            {
                B = false;
            }
            int ans = 0;
            for (int i = 1; i < s.Length; i++)
            {
                if (s[i] == 'B' && B == false)
                {
                    B = true;
                    ans++;
                }
                else if(s[i] == 'W' && B == true)
                {
                    B = false;
                    ans++;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11232
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[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(std::io::BufReader::new(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, $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, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// -----------------------------------------------------------------------------
// main
// -----------------------------------------------------------------------------
fn main(){
    input!{
        s: chars
    }
    let mut ans = "WA";
    if s[0]=='A' 
      && s[2..s.len()-1].iter().filter(|&&c| c=='C').count() == 1
      && s.iter().filter(|c| c.is_uppercase()).count() == 2
    {
        ans = "AC";
    }
    println!("{}", ans);
}



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

using namespace std;

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  vector<char> St(100);
  
  for (int i = 0; i < S.size(); i++) {
    char a = S.at(i);
    St.at(i) = a;
  }
  
  if (S.size() > K) {
    for (int i = 0; i < K; i++) {
      cout << St.at(i);
    }
    cout << "..." << endl;
  } else if (S.size() <= K) {
    cout << S << endl;
  }
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////


int main(){fastio
    /*ll n;cin>>n;
    string s;cin>>s;
    ll cr=0;
    rep(i,0,n-1){
        if(s[i]=='R')cr++;
    }*/
    ll n,d;cin>>n>>d;
    ll ans=0;
    rep(i,0,n-1){
        ll x,y;cin>>x>>y;
        if(x*x+y*y<=d*d)ans++;
    }
    cout<<ans<<endl;
    
    
    return 0;
}


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

using namespace std;

const int INF = 1 << 30;

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

  int L = D + D + W + W;
  deque< pair< int, int > > range;
  for(int i = 0; i < N; i++) {
    int X, Y;
    char F;
    cin >> X >> Y >> F;
    if(F == 'N') range.emplace_back(X + Y, D + X + D - Y);
    if(F == 'E') range.emplace_back(D + X + D - Y, L - X - Y);
    if(F == 'S') range.emplace_back(L - X - Y, L - X + Y);
    if(F == 'W') range.emplace_back(L - X + Y, X + Y + L);
  }


  int ret = INF;
  for(int i = 0; i < N; i++) {

    sort(begin(range), end(range), [&](pair< int, int > a, pair< int, int > b)
    {
      swap(a.first, a.second);
      swap(b.first, b.second);
      return (a < b);
    });

    int count = 0;
    for(int j = 0; j < N;) {
      int ps = range[j].second;
      while(j < N && range[j].first <= ps) ++j;
      ++count;
    }
    ret = min(ret, count);
    range.front().first += L;
    range.front().second += L;
    range.push_back(range.front());
    range.pop_front();
  }
  cout << ret << endl;

}

Measured memory_bytes: 3132
#include<atcoder/all>
#include<iostream>
using namespace std;
using namespace atcoder;

int main() {
  int T; cin >> T;
  int n, m, a, b;
  for (int t = 0; t < T; t++) {
    cin >> n >> m >> a >> b;
    cout << floor_sum(n, m, a, b) << endl;
  }
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
        cout<<"a < b\n";
    else if(a>b)
        cout<<"a > b\n";
    else
        cout<<"a == b\n";
    return 0;
}



Measured memory_bytes: 3024
#include <stdio.h>
 
int main(void){
  int i,sum;
  char num[1001];
 
  for(;;){
    scanf("%s", &num);
    if(num[0] == '0') break;
     
    sum = 0;
    for(i=0;num[i]!='\0';i++)
      sum += num[i] - '0';
    printf("%d\n", sum);
  }
   
  return 0;
}


Measured memory_bytes: 2056
#include<iostream>
using namespace std;
int main(){
	string a;
	cin>>a;
	int c=0;
	for(int i=0;i<a.size();i++){
		if(a[i]=='C'){
			c=1;
		}
		if(a[i]=='F'&&c==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}
 

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long D = int.Parse(str[1]);
        long[] P = new long[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            P[i] = int.Parse(str[i]);
        }
        long[] DP = new long[N+1];
        DP[N] = 1;
        for(int i=N-1;i>=0;i--){
            if(P[i] >= 2*DP[i+1]){
                DP[i] = DP[i+1];
            }
            else{
                DP[i] = DP[i+1] + P[i];
            }
        }
        bool[] b = new bool[N];
        for(int i=0;i<N;i++){
            b[i] = D >= DP[i+1];
            D = Math.Min(D,Math.Max(D-P[i],P[i]-D));
        }
        int Q = int.Parse(Console.ReadLine());
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<Q;i++){
            if(b[int.Parse(str[i])-1]){
                sb.Append("YES\n");
            }
            else{
                sb.Append("NO\n");
            }
        }
    }
}

Measured memory_bytes: 84024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
ll func(ll n,ll X){
  if (n>=0)
  {
    /* code */
    return n/X+1;
  }
  else
  {
    return 0;
  }
  
  
}
int main(){
  ll a,b,x;cin>>a>>b>>x;
  ll ans=func(b,x)-func(a-1,x);
  cout<<ans<<endl;
      
  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int l=s.length();
	if(s[0]==s[l-1]){
		if(l%2==0){
			cout<<"First"<<endl;
			return 0;
		}
		else{
			cout<<"Second"<<endl;
			return 0;
		}
	}
	else{
		if(l%2==0){
			cout<<"Second"<<endl;
			return 0;
		}
		else{
			cout<<"First"<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;

int main(){
	int m,n,s=0;
	cin>>n>>m;
	int arr[m];
	for(int i=0;i<m;i++){
		cin>>arr[i];
		s+=arr[i];
	}
	if(n<s)cout<<"-1";
	else cout<<n-s;
	
	
	
	
	
	
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>>sv(n,vector<int>(26));
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<s.length();j++){
            sv[i][s[j]-'a']++;
        }
    }   
    
    for(int i=0;i<n-1;i++){
        for(int j=0;j<26;j++){
            sv[i+1][j]=min(sv[i][j],sv[i+1][j]);
        }
    }
    string s="";
    for(int j=0;j<26;j++){
        char tempchar=j+'a';
        for(int k=0;k<sv[n-1][j];k++){
            s+=tempchar;
        }        
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {

  int count,tp = 0,hp = 0;
  char t[100],h[100];
  for(int a = 0;a<100;a++){
    t[a] = '0';
    h[a] = '0'; 
  }
  cin >> count;
  for(;count>0;count--){
    cin >> t >> h;
    for(int a = 0;;a++){
      char T = t[a],H = h[a];
      if(T == '0'){
        if(H == '0'){
          tp++;
          hp++;
          break;
        }
        else{
          hp+=3;
          break;
        } 
      }
      else if(H == '0'){
        tp+=3;
        break;
      }
      if(T > H){
        tp+=3;
        break;
      }
      else if(T != H){
        hp+=3;
        break;
      }
    }
    for(int a = 0;a<100;a++){
      t[a] = '0';
      h[a] = '0'; 
    }
  }
  cout << tp << " " << hp << endl;
  return 0;
}


Measured memory_bytes: 3100
using System;

namespace question3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] H = new int[N];

            for (int i = 0; i < N; i++)
            {
                H[i] = int.Parse(str[i]);
            }
            int flag = 0;
            for (int i = 1; i < N; i++)
            {
                if ((H[N - i] - H[N - i - 1]) == -1)
                {
                    H[N - i - 1] -= 1;
                }
                else if ((H[N - i] - H[N - i - 1]) < -1) break;

                if (i == (N - 1)) flag = 1;

            }

            if (flag == 1) Console.WriteLine("Yes");
            else if (N==1) Console.WriteLine("Yes");
            else Console.WriteLine("No");
            //Console.ReadLine();

            
        }
    }
}


Measured memory_bytes: 26972
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!

bool b[200001];
int dp[200001];

int main()
{
    fast;
//int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
        string s; cin >> s;
        if(s=="ABC") cout << "ARC";
        else cout << "ABC";
    }
    return 0;
}
    

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int health, n;
	cin >> health >> n;
	
	vector<int> damage(n), cost(n);
	for(int i = 0; i < n; i++) {
		cin >> damage[i] >> cost[i];
	}
	
	vector<vector<int>> dp(n+1, vector<int>(health+1, 1e9)); 
	for(int i = 0; i <= n; i++) {
		dp[i][0] = 0;
	}
	
	for(int i = 1; i <= n; i++) {
		for(int h = 1; h <= health; h++) {
			dp[i][h] = min(dp[i-1][h], dp[i][max(0, h-damage[i-1])] + cost[i-1]);
		}
	}
	
	cout << dp[n][health] << endl;
}


Measured memory_bytes: 39424
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;

double dp[310][310][310];
ll n;

double solve(ll a,ll b,ll c)
{
	if(a == 0 && b == 0 && c == 0)
		return 0.0;
	
	if(dp[a][b][c] != -1)
		return dp[a][b][c];
	
	double curr = 1.0*n/(a + b + c);
	
	if(a)
	{
		curr += solve(a-1,b,c)*(1.0*a/(a + b + c));
	}
	if(b)
	{
		curr += solve(a+1,b-1,c)*(1.0*b/(a + b + c));
	}
	if(c)
	{		
		curr += solve(a,b+1,c-1)*(1.0*c/(a + b + c));
	}
	
	
	dp[a][b][c] = curr;

	return dp[a][b][c];
}
	
	

int main()
{
    fastio;
    //preset
    for(ll i=0;i<=305;i++)
		for(ll j=0;j<=305;j++)
			for(ll k=0;k<=305;k++)
				dp[i][j][k] = -1;
    
    
    cin>>n;
    ll arr[n];
    ll a = 0;
    ll b = 0;
    ll c = 0;
    for(ll i=0;i<n;i++)
    {
		cin>>arr[i];
		if(arr[i] == 1)
			a++;
		else if(arr[i] == 2)
			b++;
		else
			c++;
	}
	
	double ans = solve(a,b,c);
	cout<<setprecision(14);
	cout<<fixed<<ans<<endl;
	
	
	
	
    return 0;
    
}


Measured memory_bytes: 231684
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (p, q, r) = input!(u64, u64, u64);

    println!("{}", std::cmp::min(q + r, std::cmp::min(p + r, p + q)));
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <iostream>
#include <map>
using namespace std;
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main() {
  int N, C, K; scanf("%d%d%d", &N, &C, &K);
  map<int, int>T;
  int t;
  for (int i{0}; i < N; ++i) {
    scanf("%d", &t); ++T[t];
  }

  int total{0};

  for (auto& kv : T) {
    int temp = kv.second; kv.second = 0;
    if (temp % C != 0) {
      decltype(T)::iterator it = T.lower_bound(kv.first + 1);
      decltype(T)::iterator last = T.upper_bound(kv.first + K);
      while (it != last) {
        int add = MIN(C - temp % C, it->second);
        temp += add; it->second -= add;
        if (temp % C == 0) break;
        ++it;
      }
    }
    total += (temp + (C - 1)) / C;
  }

  printf("%d\n", total);
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ll long long
#define ld long double
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define REPE(i,a,b) for(ll i = a; i <= b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
const double pi = 2*acos(0.0);
const int INF = 1e9+1;
const int mod = 1e9+7;
const int mod1 = 998244353;
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}

bool compare(const pair<int, int>&i, const pair<int, int>&j) {
   return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void test() {
   ll a;
   cin >> a;

   cout << a + a*a + a*a*a;
} 

int main() {
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   faster;
   cout.precision(10);
   cout << fixed;

   int t = 1;
   //cin >> t;
   while(t--) {
      test();
   }
   return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	char x; cin >> x;
	if (tolower(x) == x) cout << 'a' << endl;
	else cout << 'A' << endl;
	return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	static List<Long> primList = new ArrayList<Long>();

	public static void main(String[] args) throws NumberFormatException, IOException {
		read();
	}

	public static boolean isPrime(long N) {
		if (N <= 1) {
			return false;
		}
		long t = (long) Math.sqrt(N);
		for (long i = 2; i <= t; i++) {
			if (N % i == 0) {
				return false;
			}
		}
		return true;
	}

	public static void init() {
		for (long i = 2; i <= 1000000; i++) {
			if (isPrime(i)) {
				primList.add(i);
			}
		}
	}

	public static void fenjie(long n) {
		int index = 0;
		long t = primList.get(index);
		HashMap<Long, Integer> map = new HashMap<>();
		while (n != 1 && index < primList.size()) {
			t = primList.get(index);
			if (n % t == 0) {
				Integer v = map.get(t);
				if (v == null) {
					map.put(t, 1);
				} else {
					map.put(t, v + 1);
				}
				n = n / t;
			} else {
				index++;
			}
		}
		if (n != 1) {
			map.put(n, 1);
		}
		long res = 0;
		for (Entry<Long, Integer> entry : map.entrySet()) {
			long v = entry.getValue();
			t = (long)Math.sqrt(2*v);
			if( t*(t+1) > 2*v) {
				res += t-1;
			}else{
				res += t;
			}
		}
		System.out.println(res);
		
	}

	private static void read() throws IOException {
		init();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		long n = Long.valueOf(str);
		fenjie(n);

		br.close();

	}

}


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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) cout << c;
	return out;
}

template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}

template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}

void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second

template<class T> int size(T && a) {
	return a.size();
}

using LL = long long;
using PII = pair<int, int>;

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

	int n, a, b;
	cin >> n >> a >> b;

	cout << min(a * n, b);
}


Measured memory_bytes: 892
/* ***************************************
Author        :Scau.ion
Created Time  :2017/02/04 19:59:18 UTC+8
File Name     :ion.cpp
*************************************** */

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

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
    IOS;
    int n;
    cin>>n;
    int sum=0;
    for (int j=1;j<=n;++j)
    {
        int x;
        cin>>x;
        if (x%2) ++sum;
    }
    if (sum%2) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#define int long long
using namespace std;

unordered_map<int, int>U;
signed main() {
	int a; cin >> a;
	for (int b = 2; b <= a; b++) {
		int d = b;
		for (int c = 2; c*c <= b; c++) {
			while (d%c == 0) {
				d /= c;
				U[c]++;
			}
		}
		if (d != 1)U[d]++;
	}
	int k = 1;
	for (auto i = U.begin(); i != U.end(); i++) {
		k = k*(i->second + 1) % 1000000007;
	}
	cout << k << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)

int a[100000]={};
using namespace std;
int main(){
  int n; 
  cin >> n;
  rep(i,n){
    int t;
    cin >> t;
    a[t]++;
  }
  if(n%2==1){
    if(a[0]!=1){
      cout << 0 << endl;
      return 0;
    }
    REP(i,1,n/2+1){
      if(a[i*2]!=2){
        cout << 0 << endl;
        return 0;
      }
    }
  }else{
    rep(i,n/2){
      if(a[i*2+1]!=2){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long long ans = 1;
  rep(i,n/2){
    ans *= 2;
    ans %= 1000000007;
  }
  cout << ans << endl;
 
  return 0;
 
}

Measured memory_bytes: 640
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

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

	READV(N);
	READAR(A,N);
	sort(A,A+N);
	ll mid=N/2;
	cout<<A[mid]-A[mid-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const long double INF = 5000000000000000.0;


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

  print((A-1) * (B-1));

  return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

std::string s;
int main() {
    std::cin >> s;
    int ans = 0;
    ans += (s[0] == '1');
    ans += (s[1] == '1');
    ans += (s[2] == '1');

    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

int main() {
	int n, q;
	std::string s;
	std::cin >> n >> q >> s;

	std::vector<std::pair<char, char>> query(q);
	for (auto&& e : query)
		std::cin >> e.first >> e.second;

	auto simulatePos = [&](int idx) -> int {
		for (auto&& e : query) {
			if (e.first != s[idx])
				continue;

			if (e.second == 'L')
				--idx;
			else
				++idx;

			if (idx == -1 || idx == n)
				return idx;
		}

		return idx;
	};
	auto countLeftFall = [&]() {
		int l = 0, r = n;

		while (r - l > 1) {
			int mid = (l + r) / 2;

			if (simulatePos(mid) == -1)
				l = mid;
			else
				r = mid;
		}

		if (l == 0)
			return static_cast<int>(simulatePos(0) == -1);
		else
			return l + 1;
	};
	auto countRightFall = [&]() {
		int l = -1, r = n - 1;

		while (r - l > 1) {
			int mid = (l + r) / 2;

			if (simulatePos(mid) == n)
				r = mid;
			else
				l = mid;
		}

		if (r == n - 1)
			return static_cast<int>(simulatePos(n - 1) == n);
		else
			return n - r;
	};
	
	int ans = n;

	ans -= countLeftFall();
	ans -= countRightFall();

	std::cout << ans << std::endl;
}

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

if n[3]%2==1 :
    n[0]*=(-1)
else :
    n[1]*=(-1)
    

if n[0]+n[1] > 1000000000000000000 :
    print('Unfair')
else :
    print(n[0]+n[1])


Measured memory_bytes: 2940
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	int len,ans=0,a[27]={0};
	cin>>s;
	len=s.length();
	if(len>26)cout<<"no";
	else{
		for(int i=0;i<len;i++){
			if(a[s[i]-'a'+1]==1){
				cout<<"no";
				return 0;
			}
			a[s[i]-'a'+1]=1;
		}
		cout<<"yes";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  char a;
  cin >>a;
  if(a=='A')
    cout<<"T";
  else if(a=='T')
    cout<<"A";
  else if(a=='G')
    cout<<"C";
  else if(a=='C')
    cout<<"G";
  return 0;
}

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

int main(){
 int n, result=0;
 int a, b;
 cin >> n;

 for(int i=0;i<n;i++){
 	cin >> a >> b;
   	result += b-a+1;
 }
 cout << result << endl;
 
}

Measured memory_bytes: 256
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = num()
S,T = [],[]
for _ in range(N):
    si,ti = input().split()
    ti = int (ti)
    S.append(si)
    T.append(ti)
X = input()
idx = S.index(X)
print(sum(T[idx+1:]))

Measured memory_bytes: 5588
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){


    ll n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    ll ans = 100000000000;
    for(ll to = -100; to <= 100; to++){
        ll sum = 0;
        for(int i = 0; i < n; i++){
            sum += (v[i] - to) * (v[i] - to);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {

	ull k;
	cin >> k;
	int n = 50;
	vector<ull>a(n);
	rep(i, n)a[i] = i;
	
	ull bias = k / n;
	rep(i, n)a[i] += bias;
	rep(i, k%n) {
		ull mi = n+bias, mii;
		rep(i, n) {
			if (a[i] < mi) {
				mi = a[i];
				mii = i;
			}
		}
		rep(i, n) {
			if (i != mii) {
				a[i]--;
			}
			else {
				a[i] += n;
			}
		}
	}
	cout << n << endl;
	rep(i, n)cout << a[i] << " ";
	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

const int MAX = 10000;
struct Node { int p, l, r; };
vector<struct Node> T(MAX);
int n;

void preParse(int u) {
	if (u == NIL) return;
	cout << ' ' << u;
	preParse(T.at(u).l);
	preParse(T.at(u).r);
}

void inParse(int u) {
	if (u == NIL) return;
	inParse(T.at(u).l);
	cout << ' ' << u;
	inParse(T.at(u).r);
}

void postParse(int u) {
	if (u == NIL) return;
	postParse(T.at(u).l);
	postParse(T.at(u).r);
	cout << ' ' << u;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) T.at(i).p = NIL;
	
	int v, l, r;
	for (int i = 0; i < n; i++) {
		cin >> v >> l >> r;
		T.at(v).l = l;
		T.at(v).r = r;
		if (l != NIL) T.at(l).p = v;
		if (r != NIL) T.at(r).p = v;
	}

	int root;
	for (int i = 0; i < n; i++) {
		if (T.at(i).p == NIL) root = i;
	}

	cout << "Preorder" << endl;
	preParse(root);
	cout << endl;
	cout << "Inorder" << endl;
	inParse(root);
	cout << endl;
	cout << "Postorder" << endl;
	postParse(root);
	cout << endl;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

ll C[51][51];

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, P;

  cin >> N >> P;

  int odd_n = 0;
  int even_n = 0;

  rep(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 0) even_n++;
    else odd_n++;
  }

  C[0][0] = 1;

  REP(n, 1, N+1) rep(k, n+1) {
    if (k - 1 >= 0) C[n][k] = C[n-1][k-1] + C[n-1][k];
    else C[n][k] = C[n-1][k];
  }

  ll all_pattern = pow(2, N);

  ll ans = 0;

  for (int i = 1; i <= odd_n; i += 2) {
    ll odd_c = C[odd_n][i];
    for (int j = 0; j <= even_n; j++) {
      ans += odd_c * C[even_n][j];
    }
  }

  if (!P) ans = all_pattern - ans;

  cout << ans << endl;

  return 0; 
}

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc,const char * arg[])
{
    int i,x,y;
    
    for (i=1;i<=10000;i++) {
        scanf("%d %d", &x, &y);
        if (x==0 && y==0) break;
        if (x<=y) {
            printf("%d %d\n", x, y);
        }else {
            printf("%d %d\n", y, x);
        }
    }
    return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    int b[205],a[205];
    int m=0;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
    	b[i]=i+l;
    	m+=b[i];    	
    	if(b[i]<0){
    		a[i]=1;
    		b[i]=-b[i];
		}
	}
	int min=0;
	for(int i=1;i<n;i++){
		if(b[i]<b[min]){
			min=i;
		}
	}
	int d;
	if(a[min]){
	    d=m+b[min];	
	}
	else{
	   d=m-b[min];	
	}
	cout<<d;
	return 0;
}

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

namespace MyProgram{
    public class Program
    {	
        public static void Main(string[] args)
    	{
            int n = int.Parse(Console.ReadLine());
            int x = 0;
            string s = Console.ReadLine();
            int max = 0;
            
            for(int i = 0 ; i < n ; i++)
            {
                if(s[i] == 'I')
                {
                    x++;
                }    
                else
                {
                    x--;
                }
                max = Math.Max(max,x);
            }
            Console.WriteLine(max);
    	}
    }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.readline

N = int(input())

mod = 1e9+7

ten = 1
nine = 1
eight = 1

for _ in range(N):
    ten *= 10
    ten %= mod
    nine *= 9
    nine %= mod
    eight *= 8
    eight %= mod

ans = ten - 2 * nine + eight
ans = int(ans)
ans %= mod
if ans < 0:
    ans += mod

print(int(ans))


Measured memory_bytes: 73096
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String c[] = new String[S.length()];
    for(int i=0;i<S.length();i++){
      c[i]=S.substring(i,i+1);
    }
    Arrays.sort(c);
    for(int i=0;i<S.length()-1;i++){
      if(c[i].equals(c[i+1])){
        System.out.println("no");
        return;
      }
    }
    System.out.println("yes");
  }
  

  
}


Measured memory_bytes: 23764
from sys import exit

N, Q = map(int, input().split())

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])


Measured memory_bytes: 6188
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N, M, S, T;
const int MAX_M = 100000;
int u[MAX_M], v[MAX_M];

// set V in main
// d[MAX_V] shows the answer

const int MAX_V = 300000;

struct edge{int to; ll cost;};
typedef pair<ll, int> P;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>  > que;
    fill(d, d + V, INFll);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
        edge e = G[v][i];
        if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        }
    }
    }
}

int main(){
  cin >> N >> M;
  REP(i, M) cin >> u[i] >> v[i];
  cin >> S >> T;

  REP(i, M) {
    u[i]--;
    v[i]--;
    G[u[i]].pb(edge{v[i] + N, 1});
    G[u[i] + N].pb(edge{v[i] + 2 * N, 1});
    G[u[i] + 2 * N].pb(edge{v[i], 1});
  }
  S--;
  T--;

  V = 3 * N;
  dijkstra(S);

  if(d[T] == INFll) {
    cout << -1 << endl;
  } else {
    cout << d[T] / 3 << endl;
  }

  return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> aa(9);
	vector<int> num;
	for (int i = 0; i < 9; i++) {
		cin >> aa[i]; 
		num.push_back(i + 1);
	}

	int count = 0;

	do {
		bool h = true;
		for (int i = 0; i < 9; i++) {
			if (aa[i] != -1 && aa[i] != num[i]) {
				h = false;
			}
		}
		if (h) {
			int a, b, c, d;
			a = num[0];
			b = num[1] * 10 + num[2];
			c = num[3] * 100 + num[4] * 10 + num[5];
			d = num[6] * 100 + num[7] * 10 + num[8];
			if (a + b + c == d) {
				count++;
			}
		}
	} while (next_permutation(num.begin(), num.end()));

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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 main(){
    int n;
    cin>>n;
    svec s(n);
    vec t(n);
    rep(i,n)cin>>s[i]>>t[i];
    string x;
    cin>>x;
    int cnt=0;
    int sum=0;
    rep(i,n)sum+=t[i];
    rep(i,n){
        cnt+=t[i];
        if(s[i]==x)break;
    }
    cout<<sum-cnt<<endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
        String x = a.readLine();
        int i = Integer.parseInt(x);
        int h, m, s;
        h = i / 3600;
        m = (i % 3600) / 60;
        s = ((i % 3600) % 60);
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	map<char,ll>a;
	for(ll i=0;i<s.size();i++){
		char now=s[i];
		a[now]++;
	}
	ll n=s.size()*(s.size()-1)/2;
	ll k1=0;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ll val=itr->second;
		k1+=val*(val-1)/2;
	}
	cout << 1+n-k1;
	// your code goes here
	return 0;
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)  //a~(b - 1)?????§
#define print(i) cout << i << endl //?°??????????Python?????????
#define all(i) (i).begin(),(i).end() //??¨??????(sort??¨???)
#define mp make_pair //mp(OO, OO)??¨???:::pint??¨???

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/

int main(void)
{
  int w, n, a, b; cin >> w >> n;
  int x[35];
  FOR(i, 0, w + 1) x[i] = i;

  FOR(i, 0, n){
    scanf("%d,%d", &a, &b);
    swap(x[a], x[b]);
  } 

  FOR(i, 1, w + 1) cout << x[i] << endl;

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int func(int x){
    int count=0;
    for(int i=1;i<=x;i++){
        if(x%i==0){count++;}
    }
    return count;
}
int main() {
 int N;
 cin>>N;
 int count2=0;
 for(int i=1;i<=N;i++){
     if(i%2!=0&&func(i)==8){count2++;}
 }
 cout<<count2<<endl;
 return 0;}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

std::vector<std::string> ans;

void rec(std::string str, char max_c, int n) {
	if (str.size() == n) {
		ans.push_back(str);
		return;
	}
	for (char c = 'a'; c <= max_c + 1; ++c) {
		str.push_back(c);
		if (c == max_c + 1) rec(str, max_c + 1, n);
		else rec(str, max_c, n);
		str.pop_back();
	}
}

int main(void) {
	int n;
	std::cin >> n;

	rec("a", 'a', n);

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

	for (int i = 0; i < ans.size(); ++i) std::cout << ans[i] << std::endl;
	return 0;
}


Measured memory_bytes: 7336
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
int64_t Luca(int64_t N){
    if(N==0){
        return 2;
    }
    else if(N==1){
        return 1;
    }
    else{
        return (Luca(N-1)+Luca(N-2));
    }
} 
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> Lucas(N+1);
  Lucas.at(0) = 2;
  Lucas.at(1) = 1;
  for(int i = 2; i <= N ; i++){
      Lucas.at(i)=Lucas.at(i-1) + Lucas.at(i-2);
  }
  cout << Lucas.at(N) << endl;

}

Measured memory_bytes: 256
// ITP1_7_C:   Spreadsheet
// 2017.7.27

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int e[101][101];
	int R, C, r, c;
	int s, total;

	scanf("%d%d", &R, &C);
	for (r = 1; r <= R; r++) {
		for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
	}
	
	for (r = 1; r <= R; r++) {
		s = 0;
		for (c = 1; c <= C; c++) s += e[r][c];
		e[r][0] = s;
	}
	total = 0;
	for (c = 1; c <= C; c++) {
		s = 0;
		for (r = 1; r <= R; r++) s += e[r][c];
		e[0][c] = s;
		total += s;
	}
	for (r = 1; r <= R; r++) {
		for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
		printf("%d\n", e[r][0]);
	}
	for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
	printf("%d\n", total);
	return 0;
}

Measured memory_bytes: 640