akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, K; cin >> N >> K;
        vector<int> A(N); cin >> A;
        cout << (N - 1) / (K - 1) + (((N - 1) % (K - 1)) != 0) << endl;
        return 0;
    }
};

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


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

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

static const int MAX=100100;
static const ll INF=1e15;

ll d[MAX];

struct edge{
    int to,cost;
};

vector<edge> g[MAX];

void daijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+MAX,INF);
    que.push(P(0,s));
    d[s]=0;
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<g[v].size();i++){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }

}

int main(){
    
    int N;
    cin >> N;
    for(int i=0;i<N-1;i++){
        int a,b,c; 
        cin >> a >> b >> c;
        a--;b--;
        g[a].push_back(edge{b,c});
        g[b].push_back(edge{a,c});
    } 
    int Q,K; cin >> Q >> K;
    K--;
    daijkstra(K);
    while(Q--){
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << d[x]+d[y] << endl;
    }
}

Measured memory_bytes: 9460
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = Math.max(a,b);
    if(a>b) System.out.println("a > b");
    else if (a==b)System.out.println("a == b");
    else System.out.println("a < b");
  }
}

Measured memory_bytes: 26232
#include <vector>
#include <iostream>

int main(void){
	bool isPrime[10010];
	std::vector<int> prime,input;
	int i,j,k,ans;

	for(i=0;i<10010;++i) isPrime[i]=true;
	for(i=2;i<10010;++i){
		for(j=i*2;j<10010;j+=i) isPrime[j]=false;
	}
	for(i=2;i<10010;++i){
		if(isPrime[i]) prime.push_back(i);
	}

	while(true){
		std::cin >> i;
		if(i==0) break;
		input.push_back(i);
	}

	for(int in=0;in<input.size();++in){
		ans=0;
		for(i=0;true;++i){
			if(prime[i]>input[in]) break;
			k=input[in];
			for(j=i;true;++j){
				k-=prime[j];
				if(k<0) break;
				if(k==0) ++ans;
			}
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

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

int main() {

	int n, l;
	cin >> n >> l;

	vector<string>s(n);
	rep(i, n)
		cin >> s[i];

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

	rep(i, n)
		cout << s[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String[] sArray = new String[s.length()];

		for (int i = 0; i < s.length(); i++) {
			sArray[i] = String.valueOf(s.charAt(i));
		}

		int count = 0;
		int sLength = s.length();

		for (int i = 0; i < sLength / 2; i++) {
			if (!sArray[i].equals(sArray[sLength - (i + 1)])) {
				count++;
			}
		}

		System.out.print(count);

	}

}


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

int main()
{
  int x,ans;
  vector<int> v;
  cin >> x;
  
  ans = 0;
  for (int i = 0; i < x; i++)
  {
    int n;
    cin >> n;
    v.push_back(n);
  }
  for (int i = 0; i < x; i++)
  {
    for (int j = i + 1; j < x; j++)
    {
      ans += v[i]*v[j];
    }
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 2e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ll x = n / i;
		if(n % i == 0)
			x--;
		ans += x;
	}
	cout << ans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


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

namespace myApp
{
    class Program
    {
        static bool BinarySearch(int[] A, int n, int key) {
            int     left = 0;
            int     right = n;
            while (left < right) {
                int     mid = (left + right) / 2;
                if (A[mid] == key) {
                    return true;
                } else if (key < A[mid]) {
                    right = mid;
                } else if (A[mid] < key) {
                    left = mid + 1;
                }
            }

            // 見つからなかった
            return false;
        }

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            var q = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            var sum = 0;
            for (int i = 0; i < q; i++) {
                if (BinarySearch(S, n, T[i])) sum++;
            }

            Console.WriteLine(sum);
        }
    }
}



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

int main(){
	int n, m0;
	unordered_map <int, int> m;
	cin >> n >> m0;
	for(int i=0; i<m0; i++){
		int a, b;
		cin >> a >> b;
		if(a==1){
			m[b] |= 1;
			if(m[b]==3) {
				cout << "POSSIBLE";
				return 0;
			}
		} else if (b == 1) {
			m[a] |= 1;
			if(m[a]==3) {
				cout << "POSSIBLE";
				return 0;
			}
		} else if (a == n) {
			m[b] |= 2;
			if(m[b]==3) {
				cout << "POSSIBLE";
				return 0;
			}
		} else if (b == n) {
			m[a] |= 2;
			if(m[a]==3) {
				cout << "POSSIBLE";
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}



Measured memory_bytes: 8520
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> b(n);
  vector<int> a(n);
  int i;
  for(i=1;i<n;i++) cin >> b[i];
  a[0] = b[1];
  for(i=1;i<n-1;i++) a[i] = min(b[i],b[i+1]);
  a[n-1]=b[n-1];
  long long sum = 0;
  for(i=0;i<n;i++) sum += a[i];
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    ll mx = a[0];
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        if (a[i] < mx) { ans += mx - a[i]; }
        else mx = a[i];
    }
    cout << ans << '\n';

}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
bool vis[N];
vector<ll> adj[N];
bool dfs(ll node,ll pr,ll avoid){
    if(vis[node])return 1;
    vis[node]=1;
    for(auto &u:adj[node])if(u!=pr && u!=avoid && dfs(u,node,avoid))return 1;
    return 0;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    for(ll i=0,u,v;i<m;i++)cin>>u>>v,adj[u].push_back(v),adj[v].push_back(u);
    for(ll i=1;i<=n;i++)if(adj[i].size()&1)return cout<<"No" , 0;
    for(ll i=1;i<=n;i++)if(adj[i].size()>=6)return cout<<"Yes" , 0;
    for(ll i=1;i<=n;i++){
        if(adj[i].size()!=4)continue;
        for(auto &v:adj[i]){
            memset(vis,0,sizeof(vis));
            if(dfs(v,0,i))return cout<<"Yes" , 0;
        }
        return cout<<"No" , 0;
    }
    cout<<"No";
}


Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int solve(int y,int m,int d){
	int res=0;
	if(y%3==0){
		res+=(10-m)*20+20-d;
	}else{
		if(m%2==0){
			res+=(19-d);
		}else{
			res+=(19-d);
		}
		m++;
		for(;m<11;m++){
			if(m%2==0){
				res+=20;
			}else{
				res+=19;
			}
		}
	}
	y++;
	for(;y<1000;y++){
		if(y%3==0){//allbig
			res+=20*10;
		}else{//big and small
			res+=20*5+19*5;
		}
	}
	res++;
	return res;
}


int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int y,m,d,ans;
		cin>>y>>m>>d;
		ans=solve(y,m,d);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    final int M = 1_000_000_007;
    int N = scanner.nextInt();
    int[] c = new int[N];
    for (int i = 0; i < N; i++) c[i] = scanner.nextInt();
    HashMap<Integer, Integer> lastPos = new HashMap<>();
    long[] dp = new long[N + 1];
    dp[0] = 1;
    for (int i = 1; i <= N; i++) {
      dp[i] = dp[i - 1];
      int color = c[i - 1];
      if (lastPos.containsKey(color) && lastPos.get(color) < i - 1) {
        dp[i] += dp[lastPos.get(color)];
        if (dp[i] >= M) dp[i] -= M;
      }
      lastPos.put(color, i);
    }
    System.out.println(dp[N]);
  }
}


Measured memory_bytes: 96932
#include <cstdio>
#include <iostream>
#include <algorithm>

#define MAX_N 200000

using namespace std;

int A[MAX_N];
int answer[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 2; i <= N; i++) cin >> A[i];
    for (int i = 2; i <= N; i++) answer[A[i]]++;
    for (int i = 1; i <= N; i++) cout << answer[i] << endl;

    return 0;
}

Measured memory_bytes: 4628
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i=0; i<N; i++) cin >> S[i];
  int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  for (int i=0; i<N; i++) {
    if (S[i]=="AC") c0++;
    else if (S[i]=="WA") c1++;
    else if (S[i]=="TLE") c2++;
    else c3++;
  }
  cout << "AC " << "x" << " " << c0 << endl;
  cout << "WA " << "x" << " " << c1 << endl;
  cout << "TLE " << "x" << " " << c2 << endl;
  cout << "RE " << "x" << " " << c3 << endl;
  return 0;
}

