akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main()
{
    int one_two;
    cin >> one_two;
    if (one_two == 1){
        cout << "Hello World" << endl;
    }
    else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int n;
	while(cin>>n){
		printf("3C%02d\n",(n%39)?n%39:39);
	}
	return 0;
}

Measured memory_bytes: 1160
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


  int n;
  set<int> s;
  cin >> n;
  for(int i=1;i<=n;i++){
    int x;
    cin >> x;
    s.insert(x);
  }
  if(s.size()==n){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }


return 0;
}
///....


Measured memory_bytes: 9600
if true then
  fh=STDIN
else
  fh=open("in0104.txt")
end

while true
  h,w=fh.gets.chomp.split.map{|x| x.to_i}
  break if h==0 and w==0

  fvisit = Array.new(h).map{|i| Array.new(w,false)}
  tl = []

  0.upto(h-1){|i|
    f=fh.gets.chomp.split(//)
    abort("w data strange") if f.length != w
    tl.push(f)
  }
  abort("h data strange") if tl.length != h

  x = 0
  y = 0
  while true
    if not fvisit[y][x] then
      fvisit[y][x] = true
    else
      st = "LOOP"
      break
    end
    case tl[y][x]
    when '>' then
      x += 1
    when '<' then
      x -= 1
    when '^' then
      y -= 1
    when 'v' then
      y += 1
    else
      st="STOP"
      break
    end
    abort("OUT") if x<0 or x>w-1 or y<0 or y>h-1
  end

  if st=="LOOP" then
    puts "LOOP"
  elsif st=="STOP" then
    puts "#{x} #{y}"
  else
    abort("Unknown")
  end
end

Measured memory_bytes: 9008
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n-1);
    for (auto &&i : v) scanf("%d", &i);
    vector<int> ans(n);
    ans[0] = v[0]; ans[n-1] = v[n-2];
    for (int i = 1; i < n-1; ++i) {
        ans[i] = min(v[i-1], v[i]);
    }
    cout << accumulate(ans.begin(),ans.end(), 0) << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;


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

        for (int i = 1; i <= 10; i++) {
            int x_new = r * x - d;
            System.out.println(x_new);
            x = x_new;
        }
    }
}






Measured memory_bytes: 22740
#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i]; 
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    string c;
  	cin>>c;
    if(c[c.size()-1]=='s'){
      cout<<c<<"es\n";
    }
    else
      cout<<c<<"s\n";
}

Measured memory_bytes: 3644
/*やったぜ。　投稿者：変態糞土方 (8月16日（水）07時14分22秒)

昨日の8月15日にいつもの浮浪者のおっさん（60歳）と先日メールくれた汚れ好きの土方のにいちゃん

（45歳）とわし（53歳）の3人で県北にある川の土手の下で盛りあったぜ。

今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、

そこでしこたま酒を飲んでからやりはじめたんや。

3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。

しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。

浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、

先に兄ちゃんがわしの口に糞をドバーっと出して来た。

それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、

3人で出した糞を手で掬いながらお互いの体にぬりあったり、

糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ～～たまらねえぜ。

しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。

浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると

けつの穴が糞と小便でずるずるして気持ちが良い。

にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。

糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。

それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、

糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。

やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。

ああ～～早く糞まみれになろうぜ。

岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や

糞まみれでやりたいやつ、至急、メールくれや。

土方姿のまま浣腸して、糞だらけでやろうや。*/
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define llMIN numeric_limits<long long>::min()
#define intMIN numeric_limits<int>::min()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
vll words(26,vl(0));
ll cnt=0;
int searchindex(ll alhpanum,ll now){
  ll l=0;
  ll r=words[alhpanum].size()-1;
  if(words[alhpanum][r]<=now || words[alhpanum].size()==1 ){
    cnt++;
    return 0;
  }
  if(words[alhpanum][0]>now){
    return 0;
  }
  while(l!=r){
    ll mid = (l+r)/2;
    if(now<words[alhpanum][mid]){
      r=mid;
    }else{
      l=mid+1;
    }
  }
  return l;
}
int main(void){
  string s,t;
  cin>>s>>t;
  ll ssize=s.size();
  rep(i,ssize){
    words[s[i]-'a'].pb(i);
  }
  ll now=-1;
  ll preloc=-1;
  rep(i,t.size()){
    if(words[t[i]-'a'].size()==0){
      cout<<-1<<endl;
      return 0;
    }
    ll minnextindex;
    if(now<0){
      minnextindex=searchindex(t[i]-'a',-1);
    }else{
      minnextindex=searchindex(t[i]-'a',now%ssize);

    }
    if(now==-1){
      now=words[t[i]-'a'][minnextindex];
      preloc=now;
      continue;
    }
    //cout<<minnextindex<<endl;
    if(preloc==words[t[i]-'a'][minnextindex] && words[t[i]-'a'].size()==1){
      now+=ssize;
      continue;
    }
    now+=(ssize*1000 + words[t[i]-'a'][minnextindex] - (now%ssize))%ssize;
    preloc=words[t[i]-'a'][minnextindex];
  }
  cout<<now+1<<endl;
  return 0;
}


