akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<min(a+b,min(a+c,b+c))<<endl;

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(k);
	VLL digits;
	while(n != 0) {
		digits.push_back(n % k);
		n /= k;
	}
	while(digits.back() == 0)	digits.pop_back();
	LL ans = max(1ll, (LL)digits.size());
	pll(ans); nl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define X first
#define Y second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define MAXN 100100
#define INF 1001001001

vector<ii> g[MAXN];
int dp[MAXN];
int ok = 1;
vector<int> po;

/*int bio[MAXN];
void dfs1(int cv)
{
  if (bio[cv]) return;
  bio[cv] = 1;

  for (ii i: g[cv])
    dfs1(i);

  po.pb(cv);
}*/

void dfs(int cv, int d)
{
  if (ok == 0) return;
  dp[cv] = d;

  for (ii i: g[cv]) {
    if (dp[i.X] == INF)
      dfs(i.X, i.Y + dp[cv]);
    if (dp[i.X] != i.Y + dp[cv]) ok = 0;
    if (ok == 0) return;
  }
}

int main()
{
  for (int i = 0; i < MAXN; i++) { dp[i] = INF; }
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int q, w, e;
    scanf("%d%d%d", &q, &w, &e);
    q--; w--;
    g[q].pb({w, e});
    g[w].pb({q, -e});
  }
  /*for (int i = 0; i < n; i++) {
    dfs1(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    int cv = po[i];
    for (ii i: g[cv]) {
      if (dp[i.X] == INF)
        dp[i.X] = dp[cv] + i.Y;
      else if (dp[i.X] != i.Y + cv) ok = 0;
      if (ok == 0) return;
    }
  }*/
  for (int i = 0; i < n; i++) {
    if (dp[i] == INF)
      dfs(i, 0);
  }
  if (ok)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

int main(){

    string s,t;
    cin >> s >> t;

    rep(i,s.length()){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
   
   cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3628
//By Zank100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define din(t) long long t;cin>>t;
#define in(t) cin>>t;
int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	din(n);din(W);
	ll w[n],v[n];
	for(ll i=0;i<n;i++)
	{
	    in(w[i]);in(v[i]);
	}
	ll k[n+1][W+1];
	for(ll i=0;i<=n;i++)
	{
	    for(ll j=0;j<=W;j++)
    	{
    	   if(i==0||j==0)
    	   {
    	       k[i][j]=0;
    	   }else if(w[i-1]>j){
    	       k[i][j]=k[i-1][j];
    	   }else{
    	       k[i][j] = max(v[i-1]+k[i-1][j-w[i-1]],k[i-1][j]);
    	   }
    	}
	}
	ll ans=k[n][W];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 79232
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

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

  scanf("%lld %lld %lld",&a,&b,&n);

  if(b-1<=n) ans=(long long int)floor((double)a*((double)(b-1)/(double)b));
  else ans=(long long int)floor((double)a*((double)n/(double)b));

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 2216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
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;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;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);

l_l b[100000];
ll kyori(l_l x,l_l y){
    return (abs(x.first-y.first)+abs(x.second-y.second));
}

int main(){
    ll h,w,d;cin>>h>>w>>d;
    ll a[h][w];
    l_l b[h*w+1];
    rep(i,0,h-1){
        rep(j,0,w-1){
            cin>>a[i][j];
            b[a[i][j]]=make_pair(i,j);
        }
    }
    ll dp[d][(h*w+1)/d+10];
    ll c;
    rep(i,0,d-1){
        dp[i][0]=0;
        c=1;
        while(c*d+i<=h*w){
            dp[i][c]=dp[i][c-1]+kyori(b[d*(c-1)+i],b[d*c+i]);
            c++;
        }
    }
    ll q;cin>>q;
    ll l,r;
    ll ans[q];
    rep(i,0,q-1){
        cin>>l>>r;
        if(l<d){
            ans[i]=dp[l][(r-l)/d];
        }else{
            ans[i]=dp[l%d][(r-l%d)/d]-dp[l%d][(l-l%d)/d];
            //cout<<dp[l%d][(r-l%d)/d]<<' '<<dp[l%d][(l-l%d)/d]<<endl;
        }
    }
    rep(i,0,q-1){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 11008
#!/usr/bin/ruby
# encoding: utf-8

# ABC 110 B 

N,M,X,Y = gets.split.map(&:to_i)
coordX = gets.split.map(&:to_i)
coordY = gets.split.map(&:to_i)

coordX.push(X)
coordY.push(Y)

if X < Y
  if coordX.max < coordY.min
    puts "No War"
  else
    puts "War"
  end
else
  if coordY.max < coordX.min
    puts "No War"
  else
    puts "War"
  end
end


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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define F0R(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define sz (int)size
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define f first
#define s second

const int MX = 200;

int N, a[MX];

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}


int main() {
	cin >> N;
	F0R(i, 2 * N) cin >> a[i];
	sort(a, a + 2 * N);

	int ans = 0;
	for (int i = 0; i < 2 * N; i += 2) {
		ans += a[i];
	}

	cout << ans << "\n";
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 256
N = int(input())

c = [[0 for _ in range(9)] for _ in range(9)]

for n in range(1, N + 1):
  l = n % 10
  if l == 0:
    continue
  t = n // (10 ** (len(str(n)) - 1))
  c[t - 1][l - 1] += 1

ans = 0
for i in range(9):
  for j in range(9):
    ans += c[i][j] * c[j][i]
print(ans)

Measured memory_bytes: 3064
using System;

using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int W = int.Parse(s[0]);
            int H = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);

            int a = x - r;
            int b = x + r;
            int c = y - r;
            int d = y + r;


            if (a >= 0 && b <= W&&c >= 0 && d <= H)
            {
                Console.WriteLine("Yes");

            }

            else  
            {
                Console.WriteLine("No");

            }

           

           
          











           

        }
    }
}

