akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n,m;
pii a[111111];
ll ans;
priority_queue<int>q;

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	n=read();m=read();
	FOR(i,0,n){
		a[i].first=read();
		a[i].second=read();
	}
	sort(a,a+n);
	int j=0;
	FOR(i,1,m+1){
		while(j<n&&a[j].first<=i){
			q.push(a[j].second);
			j++;
		}
		if(q.size()){
			ans+=q.top();
			q.pop();
		}
	}
	Tone(ans);
	return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int d[111];
int main(void){
  int a,b;
  while(cin >> a >> b){
    memset(d,0,sizeof(d));
    int n = 1;
    d[a]++; 
    d[b]++; 
    while(cin >> a >> b && a){
      n++;
      d[a]++; 
      d[b]++; 
    }

    bool f = true;
    for(int i = 3; i <= 100; i++){
      if(d[i]%2){
	f = false;
	//cout << i << endl;
      }
    }
    cout << ((f&&d[1]%2&&d[2]%2)?"OK":"NG") << endl;
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	map<char, int> color_map;
	char color;
	for (int i = 0; i < N; i++) {
		cin >> color;
		if (color_map.find(color) != color_map.end()) {
			color_map[color] = 1;
		} else {
			color_map[color] += 1;
		}
	}

	int kind = 0;
	if (color_map.count('P') > 0) {
		kind++;
	}
	if (color_map.count('W') > 0) {
		kind++;
	}
	if (color_map.count('G') > 0) {
		kind++;
	}
	if (color_map.count('Y') > 0) {
		kind++;
	}

	cout << ((kind == 3) ? "Three" : "Four") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod = 1e9 + 7;
int game_strat(int i,int j,vector<int>&A,vector<vector<int>>&dp)
{
    if (i>j)return 0;
    if (dp[i][j]!=-1)return dp[i][j];
    return dp[i][j] = max(A[i]+min(game_strat(i+2,j,A,dp),game_strat(i+1,j-1,A,dp)),A[j]+min(game_strat(i,j-2,A,dp),game_strat(i+1,j-1,A,dp)));
}
int32_t main()
{
    int n;
    cin>>n;
    vector<int>A(n);
    int tot = 0;
    for (int i = 0;i<n;i++){cin>>A[i];tot+=A[i];}
    vector<vector<int>>dp(n+1,vector<int>(n+1,-1));
    cout<<2*game_strat(0,n-1,A,dp)-tot<<endl;
    return 0;
}

Measured memory_bytes: 73980
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			char[] s = in.next().toCharArray();
			int n = s.length;
			long ans = 1;
			int[] am = new int[256];
			for (int i = 0; i < n; i++) {
				ans += i - am[s[i]];
				++am[s[i]];
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

	}
}



Measured memory_bytes: 25360
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

const int MOD = 998244353;
int dp[3005];
ll ans = 0;

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

    int n, S;
    cin>>n>>S;
    vi a = readVector<int>(n);

    FOR(i,n) {
        int ai = a[i];
        REV(s, S-ai, 0) {
            dp[s+ai] += dp[s];
            dp[s+ai] %= MOD;
        }
        dp[ai] += i+1;
        dp[ai] %= MOD;

//        cerr<<i<<" = "<<dp[S]<<endl;
        ans += dp[S];
        ans %= MOD;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<5000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((for {
      i <- 0 until n
      if isPrime(readInt)
    } yield 1).length)
  }
}