Measured memory_bytes: 1724
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    map<string,int> mp;
    vector<pair<int,string> > an;
    cin >>n;
    for(int i=0;i<n;i++){
      cin >>s;
      mp[s]--;
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      an.emplace_back(itr->se,itr->fi);
    }
    sort(an.begin(),an.end());
    int a=an[0].fi;
    for(int i=0;i<an.size();i++){
      if(a!=an[i].fi) break;
      cout <<an[i].se<<'\n';
    }
    return (0);
}


Measured memory_bytes: 28272
// ------------------------------------
// Date:2018/ 2/24
// Problem:AGC 003 WannaGoBackHome a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

int main()
{
  string S;
  bool check[4];
  cin >> S;
  memset(check,false,sizeof(check));
  REP(i,S.size()) {
    switch(S[i]) {
      case 'N':
        check[0] = true;
        break;
      case 'S':
        check[1] = true;
        break;
      case 'E':
        check[2] = true;
        break;
      case 'W':
        check[3] = true;
        break;
    }
  }
  if (!(check[0] == check[1])) {
    cout << "No" << endl;
    return 0;
  }
  if (!(check[2] == check[3])) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
flag = 0
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 5 != 0 and A[i] % 3 != 0:
            flag = 1
            break
if flag == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
double dp[3005][3005], p[3005];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= i; j++){
            if(j - 1 >= 0)
                dp[i][j] += dp[i - 1][j - 1] * p[i];
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n; i++)
        ans += dp[n][i];
    printf("%.10f\n",ans);
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;

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