Measured memory_bytes: 19636
local n, k = io.read("*n", "*n")
local h = {}
for i = 1, n do h[i] = io.read("*n") end
table.sort(h)
local mindiff = h[k] - h[1]
for i = 2, n - k + 1 do
  mindiff = math.min(mindiff, h[i + k - 1] - h[i])
end
print(mindiff)


Measured memory_bytes: 2424
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < class Value >
bool bat(Value x, std::size_t pos) { return (x >> pos) & Value{1}; }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  int n = s.length() ;
  std::vector< int > a(n);
  std::transform(all(s), a.begin(), [](char c){ return c - '0'; });
  int head = a.front();
  a.erase(a.begin());
  n--;
  debug(a);

  auto cal = [&] (std::vector< int > a) {
    lint ans = 0;
    for (int x : a) {
      ans *= 10;
      ans += x;
    }
    return ans;
  };
  debug(cal(std::vector< int >{0,1,2,0}));

  lint ans = 0;
  int N = 1 << n;
  rep(bs, 0, N) {
    debug(bs);
    lint now = 0;
    std::vector< int > vec = { head };
    rep(i,0,n) {
      if (bat(bs, i)) {
        lint tmp = cal(vec);
        debug(tmp);
        now += tmp;
        vec.clear();
      }
      vec.emplace_back(a.at(i));
    }
    lint tmp = cal(vec);
    debug(tmp);
    now += tmp;
    ans += now;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	std::string str; std::cin >> str;
	if (str == "SUN") {
		std::cout << "7\n";
	}
	else if (str == "MON") {
		std::cout << "6\n";
	}
	else if (str == "TUE") {
		std::cout << "5\n";
	}
	else if (str == "WED") {
		std::cout << "4\n";
	}
	else if (str == "THU") {
		std::cout << "3\n";
	}
	else if (str == "FRI") {
		std::cout << "2\n";
	}
	else {
		std::cout << "1\n";
	}
}

Measured memory_bytes: 888
def main():
    N, M = map(int, input().split())
    
    A = []
    B = []
    for _ in range(N):
        hoge = list(map(int, input().split()))
        A.append(hoge[0])
        B.append(hoge[1])

    C = []
    D = []
    for _ in range(M):
        hoge = list(map(int, input().split()))
        C.append(hoge[0])
        D.append(hoge[1])

    for x in range(N):
        fuga = 10 ** 9
        c = 0
        for y in range(M):
            hoge = abs(A[x] - C[y]) + abs(B[x] - D[y])
            if hoge < fuga:
                fuga = hoge
                c = y + 1
        print(c)



