akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define p2(x) (x)*(x)
#define len(x) (int)(x).size()
using namespace std;
typedef long double ld;
typedef long long ll;
const int N = 1e5 + 1;
vector < int > g[N];
int coledge[N];
array<int,2>edges[N];
int MX = 0;

void dfs(int v , int p , int pc){
    int cnt = 1;
    for(auto u : g[v]){
        int to = ((edges[u][0] == v) ? edges[u][1] : edges[u][0]);
        if(to != p){
            if(cnt == pc)++cnt;
            coledge[u] = cnt;
            MX = max(MX , cnt);
            dfs(to , v , cnt);
            ++cnt;
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;

    for(int j = 0 ; j  < n - 1;  ++j){
        int a , b;
        cin >> a >> b;
        --a , --b;
        edges[j] = {a , b};
        g[a].pb(j);
        g[b].pb(j);
    }
    dfs(0 , -1 , -1);
    cout << MX << '\n';
    for(int j = 0 ; j < n - 1; ++j)
        cout << coledge[j] << '\n';
    return 0;
}


Measured memory_bytes: 9856
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main() {
	int n, m, c = 0;
	cin >> n >> m;
	vector<int> x(m), y(m), f(n), z(n, 1);
	rep(i, 0, m)cin >> x[i] >> y[i], x[i]--, y[i]--;
	f[0] = 1;
	rep(i, 0, m) {
		z[y[i]]++;
		z[x[i]]--;
		f[y[i]] |= f[x[i]];
		if (z[x[i]] == 0)f[x[i]] = 0;
	}
	rep(i, 0, n)if (f[i])c++;
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 1792
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s = readln.chomp.to!(char[]);

  writefln("%s%s%s", s[0], s.length - 2, s[$ - 1]);
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
fun main (args : Array<String>) {
	val (a, b, c) = readLine()!!.split(" ")
	val A : Int = a.toInt()
	val B : Int = b.toInt()
	val C : Int = c.toInt()
	if (C <= (A - B)) {
		println("0")
	} else {
		println("${C - (A - B)}")
	}
}

Measured memory_bytes: 37904
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  bool ok = true;
  bool spc = false;
  for (int i = b + 1; i <= d; i++) {
    if (s[i] == '#' && s[i - 1] == '#') {
      ok = false;
      break;
    }

    if(s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') {
      spc = true;
    }
  }
  if (ok && !spc) {
    s[d] = '#';
  }

  for (int i = a + 1; i <= c; i++) {
    if (s[i] == '#' && s[i - 1] == '#') {
      ok = false;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << ln;

  return 0;
}

Measured memory_bytes: 592
def main():
    N = int(input())
    A = input()
    B = input()
    C = input()
    ans = 0
    for a,b,c in zip(A,B,C):
        now = set([a,b,c])
        if len(now)==1:
            pass
        elif len(now)==2:
            ans += 1
        else:
            ans += 2
    
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n;
cin >> n;
vector<int> dp(n + 1, n + 1);
dp[0] = 0;
for (int i = 0; i < n; i++) {
  dp[i + 1] = min(dp[i + 1], dp[i] + 1);
  for (int x = 6; i + x <= n; x *= 6) {
    dp[i + x] = min(dp[i + x], dp[i] + 1);
  }
  for (int x = 9; i + x <= n; x *= 9) {
    dp[i + x] = min(dp[i + x], dp[i] + 1);
  }
}
  cout << dp[n] << endl;
 
return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  if (A > B) cout << "Alice" << endl;
  else if (A < B) cout << "Bob" << endl;
  else cout << "Draw" << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[2][n];
  vector<int> ue(n+1),sita(n+1);
  ue[0]=0;
  sita[0]=0;
  for(int i=0;i<2;++i){
    for(int j=0;j<n;++j){
      cin >> a[i][j];
      if(i==0){
        ue[j+1]=ue[j]+a[i][j];
      }else{
        sita[j+1]=sita[j]+a[i][j];
      }
    }
  }
  vector<int> ans(n);
  int uel,uer;
  int sital,sitar;
  uel=0;
  sitar=n;
  int cal=0;
  for(int i=0;i<n;++i){
    uer=i+1;
    sital=i;
    ans[i]=(ue[uer]-ue[uel])+(sita[sitar]-sita[sital]);
    cal=max(cal,ans[i]);
  }
  cout << cal << endl;

}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int a, b, c; cin >> a >> b >> c&&a;) {
		vector<int> P(a); rep(i, 0, a) { cin >> P[i]; }
		int g = INF;
		int ans = 0;
		rep(i, 1, a) {
			if (i >= b&&i <= c) {
				if (g >= P[i] - P[i - 1]) {
					g = P[i] - P[i - 1];
					ans = i;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

struct Node{
	int iKey_;
	Node *pParent_;
	Node *pLeftChild_;
	Node *pRightChild_;
};

class Tree {
public:
	Tree(int iNum) :iMaxNodeNum_(iNum), iCurNodeNum_(0) {}

	void setNodeValue() {
		for (int iCurNode_i = 0; iCurNode_i < iMaxNodeNum_; iCurNode_i++) {
			string sCommand;
			cin >> sCommand;
			if (sCommand[0] == 'i') {
				int iKey;
				cin >> iKey;
				insertNode(iKey);
			}
			else {
				print();
			}
		}
	}

private:
	void insertNode(int iKey) {
		Node *pNewNode = new Node;
		//????????????
		pNewNode->iKey_ = iKey;
		pNewNode->pParent_ = NULL;
		pNewNode->pLeftChild_ = NULL;
		pNewNode->pRightChild_ = NULL;
		iCurNodeNum_++;
		if (iCurNodeNum_ == 1) { //??????????????????????????????
			pRoot_ = pNewNode;
			return;
		}

		searchNewNodeLocation(pNewNode);
	}
	void searchNewNodeLocation(Node *pNewNode) {
		Node *pCurNode = pRoot_;
		Node *pCurParentNode = NULL;
		while (pCurNode != NULL) {
			pCurParentNode = pCurNode;
			if (pNewNode->iKey_ < pCurNode->iKey_) pCurNode = pCurNode->pLeftChild_;
			else                                   pCurNode = pCurNode->pRightChild_;
		}
		pNewNode->pParent_ = pCurParentNode;

		if (pNewNode->iKey_ < pCurParentNode->iKey_) pCurParentNode->pLeftChild_  = pNewNode;
		else                                   pCurParentNode->pRightChild_ = pNewNode;
	}

	void print() {
		printWidthInorder(pRoot_);
		cout << endl;
		printWidthPreorder(pRoot_);
		cout << endl;
	}
	void printWidthPreorder(Node *pN) {
		if (pN == NULL) return;
		cout << " " << pN->iKey_;
		printWidthPreorder(pN->pLeftChild_);
		printWidthPreorder(pN->pRightChild_);
	}
	void printWidthInorder(Node *pN) {
		if (pN == NULL) return;
		printWidthInorder(pN->pLeftChild_);
		cout << " " << pN->iKey_;
		printWidthInorder(pN->pRightChild_);
	}

	Node *pRoot_;
	int iCurNodeNum_;
	const int iMaxNodeNum_;
};

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

	//?????????
	Tree trNodeTree(iNodeNum);

	//???????????§??\????????????
	trNodeTree.setNodeValue();

	return 0;
}

Measured memory_bytes: 26460
N, M, R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i)
d = Array.new(201) { Array.new(201, Float::INFINITY) }

M.times do
  a, b, c = gets.split.map(&:to_i)
  d[a][b], d[b][a] = [c] * 2
end

1.upto(N) do |k|
  1.upto(N) do |i|
    1.upto(N) do |j|
      distance = d[i][k] + d[k][j]
      d[i][j] = distance if d[i][j] > distance
    end
  end
end

min_distance = Float::INFINITY
r.permutation(R) do |route|
  distance = 0
  (1...route.size).each do |i|
    distance += d.dig(route[i - 1], route[i])
  end

  if distance < min_distance
    min_distance = distance
  end
end

puts min_distance

Measured memory_bytes: 2300
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int N;  cin >> N;
  for(int i = 0; i < N; i++){
    int k, p;
    cin >> k >> p;
    if(k <= p) cout << k << endl;
    else if(k % p == 0) cout << p << endl;
    else cout << k % p << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
  int A, B, C, D, E, F, maxW{}, maxS{};
  double m{};
  cin >> A >> B >> C >> D >> E >> F;
  for (int a = 0; a < F; a += 100*A) {
    for (int b = 0; a + b < F; b += 100*B) {
      for (int c = 0; a + b + c <= F; c += C) {
        if (100.*c/(a+b+c) > E) break;
        for (int d = 0; a + b + c + d <= F; d += D) {
          auto co = 100.*(c+d)/(a+b+c+d);
          if (co > m) {
            if (c+d > (a+b)/100*E) break;
            m = co;
            maxW = a+b+c+d;
            maxS = c+d;
          }
        }
      }
    }
  }
  if (!maxW) maxW = 100*A;
  cout << maxW << " " << maxS << endl;
}


Measured memory_bytes: 3540
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
 
class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};
 
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
 
	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;
 
	UnionFind Uni(N);
 
	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];
 
		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}
 
	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3328
function Main(input) {
  var tmp = input.trim().split('\n')
  var N = parseInt(tmp[0].split(' ')[0])
  var K = parseInt(tmp[0].split(' ')[1])
  tmp.shift()
  var h = tmp

  var H = h.sort(function (a, b) { return parseInt(a) - parseInt(b) })

  var result = Number.MAX_SAFE_INTEGER

  for (var j = 0; j <= N - K; j++) {
    var v = H[j + K - 1] - H[j]
    if (result > v) {
      result = v
    }
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 19140
#include<bits/stdc++.h>
using namespace std;
int t,n,k,d,A;
int main()
{
	cin>>t;
	while(t--&&cin>>n>>k)
	{
		while(n%k!=0)
			d=n/k+1,n-=((n-n/k*k-1)/d+1)*d;
		A^=n/k;
	}
	if(A)
		cout<<"Takahashi";
	else
		cout<<"Aoki";
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

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

cnt0 = Counter(vs[0::2])
cnt1 = Counter(vs[1::2])

cnt0[0] = 0
cnt1[0] = 0

ans = n
for v0, num0 in cnt0.most_common(2):
    for v1, num1 in cnt1.most_common(2):
        if v0 != v1:
            ans = min(ans, n - (num0 + num1))

print(ans)


Measured memory_bytes: 18656
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  cout << a - b + 1 << endl;

  return (0);
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
    int num,i,j,save;
    int first[100];
    int second[100];
    int third[100];
    
    scanf("%d",&num);
    
    for(i=0;i<100;i++){
        first[i]=0;second[i]=0;third[i]=0;
    }
    
    for(i=1;i<=num;i++){
        scanf("%d",&save);
        if(first[save-1]==0){
            first[save-1]=i;
        }
        else{
            first[save-1]=-1;
        }
        scanf("%d",&save);
        if(second[save-1]==0){
            second[save-1]=i;
        }
        else{
            second[save-1]=-1;
        }
        scanf("%d",&save);
        if(third[save-1]==0){
            third[save-1]=i;
        }
        else{
            third[save-1]=-1;
        }
    }
    for(i=1;i<=num;i++){
        save=0;
        for(j=0;j<100;j++){
            if(first[j]==i){
                save+=j+1;
            }
        }
        for(j=0;j<100;j++){
            if(second[j]==i){
                save+=j+1;
            }
        }
        for(j=0;j<100;j++){
            if(third[j]==i){
                save+=j+1;
            }
        }
        printf("%d\n",save);
    }
}



Measured memory_bytes: 2104
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,k;
struct Perm
{
	int p[100005];
	Perm(){memset(p,0,sizeof(p));}
	int&operator[](int i){return p[i];}
	Perm operator*(Perm q)
	{
		Perm a;
		for(int i=1;i<=n;i++)a[i]=p[q[i]];
		return a;
	}
	Perm Inv()
	{
		Perm a;
		for(int i=1;i<=n;i++)a[p[i]]=i;
		return a;
	}
}p,q,ip,iq,t,it,ans,a[10];
Perm quick_pow(Perm x,int a)
{
	Perm ans;
	for(int i=1;i<=n;i++)ans[i]=i;
	while(a)
	{
		if(a&1)ans=ans*x;
		x=x*x;
		a>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)scanf("%d",&q[i]);
	ip=p.Inv();
	iq=q.Inv();
	t=q*ip*iq*p;
	it=t.Inv();
	k=(m-1)/6;
	m-=6*k;
	a[1]=p;
	a[2]=q;
	for(int i=3;i<=6;i++)a[i]=a[i-1]*a[i-2].Inv();
	Perm ans=quick_pow(t,k)*a[m]*quick_pow(it,k);
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

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

int main() {
	int N, K;
	cin >> K >> N;
	long nums[N];
	for (int i = 0; i < N; i++) {
		cin >> nums[i];
	}
	sort(nums, nums + N);
	long differences[N - 1];
	for (int i = 0; i < N - 1; i++) {
		differences[i] = nums[i + 1] - nums[i];
	}
	sort(differences, differences + N - 1);
	long ans = 0;
	for (int i = 0; i < N - K; i++) {
		ans += differences[i];
	}
	cout << ans << endl;
}


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

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int x, y;

            x = cin.GetInt();
            y = cin.GetInt();

            Console.WriteLine("{0} {1}", x * y, 2 * x + 2 * y);
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public string GetLine()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            string line;
            this._i = 0;
            do
            {
                line = Console.ReadLine();
            } while (line == "");

            this._s = line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);

            return this._s[this._i++];
        }

        public int GetInt()
        {
            return int.Parse(this.GetLine());
        }

        public long GetLong()
        {
            return long.Parse(this.GetLine());
        }

        public double GetDouble()
        {
            return double.Parse(this.GetLine());
        }
    }
}