int main()
{
  ll N, n;
  cin >> N;


  ll nf = 0;
  ll f = 0;
  ll t = 0;
  rep(i, N)
  {
    cin >> n;
    if(n%2!=0 && n%4!=0)
      nf++;
    else
    if(n%4==0)
      f++;
    else
    if(n%2==0)
      t++;
  }

  if(t==0)
    nf--;
  if(f>=nf)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=200010;
const ll mod=1e9+7;

int n;
vector<P> tasks;

int main(){
  cin >> n;
  for(int i=0; i<n; i++){
    int a,b;
    cin >> a >> b;
    tasks.emplace_back(b,a);
  }
  sort(tasks.begin(),tasks.end());
  
  int totaltasks=0;
  bool flag=true;
  
  for(auto v : tasks){
    totaltasks += v.second;
    if(totaltasks > v.first){flag=false;break;}
  }

  cout << (flag?"Yes":"No")<< endl;
  return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>

int main(void)
{
  long long int X,Y;
  long long int a,b,i;
  scanf("%lld%lld",&X,&Y);
  long long int N=1;
  
  if((2*Y-X)%3!=0||(2*X-Y)%3!=0||2*X<Y||2*Y<X){
    N=0;
  }
  
  a=(2*Y-X)/3;
  b=(2*X-Y)/3;
  
  long long int S=1,T=1;
  for(i=b+1;i<=a+b;i++){
    S=S*i;
    S=S%1000000007;
  }
  for(i=1;i<=a;i++){
    T=T*i;
    T=T%1000000007;
  }
  
  long long int A[30];
  long long int P;
  A[0]=T;
  for(i=1;i<=29;i++){
    A[i]=A[i-1]*A[i-1];
    A[i]=A[i]%1000000007;
  }
  P=A[0];
  P=P%1000000007;
  P=P*A[2];
  P=P%1000000007;
  P=P*A[9];
  P=P%1000000007;
  P=P*A[11];
  P=P%1000000007;
  P=P*A[14];
  P=P%1000000007;
  P=P*A[15];
  P=P%1000000007;
  P=P*A[17];
  P=P%1000000007;
  P=P*A[19];
  P=P%1000000007;
  P=P*A[20];
  P=P%1000000007;
  P=P*A[23];
  P=P%1000000007;
  P=P*A[24];
  P=P%1000000007;
  P=P*A[25];
  P=P%1000000007;
  P=P*A[27];
  P=P%1000000007;
  P=P*A[28];
  P=P%1000000007;
  P=P*A[29];
  P=P%1000000007;
  
  S=S*P*N;
  S=S%1000000007;
  
  printf("%lld",S);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> b(n),a(n);
  for(ll i = 0; i < n-1; ++i) cin >> b[i];
  a[0] = b[0];
  a[n-1] = b[n-2];
  for(ll i = 1; i < n-1; ++i) a[i] = min(b[i],b[i-1]);
  ll ans = 0;
  for(ll i : a) ans += i;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s;
    cin >> s;
    for(auto&& c: s) {
        if(c == '7') {
            cout << "Yes" << '\n';
            return 0;
        }
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n;
    cout<<(int)(sqrt(n))*(int)(sqrt(n));
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
}

Measured memory_bytes: 96328
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

string board[60];
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void)
{
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i < X; i++)
        cin >> board[i];

    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            if (board[i][j] == '.')
            {
                int cnt = 0;
                for (int k = 0; k < 8; k++)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#')
                    {
                        cnt++;
                    }
                    board[i][j] = cnt + '0';
                }
            }
        }
    }
    for (int i = 0; i < X; i++)
    {
        cout << board[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
using namespace std;

using ll = long long;

ll nCk(ll n, ll k) {
    k = min(k, n - k);
    if (k <= 0) return 1;
    else if (k == 1) return n;
    return n * nCk(n - 1, k - 1) / k;
}

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

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

    sort(v.begin(), v.end(), greater<ll>());
    ll sum = 0;

    for (int i = 0; i < a; i++) {
        sum += v[i];
    }
    cout << fixed << setprecision(10) << (double)sum / (double)a << endl;

    ll ans = 0;
    for (int i = a; i <= b; i++) {
        // i個使う場合
        ll back = v[i - 1];
        if (i > a) {
            // cout << "?" << endl;
            if (sum * i > (sum + back) * (i - 1)) {
                // cout << "foo" << endl;
                break;
            }
            // cout << "[" << i << "]" << endl;
            // cout << sum * (i + 1) << " and " << (sum + back) * i << endl;
            sum += back;
        }
        // cout << "a" << endl;

        map<ll, int> counter, counter2;
        for (int j = 0; j < i; j++) {
            counter[v[j]]++;
        }
        for (int j = i; j < n; j++) {
            counter2[v[j]]++;
        }
        ll all = counter[back] + counter2[back];
        // cout << "(" << counter[back] << ", " << counter2[back] << ")" << endl;
        ans += nCk(all, counter[back]);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll A, B;

ll gcd(ll a, ll b)
{
    if (a%b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a%b));
    }
}

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

int main() {
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
using namespace std;
 
long long int gcd(int a, int b)
{
  if (a < b) 
  {
    int tmp;
    tmp = a;
    a   = b;
    b   = tmp;
  }
 
  int r = a % b;
  while (r != 0)
  {
    a = b;
    b = r;
    r = a % b;
  }
 
  return b;
}
 
 
long long int lcm(long int a, long int b)
{
  return a * b / gcd(a, b);
}
 
void snack()
{
  long long int a, b;
  cin >> a >> b;
 
  cout << lcm(a, b) << "\n";
}
 
 
bool is_prime(int n)
{
  if (n <= 1) return false;
  if (n == 2) return true;
 
  if (n % 2 == 0)return false;
 
  for (int i = 3; i * i <= n; i += 2)
  {
    if (n % i == 0) return false;
  }
 
  return true;
}
 
 
void next_prime()
{
  int x;
  cin >> x;
 
  int prime = x;
  while (!is_prime(prime)) prime++;
 
  cout << prime << "\n";
}
 
 
int factorial(int n)
{
  int fact = 1;
  for (int i = n; i > 0; i--) fact *= i;
  return fact;
}
 
 
int calc_order(int n, vector<int> x)
{
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    cnt += (x[i] - 1) * factorial(n - 1 - i);
    for (int j = i + 1; j < n; j++) {
      if (x[j] > x[i]) x[j]--;
    }
  }
  return cnt;
}
 
 
void count_order()
{
  int n;
  cin >> n;
 
  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> q[i];
 
  int p_cnt = 0, q_cnt = 0;
  p_cnt = calc_order(n, p);
  q_cnt = calc_order(n, q);
 
  cout << abs(p_cnt - q_cnt);
}
 
 
 
 
int main()
{
  snack();
  //next_prime();
  //count_order();
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[100][100] = { -1 }, f[100100], g[10000], h[10000], m[100] = { 0 }, counto = 0, x[100] = { 0 }, y = 0;
long long ab[100000], u = 0, p = 0, z = 0, s = 0;
pair<int, int>manji[1500], daburu[100];
char rikka, toka[50][50];
string saya, homu, kyok, mami[100], mado[100];
bool gg = true;
vector<char>uc;
vector<int>gachi;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		cin >> f[i];
		
	}
	c = 1;
	while (c < a) {
		counto++;
		c += b - 1;
	}
	cout << counto << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define maxn 2000100
#define LL long long 
using namespace std;
char str[maxn];
LL num[1000];
int main(){
	cin>>str;
	int n=strlen(str);
	LL ans=1;
	for(int i=0;i<n;i++){
		ans+=i-num[str[i]];
		num[str[i]]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int ac = 0;
		int[] wa = new int[n];
		int wawa = 0;

		TreeMap<Integer, String> ans = new TreeMap<>();

		for (int i = 0; i < m; i++) {
			int p = sc.nextInt();
			String s = sc.next();
			if (ans.containsKey(p)) {
				if (ans.get(p).equals("AC")) {
					continue;
				} else {
					ans.put(p, s);
					if (s.equals("AC")) {
						ac++;
						continue;
					} else if(s.equals("WA")){
						wa[p-1]++;
						continue;
					}
				}
			} 
			ans.put(p, s);
				if (s.equals("AC")) {
					ac++;
				} else if(s.equals("WA")){
					wa[p-1]++;
				}
			}
		
		System.out.println(ac);
		for(Integer key : ans.keySet()) {
			if(ans.get(key).equals("AC")) {
				wawa = wawa + wa[key-1];
			}
		}
		
		System.out.println(wawa);
		

		}
}

Measured memory_bytes: 73888
#include <bits/stdc++.h>
//#include <iostream>
//#include <cstdio>

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 2000000000

typedef long long ll;
typedef unsigned long long ull;
//typedef Pair<int,int> P;

using namespace std;

int main(void){
	string a, b, c;
	cin>>a>>b>>c;
	cout<<"A"<<b[0]<<"C";
	
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    string s;cin >>s;
    ll n=s.size();
    bool flg=true;
    if(s[0]==s[n-1]&&n%2!=0)flg=false;
    if(s[0]!=s[n-1]&&n%2==0)flg=false;
    if(flg)puts("First");
    else puts("Second");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1 << 30);
 
int main() {
  int n,h[110000];
  cin >> n;
  for(long i = 0; i < n; i++)
    cin >> h[i];

  vector<long> dp(n, INF);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; i++) {
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
  }

  cout << dp[n-1] << endl;
}

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