if __name__ == "__main__":
    main()

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var a1 = Input().ToInt();
		var a2 = Input().ToInt();
		var a3 = Input().ToInt();
		
		var a = new int[3, 3];
		for(int i = 0; i < 3; i++)
		{
			a[0,i] = a1[i];
			a[1,i] = a2[i];
			a[2,i] = a3[i];
		}
			
		var n = Console.ReadLine().ToInt();
		for(int i = 0; i < n; i++)
		{
			var k = Console.ReadLine().ToInt();
			for(int y = 0; y < 3; y++)
				for(int x = 0; x < 3; x++)
					if(a[y,x] == k) a[y,x]= -1;
		}
		
		bool bingo = false;
		
		for(int y = 0; y < 3; y++)
		{
			bool l = true;
			for(int x = 0; x < 3; x++)
			{
				if(a[y,x] != -1)
				{
					l = false;
					break;
				}
			}
			if(l) bingo = true;
		}
		
		for(int x = 0; x < 3; x++)
		{
			bool l = true;
			for(int y = 0; y < 3; y++)
			{
				if(a[y,x] != -1)
				{
					l = false;
					break;
				}
			}
			if(l) bingo = true;
		}
		
		if(a[0,0] == -1 && a[1,1] == -1 && a[2,2] == -1)
			bingo = true;
		
		if(a[0,2] == -1 && a[1,1] == -1 && a[2,0] == -1)
			bingo = true;
		Console.WriteLine(bingo?"Yes":"No");
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll a,b; cin >> a >> b; ll num = -1;
  rep(i,1001){
    if(8*i/100 == a && i/10 == b){
      num = i;
      break;
    }
  }
  
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int a,b;
int main(){
	cin>>a>>b;
	if((a+b)%2==1){
		cout<<"IMPOSSIBLE"<<endl;
	}else{
		cout<<(a+b)/2<<endl;
	}
	return 0;
}

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