Measured memory_bytes: 5628
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
class Item {
public:
	int w, v;
	bool operator<(const Item &other) {
		return w > other.w;
	}
};
signed main() {
	int N, W; cin >> N >> W;
	vector<Item>item(N + 1);
	item[0].w = INF;
	rep(i, 1, N + 1)cin >> item[i].v >> item[i].w;
	sort(all(item));
	
	vector<vector<int>>dp(N + 1, vector<int>(W + 1, 0));
	rep(i, 1, N + 1)rep(j, 1, W + 1) {
		dp[i][j] = dp[i - 1][j];
		if (j - item[i].w >= 0)
			dp[i][j] = max(dp[i][j - item[i].w] + item[i].v, dp[i][j]);
	}
	cout << dp[N][W] << endl;
	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  ll N;
  cin >> N;
  llvec L(N);
  rep(i, N){
    cin >> L[i];
  }
  sort(ALL(L));

  /*
  rep(i, N){
    cout << L[i] << " ";
  }
  */
  
  ll ans = 0;
  rep(i, N){
    for(int j=i+1;j<N;j++){
      ll length=L[i]+L[j];
      auto it = lower_bound(ALL(L), length);
      ans += max(0, (int)(it-L.begin()) - j-1);
      //cout << ans << endl;
    }
  }

  cout << ans;
  /*
  vector<llvec> r(N, L);
  rep(i, N){
    rep(j,N){
      r[i][j] = L[i] + L[j];
    }
  }

  ll ans = 0;

  rep(ii, N){
    int i = N-1 - ii;
    upper_bound(ALL(r[i], L[i]))
    }*/
  
  return 0;
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

vector<int> a;
int dp[111][11];

int calc(int idx,int md){
	if(idx == a.size())return (md ? 0 : -1e9);
	int &ret = dp[idx][md];
	if(ret != -1)return ret;
	ret = max(calc(idx+1,(md+a[idx])%10) + a[idx] , calc(idx+1,md));
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	#endif
	int n;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++)cin>>a[i];
	memset(dp,-1,sizeof(dp));
	cout << max(0,calc(0,0)) << endl;
}	

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#define lint long long
#define LOG 17
#define maxK 10
#define V 1<<LOG
#define N 42
#define mod 1000000007
using namespace std;
inline int updv(int x,int p) { return x|(1<<(p-1)); }
int dp[N][V],can[V];
int fast_pow(int x,int k)
{
    int ans=1;
    while(k)
    {
        if(k&1) ans=(lint)ans*x%mod;
        x=(lint)x*x%mod,k>>=1;
    }
    return ans;
}
int show(int x)
{
    for(int i=1;i<=LOG;i++)
        printf("%d",(x&(1<<(i-1)))>>(i-1));
    cout<<endl;
    return 0;
}
int main()
{
    int n,x,y,z;scanf("%d%d%d%d",&n,&x,&y,&z);
    int all=(1<<LOG)-1,v=0,ans=0;dp[0][0]=1;
    v=updv(v,x+y+z),v=updv(v,y+z),v=updv(v,z);
    for(int i=0;i<=all;i++) can[i]=((i&v)!=v);
    for(int i=0,x;i<n;i++)
        for(int j=0;j<=all;j++)
            if(can[j]&&(x=dp[i][j]))
                for(int k=1;k<=maxK;k++)
                    (dp[i+1][all&updv(j<<k,k)]+=x)%=mod;
    for(int i=1;i<=all;i++)
        if(can[i]) (ans+=dp[n][i])%=mod;
    printf("%d\n",(fast_pow(10,n)-ans+mod)%mod);
    return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int modPow(int a, int n, int mod) {
    if(n==0)return 1;
    if(n==1)return a%mod;
    if (n%2==1)return(a*modPow(a,n-1,mod))%mod;
    int t=modPow(a,n/2,mod);
    return (t*t)%mod;
}

int K;

signed main(){
    cin>>K;
    int mod=0;
    int t=0;
    while(true){
        mod+=7*modPow(10,t,K);
        mod%=K;
        t++;
        if(mod==0){
            cout<<t<<endl;
            return 0;
        }
        if(t>1000000){
            cout<<-1<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

struct Sushi
{
	int x;
	int v;
	Sushi(int x, int v)
	{
		this->x = x;
		this->v = v;
	}
};

int N, C;
vector<Sushi> sushi;

int R[100000];
int L[100000];

int Rmax()
{
	int max = 0;
	int v = 0;
	int w = 0;
	int x = 0;
	for (int i = 0; i < N; i++)
	{
		v += sushi[i].v;
		w = sushi[i].x;
		int value = (v - w);
		if (max < value)
		{
			max = value;
		}
		R[i] = max;
	}

	int ans = R[N - 1];

	v = 0;
	w = 0;
	for (int i = 0; i < N; i++)
	{
		v += sushi[N - i - 1].v;
		w = (C - sushi[N - i - 1].x);
		int value = v - w;
		if (ans < value)
		{
			ans = value;
		}
		if (N - i - 2 >= 0)
		{
			value -= w;
			value += R[N - i - 2];
			if (ans < value)
			{
				ans = value;
			}
		}
	}

	return ans;
}

int Lmax()
{
	int max = 0;
	int v = 0;
	int w = 0;
	int x = 0;
	for (int i = 0; i < N; i++)
	{
		v += sushi[N - i - 1].v;
		w = (C - sushi[N - i - 1].x);
		int value = (v - w);
		if (max < value)
		{
			max = value;
		}
		L[N - i - 1] = max;
	}

	int ans = L[0];

	v = 0;
	w = 0;
	for (int i = 0; i < N; i++)
	{
		v += sushi[i].v;
		w = sushi[i].x;
		int value = v - w;
		if (ans < value)
		{
			ans = value;
		}
		if (i + 1 < N)
		{
			value -= w;
			value += L[i + 1];
			if (ans < value)
			{
				ans = value;
			}
		}
	}

	return ans;
}

signed main()
{
	cin >> N >> C;
	REP(i, N)
	{
		int x, v;
		cin >> x >> v;
		sushi.push_back(Sushi(x, v));
	}
	
	int r = Rmax();
	int l = Lmax();
	cout << MAX(r, l) << endl;
}







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

char grid[50][50];

int main() {
    int H, W, flag = 0;
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '#') {
                if (i == 0 && j == 0) {
                    if (grid[0][1] != '#' && grid[1][0] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (i == 0 && j == W - 1) {
                    if (grid[i][j - 1] != '#' && grid[i + 1][j] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (i == H - 1 && j == 0) {
                    if (grid[i - 1][j] != '#' && grid[i][j + 1] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (i == H - 1 && j == W - 1) {
                    if (grid[i - 1][j] != '#' && grid[i][j - 1] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (i == 0) {
                    if (grid[i][j - 1] != '#' && grid[i + 1][j] != '#' && grid[i][j + 1] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (i == H - 1) {
                    if (grid[i][j - 1] != '#' && grid[i - 1][j] != '#' && grid[i][j + 1] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (j == 0) {
                    if (grid[i - 1][j] != '#' && grid[i][j + 1] != '#' && grid[i + 1][j] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else if (j == W - 1) {
                    if (grid[i - 1][j] != '#' && grid[i][j - 1] != '#' && grid[i + 1][j] != '#') {
                        flag = 1;
                        break;
                    }
                }
                else {
                    if (grid[i - 1][j] != '#' && grid[i][j - 1] != '#' && grid[i + 1][j] != '#' && grid[i][j + 1] != '#') {
                        flag = 1;
                        break;
                    }
                }
            }
        }
    }

    if (flag) cout << "No\n";
    else cout << "Yes\n";

    return 0;
    
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int hist[N]={0};
	for(int i=0;i<M;i++){
		int a, b;
		cin >> a >>b;
		a--; b--;
		hist[a]++;
		hist[b]++;
	}
	for(int i=0;i<N;i++){
		cout << hist[i] <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<LL> X(N);
	for(int i=0;i<N;++i){
		cin >> X[i];
	}
	vector<LL> D(N-1);//元
	for(int i=0;i<N-1;++i){
		D[i] = X[i+1]-X[i];
	}
	LL M,K;
	cin >> M >> K;
	vector< vector<int> > dp(64,vector<int>(N-1));
	for(int i=0;i<N-1;++i){
		dp[0][i] = i;
	}
	dp[1] = dp[0];
	
	vector<int> AA;
	for(int i=0;i<M;++i){
		int A;
		cin >> A;
		AA.push_back( A );
		swap(dp[1][A-2], dp[1][A-1]);
	}
	sort(AA.begin(), AA.end());

	for(int k=2;k<64;++k){//ダブリング
		//dp[k-1]からdp[k]を作る
		for(int i=0;i<N-1;++i){
			int pos1 = dp[k-1][i];//pos1->i
			int pos2 = dp[k-1][pos1];//pos2->pos1
			dp[k][i] = pos2;//pos2->i
		}
	}
	LL num = K;
	int pow = 1;
	vector<int> ans = dp[0];
	while(num){
		if(num&1){
			vector<int> temp = ans;
			for(int i=0;i<N-1;++i){
				int pos1 = dp[pow][ i ];//pos1->i
				temp[i] = ans[pos1];
			}
			ans = temp;
		}
		num >>=1;
		++pow;
	}
	LL now = X[0];
	cout << now << endl;
	for(int i=0;i<N-1;++i){
		now += D[ ans[i] ];
		cout << now << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 29048
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(ll i=a;i<b;i++)
#define bFor(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll lpow(ll a,ll b){
  ll res=1;
  rep(i,b){
    res*=a;
  }
  cout<<res;
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  string ss,t;cin>>ss;
  if(ss[0]=='S'){
    t="Cloudy";
  }else if(ss[0]=='R'){
    t="Sunny";
  }else{
    t="Rainy";
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int A[100000];
int B[100000];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>A[i];
            B[i]=A[i];
        }
    sort(B+1,B+n+1);


    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(A[i]!=B[i])
            cnt++;
    }

/*
    for(int i=1;i<=n;i++)
        cout<<A[i]<<" ";
    cout<<endl;

    for(int i=1;i<=n;i++)
        cout<<B[i]<<" ";
    cout<<endl;
*/
    if(cnt==2||cnt==0)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    sort(A.begin(), A.end(), greater<int>());
    ll sum = A[0];
    int c = 1, d = 0;
    rep(i, N-2) {
        sum += A[c];
        d++;
        if (d == 2) {
            c++;
            d = 0;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 4056
s=input()
q=int(input())
head=''
foot=''

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if (f^a)&1==0:
      foot+=c
    else:
      head+=c
s=head[::-1]+s+foot
if a==1:
  s=s[::-1]
print(s)

Measured memory_bytes: 4468
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
//(1,1)を左上,(n,m)を右下としたときに、その長方形に含まれる青色のマスの個数
int num[2001][2001];
int connum[4001][4001];
bool blue[2001][2001];
int con[4001][4001];
int main() {
	int n, m, q; cin >> n >> m >> q;
	rep1(i, n) {
		rep1(j, m) {
			char t; cin >> t;
			if (t == '1')blue[i][j] = true;
		}
	}
	rep(i, n + 1) {
		rep(j, m + 1) {
			if (i == 0 || j == 0)num[i][j] = 0;
			else {
				num[i][j] = num[i - 1][j] + num[i][j - 1] - num[i - 1][j - 1];
				if (blue[i][j])num[i][j]++;
			}
		}
	}
	rep1(i, n) {
		rep1(j, m - 1) {
			if (blue[i][j] && blue[i][j + 1])con[2 * i][2 * j + 1]++;
		}
	}
	rep1(i, m) {
		rep1(j, n - 1) {
			if (blue[j][i] && blue[j + 1][i])con[2 * j + 1][2 * i]++;
		}
	}
	rep(i, 2 * n + 1) {
		rep(j, 2 * m + 1) {
			if (i == 0 || j == 0)connum[i][j] = 0;
			else connum[i][j] = connum[i - 1][j] + connum[i][j - 1] - connum[i - 1][j - 1] + con[i][j];
		}
	}
	rep(i, q) {
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		int out = num[x2][y2] - num[x1-1][y2] - num[x2][y1-1] + num[x1-1][y1-1];
		out -= connum[x2 * 2][y2 * 2] - connum[x1 * 2 - 1][y2 * 2] - connum[x2 * 2][y1 * 2 - 1] + connum[x1 * 2 - 1][y1 * 2 - 1];
		cout << out << endl;
	}
	return 0;
}


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

primes = []
prime_idx = {}
furui = [-1]*(10**6+10)
furui[0] = 0
furui[1] = 1
for i in range(2,10**6 + 10):
    if furui[i] == -1:
        prime_idx[i] = len(primes)
        primes.append(i)
        x = i
        while x < 10**6 + 10:
            furui[x] = i
            x += i

appered = [0]*len(primes)
for a in A:
    x = a
    has = set()
    while x>1:
        has.add(prime_idx[furui[x]])
        x //= furui[x]
    for prime in has:
        appered[prime] += 1
flag = 0
for ap in appered:
    if ap > 1:
        flag = max(flag, 1)
    if ap == n:
        flag = max(flag, 2)
if flag == 2:
    print("not coprime")
elif flag == 1:
    print("setwise coprime")
else:
    print("pairwise coprime")


Measured memory_bytes: 205040
from sys import stdin
input = stdin.readline

N, X, M = map(int, input().split())

ls = []
s = set([])

a = X
s.add(a)
ls.append(a)
ind = -1
new_ls = []

while True:
    a = pow(a, 2, M)

    if a in s:
        ind = ls.index(a)
        break
    elif len(ls) == N:
        break
    else:
        s.add(a)
        ls.append(a)

if ind != -1:
    new_ls = ls[ind:len(ls)]

ans = sum(ls)

if len(new_ls) != 0:
    ans += sum(new_ls) * (max(0, (N - len(ls))) // len(new_ls))

    tmp = max(0, (N - len(ls))) % len(new_ls)

    if tmp != 0:
        for i in range(tmp):
            ans += new_ls[i % len(new_ls)]

print(ans)


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

int main() {
    int n,m,c ; cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) {
        cin >> b[i];
    }

    int ans = 0;
    int tmp_ans = 0;
    int tmp;
    rep(i, n) {
        tmp_ans = 0;
        rep(j, m) {
            cin >> tmp;
            tmp_ans += tmp * b[j];
        }
        if(tmp_ans + c > 0) ans++;
    }

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



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

int main() {
    int N , a , b , c , d;
    cin >> N;
    a = N / 1000;
    b = N % 1000 / 100;
    c = N % 1000 % 100 / 10;
    d = N % 1000 % 100 % 10;
    if (a == b && b == c) {
        cout << "Yes" << endl;
    }
    else if (b == c && c == d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
int m,n;
double total;
double dp[110][110];
int Just;
//vector<double> matrix[110];
double matrix[110][110];
/*
double rec(int next,int counter){
  if(dp[next][counter] > 0)return dp[next][counter];
  if(counter  == 0){
    return 1.0;
  }
  double HANMA = 0.0,test=0.0;
 
 
  for(int i=0;i<n;i++){   
    
    //HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i,counter-1)*matrix[next][i];
    if(test > HANMA)HANMA = test;
  }  
  dp[Just][counter] = HANMA;
  return HANMA;
}
*/

int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    //for(int i=0;i<=n;i++)matrix[i].clear();
    
    for(int i=m;i>=0;i--)for(int j=0;j<n;j++)dp[j][i] = -10;
   
 

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	scanf("%lf",&matrix[i][j]);
      }
    }
  for(int i=0;i<n;i++)dp[i][0] = dp[i][1] = 1;

    double ans = -1; 
    for(int i=2;i<=m;i++){
      for(int j=0;j<n;j++){
	ans = -1;
	for(int k=0;k<n;k++)if(ans < dp[k][i-1]*matrix[j][k])ans = dp[k][i-1]*matrix[j][k];
      
	dp[j][i] = ans;
      }
    }  
 
    double Fans = 0;
    for(int i=0;i<n;i++)if(Fans < dp[i][m])Fans = dp[i][m];
      //cout << endl;

    printf("%.2f\n",Fans);

  }
  return 0;
}

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

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

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

int main() {
    int x;
    while(cin >> x, x){
        int ans = INF<int>;
        for (int i = 0; i*200 <= x; ++i) {
            for (int j = 0; i*200+j*300 <= x; ++j) {
                if((x-i*200-j*300)%500) continue;
                int k = (x-i*200-j*300)/500;
                ans = min(ans, i/5*1520+i%5*380+j/4*1870+j%4*550+k/3*2244+k%3*850);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){

  int N,asn;
  cin>>N;
  if(N%2==0){
    asn = N/2;
  }else{
    asn=N/2+1;
  }

  cout<<asn<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const int MOD = 1e9+7;
#define REP(i,n) for (int i = 0; i < (N); ++i)
#define ar array
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	int N,A,B;
	cin >> N >> A >> B;
	int ans = min(N*A, B);

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


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	ll a, b;
	string s;
	cin >> a >> s;
	b = (s.at(0) - '0')*100 + (s.at(2) - '0')*10 + (s.at(3) - '0');
//	cout << b << endl;
	cout << a*b/100 << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<ll,ll>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;cin >> n;
    vector<vi> v(3, vi(n));
    rep(i,n) cin >> v[0][i] >> v[1][i] >> v[2][i];

    vector<vl> dp(n+10, vl(3,0));
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(j==k) continue;
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + v[j][i]);
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

Measured memory_bytes: 6904
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def prime_fact(g):
    s = {1}
    i = 2
    # N=p x qとした時、(p < q)
    # 必ず p <= root(N)
    # そのためp**2までを調べればok
    while i*i <= g:
        while g % i == 0:
            g //= i
            s.add(i)
        i += 1
    s.add(g)
    return s


a, b = map(int, input().split())
G = gcd(a, b)
print(len(prime_fact(G)))


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //#ifndef ONLINE_JUDGE
    //    freopen("take.in","r",stdin);
    //    freopen("give.out","w",stdout);
    //#endif
    ios_base::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    bool on[h+1][w+1];
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            char c;
            cin>>c;
            if(c=='#') on[i][j]=1;
            else on[i][j]=0;
        }
    }
    bool sure[h+1][w+1];
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            int sum=(on[i][j]+on[i+1][j]+on[i][j+1]+on[i+1][j+1]);
            if(sum%2) sure[i][j]=0;
            else sure[i][j]=1;
        }
    }
    int L[w+1],R[w+1];
    int hi[w+1];
    memset(hi,0,sizeof hi);
    int ans=max(h,w);
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(sure[i][j]) hi[j]++;
            else hi[j]=0;
        }
        hi[w]=-1;
        hi[0]=-1;
        stack<int>s;
        s.push(0);
        for(int j=1;j<w;j++)
        {
            while(hi[s.top()]>=hi[j]) s.pop();
            L[j]=s.top();
            s.push(j);
        }
        while(!s.empty()) s.pop();
        s.push(w);
        for(int j=w-1;j>0;j--)
        {
            while(hi[s.top()]>=hi[j]) s.pop();
            R[j]=s.top();
            s.push(j);
        }
        for(int j=1;j<w;j++)
        {
            ans=max(ans,(R[j]-L[j])*(hi[j]+1));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

bool ispalin(string X){
	string XR=X;
	reverse(all(XR));
	//cout << X << (X==XR) << "\n";
	return X==XR;
}

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string S;cin>>S;
	int N=S.length();
	if (ispalin(S) && ispalin(S.substr(0,(N-1)/2)) && ispalin(S.substr((N+3)/2-1,(N-1)/2))) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c)
{
  stack<int> S;
  S.push(r);
  color[r] = c;
  while (!S.empty()) {
    int u = S.top(); S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor()
{
  int id = 1;
  for (int i = 0; i < n; i++) {
    color[i] = NIL;
  }
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL) {
      dfs(u, id++);
    }
  }
}

int main()
{
  int s, t, m, q;

  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

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

int main() 
{
    int n;
    cin >> n;
    for (int i=1; i<=9; i++) {
        for (int j=1; j<=9; j++) {
            if (i*j == n) {
                cout << "Yes" << endl;
                 return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256