int main() {
  int h, w;
  string a;
  cin >> h >> w;

  for (int i = 0; i < h+2; i++) {
    if (i == 0) {
      for (int j = 0; j < w+2; j++) cout << '#';
      cout << "" << endl;
    } else if (i == h+1) {
      for (int j = 0; j < w+2; j++) cout << '#';
      cout << "" << endl;
    } else {
      cin >> a;
      cout << '#' << a << '#' << endl;;
    }
  }
}


Measured memory_bytes: 256
import sys

global N, M
global edgeList

global longestPathFrom

def dfs(x):
    if longestPathFrom[x] == -1:
        # get
        longest = -1
        for nextNode in edgeList[x]:
            longest = max(longest, dfs(nextNode))
        # set
        if longest == -1:
            longestPathFrom[x] = 0
        else:
            longestPathFrom[x] = longest + 1
    # -- longest path from x has been calculated
    return longestPathFrom[x]

# -- main
if __name__ == '__main__':
    # -- 
    sys.setrecursionlimit(1000001)

    # -- input
    N, M = map(int, input().split())
    edgeList = [[] for node in range(N)]

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1; y -= 1;
        edgeList[x].append(y)

    # -- process
    longestPathFrom = [-1] * N

    for node in range(N):
        if longestPathFrom[node] == -1:
            dfs(node)

    # -- output
    print(max(longestPathFrom))