int main(){
    int N, m, ans;
    map<int, int> r;
    map<int, int> c;
    m=0;
    ans=0;
    cin >> N;
    for(int i=1; i<=N; ++i){
        cin >> m;
        r[i]=m;
    }
    m=0;
    for(int i=1; i<=N; ++i){
        cin >> m;
        c[i]=m; 
    }
    for(int i=1; i<=N; ++i){
        if(r[i]-c[i]>0)
            ans+=(r[i]-c[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
inputs=[list(map(int,input().split())) for _ in range(n+1)]
Bs=inputs[0]
As=inputs[1:]

ans=0
for a in As:
  total=0
  for i in range(m):
    total+=Bs[i]*a[i]
  if total+c>0:
    ans+=1
print(ans)

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

int main()
{
  int N, M;
  cin >> N >> M;
  char A[50][50];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  char B[50][50];
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < N - M + 1; j++) {
      for (int x = 0; x < M; x++) {
        for (int y = 0; y < M; y++) {
          if (A[i + x][j + y] != B[x][y]) {
            goto next;
          }
        }
      }
      cout << "Yes" << endl;
      return 0;
      next:;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  string x;
  cin >> x;
  bool pow10 = true;
  if (x[0] != '1')
    pow10 = false;
  else {
    for (int i = 1, l = x.length(); i < l; i++) {
      if (x[i] != '0') {
        pow10 = false;
        break;
      }
    }
  }
  if (pow10) {
    cout << 10 << endl;
  } else {
    int sum = 0;
    for (char c : x) sum += c - '0';
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
S = int(input())

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

if ans == -1:
    for i in range(int(N**.5),0,-1):
        b = (N-S)//i + 1
        if b>1:
            if f(b,N)==S:
                ans = b
                break

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
const int INF=INT_MAX/3;
const int V_MAX=10000,E_MAX=10000;
const int N=10000;

int V,E;

int par[N];
int rank[N];

int n,q;

void init(){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

int find(int x){
  if(x==par[x]) return x;
  return (par[x]=find(par[x]));

}

int same(int x,int y){
  if(find(x)==find(y)) return 1;
  else return 0;
}

void unite(int x,int y){

  int rx=find(x),ry=find(y);
  if(rank[rx]<rank[ry]) par[rx]=ry;
  else{
    par[ry]=rx;
    if(rank[rx]==rank[ry]) rank[ry]++;
  }
}

void print(){
  for(int i=0;i<n;i++)
    cout<<"par["<<i<<"]"<<par[i]<<endl;
}
  
int main(){

  cin>>n>>q;
  init();
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c==0) unite(x,y);
    if(c==1) cout<<same(x,y)<<endl;
    if(c==2) print();
  }


  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int n,sz[100005];
vector<pair<int,int> > v[100005];
long long sum;
int dfs(int node,int p,int c)
{
	sz[node]=1;
	for (auto u:v[node])
	{
		if (u.first!=p)
		sz[node]+=dfs(u.first,node,u.second);
	}
	sum+=2LL*min(sz[node],n-sz[node])*c;
	return sz[node];
}
int find(int node,int p)
{
	for (auto u:v[node])
	{
		if (u.first!=p && sz[u.first]>n/2)
		return find(u.first,node);
	}
	return node;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		v[a].push_back({b,c});
		v[b].push_back({a,c});
	}
	dfs(1,0,0);
	int c=find(1,0),mn=1e9;
	for (auto u:v[c])
	{
		if (sz[u.first]==(n+1)/2)
		{
			mn=0;
			sum-=u.second;
			break;
		}
		mn=min(mn,u.second);
	}
	printf("%lld",sum-mn);
}

Measured memory_bytes: 16168
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define pb push_back
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll,ll> 
ll fac[1000001];
void powe(ll p)
{
     fac[0] = 1; 

     
    for (ll i = 1; i <= 1000000; i++) 
        fac[i] = (fac[i - 1] *i) % p; 
  
}
 
 
        
      long long power( long long x, 
                         ll y, ll p) 
{ 
   long long res = 1; // Initialize result 
  
    x = x % p; 
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
 long long modInverse( long long n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
 long long nCrModPFermat( long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
       return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
 ll gcd(ll a,ll b)
 {
     if(b==0)
     return a;
     return gcd(b,a%b);
 }
  
int main() {
   ll t=1;

   //cin>>t;
  
   while(t--)
   {
  string s;
  cin>>s;
  if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
  cout<<3;
  else
  {
      ll ct=0;
      if(s[0]=='R')
      ct++;
      if(s[1]=='R')
      ct++;
      
      if(s[2]=='R')
      ct++;
      
      if(ct==2)
      {if(s[1]=='S')
      cout<<1;
      
          else
          cout<<2;
          
      }
      else
      cout<<ct<<endl;
      
  }
    
    
    
   }
  
   

      

return 0;    
}

Measured memory_bytes: 3604
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	H := nextInts(N)
	for i := 1; i < N; i++ {
		if H[i] > H[i-1] {
			H[i]--
		}
		if H[i-1] > H[i] {
			fmt.Fprint(out, "No\n")
			return
		}
	}
	fmt.Fprint(out, "Yes\n")
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 3072
#include<iostream>

int main()
{
    int n,x=0,maxim=0;
    std::string str;
    std::cin>>n;
    std::cin.ignore();
    std::cin>>str;
    for(int i=0;i<n;i++){
        if(str[i]=='I')x++;
        else x--;
        if(x>maxim){
            maxim = x;
        }
    }
    std::cout<<maxim<<std::endl;
}


Measured memory_bytes: 3136
#include "bits/stdc++.h"

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N;
	int ma=-INF, mi=INF;

	cin >> N;
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}

	cout << abs(ma-mi) << endl;

	return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 -dx
y4 = y3 -dy

print(x3,y3,x4,y4)

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

int main() {
    while (true)
    {
        int x, y;
        cin >> x >> y;

        if (x == 0 && y ==0)
        {
            break;
        }
        else if (x < y)
        {
            cout << x << " " << y << "\n";
        }
        else
        {
            cout << y << " " << x << "\n";
        }
    }

    
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                \
  cerr << #__VA_ARGS__ << ": "; \
  debug(__VA_ARGS__);           \
  cerr << " (L" << __LINE__ << ")" << endl
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  bool flipped = false;
  deque<char> que(ALL(S));
  REP(q, Q) {
    int T;
    cin >> T;
    if (T == 1) {
      flipped = !flipped;
      continue;
    }
    int F;
    char C;
    cin >> F >> C;
    if ((F == 1) ^ flipped) {
      que.push_front(C);
    } else {
      que.push_back(C);
    }
  }
  string s(ALL(que));
  if (flipped) {
    reverse(ALL(s));
  }
  cout << s << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;
typedef pair<ll, ll> pint;


void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

const ll INF = 1e18;
ll dp[200005][4];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int k = 1 + n%2;
    rep(i, n+1) rep(j, k+1) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, k+1) {
            chmax(dp[i+1][j+1], dp[i][j]);
            ll now = dp[i][j];
            if ((i+j) % 2 == 0) now += a[i];
            chmax(dp[i+1][j], now);
        }
    }

    ll ans = dp[n][k];
    cout << ans << endl;

}

Measured memory_bytes: 10376
a,b,c,d = input().split()
a,b,c,d = int(a),int(b),int(c),int(d)
while a:
  c = c-b
  if c<=0:
    break
  a = a-d
  if a<=0:
    break
if a>=0 and c<=0:
  print("Yes")
if a<=0 and c>=0:
  print("No")

Measured memory_bytes: 9100
#include <algorithm>
#include <bitset>
#include <boost/rational.hpp>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  int64_t K = 0;
  vector<int> a(N), b(N);
  rep(i, N) {
    cin >> a[i];
    K -= a[i];
  }
  rep(i, N) {
    cin >> b[i];
    K += b[i];
  }

  rep(i, N) { K -= max((b[i] - a[i] + 1) / 2, 0); }
  cout << (K >= 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin>>a>>b;
    bool dp[b+1];
    int arr[a];
    for (int i=0; i<a; i++) cin>>arr[i];
    for (int i=0; i<=b; i++) dp[i]=0; //base case
    dp[0]=0; // base case
    for (int i=1; i<=b; i++){
        for (int j=0; j<a; j++){
            if (i-arr[j]<0) continue;
            if (dp[i-arr[j]]==0){
                dp[i]=1;
                break;
            }
        }
    }
    if (dp[b]==0) cout<<"Second\n";
    else cout<<"First\n";
}
//Game theory task (Nim game), using dp (memoization) to solve

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll l, r;
ll x[60], y[60];
ll dp[61][2][2][2];

int main() {
    cin >> l >> r;
    rep(i,60) {
        x[i] = l%2;
        y[i] = r%2;
        l /= 2; r /= 2;
    }
    reverse(x, x+60);
    reverse(y, y+60);
    dp[0][0][0][0] = 1;
    rep(i,60) rep(fx,2) rep(fy,2) rep(st,2) {
        // 0 0
        if (fx || x[i] == 0) {
            (dp[i+1][fx][fy||y[i]==1][st] += dp[i][fx][fy][st]) %= MOD;
        }
        // 0 1
        if ((fx || x[i] == 0) && (fy || y[i] == 1) && st == 1) {
            (dp[i+1][fx][fy][st] += dp[i][fx][fy][st]) %= MOD;
        }
        // 1 1
        if (fy || y[i] == 1) {
            (dp[i+1][fx||x[i]==0][fy][1] += dp[i][fx][fy][st]) %= MOD;
        }
    }
    ll ans = 0;
    rep(i,2) rep(j,2) (ans += dp[60][i][j][1]) %= MOD;
    cout << ans << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    string s; cin >> s;
    string t = s.substr(0,n/2);
    if (s == t+t) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}



Measured memory_bytes: 256
A,B,M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans=min(a)+min(b)
for i in range(M):
    x,y,c=map(int, input().split())
    tmp=a[x-1]+b[y-1]-c
    if ans > tmp:
        ans=tmp
print(ans)

Measured memory_bytes: 18736
#include<iostream>
using namespace std;
#define ll long long

int main(){
  ll N, ans=0, a;
  cin >> N;
  for(ll i=0; i<N; ++i) {
    cin >> a;
    while(a%2==0){ a/=2; ++ans; }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))

xdl = []
ydl = []
for x2,x1 in zip(xl[1:],xl[:-1]):
    xdl.append(x2-x1)

for y2,y1 in zip(yl[1:],yl[:-1]):
    ydl.append(y2-y1)


MOD = 10**9+7
ys = 0
for i,d in enumerate(xdl):
    pattern = (i+1)*(n-1-i)
    ys += pattern*d
    ys%=MOD

# print(ys)
ans = 0

for i,d in enumerate(ydl):
    pattern = (i+1)*(m-1-i)
    ans += pattern*ys*d
    ans%=MOD

print(ans)

Measured memory_bytes: 102988
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		Map<String, Integer> mp = new HashMap<String, Integer>();
 		mp.put("AC",  0);
 		mp.put("RE",  0);
 		mp.put("WA",  0);
 		mp.put("TLE",  0);
 		int t = Integer.parseInt(bf.readLine());
  		for(int i = 0;i<t;i++){
//	 		
  			String a = bf.readLine().trim();
  			mp.put(a, mp.get(a)+1);
  		
 		}
 		out.println("AC x " + mp.get("AC"));
 		out.println("WA x " + mp.get("WA"));
 		out.println("TLE x " + mp.get("TLE"));
 		out.println("RE x " + mp.get("RE"));
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




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

using namespace std;

int main(){

  int n;

  while(1){
	cin >> n;

	if(n == 0)
	  break;

	vector<int> a(n);

	for(int i = 0;i < n;++i)
	  cin >> a[i];

	int min_g = 1000000;
	
	for(int i = 0;i < n - 1;++i){
	  for(int j = i + 1;j < n;++j){
		min_g = min(min_g,abs(a[i] - a[j]));
	  }
	}

	cout << min_g << endl;
	
  }

}



Measured memory_bytes: 3104
def int_input():
    line = input()
    return [int(x) for x in line.split()]

n, k = int_input()
nums = {}

for i in range(n):
    a, b = int_input()
    nums[i] = (a, b)

s = 0
for i, x in sorted(nums.values()):
    s += x
    if k <= s:
        print(i)
        break


Measured memory_bytes: 26168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string t1[100010];
int main() {
	int n, k;
	int r, s, p;
	long long ans = 0;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	for (int i = 0; i < n; i++) {
		t1[i % k] += t[i];
	}
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < t1[i].size(); j++) {
			if (t1[i][j] == 's') {
				if (j>0&&t1[i][j] == t1[i][j - 1]) {
					t1[i][j] = 'a';
					continue;
				}
				ans += r;
			}
			else if (t1[i][j] == 'p') {
				if (j>0&&t1[i][j] == t1[i][j - 1]) {
					t1[i][j] = 'a';
					continue;
				}
				ans += s;
			}
			else if (t1[i][j] == 'r') {
				if (j > 0 && t1[i][j] == t1[i][j - 1]) {
					t1[i][j] = 'a';
					continue;
				}
				ans += p;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5248
#include<cstdio>
inline int min(const int x,const int y){return x<y?x:y;}
char col[105][105];
bool c[105][105];
int f[105][105][105][105];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)scanf("%s",col[i]+1);
	for(int i=1;i<=h;++i)for(int j=1;j<=w;++j)
			f[i][j][i][j]=c[i][j]=col[i][j]=='#'?1:0;
	for(int i=1;i<h;++i)for(int j=1;j<w;++j){
			for(int k=i;k<=h;++k)for(int l=j;l<=w;++l){
				if(k!=i || l!=j)f[i][j][k][l]=100000000;
				if(l!=j)if(c[k][l-1] || !c[k][l])
						f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k][l-1]);
					else f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k][l-1]+1);
				if(k!=i)if(c[k-1][l] || !c[k][l])
						f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k-1][l]);
					else f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k-1][l]+1);
			}
	}
	return printf("%d\n",f[1][1][h][w]),0;
}