Measured memory_bytes: 67960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int c = (a*b)%2;
  if (c == 1){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define min(a,b) (((a)>(b)) ? (b):(a))
#define M 1000
#define INF 100000

int mcm();

int main(){
  int num,p[M],m[M][M];
  int i,l,j,k;
  
  scanf("%d",&num);

  for(i=1;i<=num;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=num;i++) m[i][i]=0;
  for(l=2;l<=num;l++){
    for(i=1;i<=num-l+1;i++){
      j=i+l-1;
      m[i][j]=INF;
      for(k=i;k<=j-1;k++) m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }
  printf("%d\n",m[1][num]);

  
  return 0;
}



Measured memory_bytes: 2136
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mxn = 1e5;
int cnt1[mxn+2],cnt2[mxn+2];

void solve(){
	int n;
	cin >> n;
	int a[n];
	for(int i =0;i<n;i++)
		cin >> a[i];
	int v1[mxn+1],v2[mxn+1];
	// memset()
	for(int i =0;i<n;i+=2){
		cnt1[a[i]]++;
	}
	for(int i=1;i<n;i+=2)
		cnt2[a[i]]++;
	memset(v1,0,sizeof(v1));
	memset(v2,0,sizeof(v2));
	for(int i =1;i<=mxn;i++){
		v1[i] = ((n+1)/2) - cnt1[i];
		v2[i] = ((n/2)) - cnt2[i];
	}
	pii p1,p11,p2,p22;
	p1 = p2 = p11 = p22 = mp(mxn+2,-1);

	for(int i=1;i<=mxn;i++){
		if(v1[i]<p1.first){
			p11.first = p1.first;
			p11.se = p1.se;
			p1.first = v1[i];
			p1.se = i;
		}
		else if(v1[i]<p11.first){
			p11.first = v1[i];p11.se = i;
		}

		if(v2[i]<p2.first){
			p22.first = p2.first;
			p22.se = p2.se;
			p2.first = v2[i];
			p2.se = i;
		}
		else if(v2[i]<p22.first){

			p22.first = v2[i];p22.se = i;
		}

	}

	if(p1.se != p2.se){
		cout << p1.fi+p2.fi << endl;
	}
	else{
		cout << min(p1.fi + p22.fi,p11.fi + p2.fi) << endl;
	}


}

int main(){
	fast;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int h,w;
  cin >> h >> w;
  vector<vector<char>> c(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
    }
  }

  int res =0;
  vector<vector<int>> d(h,vector<int>(w));  
  rep(i,h){
    rep(j,w){
      rep(k,h){
	rep(l,w){
	  if(c[i][j]=='.'&&c[k][l]=='.'){
	    rep(a,h){
	      d[a].assign(w,-1);
	    }
	    queue<pair<int,int>> q;
	    d[i][j] = 0;
	    q.push(make_pair(i,j));
	    while(!q.empty()){
	      pair<int,int> p = q.front();
	      q.pop();
	      int x = p.first;
	      int y = p.second;
	      if(x-1>=0){
		if(d[x-1][y]<0&&c[x-1][y]=='.'){
		  d[x-1][y] = d[x][y] + 1;
		  q.push(make_pair(x-1,y));
		}
	      }
	      if(x+1<h){
		if(d[x+1][y]<0&&c[x+1][y]=='.'){	     
		  d[x+1][y] = d[x][y] + 1;
		  q.push(make_pair(x+1,y));
		}
	      }
	      if(y-1>=0){
		if(d[x][y-1]<0&&c[x][y-1]=='.'){
		  d[x][y-1] = d[x][y] + 1;
		  q.push(make_pair(x,y-1));
		}
	      }
	      if(y+1<w){
		if(d[x][y+1]<0&&c[x][y+1]=='.'){
		  d[x][y+1] = d[x][y] + 1;
		  q.push(make_pair(x,y+1));
		}
	      }	    
	    }
	    // cout << i << ":" << j << "\n";
	    // cout << k << ":" << l << "\n";
	    // cout << d[k][l] << "\n";
	    res = max(res,d[k][l]);
	  }
	}	  
      }
    }
  }
  cout << res << "\n";
  
  return 0;
}


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

N = cin()[0]
S = input()

tmp = S[::]
for i in range(100): tmp = tmp.replace("()", "")
cnt1 = 0
cnt2 = 0
for i in range(len(tmp)):
    if tmp[i] == '(': cnt1 += 1
    else: cnt2 += 1

ans = S[::]
ans = "(" * cnt2 + S + ')' * cnt1;
print(ans);

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	double l;
	cin >> l;
	cout << DOUBLE << pow(l/3,3) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second

#define MM INT_MAX/5
#define MIM INT_MIN/2

int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

#define MAX (int)1e5+1

bool dp[MAX];
int N;
int K;

int main()
{
	cin >> N >> K;
	vector<int> stones(N);
	for (int i = 0; i < N; i++)
		cin >> stones[i];
	dp[0] = false;
	for (int i = 1; i <= K; i++) {
		bool res = false;
		for (int stone : stones)
		{
			if (i - stone >= 0 && !dp[i - stone])
				res = true;
		}
		dp[i] = res;
	}
	if (dp[K])
		cout << "First";
	else
		cout << "Second";

}


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

int main() {

	ll n, m; cin >> n >> m;
	vector<vector<ll>> jobs(m);
	for (ll i = 0; i < n; i++) {
		ll a, b; cin >> a >> b;
		if (m < a) continue;
		jobs[m - a].push_back(b);
	}
	ll ans = 0;
	priority_queue<ll> q;
	for (ll date = m - 1; date >= 0; date--) {
		for (ll i = 0; i < jobs[date].size(); i++) {
			q.push(jobs[date][i]);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8364
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n), o(n);
  for(int i = 0; i < n; ++i){
    cin >> v[i];
    o[i] = v[i];
  }
  sort(v.rbegin(), v.rend());
  int max_num = v.front();
  for(int i = 0; i < n; ++i){
    if(max_num == o[i]){
      cout << v[1] << endl;
    }
    else cout << max_num << endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  int l=s.size();
  int ans=0;
  for(int i=0;i<l;i++){
    char a=s.at(i);
    int b=int(a)-int('0');
    ans+=b;
  }
  if(ans%9==0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3764
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int n,m;
  int a,b;
  int count=0;
  
  cin>>n>>m;
  
  vector<long long int> h(n);
  vector<int> check(n);
  fill(check.begin(),check.end(),0);
  
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
  
  for(int j=0;j<m;j++)
  {
    cin>>a>>b;
    
    if(h[a-1]<h[b-1])
    {
      check[a-1]=-1;
      if(check[b-1]==0)
      {
        check[b-1]=1;
      }
    }
    else if(h[a-1]==h[b-1])
    {
      check[a-1]=-1;
      check[b-1]=-1;
    }
    if(h[a-1]>h[b-1])
    {
      check[b-1]=-1;
      if(check[a-1]==0)
      {
        check[a-1]==1;
      }
    }
  }
  
  for(int s=0;s<n;s++)
  {
    if(check[s]==-1)
    {
      count++;
    }
  }
  
  cout<<n-count<<endl;
  
  return 0;
}


Measured memory_bytes: 4584
N,M = map(int,input().split())

# 無向グラフ
d = [[False] * N
    for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    d[A - 1][B - 1] = True
    d[B - 1][A - 1] = True

# 訪問したかどうか:スタート頂点の1以外訪問していないとする
visited = [False for _ in range(N)]
visited[0] = True

#Depth first serch
def dfs(v, N, visited):
    if all(visited): #すべて訪問済みなら1を返す
        return 1

    ret = 0
    for i in range(N):
        # 経路存在と訪問済み確認
        if not d[v][i] or visited[i]: #経路がない or 訪問済みなら次
            continue

        visited[i] = True
        
        #再帰
        ret += dfs(i, N, visited)
        
        # 再帰後に元に戻す
        visited[i] = False

    return ret

ans = dfs(0, N, visited)

print(ans)
        
        
        
        
        
        
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(b>n) cout<<a*n/b;
    else cout<<a*(b-1)/b;
}

Measured memory_bytes: 3588
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const mint dv = mint(1) / 9;
struct S { mint a, b; };
using F = int;
S op(S l, S r) { return S{l.a * r.b + r.a, l.b * r.b}; }
S e() { return S{0, 1}; }
F id() { return -1; }
S mapping(F f, S x) { return f == id() ? x : S{(x.b - 1) * dv * f, x.b}; }
F composition(F f, F g) { return f == id() ? g : f; }
main() {
    int n, q;
    scanf("%d%d", &n, &q);
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vector(n, S{1, 10}));
    while (q--) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        seg.apply(l - 1, r, d);
        printf("%d\n", seg.all_prod().a.val());
    }
}

Measured memory_bytes: 9832
#include <iostream>
 int main() {
  int W, H, x, y, r;
   std::cin >> W >> H >> x >> y >> r;
    
    if (W < x + r || H < y + r || 0 > x - r || 0 > y - r) {
     std::cout << "No" <<std::endl;
    } else {
     std::cout << "Yes" <<std::endl;
    }





 return 0;




}

 



Measured memory_bytes: 3100
m,d = (int(num) for num in input().split())
ans = 0
for i in range(1,m+1):
    for j in range(10,d+1):
        d1 = j//10
        d2 = j%10
        if i == d1*d2 and d1 >= 2 and d2 >= 2:
            ans += 1
print(ans)

Measured memory_bytes: 3060
S = input()

res = 0
at = ['A', 'T', 'C', 'G']
tmp = 0
for i in range(len(S)):
    if S[i] in at:
        tmp += 1
    else:
        res = max(res, tmp)
        tmp = 0
   
res = max(tmp, res)
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 100
#define INF 1e9 + 5
#define MO 1e9 + 7
#define LINF 1e18 + 5
#define rep(i, N) for (int i = 0; i < N; i++)
#define repp(i, N) for (int i = 1; i <= N; i++)
using namespace std;
using ll = long long;

int n;
double dp[302][302][302];
bool chk[302][302][302];
int sushi[4];

double solve(int a, int b, int c)
{
    if (a == 0 && b == 0 && c == 0)
        return 0.0;
    if (chk[a][b][c])
        return dp[a][b][c];
    double res = 0.0;
    //아무것도 없는 접시를 선택하는 경우를 생각한다.
    res += (n - a - b - c) * 1.0 / (a + b + c) * 1.0;
    //1개 있는 접시를 선택하는 경우를 생각하자.
    if (a > 0)
        res += (solve(a - 1, b, c) + 1) * a / (a + b + c) * 1.0;
    //2개 있는 접시를 선택하는 경우를 생각하자.
    if (b > 0)
        res += (solve(a + 1, b - 1, c) + 1) * b / (a + b + c) * 1.0;
    //3개 있는 접시를 선택하는 경우를 생각하자.
    if (c > 0)
        res += (solve(a, b + 1, c - 1) + 1) * c / (a + b + c) * 1.0;
    chk[a][b][c] = 1;
    return dp[a][b][c] = res;
}

int main()
{
    cin >> n;
    rep(i, n)
    {
        int t;
        scanf("%d", &t);
        sushi[t]++;
    }
    dp[0][0][0] = 1.0;
    printf("%.10f", solve(sushi[1], sushi[2], sushi[3]));
    return 0;
}

Measured memory_bytes: 241920
a,b,c,n=map(int,input().split())
d=[a,b,c]
d.sort()
a=d[0]
b=d[1]
c=d[2]
e=0
for i in range(0,n//c+1):
    for k in range(0,(n-c*i)//b+1):
        if ((n-c*i-b*k)%a)==0:
            e=e+1
print(e)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool can_make(vector<int> &A, int m, vector<vector<int>> &dp, size_t i=0) {
    if (i == A.size()) return !m;
    if (!m) return (dp[m][i] = 1);
    if (m < 0) return false;
    if (~dp[m][i]) return dp[m][i];

    if (m >= A[i])
        if (can_make(A, m-A[i], dp, i+1))
            return (dp[m][i] = 1);

    return (dp[m][i] = can_make(A, m, dp, i+1));
}

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> A(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &A[i]);

    size_t q;
    scanf("%zu", &q);

    for (size_t i=0; i<q; ++i) {
        int m;
        scanf("%d", &m);

        vector<vector<int>> dp(m+1, vector<int>(A.size(), -1));
        printf("%s\n", can_make(A, m, dp)? "yes":"no");
    }

    return 0;
}

Measured memory_bytes: 2808
x = int(input())
y = int(pow(x, 1/5))*2
A = [i**5 for i in range(y+1)]
B = [i**5 for i in range(y+1)]

for i in range(len(A)):
  for j in range(len(B)):
    if ( A[i] + B[j] ) == x:
      if A[i] > B[j]:
        exit(print(i, -j))
      else:
        exit(print(j, -i))
    elif ( A[i] - B[j] ) == x:
      exit(print(i, j))


Measured memory_bytes: 9416
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R PI = acos(-1.0);
const R EPS = 1e-5;


int main(void){
	int n;
	cin >> n;
	vector<ll> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];

	using state = tuple<R, int>;
	vector<state> ary;

	rep(i, n) {
		if(x[i] == 0 and y[i] == 0) continue;
		ary.push_back(state(atan2(y[i], x[i]), i));
	}

	const int m = ary.size();
	sort(begin(ary), end(ary));

	R ans = 0.0;

	rep(is, m) {
		ll cx = 0LL, cy = 0LL;
		
		rep(ii, m) {
			const int i = get<1>(ary[(is + ii) % m]);
			cx += x[i], cy += y[i];
			const R tmp = sqrt(cx * cx + cy * cy);
			chmax(ans, tmp);
		}
	}

	cout.precision(20);
	cout << fixed << ans << endl;

	return 0;
}


Measured memory_bytes: 512
/***
*   author:   ashikur rahman
*   created:  30.08.2020 14:19:12
***/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<ll> ar(n);
  ll sum = 0;
  for (int i = 0; i < n; i++){
    cin >> ar[i];
    sum += ar[i];
    sum %= mod;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++){
    sum -= ar[i];
    if (sum < 0){
      sum += mod;
    }
    ans += (sum * ar[i]) % mod;
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 4756
#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>

using std::string;
using std::vector;


int main(){
    int n = 0;
    while(true) {
        scanf("%d", &n);
        if(n == 0) break;

        vector<int> scores = {};
        int sum = 0;
        for(int i = 0; i < n; i++) {
            int s = 0;
            scanf("%d", &s);
            scores.push_back(s);
            sum += s;
        }
        const double ave = double(sum) / double(n);
        double bunsan = 0;
        for(int each: scores) {
            bunsan += std::pow(double(each) - ave, 2.0) / n;
        }
        printf("%lf\n", std::sqrt(bunsan));
    }


    return 0;
}


Measured memory_bytes: 3260
var c,s,f:array[0..500]of longint;
    i,j,tmp,n:longint;
begin
  readln(n);
  for i:=0 to n-2 do
    read(c[i],s[i],f[i]);
  for i:=0 to n-2 do
  begin
    tmp:=s[i]+c[i];
    for j:=i to n-3 do
    begin
      if tmp<s[j+1] then
        tmp:=s[j+1]
      else
      while (tmp-s[j+1]) mod f[j+1]<>0 do
        inc(tmp);
      inc(tmp,c[j+1]);
    end;
    writeln(tmp);
  end;
  writeln(0);
end.

Measured memory_bytes: 128
#include<iostream>
#include<cmath>

using namespace std;
int main(){
    int a, b;
    string op;
    while(1){
        cin >> a >> op >> b;
        if(op.compare("?") == 0){
            break;
        }else{
            if(op.compare("+") == 0){
                cout << a + b << endl;
            }else if(op.compare("-") == 0){
                cout << a - b << endl;
            }else if(op.compare("*") == 0){
                cout << a * b << endl;
            }else{
                cout << a / b << endl;
            }
        }
    }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define lep(j,n) for(int j=0; j<(n); j++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define leps(j,n) for(int j=1; j<(n); j++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

#define return(Z) re:(Z)

long long h[10000010],x[10000010],z[10000010];

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    int c=(a+b)/2;
    if((a+b)%2!=0) c++;
    cout<<c<<'\n';
}

Measured memory_bytes: 256
N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if len(str(i)) != N:
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)


Measured memory_bytes: 38384
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;

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

int N;
string S;

int x = 0, m = 0;

int main()
{
    cin >> N >> S;
    rep(i, N)
    {
        if (S[i] == 'I') ++x;
        if (S[i] == 'D') --x;
        if (m < x) m = x;
    }
    cout << m;
    return 0;   
}

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

bool isA( string& s )
{
	int ptr = 0;
	if( s.size() < 6 || s[ 0 ] != '>' || s[ 1 ] != '\'' || s[ s.size() - 1 ] != '~' ){
		return false;
	}
	ptr = 2;
	while( ptr < s.size() - 1 && s[ ptr ] == '=' ){
		++ptr;
	}
	if( s[ ptr ] != '#' ){
		return false;
	}
	int halfLength = ptr - 2;
	if( s.size() != 4 + halfLength * 2 ){
		return false;
	}
	++ptr;
	for( int i = 0; i < halfLength; ++i, ++ptr ){
		if( s[ ptr ] != '=' ){
			return false;
		}
	}
	return true;
}

bool isB( string& s )
{
	int ptr = 0;
	if( s.size() < 6 || s[ 0 ] != '>' || s[ 1 ] != '^' || s[ s.size() - 1 ] != '~' || s[ s.size() - 2 ] != '~' ){
		return false;
	}
	int restLength = s.size() - 4;
	if( restLength % 2 > 0 ){
		return false;
	}
	ptr = 2;
	while( ptr < restLength + 2 ){
		if( s[ ptr ] != 'Q' || s[ ptr + 1 ] != '=' ){
			return false;
		}
		ptr += 2;
	}
	return true;
}

int main()
{
	int n;

	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			string snake;
			cin >> snake;

			string result;
			if( isA( snake ) )      result = "A";
			else if( isB( snake ) ) result = "B";
			else                    result = "NA";

			cout << result << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1204
/**
*    author:  boutarou
*    created: 10.06.2020 20:12:43
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const long long MOD = 1e9 + 7;
const long long INF = 3e18;
const double PI = 3.1415926535897932;

int n;
vector<P> a, b;
int ans = 0;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		a.push_back({x, y});
	}
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		b.push_back({x, y});
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	rep(i, n) {
		int now_x = b[i].first, now_y = b[i].second;
		int ma_y = -1;
		rep(j, n) {
			if (a[j].first > now_x) break;
			if (a[j].second < now_y) {
				chmax(ma_y, a[j].second);
			}
		}
		if (ma_y == -1) continue;
		ans++;
		rep(j, n) {
			if (a[j].second == ma_y) {
				a.erase(a.begin() + j);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

int main() {

    string N; cin >> N;
    string ans;
    for(int i=0; i < 3; i++) {
        if(N.at(i) == '1') {
            ans += '9';
        } else {
            ans += '1';
        }
    }

    cout << ans << endl;

    return 0;
}



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

vector<ll> s(100005, INF);
vector<ll> t(100005, INF);

int main(){
    int a, b, q;
    cin >> a >> b >> q;
    for(int i = 0; i < a; i++) cin >> s[i];
    for(int i = 0; i < b; i++) cin >> t[i];
    for(int i = 0; i < q; i++){
        ll x;
        cin >> x;
        int l = 0, r = a - 1;
        vector<ll> S, T;
        while(r - l > 1){
            int mid = (l + r) / 2;
            if(s[mid] < x) l = mid;
            else r = mid;
        }
        S.push_back(s[l]);
        S.push_back(s[r]);
        l = 0, r = b - 1;
        while(r - l > 1){
            int mid = (l + r) / 2;
            if(t[mid] < x) l = mid;
            else r = mid;
        }
        T.push_back(t[l]);
        T.push_back(t[r]);
        ll res = INF;
        for(int f1 = 0; f1 < 2; f1++){
            for(int f2 = 0; f2 < 2; f2++){
                ll d1 = abs(S[f1] - x) + abs(T[f2] - S[f1]);
                ll d2 = abs(T[f2] - x) + abs(T[f2] - S[f1]);
                res = min({res, d1, d2});
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input_1 = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = input_1[0];
            var M = input_1[1];
            int[] p = new int[M];
            bool[] S = new bool[M];
            for(var i = 0; i < M; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                p[i] = int.Parse(input[0]);
                S[i] = input[1] == "AC" ? true : false;
            }

            bool[] flag = Enumerable.Repeat<bool>(false, N).ToArray();
            int[] penalty = Enumerable.Repeat<int>(0, N).ToArray();

            for (var i = 0; i < M; i++)
            {
                if (S[i])
                {
                    flag[p[i]-1] = true;
                }
                else
                {
                    if(!flag[p[i]-1])penalty[p[i] - 1]++;
                }
            }
            var sum = 0;
            var sum_penalty = 0;
            for(var i=0;i<N;i++)
            {
                if (flag[i])
                {
                    sum++;
                    sum_penalty += penalty[i];
                }
            }
            Console.WriteLine("{0} {1}", sum, sum_penalty);
        }

    }
}


Measured memory_bytes: 19404
#include<stdio.h>

int main(){
	int a,b,i;
	scanf("%d %d",&a,&b);
	if(a>=b){
      for(i=0;i<a;i++){
        printf("%d",b);
      }
    }else{
      for(i=0;i<b;i++){
        printf("%d",a);
      }
    }
	return 0;
}


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

int main() {
  
  int N, M; cin >> N >> M; int ans = 0;
  
  vector<int> vecH(N); vector<bool> vecAns(N, true);
  
  for (int i = 0; i < N; i++) cin >> vecH[i];
  
  for (int i = 0; i < M; i++) {
    
    int A, B; cin >> A >> B; A--; B--;
    
    if (vecH[A] < vecH[B]) vecAns[A] = false;
    
    if (vecH[B] < vecH[A]) vecAns[B] = false;
    
    if (vecH[A] == vecH[B]) {
      vecAns[A] = false; vecAns[B] = false;
    }
    
  }
  
  for (bool flag : vecAns) if (flag) ans++;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
lli mod = 1e9 +7;

lli ExGCD(lli a, lli b, lli &x, lli &y){
	lli d=a;
	x=1; y=0;
	if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
	return d;
}
lli fact[300001];
lli inv[300001];
void maketable(){
	fact[0] = 1;
	for(int i=0; i<300000; i++){
		fact[i+1] = fact[i]*(i+1) %mod;
	}
	lli y;
	for(int i=0; i<300000; i++){
		ExGCD(fact[i], mod, inv[i], y);
		while(inv[i]<0) inv[i]+=mod;
	}
}

lli nCr(lli n, lli r){
	return fact[n] *inv[n-r] %mod *inv[r] %mod;
}

int main(){
	maketable();
	int n;
	cin >> n;
	n++;
	vector<int> a(n), b(n,0);
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]--;
		b[a[i]]++;
	}
	lli side = 0;
	for(int i=0; i<n; i++){
		if(b[i] != 2) continue; 
		for(int j=0; j<n; j++){
			if(a[j] == i) break;
			side++;
		}
		for(int j=n-1; j>=0; j--){
			if(a[j] == i) break;
			side++;
		}
	}
	for(int i=1; i<=n; i++){
		lli ans = nCr(n, i);
		if(i-1 <= side){
			ans -= nCr(side, i-1);
			ans = (ans +mod) %mod;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int K;
int main(){
 cin>>K;
 int hun=0;
 int ten=0;
 int one=0;
 hun=K/100;
 ten=(K-hun*100)/10;
 one=K%10;
 int res=(10-hun)*100+(10-ten)*10+(10-one);
 cout<<res;
}

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

using namespace std;

int a, b, c;

int ma, mb, mc;
int pa, pb, pc;

int n;

int main(void)
{
	
	cin >> n;
	
	cin >> ma >> mb >> mc;
	
	for(int i=1;i<n;i++)
	{
		
		cin >> a >> b >> c;
		
		pa=ma;
		pb=mb;
		pc=mc;
		
		ma=a+max(pb, pc);
		mb=b+max(pa, pc);
		mc=c+max(pa, pb);
		
	}
	
	cout << max( ma, max( mb, mc ) );
	
	return(0);
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  const ll H = 19, W = 15;
  char S[H][W];
  REP(i, 0, H) REP(j, 0, W) cin >> S[i][j];

  pll white;
  vector<pll> black, cand;
  REP(i, 0, H) REP(j, 0, W) {
    if(S[i][j] == 'O') {
      white = pll(i, j);
      cand.push_back(pll(i, j));
    }
    if(S[i][j] == 'X') {
      black.push_back(pll(i, j));
      REP(di, -1, 2) REP(dj, -1, 2) if(di != 0 || dj != 0) {
        ll ni = i + di, nj = j + dj;
        if(!(0 <= ni && ni < H && 0 <= nj && nj < W)) break;
        cand.push_back(pll(i + di, j + dj));
      }
    }
  }
  sort(black.begin(), black.end());
  sort(cand.begin(), cand.end());
  cand.erase(unique(cand.begin(), cand.end()), cand.end());

  ll N = black.size(), M = cand.size();
  map<pll, bool> visited;

  struct state { ll s, v, d; };
  queue<state> q;
  q.push((state) { (1LL << N) - 1, lower_bound(cand.begin(), cand.end(), white) - cand.begin(), 0 });

  while(!q.empty()) {
    ll s = q.front().s, v = q.front().v, d = q.front().d;
    ll y = cand[v].first, x = cand[v].second;
    q.pop();

    visited[pll(s, v)] = true;

    REP(i, -1, 2) REP(j, -1, 2) if(i != 0  || j != 0) {
      ll ns = s, ny = y + i, nx = x + j, nd = d + 1;
      ll cnt = 0;

      while(1) {
        if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) break;
        if(S[ny][nx] != 'X') break;

        ll b = lower_bound(black.begin(), black.end(), pll(ny, nx)) - black.begin();
        if(b == N) break;
        if(!(ns & (1LL << b))) break;

        ns = ns - (1LL << b);
        ny += i;
        nx += j;
        cnt++;
      }

      if(cnt > 0 && ((ny == H - 1 && 0 <= nx && nx < W) || ny >= H)) {
        cout << nd << endl;
        return 0;
      } else if(cnt > 0 && 0 <= ny && ny < H && 0 <= nx && nx < W) {
        ll nv = lower_bound(cand.begin(), cand.end(), pll(ny, nx)) - cand.begin();
        if(!visited[pll(ns, nv)]) q.push((state) { ns, nv, nd });
      }
    }
  }
  cout << -1 << endl;
}



Measured memory_bytes: 38312
#!/usr/bin/env python3


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]

    first_vis = dict() #key = machi, value = visited k
    loop = dict()
    k = 0
    c_cur = 1
    while k < K:
        #print('k = {} at {}, vis={}, loop={}'.format(k, c_cur, first_vis, loop))
        if c_cur in loop:
            len_loop = loop[c_cur]
            if k + len_loop <= K:
                k += len_loop * ((K - k) // len_loop)
                continue

        if c_cur in first_vis:
            loop[c_cur] = k - first_vis[c_cur]
        else:
            first_vis[c_cur] = k
        c_cur = A[c_cur-1]
        k += 1
    print(c_cur)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		    Scanner sc = new Scanner(System.in);
		    int n = sc.nextInt();
		    int[] b = new int[n+1];
		    for(int i=1;i<n;i++) {
		    	b[i]=sc.nextInt();
		    }
		    b[0]=b[n]=1000000;
		    int ans = 0;
		    for(int i=0;i<n;i++){
		      ans = ans+Math.min(b[i],b[i+1]);
		    }
		    System.out.println(ans);
		  }
		}
		           



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

int main()
{
        int n;
        long long k;
        std::cin >> n >> k;

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

        std::vector<int> point(n+1,-1);
        std::vector<int> log;
        int v = 1;

        while(point[v] == -1)
        {
                point[v] = log.size();
                log.push_back(v);
                v = a[v-1];
        }
        int T = log.size() - point[v];
        int l = point[v];

        if(k < l)
                std::cout << log[k] << std::endl;
        else
        {
                k -= l;
                k %= T;
                std::cout << log[l+k] << std::endl;
        }
}


Measured memory_bytes: 5852
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	N = s.size();
	vector<vector<int>>dp(2, vector<int>(N, -MOD));
	dp[0][0] = 1;
	dp[1][1] = 1;
	for (int i = 0; i < N; i++) {
		if (i + 1 < N) {
			string t, u;
			t = s[i];
			u = s[i + 1];
			if (t != u) {
				dp[0][i + 1] = max(dp[0][i + 1], dp[0][i] + 1);
			}
			if (i + 2 < N)dp[1][i + 2] = max(dp[1][i + 2], dp[0][i] + 1);
		}
		if (i) {
			string t, u;
			t = s[i - 1];
			t += s[i];
			if (i + 2 < N) {
				u = s[i + 1];
				u += s[i + 2];
				if (t != u) {
					dp[1][i + 2] = max(dp[1][i + 2], dp[1][i] + 1);
				}
			}
			if (i + 1 < N) {
				dp[0][i + 1] = max(dp[0][i + 1], dp[1][i] + 1);
			}
		}
	}
	cout << max(dp[0].back() ,dp[1].back())<< endl;
}



Measured memory_bytes: 2964
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000
#define INF 1000000000
#define EPS 1e-9
using namespace std;

const int MAXN = 100010;
int cnt[MAXN];
int main() {
    int n; scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int x; scanf("%d", &x);
        cnt[x]++;
        if(x != 0) cnt[x-1]++;
        cnt[x+1]++;
    }
    int rez = 0;
    for(int i = 0; i < MAXN; i++) {
        rez = max(rez, cnt[i]);
    }
    printf("%d", rez);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a[1800][50],n;
int main(){
	n = 38;
	int x = n*(n-1)+1,y = n,nxt = 2;
	cout<<x<<" "<<y<<endl;
	repn(i,n){
		a[i][1] = 1;
		for(int j=2;j<=n;j++){
			a[i][j] = nxt++;
		}
	}
	int nxt2 = n+1;
	for(int i=0;i<y-1;i++){
		for(int beg=2;beg<=n;beg++){
			a[nxt2][1] = 2+i;
			int cur = beg-2;
			for(int j=2;j<=n;j++){
				a[nxt2][j] = a[j][cur+2];
				cur += i;
				cur %= (n-1);
			}
			nxt2++;
		}
	}
	int cnt[1800]={};
	for(int i=1;i<=x;i++){
		for(int j=1;j<=n;j++){
			cnt[a[i][j]]++;
		}
	}
	for(int i=1;i<=x;i++){ for(int j=1;j<=n;j++) cout<<a[i][j]<<" "; cout<<endl;
	}
	/*for(int i=1;i<=x;i++){
		if(cnt[i] != n){
			puts("kill"); return 0;
		}
	}
	for(int i=1;i<=x;i++){
		for(int j=i+1;j<=x;j++){
			set<int>S;
			for(int k=1;k<=n;k++) S.insert(a[i][k]),S.insert(a[j][k]);
			if(S.size() != 2*n-1){
				puts("kill"); return 0;
			}
		}
	}*/
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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





///////////////////////////




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

	ll S = 0;

	ll n = N;
	while (n > 0) {
		S += n % 10;
		n /= 10;
	}

	if (N%S == 0) { cout << "Yes"; }
	else { cout << "No"; }

	system("PAUSE");

}


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

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef long double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;
const D PI=acos(-1);

namespace std{
  bool operator<(const P& a,const P& b){
    return a.X==b.X?a.Y<b.Y:a.X<b.X;
  }
}
bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

enum{OUT,ON,IN};
int contains(vector<P> poly,P p) {
  int n=poly.size();
  bool in=false;
  for(int i=0;i<n;i++){
    P a=poly[i]-p, b=poly[(i+1)%n]-p;
    if(a.Y>b.Y)swap(a,b);
    if(a.Y<=0&&0<b.Y){
      if(cross(a,b)<0)in=!in;
    }
    if(cross(a,b)==0&&dot(a,b)<=0)return ON;
  }
  return in?IN:OUT;
}

int main(){
	cin.sync_with_stdio(false);
  int n;
  vector<P> polygon;
  cin>>n;
  rep(i,n){
    D x,y;
    cin>>x>>y;
    polygon.push_back(P(x,y));
  }
  int q;
  cin>>q;
  while(q--){
    D x,y;
    cin>>x>>y;
    int res=contains(polygon,P(x,y));
    cout<<res<<endl;
  }
	return 0;
}

Measured memory_bytes: 3320