Measured memory_bytes: 137064
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	string s;
	cin >> s;
	for(int i = 0; i + 1 < s.size(); i++){
		if(s[i] == s[i + 1]){
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
  map<string, int> fq;
  string s, ms = "";
  while (cin >> s) {
    ++fq[s];
    if (ms.size() < s.size())
      ms = s;
  }

  int cnt = 0;
  for (map<string, int>::iterator it = fq.begin(); it != fq.end(); ++it) {
    if (cnt < (*it).second) {
      s = (*it).first;
      cnt = (*it).second;
    }
  }

  cout << s << " " << ms << endl;
  return 0;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int mp[222][222];

#define MAX_V 10000

struct edge{int to;long long cap,rev;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,long long cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty())
	{
		int v = que.front();que.pop();
		for(int i = 0;i < G[v].size();++i)
		{
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0)
			{
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v ,int t,long long f)
{
	if(v == t)return f;
	for(int &i = iter[v];i < G[v].size() ;++i)
	{
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to])
		{
			long long d = dfs(e.to,t,min(f,e.cap));
			if(d > 0)
			{
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

long long Dinic(int s,int t)
{
	long long flow = 0;
	while(1)
	{
		bfs(s);
		if(level[t] < 0)return flow;
		memset(iter,0,sizeof(iter));
		long long f;while((f = dfs(s,t,INF)) > 0)flow += f;
	}
}

struct seica{
	int from,to,cost,dist;
};

int main()
{
	REP(i,222)REP(j,222)mp[i][j] = INF;
	REP(i,222)mp[i][i] = 0;
	
	vector<seica> v;
	int n,m,s,t;cin >>  n >> m >> s >> t;
	s--;t--;
	
	REP(i,m){
		int a,b,c,d;cin >> a >> b >> c >> d;
		a--;b--;
		seica sei;
		sei.from = a;
		sei.to = b;
		sei.dist = c;
		sei.cost = d;
		mp[a][b] = c;
		v.PB(sei);
	}
	
	REP(k,n)REP(i,n)REP(j,n){
		mp[i][j] = min(mp[i][j],mp[i][k] + mp[k][j]);
	}
	
	REP(i,m){
	//	cout << mp[s][t] << ' ' <<  mp[s][v[i].from] + mp[v[i].from][v[i].to] + mp[v[i].to][t] << ' '<< v[i].dist  << ' ' <<  mp[v[i].from][v[i].to] << endl;
		if(mp[s][t] == mp[s][v[i].from] + mp[v[i].from][v[i].to] + mp[v[i].to][t] && v[i].dist == mp[v[i].from][v[i].to]){
	//		cout << "!!" << endl;
			add_edge(v[i].from,v[i].to,v[i].cost);
		}
	}
	
	cout << Dinic(s,t) << endl;
		
	return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <memory>
#include <cstring>
#include <iostream>

int d, g;
unsigned int dp[11][150000];

int main() {
    std::memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    std::cin >> d >> g;
    
    int p, c;
    for(int i = 0; i < d; ++i) {
        std::cin >> p >> c;
        
        for(int j = 0; j <= p; ++j) {
            for(int k = 0; k < 120000; ++k) {
                if(dp[i][k] != unsigned(-1)) {
                    auto& r = dp[i + 1][k + j * (i + 1) + (j == p ? c / 100 : 0)];

                    r = std::min(r, dp[i][k] + j);
                }
            }
        }
    }
    std::cout << *std::min_element(&(dp[d][g / 100]), &(dp[d][150000 - 1])) << std::endl;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  string t;
  ll ans=1;
  ll cnt=0;
  char now=s[0];
  rep(i,n){
    if(s[i]==now) cnt++;
    else{
      ans++;
      now=s[i];
    }
  }
  cnt=n-ans;//幸福度
  //cout<<cnt<<endl;
  cnt=min(n-1,cnt+2*k);
  cout<<cnt<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int n;
int A[20] = {0};
int q;
int m[200] = {0};


int solve(int search, int i) {
//	int j;
//	printf("%d %d\n", search, i);
	if (search == 0) return 1;
	if (i >= n || search < 0) return 0;

	return (solve(search, i + 1) || solve(search - A[i], i + 1));
}

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

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

	for (i = 0; i < q; ++i) {
		if (solve(m[i], 0)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> sum(n+1, 0);
    for (int i = 0; i < n; ++i) {
        sum[i+1] = sum[i] + a[i];
    }
    map<ll, ll> mp;
    for (int i = 0; i <= min(n, k-1); ++i) {
        mp[(sum[i] - i) % k]++;
    }

    ll res = 0;
    for (int i = 0; i <= n; ++i) {
        mp[(sum[i] - i) % k]--;
        res += mp[(sum[i] - i) % k];
        if (i+k > n) continue;
        mp[(sum[i+k] - (i+k)) % k]++;
    }
    cout << res << endl;
}

Measured memory_bytes: 18740
#include<climits>
    #include<iostream>
     
    using namespace std;
     
    int main(){
        int n;
        cin>>n;
        
        long long int sum=1LL;
        int c=0;
        long long int o=1000000000000000000LL;
        
        for(int i=1;i<=n;i++){
            long long int t;
            cin>>t;
            if(t==0){
                c=0;
                sum=0;
                break;
            }
            if(sum>o/t)
                c++;
            sum *=t;
        }
        
        cout<<(c ? -1 : sum)<<endl;
    }

Measured memory_bytes: 3636
N,W=map(int,input().split())
wv=[ tuple([int(j) for j in input().split()]) for _ in range(N) ]
w1=wv[0][0]
w2=w1+1
w3=w1+2 
w4=w1+3

wv=sorted(wv,key=lambda x:x[1],reverse=True)
wv=sorted(wv,key=lambda x:x[0])
wvv = list(map(lambda x:x[1], wv))

# print(wv)
inf = float("inf")
ans=0
from collections import defaultdict
counter = defaultdict(int)

for i in range(N):
    w,v = wv[i]
    counter[w] += 1

from bisect import bisect_left as bll

for e1 in range(0, counter[w1]+1):
  for e2 in range(0, counter[w2]+1):
    for e3 in range(0,counter[w3]+1):
      for e4 in range(0, counter[w4]+1):
          tmp=0

          if w1*e1 + w2*e2 + w3*e3 + w4*e4 > W:
              continue

          i1=bll(wv, (w1,-inf))
          i2=bll(wv, (w2,-inf))
          i3=bll(wv, (w3,-inf))
          i4=bll(wv, (w4,-inf))

          tmp= tmp \
             +sum(wvv[i1:i1+e1])  \
             +sum(wvv[i2:i2+e2])  \
             +sum(wvv[i3:i3+e3])  \
             +sum(wvv[i4:i4+e4])

          ans=max(ans,tmp)
      
print(ans)



Measured memory_bytes: 56792
#include<cstdio>
const short N_MAX = 105;
bool matrix[N_MAX][N_MAX];
int main(){
	int n;
	scanf("%d", &n);
	for(char i=0; i<n;i++){
		int degree, index;
		scanf("%u%u", &index, &degree);
		for(char j=0; j<degree; j++){
			int temp;
			scanf("%d", &temp);
			matrix[index-1][temp-1] = true;
		}
	}
	for(char r=0; r<n; r++){
		for(char c=0;c<n;c++){
			if(c!=0) printf(" ");
			printf("%d", matrix[r][c]);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2592
#include<bits/stdc++.h>
using namespace std;
int n,m[10000],cm,hm,res;
long long int x;
int main(){
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>m[i];
        hm+=m[i];
    }
    cm=x-hm;
    sort(m,m+n);
    res=cm/m[0];
    cout<<n+res<<endl;

}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


a, b = map(int, read().split())
cnt = 1
for n in set(prime_decomposition(b)) & set(prime_decomposition(a)):
    if is_prime(n):
        cnt += 1
print(cnt)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll x = gcd(a, b),ans = 1;
    for (ll i = 2; i * i <= x; ++i){
        if(x % i == 0){
            ++ans;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if(x != 1)++ans;
    pf(ans);
    return 0;
}


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

#define ll long long
#define tc                int T;cin>>T;while(T--)
int a[100000];
const int INF=1e9+5;
int main()
{
	int n, c, b, k ; cin >> n >> k;
	for (int& e : a)cin >> e;
	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int e = i + 1; e <= i + k; ++e) {
			if (e < n)
				if ((dp[i] + abs(a[e] - a[i])) < dp[e])
					dp[e] = dp[i] + abs(a[e] - a[i]);
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}


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

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

int main(){
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin>>k;
    cout<<a[k-1]<<endl;
}

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 1e5 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


ll dp[2][Max+10];

vector<ll>v[Max+10];



ll call(ll ch,ll s,ll p)
{
        ll &ret=dp[ch][s];

        if(~ret)return ret;

        ret=1;


        for(auto x : v[s])
        {
            if(x!=p)
            {
                if(ch==0)
                ret=(ret*call(1,x,s))%Mod;

                else
                {
                  ret=(ret*(call(1,x,s)+call(0,x,s)))%Mod;
                }
            }
        }

        return (ret)%Mod;
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;


      memset(dp,-1,sizeof(dp));
       cin>>n;

       for(i=1; i<n; i++)
       {
           cin>>a>>b;


           v[a].eb(b);
           v[b].eb(a);
       }

       cout<<(call(0,1,1)+call(1,1,1))%Mod<<endl;









}



Measured memory_bytes: 18976
# -*- coding: utf-8 -*-
"""
B - TAKOYAKI FESTIVAL 2019
https://atcoder.jp/contests/abc143/tasks/abc143_b

"""
import sys


from itertools import combinations

def solve(takoyaki):
    return sum(x * y for x, y in combinations(takoyaki, 2))


def main(args):
    _ = input()
    takoyaki = map(int, input().split())
    ans = solve(takoyaki)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
N = int(input())
ans = []

while N > 26:
    if N % 26 == 0:
        ans.insert(0,chr(122))
        N = N // 26-1
    else:
        ans.insert(0,chr(N%26+96))
        N = N // 26
ans.insert(0,chr(N+96))

print("".join(ans))

Measured memory_bytes: 9000
#include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <deque>
    #include <list>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <utility>
    #include <algorithm>
    #include <map>
    #include <set>
    #include <complex>
    #include <cmath>
    #include <limits>
    #include <climits>
    #include <ctime>
    #include <cassert>
    using namespace std;
     
    #define rep(i,a,n) for(int i=a; i<n; i++)
    #define repr(i,a,n) for(int i=a; i>=n; i--)
    #define pb(a) push_back(a)
    #define fr first
    #define sc second
    #define INF 999999999
     
    #define X real()
    #define Y imag()
    #define EPS (1e-10)
    #define EQ(a,b) (abs((a) - (b)) < EPS)
    #define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
    #define LE(n, m) ((n) < (m) + EPS)
    #define LEQ(n, m) ((n) <= (m) + EPS)
    #define GE(n, m) ((n) + EPS > (m))
    #define GEQ(n, m) ((n) + EPS >= (m))
     
    typedef vector<int> VI;
    typedef vector<VI> MAT;
    typedef pair<int, int> pii;
    typedef long long int ll;
     
    typedef complex<double> P;
    typedef pair<P, P> L;
    typedef pair<P, double> C;
     
    int dy[]={0, 0, 1, -1};
    int dx[]={1, -1, 0, 0};
    int const MOD = 1000000007;
     
    namespace std {
        bool operator<(const P& a, const P& b) {
            return a.X != b.X ? a.X < b.X : a.Y < b.Y;
        }
    }
     
    bool issatisfy(int n) {
        int s, t;
        s = n % 10; n /= 10;
        while(n != 0) {
            t = n % 10;
            if(t != s-1) return false;
            n /= 10; s = t;
        }
        return true;
    }
     
    int main() {
        int N; cin >> N;
        int a[1010];
        rep(i,0,N) cin >> a[i];
     
        int ans = -1;
        rep(i,0,N) {
            rep(j,i+1,N) {
                if(issatisfy(a[i] * a[j])) ans = max(ans, a[i] * a[j]);
            }
        }
     
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 3096
import math

A, B, H, M = map(int, input().split())

H_angle = 30*H + 0.5*M # (360/(12*60)) * ((60*H)+M)
M_angle = 6*M          # 360/60 * H
HM_angle = abs(H_angle - M_angle)

if HM_angle == 0:
    print(abs(A-B))
elif HM_angle == 180:
    print(A+B)
else:
    print((A**2 + B**2 - 2*A*B*math.cos(math.radians(HM_angle)))**0.5)

Measured memory_bytes: 9596
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    char C1,C2;
    string s;

    cin >> a >> b;

    if((a+b)%2) cout << "IMPOSSIBLE\n";
    else cout << (a+b)/2 << "\n";

    return 0;
}

Measured memory_bytes: 256
n=int(input())
t=[]
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    t.append(i)
hantei=10**10+1
for i in range(len(t)):
  x=len(str(t[i]))
  y=len(str(n//t[i]))
  if hantei>max(x,y):
    hantei=max(x,y)
print(hantei)
  

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 1005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
  	
  		signed main()
  		{
  			FAST_IO;
  				
  			int n;
  			cin>>n;
  			
  			int ans=0;
  			for(int i=1;i<=n;i++)
  			{
  				int p=i;
  				ans=0;
				for(int j=1;j*j<=p;j++)
				{
					for(int k=1;k*k<=p;k++)
					{
						int f=i-(j*j+k*k+j*k);
						
						double z=1.0*(-(j+k)+sqrt((j+k)*(j+k)+4*f))/2.0;
					
						if(z>0 && z<=n && z-(int)z==0)
						ans++;
					}
				}	
				cout<<ans<<endl;
			}
	
		}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    mp[i + 1] = x;
  }
  int i = 1;
  int t = mp[i], ans = 0;
  set<int> s;
  bool ok = true;
  while (t != 2) {
    if (s.find(t) != s.end()) {
      ok = false;
      break;
    } else {
      s.insert(t);
      t = mp[t];
    }
    ++ans;
  }
  if (ok)
    cout << ans + 1;
  else
    cout << -1;

  return 0;
}


Measured memory_bytes: 12872