Measured memory_bytes: 452864
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
  int N, X, i, min = 0, div;
  scanf("%d %d", &N, &X);
  int *x = (int *)malloc(N*sizeof(int));
  for(i=0; i<N; i++){
    scanf("%d", &x[i]);
    x[i] = abs(x[i] - X);
    if(x[i] < x[min])
      min = i;
  }
  i=0;
  for(int j=x[min]; j>0; j--){
    if(x[min]%j == 0)
      div = j;
    else
      continue;
    while(i<N && x[i]%div == 0)
      i++;
    if(i==N){
      printf("%d\n", div);
      break;
    }
  }
    
  
  free(x);
  
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using ull = unsigned long long;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

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

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

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
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; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  int n,m;cin>>n>>m;
  auto tree = atcoder::dsu(n);
  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    tree.merge(a,b);
  }
  print(tree.groups().size()-1);
  return 0;
}

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

const long long INF = 1e18;

int main() {
  int n;
  long long k;
  cin >> n >> k;
  int p[n+1];
  long long c[n+1];
  for ( int i = 1; i <= n; i++ ) { cin >> p[i]; }
  for ( int i = 1; i <= n; i++ ) { cin >> c[i]; }

  long long ans = -INF;

  for ( int i = 1; i <= n; i++ ) {
    // iスタートにおける1ループ距離遷移数と獲得点
    long long loop_sum = 0;
    int loop_num = 0;
    int pos = i;
    while ( true ) {
      loop_num++;
      loop_sum += c[pos];
      pos = p[pos];
      if ( pos == i ) { break; }
    }

    // iスタートにおける1ループできない場合の最大獲得点
    long long sum = 0;
    int num = 0;
    pos = i;
    while ( true ) {
      num++;
      sum += c[pos];
      if ( num > k ) { break; }

      long long can_loop = (k - num) / loop_num;
      long long point = sum + max(0ll, loop_sum) * can_loop;
      ans = max(ans, point);

      pos = p[pos];
      if ( pos == i ) { break; }
    }
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > H(N);
  cin >> H;
  --H[0];
  for(int i = 1; i < N; i++) {
    for(int p = -1; p <= 0; p++) {
      int cur = H[i] + p;
      if(H[i - 1] <= cur) {
        H[i] = cur;
        break;
      }
    }
    if(H[i] < H[i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}




Measured memory_bytes: 640
# -*- coding: utf-8 -*-
 
s=input()

a=int(0)
c=int(0)
x=int(0)

if s[0]=='A':
    s='a'+s[1:len(s)]
    a=1

for i in range(2,len(s)-1):
    if a==0:
        break
    if s[i]=='C':
      s=s[:i]+'c'+s[i+1:]
      c=1
      break

t=s.lower()

if a==1:
    if c==1:
        if t==s:
            print('AC')
            x=1
if x==0:
    print('WA')

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

ll n,d;

int main(){
    cin >> n >> d;
    ll count=0;
    for(ll i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d*d) count++;
    }
    cout << count << endl;
}  


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

double max(double a,double b){
	if(a>=b) return a ;
	else return b ;
}
double min(double a,double b){
	if(a<=b) return a ;
	else return b ;
}
double sa(double a,double b){
	return max(a,b)-min(a,b) ;
}

int main(){
	double n ; cin >> n ;
	vector<int> a(n) ;
	double sum = 0 ;
	for(int i=0;i<n;i++){
		cin >> a.at(i) ;
		sum += a.at(i) ;
	}
	double avr = sum/n ;
	int m = 0 ;
	double sm = 10000 ;
	for(int i=0;i<n;i++){
		if(a.at(i)==avr){
			cout << i << endl ;
			return 0 ;
		}
		if(sa(a.at(i),avr)<sm){
			sm = sa(a.at(i),avr) ;
			m = i ;
		}
	}
	cout << m << endl ;
}


Measured memory_bytes: 384
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import sys

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

input = lambda: sys.stdin.readline().rstrip("\r\n")

MOD = 10**9 + 7


def main():
    K, D = list(map(int, input())), int(input())
    n = len(K)

    dp = [[0] * D for _ in range(n)]
    for i in range(10):
        dp[0][i % D] += 1
    for i in range(n - 1):
        for j in range(D):
            dp[i + 1][j] = sum(dp[i][(j - k) % D] for k in range(10)) % MOD

    cnt, k = 0, 0
    for i in range(n - 1):
        cnt = (cnt + sum(dp[-i - 2][(-j - k) % D] for j in range(K[i]))) % MOD
        k += K[i]
    cnt += sum((j + k) % D == 0 for j in range(K[-1] + 1))

    print((cnt - 1) % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41628
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    int k, a,b;
    string s = "NG";
    cin>>k>>a>>b;
    
    for(int i = a;i<=b;i++){
        if(i%k==0) s = "OK";
    }
    
    
    cout<<s<<endl;
    
    return 0;
}



Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    NLIST = {}
    for i in range(N):
        s = lines.pop(0)
        if s in NLIST:
            NLIST[s] += 1
        else:
            NLIST[s] = 1

    M = int(lines.pop(0))
    for i in range(M):
        s = lines.pop(0)
        if s in NLIST:
            NLIST[s] -= 1
        else:
            NLIST[s] = -1
    print(max(max(NLIST.values()), 0))

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <numeric>

using namespace std;

int main() {
  
  using namespace std;
  
  int n;
  int count = 0;
  int countmax = 0;
  cin >> n;
  
  vector<int> height(n);
  
  for (int i = 0; i < n; i++) {
    cin >> height[i];
  }
  
  for (int i = 1; i < n; i++){
    if(height[i - 1] >= height[i]) {
      count++;
    } else {
      count = 0;
    }
    
    countmax = max(countmax, count);
  }
  
  cout << countmax << endl;
  
  return 0;
}


Measured memory_bytes: 640