Measured memory_bytes: 6420
from sys import stdin
inp = lambda : stdin.readline().strip()

n= int(inp())
prices = [int(x) for x in inp().split()]

money= 1000
buy = -1
if prices[0] <=money: 
    buy = prices[0]
for i in range(1, len(prices)):
    if prices[i] > prices[i - 1]:
        if buy != -1:
            money = money%buy + (money//buy)*prices[i]
            buy = prices[i]
    else:
        if prices[i] < buy and prices[i] < money:
            buy = prices[i]
print(money)

Measured memory_bytes: 61832
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define int long long int
int dp[105][100005];
signed main(){
    fast;
    int n,sum; cin >> n >> sum;
    int a[n+1];
    int b[n+1];
    int mx=0;
    for(int i=1 ; i<n+1 ; i++){
        cin >> a[i] >> b[i] ;
        mx +=b[i];
    }
    
    for(int i=1  ;i<=mx ; i++){
            dp[0][i] = 1e18;
    }
    for(int i=1 ; i<=n ; i++){
        for(int j=1 ; j<=mx ; j++){
                dp[i][j] = min(dp[i-1][max(1ll*0,j-b[i])] + a[i] , dp[i-1][j]);
        }
    }

    for(int i=mx ; i>=0 ; i--){
        if(dp[n][i]<=sum){
            cout << i << endl;
            break;
        }   
    }
}

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

#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
const ll N=1e5+5,inf=1e18;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vll vr,vg,vc;
	lp(i,0,a)
	{
		ll z;
		cin >> z;
		vr.pb(z);
	}	    
	lp(i,0,b)
	{
		ll z;
		cin >> z;
		vg.pb(z);
	}	    
	lp(i,0,c)
	{
		ll z;
		cin >> z;
		vc.pb(z);
	}	    
	sort(all(vr));
	sort(all(vg));
	sort(all(vc));
	vll er,eg;
	ll ans=0;
	rlp(i,a-1,a-x)
	{
		ans+=vr[i];
		er.pb(vr[i]);
	}

	rlp(i,b-1,b-y)
	{
		ans+=vg[i];
		eg.pb(vg[i]);
	}

	ll p1=x-1,p2=y-1;

	rlp(i,c-1,0)
	{
		if(p2>=0&&eg[p2]<er[p1])
		{
			if(vc[i]>eg[p2])
			{
				ans+=vc[i]-eg[p2];
				p2--;
			}
		}
		else if(p1>=0)
		{
			if(vc[i]>er[p1])
			{
				ans+=vc[i]-er[p1];
				p1--;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4852
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define l first
#define r second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int N=200010;
const ll mod=998244353;
int n,k;
ll f[N],s[N];
pii a[N];
int main()
{
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>k;
        for(int i=1;i<=n;i++) cin>>a[i].l>>a[i].r;

        f[1]=1;
        s[1]=1;
        for(int i=2;i<=n;i++)
        {
            for(int j=1;j<=k;j++)
                f[i]=(f[i]+s[max(0,i-a[j].l)]-s[max(0,i-a[j].r-1)])%mod;;
            s[i]=(s[i-1]+f[i])%mod;
        }    
        cout<<(f[n]+mod)%mod<<'\n';
    }
    return 0;
}

Measured memory_bytes: 6756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 x, y;
    cin >> x >> y;
    i64 ans = 0;
    while (x <= y) {
        x *= 2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  object Dice{
    private val north = List(2,6,3,4,1,5).map(_ - 1)
    private val east = List(4,2,1,6,5,3).map(_ - 1)
    private val ccw = List(1,4,2,5,3,6).map(_ - 1)

    def vertical(d: Dice): List[Dice] =
      List(d, d.north, d.north.north, d.south)

    def horizontal(d: Dice): List[Dice] =
      List(d, d.east, d.east.east, d.west)

    def turn(d: Dice): List[Dice] = List(d, d.ccw, d.uturn, d.uturn.ccw)

    def enumerateTop(d: Dice, n: Int = 6): List[Dice] = {
      if(n<=0)List[Dice]()
      else d :: enumerateTop(if(n%2==0)d.north else d.east, n-1)
    }

    def enumerate(d: Dice): List[Dice] = enumerateTop(d).flatMap(turn)
  }

  case class Dice(pip: List[Int] = List(1,2,3,4,5,6)) {
    private def north = Dice(Dice.north.map(pip))
    private def east = Dice(Dice.east.map(pip))
    private def south = north.north.north
    private def west = east.east.east
    private def ccw = Dice(Dice.ccw.map(pip))
    private def uturn = ccw.ccw

    def rotate(com: Char):Dice = com match {
      case 'N' => north
      case 'E' => east
      case 'S' => south
      case 'W' => west
      case _ => this
    }
  }

  @tailrec
  def loop(n:Int, all: List[Dice]):Unit = if(n>0){
    val Array(a,b,_*) = readLine.split(" ").map(_.toInt)
    val res = all.filter(d => d.pip(0)==a && d.pip(1)==b)
    println(res(0).pip(2))
    loop(n-1,all)
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    val all: List[Dice] = Dice.enumerate(Dice(pip))
    val Array(n,_*) = readLine.split(" ").map(_.toInt)
    loop(n,all)
  }
}

Measured memory_bytes: 41196
#include<iostream>

using namespace std;

int main()
{
  while(1){
    int n=0,m=0;
    cin>>n>>m;
    if(n==0 && m==0)
      break;

    int num[n];

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

    int max=0,temp=0,flagx=0,flagy=0;

    for(int i=0;i<n;i++){
      for(int j=1;j<n-i;j++){
        temp=num[i]+num[i+j];
        if(temp>m)
          flagx=1;
        else if(max<temp && temp<=m){
          max=temp;
          flagy=1;
        }
      }
    }

    if(flagx==1 && flagy==0)
      cout<<"NONE"<<endl;
    else
      cout<<max<<endl;
  }

  return 0;
}



Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <cstring>

const int MOD = 1e9 + 7;
const int MAX_K = 100000;

int f[MAX_K + 1][100], digits[MAX_K + 1], D;

inline int add(int x, int v) { return x + v >= MOD ? x + v - MOD : x + v; }

int dp(int pos, int limit, int mod) {
  if (pos < 1) return mod == 0;
  auto &ret = f[pos][mod];
  if (!limit && ret != -1) return ret;
  const int end = limit ? digits[pos] : 9;
  ret = 0;
  for (int i = 0; i <= end; ++i)
    ret = add(ret, dp(pos - 1, limit && (i == end), (mod + i) % D));
  return ret;
}

int main() {
  memset(f, -1, sizeof(f));
  std::string s;
  std::cin >> s >> D;
  int l = 0;
  for (auto i = s.crbegin(); i != s.crend(); ++i) digits[++l] = *i ^ 48;
  std::cout << add(dp(l, 1, 0), MOD - 1);
  return 0;
}

Measured memory_bytes: 40064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N ; cin >> N ;

  ll a = 0 , b = 0;

  rep(i,N){
    ll x,y; cin >> x >> y ;
    
    for(ll j = max(a/x, b/y); ; j++){
      if(j == 0) continue;
      if(((x * j)>= a) && ((y*j) >= b)){
	a = x*j;
	b = y*j;
	break;
      }
    }
  }
  cout << a+b << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
    int N,W;
    cin>>N>>W;
    vector<pair<long, long>> items;

    for(int i=0;i<N;i++) {
        long w,v;
        cin>>w>>v;
        items.push_back({w,v});
    }
    
    vector<vector<long>> table(N+1, vector<long>(W+1, 0));

    for(int i=1 ; i<=N ; i++) {
        long cur_wt = items[i-1].first;
        long cur_val = items[i-1].second;

        for(int j=0 ; j<=W ; j++) {
            if(j < cur_wt) {
                table[i][j] = table[i-1][j];
            }
            else {
                table[i][j] = max(cur_val + table[i-1][j-cur_wt],
                                    table[i-1][j]);
            }
        }
    }

    cout << table[N][W] << endl;
    // for(auto row : table) {
    //     for(auto i:row) {
    //         cout<<i<<" ";
    //     }
    //     cout<<endl;
    // }

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll n, m, nn = 0;
    ll p = 0;
    cin >> n >> m;
    vector<pair<ll, ll>> pm(n);
    for (int i = 0; i < n; i++)
        cin >> pm.at(i).first >> pm.at(i).second;
    sort(pm.begin(), pm.end());
    for (int i = 0; i < n; i++)
    {
        if (nn == m)
            break;
        p += pm.at(i).first * min(pm.at(i).second, m - nn);
        nn += min(pm.at(i).second, m - nn);
    }
    cout << p << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    int n; cin >> n;
    vector <int> A(n), B(n), C(n);
    for (int i = 0; i < n; ++i) cin >> A[i] >> B[i] >> C[i];

    vector <vector <int>> dp(n, vector<int>(3));
    dp[0][0] = A[0];
    dp[0][1] = B[0];
    dp[0][2] = C[0];

    //pull-dp
    for (int i = 1; i < n; ++i) {
        dp[i][0] = A[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = B[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = C[i] + max(dp[i-1][1], dp[i-1][0]);
    }

    cout << *max_element(all(dp[n-1]));

    return 0;
}

//recurrence, pull dp, 
//dp[i][activity] = points_activity[i] + max(dp[i-1][other_activities])


Measured memory_bytes: 6912
import sys
while True:
    c = 0
    n, x = map(int, input().split())
    if n == x == 0:
        sys.exit()
    for i in range(1, n + 1):
        if i > x - 3:
            break
        for j in range(i, n + 1):
            if i == j:
                continue
            if i + j > x - 1:
                break
            k = x - i - j
            if k != i and k != j and 1 <= k <= n and j < k:
                c += 1
    print(c)



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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

signed main()
{
  string s; cin >> s;
  int size = s.size();
  int Aindex,Zindex;
  
  for(int i = 0; i < size; ++i){
    if(s[i] == 'A'){
      Aindex = i;
      break;
    }
  }

  for(int i = size - 1; i > 0; --i){
   Zindex = i;
    if(s[i] == 'Z'){
      Zindex = i;
      break;
    }
  }
  cout << Zindex - Aindex + 1;
  
  return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;



int main()
{
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    int cnt = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ks = []
for i in range(m):
    inp = list(map(int, input().split()))
    ks.append(inp[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(1<<n):
    on_all = True
    for j in range(m):
        n_on = 0
        for s in ks[j]:
            if i&(1<<(s-1)):
                n_on += 1
        if not n_on%2 == p[j]:
            on_all = False
    if on_all:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
	const int a = 100000;
	int N;//展望台の数
	long long Ni[a];//展望台iの高さ
	int M;//
	int A[a];
	int B[a];
	int loseN[a] = {0};
 
	cin >> N;
	cin >> M;
 
	for (int i = 0; i < N; i++)
	{
		cin >> Ni[i];//高さ
	}
 
	for (int i = 0; i < M; i++)
	{
		cin >> A[i];
		cin >> B[i];
        A[i]--;// [0,N) に変換
        B[i]--;// [0,N) に変換
	}
 
	int count = N;
	for (int i = 0; i < M; i++)
	{
		if (Ni[A[i]] == Ni[B[i]])
		{
			if(loseN[A[i]] == 0) count--;
			loseN[A[i]] = 1;
			if(loseN[B[i]] == 0) count--;
			loseN[B[i]] = 1;
 
		}
		else if (Ni[A[i]] > Ni[B[i]])
		{
			if(loseN[B[i]] == 0) count--;
			loseN[B[i]] = 1;
		}
		else
		{
			if(loseN[A[i]] == 0) count--;
			loseN[A[i]] = 1;
		}
	}
 
	cout << count << endl;
}

Measured memory_bytes: 5564
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
using ll = long long;

using namespace std;
int main()
{/*四日目*/
//少数も使いたい割り算はしない方がいい(三日目）
// 数値の大きさ
//for文で0代入する場所はforの一文下
	int n,m; cin >> n>>m;
	if (n < m)
	{
		for (int i = 0;i < m;i++)
			cout << n;
	}
	else {
		for (int i = 0;i < n;i++) {

			cout << m;
		}
	}


	

}

Measured memory_bytes: 256
#----------[インポート]----------#
from collections import deque

def main():
    #----------[入力受取・初期設定]----------#
    H, W = map(int, input().split())
    C = tuple(map(int, input().split())) # 魔法の位置
    D = tuple(map(int, input().split())) # ゴール
    D_y = D[0] -1 # 0スタート
    D_x = D[1] -1 # 0スタート
    S = [list(input()) for _ in range(H)]
    visited = [[-1] * W for _ in range(H)]
    visited[C[0]-1][C[1]-1] = 0 # 初期値
    moves = [(1, 0), (0, 1), (-1, 0), (0, -1)] # 普通の移動
    main_q = deque()
    magic_q = deque() # マジック用のキュー
    main_q.append((C[0]-1, C[1]-1))
    # magic_q.append((C[0]-1, C[1]-1))

    #----------[BFS]----------#
    while main_q:
        y, x = main_q.pop()
        magic_q.append((y, x))
        for move in moves:
            dy, dx = move
            moved_y = y + dy
            moved_x = x + dx

            if moved_y < 0 or H -1 < moved_y or moved_x < 0 or W -1 < moved_x:
                continue
            if S[moved_y][moved_x] == '#':
                continue
            if S[moved_y][moved_x] == '.' and visited[moved_y][moved_x] == -1:
                main_q.append((moved_y, moved_x))
                visited[moved_y][moved_x] = visited[y][x]

        #----------[マジック用のBFS]----------#
        if not main_q: # main_qが空になった場合は探索済みからマジックを使う
            while magic_q:
                y, x = magic_q.pop()
                for dy in range(-2, 3):
                    for dx in range(-2, 3):
                        moved_y = y + dy
                        moved_x = x + dx

                        if moved_y < 0 or H -1 < moved_y or moved_x < 0 or W -1 < moved_x:
                            continue
                        if S[moved_y][moved_x] == '#':
                            continue
                        if S[moved_y][moved_x] == '.' and visited[moved_y][moved_x] == -1:
                            main_q.append((moved_y, moved_x))
                            visited[moved_y][moved_x] = visited[y][x] + 1

    answer = visited[D_y][D_x]
    print(answer)

if __name__ == "__main__":
    main()

Measured memory_bytes: 129064
(N, M) = map(int, input().split())
ships = [[int(x) for x in input().split()] for i in range(M)]

s = []
g = []

for ship in ships:
    if ship[0] == 1:
        s.append(ship[1])
    if ship[1] == N:
        g.append(ship[0])

res = False

if not (len(s) == 0 or len(g) == 0):
    res = not set(s).isdisjoint(set(g))

print('POSSIBLE' if res else 'IMPOSSIBLE')


Measured memory_bytes: 48592
from heapq import *
n = int(input())
A = [*map(lambda x: -int(x), input().split())]
heapify(A)
ans = -heappop(A)
for c in range(0, n-2, 2): ans += -heappop(A) * (1<<(c+1 < n-2))
print(ans)


Measured memory_bytes: 31724
n, x = map(int, input().split())

A = list(map(int, input().split()))


t = 0 if A[0] <= x else A[0] - x
A[0] = A[0] if A[0] <= x else x
for i in range(n - 1):
    if A[i] + A[i+1] > x:
        t += A[i+1] + A[i] - x
        A[i+1] = x - A[i]
print(t)


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    string s;
    bool ok = true;
    cin>>s;
    int n =(int)s.size();
    for(int i=0;i<n/2;++i){
        if(s[i]!=s[n-i-1])
            ok=false;
    }
    for(int i=0;i<(n-1)/2;++i){
        if(s[i]!=s[(n-1)/2-i-1])
            ok=false;
    }
    for(int i=(n+3)/2;i<n;++i){
        if(s[i]!=s[n-i-1])
            ok=false;
    }
    if(ok)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int total = 0;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        total += r - l + 1;
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	int tc = 1; //cin >> tc;
	while (tc--)
	{
		ll i, j, n, a, b;
		cin >> n >> a >> b;
		cout << (n/ (a+b))*a + min ((n%(a+b)), a) << '\n';
		
	}

	return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

ans = set()

for i in range(N-1,-1,-1):
    a = A[i]
    for j in range(i+1,N+1,i+1):
        if j in ans:
            a += 1
    if a%2:
        ans.add(i+1)

print(len(ans))
print(*ans)

Measured memory_bytes: 15756
#coding: utf-8

class MakeTree():
    def __init__(self, p=None, l=None, r=None):
        self.p = p
        self.l = l
        self.r = r


n = int(input())
List = list(map(int, input().split()))

for i in range(1,n+1):
    key = List[i-1]
    s =  "node {}: key = {}, ".format(i,key)
    if i != 1:
        p = List[i // 2 - 1]
        s += "parent key = {}, ".format(p)
    if 0 <= 2 * i <= n:
        left = List[2 * i - 1]
        s += "left key = {}, ".format(left)
    if 0 <= 2 * i + 1 <= n:
        right = List[2 * i]
        s += "right key = {}, ".format(right)
    print(s)



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

int main() {
    ll n,k;
    cin >> n >> k;
    ll v[n];
    for(ll i=0;i<n;i++) cin >> v[i];
    ll res=0;
    for(ll a=0;a<=min(n,k);a++){
        for(ll b=0;b+a<=min(n,k);b++){
            ll cur=0;
            vector<ll> vec;
            for(ll i=0;i<a;i++){
                vec.push_back(v[i]);
                cur+=v[i];
            }
            for(ll i=0;i<b;i++){
                vec.push_back(v[n-1-i]);
                cur+=v[n-1-i];
            }
            sort(vec.begin(),vec.end());
            for(ll i=0;i<min(k-a-b,(ll)vec.size());i++){
                if(vec[i]<0) cur-=vec[i];
            }
            res=max(res,cur);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  ll ans = 0;
  ans += (N + A - 1) / A;
  ll tmp = max((ll)0, N - (ans - 1) * B);  //今A-B間にいる人
  ans += max((tmp + B - 1) / B, (ll)1);
  tmp = max((ll)0, N - (ans - 2) * C);
  ans += max((tmp + C - 1) / C, (ll)1);
  tmp = max((ll)0, N - (ans - 3) * D);
  ans += max((tmp + D - 1) / D, (ll)1);
  tmp = max((ll)0, N - (ans - 4) * E);
  ans += max((tmp + E - 1) / E, (ll)1);
  cout << ans << endl;
}

Measured memory_bytes: 3624
import Data.Array
import Data.Array.ST
import Data.STRef
import Control.Monad.ST
import Control.Monad

--境界(s,e)、アレイ(s~e)、ソート済み前半部分の先頭インデックス(s-1~e)
insert::(Int,Int)->STArray s Int Int -> Int ->ST s ()
insert (s,e) ar idx= if idx == e then return () else do
   v<-readArray ar (idx+1)
   counter<-newSTRef (idx+1)
   whileM_ [idx-j |j<-[0..(idx-s)]] (\ i -> do
                                        a<-readArray ar i
                                        return (a>v))
                                    (\ i -> do
                                        a<-readArray ar i
                                        writeArray ar (i+1) a
                                        writeSTRef counter i)
   i<-readSTRef counter
   writeArray ar i v
   return ()

whileM::Monad m => [a]->(a->m Bool)->(a->m b)->m [b]
whileM []     cond proc  = return []
whileM (x:xs) cond proc  = do
  b<- cond x
  if b then do
    a<- proc x
    rest<-whileM xs cond proc
    return (a:rest)
       else return []

whileM_::Monad m => [a]->(a->m Bool)->(a-> m())->m ()
whileM_ []     cond proc = return ()
whileM_ (x:xs) cond proc = do
  b<-cond x
  if b then do
    proc x
    whileM_ xs cond proc
       else return ()

insertion_sort::(Int,Int) -> STArray s Int Int -> ST s ()
insertion_sort (s,e) ar = do
  forM_ [s..e] (insert (s,e) ar)

ins_sort::Array Int Int -> Array Int Int
ins_sort ar = runSTArray $ do
  let (s,e) =bounds ar
  mar<-thaw ar
  insertion_sort (s,e) mar
  return mar

ins_trace::Array Int Int -> [[Int]]
ins_trace ar = runST $ do
  let (s,e) = bounds ar
  mar<-thaw ar
  trace <- forM [s..e] (\ i -> do
                     insert (s,e) mar i
                     frz <- freeze mar
                     return (elems frz))
  return trace

main::IO()
main=do
  nc<-getLine
  let n = read nc
  ls<-getLine
  let ar = listArray (1,n) (map read (words ls))
  lss_print ((elems ar):init (ins_trace ar))


lss_print::[[Int]]->IO()
lss_print []     = return ()
lss_print (x:xs) = do
  putStr ((ls_show x)++"\n")
  lss_print xs

ls_show::[Int]->String
ls_show [] = []
ls_show (x:xs) = (show x)++(if xs == [] then (ls_show xs) else ' ':(ls_show xs))


Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int V, E, r;
    cin >> V >> E >> r;
    vector<vector<P>> graph(V);
    for(int i = 0; i < E; ++i){
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].emplace_back(t, d);
    }
    
    constexpr ll inf = 1e+13;
    vector<ll> dist(V, inf);
    using Pl = pair<ll, int>;
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    dist[r] = 0;
    que.emplace(0, r);
    while(!que.empty()){
        ll d = que.top().first;
        int from = que.top().second;
        que.pop();
        if(d > dist[from])  continue;
        for(P e : graph[from]){
            int to = e.first, cost = e.second;
            if(chmin(dist[to], dist[from] + cost)){
                que.emplace(dist[to], to);
            }
        }
    }
    
    for(int i = 0; i < V; ++i){
        if(dist[i] == inf)  cout << "INF\n";
        else    cout << dist[i] << '\n';
    }
}


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

int B[10010];

vector< pair<int,int> > task[10100];
int main(){
    int N,M;
    cin >> N >> M;
    int a,b,c;
    while( cin >> a >> b >> c && a){
        --a,--b;
        task[a].push_back({b,c});
    }
    int L;
    cin >> L;
    for(int i = 0 ; i < L ; i++){
        for(int j = 0 ; j < M ; j++) cin >> B[j];
        for(int i = 0 ; i < N ; i++){
            long long ans = 0;
            for(int j = 0 ; j < task[i].size() ; j++)
                ans += task[i][j].second * B[task[i][j].first];
            cout << ans;
            if(i+1==N) cout << endl;
            else cout << " ";
        }
    }


}

Measured memory_bytes: 2256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

// 連結している頂点の集合について、それらは必ず別々に別れなければならない。

int main() {
    int N, M;
    cin >> N >> M;
    auto G = vectors(0, N, 0);
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<bool> visited(N, false);
    stack<int> stk;
    for (int i = 0; i < N; ++i) {
        stk.push(i);
    }
    auto dfs = [&](auto f, int cur, int &num) -> void {
        visited[cur] = true;
        ++num;
        for (int to : G[cur]) {
            if (!visited[to]) f(f, to, num);
        }
    };
    int res = 0;
    while (!stk.empty()) {
        int vertex = stk.top();
        stk.pop();
        if (!visited[vertex]) {
            int tmp = 0;
            dfs(dfs, vertex, tmp);
            setmax(res, tmp);
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int i, j;
  int x, y;

  int nums[] = {-1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

  scanf("%d %d", &x, &y);

  if (nums[x] == nums[y]) {
    printf("Yes");
  }
  else {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, sum, Q;
LL ans=0;
LL no;

string s, t;

LL gcd(int p, int q) {
	if (p % q == 0)return q;
	return gcd(q, p % q);

}


int main() {
	cin >> N >> M;
	
	vector<LL> h(N + 1),v(N + 1),a(M),b(M);
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
		v[i] = -1;
	}
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		v[a[i]] = max(v[a[i]], h[b[i]]);
		v[b[i]] = max(v[b[i]], h[a[i]]);
	}
	
	for (int i = 1; i <= N; i++) {
		if (v[i] < h[i])ans++;
	}

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



Measured memory_bytes: 6432
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
H =[]
for i in range(0,101):
    for j in range(0, 101):
        H.append([i,j,0])

a.sort(key = lambda x: x[2], reverse=True)

for X,Y,H0 in H:
    this_sum = []
    H1 = a[0][2] + abs(X-a[0][0]) + abs(Y-a[0][1])
    for x,y,h in a:
        if h == max(H1 - abs(x-X) - abs(y-Y), 0):
            continue
        else:
            break
    else:
        print(" ".join(list(map(str, [X, Y, H1]))))

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int M,N;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for(int i=0; i<M; i++){
    cin >> s[i] >> c[i];
  }
  string num(N,'0');
  num[0]='1';
  int start=stoi(num);
  num=num+'0';
  int end=stoi(num);
  
  if (N==1) start=0;
  for(int i=start; i<end; i++){
    bool check=true;
    string x=to_string(i);
    for(int j=0; j<M; j++){
      if (x[s[j]-1]!=c[j]+'0'){
        check=false;
        break;
      }
    }
    if(check==true){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

double get_dist(vector<int> v);

int main(void){

   int N,D;
   vector< int > v;
   v.resize(2);
   vector< vector<int> > v_place;

   cin >> N >> D;
   for(int num=0; num<N; num++){
      cin >> v.at(0) >> v.at(1);
      v_place.push_back(v);
   }

   int ans = 0;

   for(int num=0; num<N; num++){
      if(get_dist(v_place.at(num)) <= (double)D){
         ans++;
      }
   }

   cout << ans;

   return 0;
}

double get_dist(vector<int> v){
   double dist = -100;
   dist = sqrt(pow(v.at(0),2) + pow(v.at(1),2));
   return dist;
}


Measured memory_bytes: 14284
import sys


class UnionFind(object):
    def __init__(self, N):
        self._parent = list(range(N))
        self.__num_components = [1] * N

    def root(self, x):
        if self._parent[x] == x:
            return x
        else:
            # root abbreviation
            self._parent[x] = self.root(self._parent[x])
            return self._parent[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def num_connected(self, x):
        return self.__num_components[self.root(x)]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return
        rank_x = self.__num_components[x]
        rank_y = self.__num_components[y]
        if rank_x < rank_y:
            self._parent[x] = y
            self.__num_components[y] += rank_x
        else:
            self._parent[y] = x
            self.__num_components[x] += rank_y
        return


fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
bridges = tuple(
    tuple(int(elem) - 1 for elem in fin().split())
    for _ in range(M)
)

uf = UnionFind(N)
num_incovenient_list = [N * (N - 1) // 2]
for A, B in bridges[::-1]:
    num_islands_A = uf.num_connected(A)
    num_islands_B = uf.num_connected(B)
    if not uf.same(A, B):
        num_incovenient_list.append(
            num_incovenient_list[-1] - num_islands_A * num_islands_B)
        uf.unite(A, B)
    else:
        num_incovenient_list.append(num_incovenient_list[-1])

num_incovenient_list.pop()
print(*num_incovenient_list[::-1], sep="\n")



Measured memory_bytes: 112732
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
    return (a % mod + mod - b % mod) % mod


def main():
    n, = list(map(int, input().split()))
    t = 1
    dd = [t]
    for _ in range(n):
        t=2*t%mod
        dd.append(t)

    xs, ys = [], []
    for _ in range(n):
        x, y = list(map(int, input().split()))
        xs.append(x)
        ys.append(y)

    ini = sorted(list(range(n)), key=lambda x:xs[x])
    for i, yi in enumerate(sorted(list(range(n)), key=lambda x:ys[x])):
        ys[yi] = i 
    nys = [ys[i] for i in ini]

    ss1 = Bit(n)
    r = 0
    for i, y in enumerate(nys):
        ss1.add(y+1, 1)
        d = ss1.sum(y)
        c = i - d
        b = (n-1) - y - c
        a = (n-1) - b - c - d
        r = (r + sub(dd[b+c] + dd[c+d] + dd[d+a] + dd[a+b],
                dd[a] + dd[b] + dd[c] + dd[d])) % mod

    print(sub((dd[n] * n) % mod, (r+n)%mod))
main()


Measured memory_bytes: 118760
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
 
typedef long long LL;
using namespace std;
 
int n, k;
int a[100005];
 
int min(int x, int y){
	return x < y ? x : y;
}
 
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
 
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		//if(a[i] < 0) a[i] = a[i] * 2;
	}
	int ans = 0x3f3f3f3f;
	for (int i = k; i <= n; i++){
		ans = min(ans, a[i] - a[i - k + 1] + min(abs(a[i]), abs(a[i - k + 1])));
	}
	printf("%d\n", ans);
 
	return 0;

}

Measured memory_bytes: 640
S = input()

odd = S[0::2]
even = S[1::2]

odd_0_count = odd.count('0')
odd_1_count = odd.count('1')

even_0_count = even.count('0')
even_1_count = even.count('1')

# 奇数を0に、偶数を1にする
pattern1 = odd_1_count + even_0_count
# 奇数を1に、偶数を0にする
pattern2 = odd_0_count + even_1_count

print(min(pattern1,pattern2))


Measured memory_bytes: 39792
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (n, m): (i64, i64) = {
    let v = read_vec();
    (v[0], v[1])
  };


  let mut ks: Vec<Vec<i64>> = Vec::new();
  for i in 0..n as usize {
    let v: Vec<i64> = read_vec();
    ks.push(v);
  }

  let mut rcd: Vec<i64> = vec![0; m as usize];
  for i in 0..n as usize{
    for j in 1..(ks[i][0] as usize + 1) {
      rcd[ks[i][j] as usize -1] += 1;
    }
  }

  println!("{}", rcd.into_iter().fold(0, |acc, i| if i == n {acc + 1} else {acc + 0}));
}


Measured memory_bytes: 4352
import fractions
a,b,k = map(int,input().split())
c = fractions.gcd(a,b)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
d = make_divisors(c)
d.sort()
print(d[-k])

Measured memory_bytes: 5304