akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
a = tuple(map(int, input().split()))

inf = 10 ** 13
res = inf
b = [inf] * n

for x in range(n):
    bsum = 0
    for i in range(n):
        j = (i - x) % n
        b[i] = min(b[i], a[j])
        bsum += b[i]
    res = min(res, k * x + bsum)

print(res)


Measured memory_bytes: 42652
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            
            int n;
            cin >> n;
            int a[n], sum[n+10] = {0};
            int const mod = 1e9 + 7;
            for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                sum[i+1] += sum[i] + a[i];
                sum[i+1] %= mod;
            }
            int ans = 0;
            for(int i = 0; i < n; i++)
            {
                ans += sum[i]*a[i];
                ans %= mod;
            }
            cout << ans << '\n';

           return 0;
        }
          

Measured memory_bytes: 6772
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

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


int main() {
    int n,k;
    cin>>n>>k;

    vector<int>a(n);
    rep(i,n)cin>>a[i];

    cout<<((n-1)+k-2)/(k-1)<<endl;

}


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

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long f=((n/(a+b))*a);
    if((n%(a+b))>=a)
        f+=a;
    else 
        f+=((n%(a+b)));
    cout << f;
    return 0;
}

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

int table[16][16][16];
int arr[16];
int n;
int m;

int maxval;

void eval() {
    auto sum = 0;
    for (int a = 1; a <= n; a++) {
        for (int b = a + 1; b <= n; b++) {
            sum += table[a][b][arr[b] - arr[a]];
        }
    }
    maxval = max(maxval, sum);
}

void score(int pos) {
    int mx = -1;

    if (pos > n) {
        eval();
        return;
    }

    for (int val = arr[pos - 1]; val <= m; val++) {
        arr[pos] = val;
        score(pos + 1);
    }
}

int main() {
    int q;
    cin >> n >> m >> q;

    for (int i = 1; i <= q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        table[a][b][c] = d;
    }

    arr[0] = 1;
    score(1);
    cout << maxval;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N; cin>>N;
  map<string,ll> M;
  for(ll i=0; i<N; i++){
    string S; cin>>S;
    M[S]++;
  }
  //最大数さがす
  ll high=0;
  for(auto n:M){
    ll n2=n.second;
    high=max(high,n2);
  }
  vector<string> ans;
  for(auto n:M){
    string n1=n.first;
    ll n2=n.second;
    if(n2==high) ans.emplace_back(n1);
  }
  sort(ans.begin(), ans.end());
  for(ll i=0; i<ans.size(); i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 27108
#include <iostream>
#include <string>

using namespace std;

 int main(void) {

	 int N, M;
	 string U[256];
	 string T;
	 bool f = true;
	 bool find;

	 cin >> N;

	 for (int i = 0; i < N; i++){
		 cin >> U[i];
	 }

	 cin >> M;

	 for (int i = 0; i < M; i++){
		 cin >> T;
		 find = false;
		 for (int j = 0; j < N; j++){
			 if (U[j] == T) find = true;
		 }
		 if (find){
			 if (f){
				 f = false;
				 cout << "Opened by ";
			 }
			 else{
				 f = true;
				 cout << "Closed by ";
			 }
		 }
		 else cout << "Unknown ";

		 cout << T << endl;
	 }

	 return 0;
	
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C058
    {
        //共通部分を取る
        public static void IntersectDic<T>(Dictionary<T, int> dicBase, Dictionary<T, int> dicNew)
        {
            int counter = 0;
            while (counter < dicBase.Count)
            {
                T key = dicBase.Keys.ToList()[counter];
                if (dicNew.ContainsKey(key))
                {
                    if (dicNew[key] < dicBase[key]) dicBase[key] = dicNew[key];
                    counter++;
                }
                else
                {
                    dicBase.Remove(key);
                }                
            }
        }

        static void Main(string[] args)
        {
            Dictionary<char, int> dicTotal = new Dictionary<char, int>();
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                string S = Console.ReadLine();
                char[] carr = S.ToCharArray();
                Dictionary<char, int> dic = new Dictionary<char, int>();
                foreach (char c in carr)
                {
                    if (!dic.ContainsKey(c)) dic.Add(c, 0);
                    dic[c]++;                    
                }

                if (i == 0) dicTotal = dic;
                else IntersectDic(dicTotal, dic);
            }


            string s="";
            foreach(var p in dicTotal.OrderBy(x => x.Key))
            {
                for (int i = 0; i < p.Value; i++)
                {
                    s += p.Key;
                }
            }
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define pi 3.1415  
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 100009
#define MOD 1000000007
#define INF (int)3000009
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    ll gcdact=__gcd(a,b);
    map<int,int> primes;
    for(int i=2;i<=sqrt(gcdact);i++){
        if(gcdact%i==0){
            while(gcdact%i==0){
                primes[i]++;
                gcdact/=i;
            }
        }
    }
    if(gcdact!=1)primes[gcdact]++;
    int ans=0;
    for(auto e: primes){
        if(e.second>0)ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}

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

using namespace std;

long long w[105], v[105], dp[2][(int)1e5+10];

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, W;
    cin >> N >> W;

    for(int i=1;i<=N;++i)
        cin >> w[i] >> v[i];
    
    int before_row=0, actual_row=1;
    dp[0][w[1]] = v[1];

    for(int i=2;i<=N;++i){
        
        for(int j=1;j<=W;++j)
            dp[actual_row][j] = 0;
        dp[actual_row][w[i]] = v[i];
        
        for(int j=1;j<=W;++j)
            if(dp[before_row][j]){
                dp[actual_row][j] = max(dp[actual_row][j], dp[before_row][j]);
                if(j + w[i] <= W)
                    dp[actual_row][j+w[i]] = max(dp[actual_row][j+w[i]], dp[before_row][j] + v[i]);
            }
        swap(before_row, actual_row);
    }

    long long maxx = 0;
    for(int i=1;i<=W;++i)
        maxx = max(maxx, dp[before_row][i]);

    cout << maxx << '\n';

    return 0;
}

Measured memory_bytes: 1792
#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 < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b;
    cin >> a >> b; 
    if (a == 1 && b == 2) cout << 3 << endl;
    else if (a == 1 && b == 3) cout << 2 << endl;
    else if (a == 2 && b == 1) cout << 3 << endl;
    else if (a == 2 && b == 3) cout << 1 << endl;
    else if (a == 3 && b == 1) cout << 2 << endl;
    else if (a == 3 && b == 2) cout << 1 << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;

vector <int> v[N];
vector < pair < int , int > > qu[N];
int clr[N],foo[N],mp[N]; 
 
int main()
{
    ios_base::sync_with_stdio(false);
    int n,m,i,j;
    cin>>n>>m;
    for(i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    } 
    int qq;
    cin>>qq;
    for(i=0;i<qq;i++){
        int v,d,c;
        cin>>v>>d>>c;
        mp[i]=c;
        qu[d].pb(mkp(v,i));
    }
    for(i=1;i<=n;i++){
        foo[i]=clr[i]=-1;
    }
    for(j=10;j>=0;j--){
        for(int k=0;k<qu[j].size();k++){
            int x = qu[j][k].fi;
            clr[x] = max(clr[x],qu[j][k].se);
        }
        for(i=1;i<=n;i++) foo[i]=clr[i];
        if(j==0) break;
        for(i=1;i<=n;i++){
            for(int k=0;k<v[i].size();k++){
                int x = v[i][k];
                clr[i] = max(clr[i],foo[x]);
            }
        }

    }
    for(i=1;i<=n;i++){
        if(clr[i]==-1) cout << 0 << endl;
        else cout << mp[clr[i]] << endl;
    }


 
    return 0;
}

Measured memory_bytes: 11256
#include <iostream>

using namespace std;

int main()
{
	int A;
	int B;
	int C;
	int K;
	cin >> A >> B >> C;
	cin >> K;
	int i = 1;
	while(i <= K && A >= B) {
		B += B;
		i++;
	}
	while(i <= K && C <= B) {
		C += C;
		i++;
	}
	if (A < B && B < C)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

int main() {
	int n, m, p;
	while (scanf("%d%d%d", &n, &m, &p), n) {
		int sum = 0, t;
		for (int i = 1; i <= n; i++) {
			int x; scanf("%d", &x);
			sum += x;
			if (i == m)t = x;
		}
		if (t == 0)puts("0");
		else printf("%d\n", sum*(100 - p) / t);
	}
}

Measured memory_bytes: 3140
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = 1
m=10**9+7
c=[]
for _ in range(N):
    c.append(int(input()))
dp = [1]*(N+1)#dp[i] i番目までの並び替え総数
last_color = [-1]*(max(c)+1)#最後にその色が出たindexの保存
last_color[c[0]] =0
for i in range(1,N):
    if c[i]==c[i-1]:#同じ色が続くとリバーシできない
        dp[i] = dp[i-1]
    else:
        if last_color[c[i]]==-1:#初めての色はリバーシできない
            dp[i] = dp[i-1]
            last_color[c[i]]=i
        else:#挟める石があるし色が連続してない
            dp[i] = dp[i-1]+dp[last_color[c[i]]]#最後に出た石と挟むか挟まないk
            last_color[c[i]]=i
print(dp[N-1]%m)


Measured memory_bytes: 766492
# A - Range Flip Find Route
h,w=map(int,input().split())
s=[input() for i in range(h)]
inf=10**18
dp=[[inf]*(w+1) for i in range(h+1)]
if s[0][0]=="#":
  dp[0][0]=1
else:
  dp[0][0]=0

for i in range(h):
  for j in range(w):
    for y,x in ([1,0],[0,1]):
      ni,nj=i+y,j+x
      if ni>=h or nj>=w:continue
      c=0
      if s[ni][nj]=="#" and s[i][j]==".":c=1
      dp[ni][nj]=min(dp[ni][nj],dp[i][j]+c)

print(dp[h-1][w-1])


Measured memory_bytes: 3064
s = input()

s01 = ''
s10 = ''
for i in range(len(s)):
    if i % 2 == 0:
        s01 += '0'
        s10 += '1'
    else:
        s01 += '1'
        s10 += '0'

cnt01 = 0
cnt10 = 0
for i in range(len(s)):
    if s[i] != s01[i]:
        cnt01 += 1
    if s[i] != s10[i]:
        cnt10 += 1

if cnt01 > cnt10:
    print(cnt10)
else:
    print(cnt01)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using P = pair<int, int>;

signed main() {
  int N;cin >>N;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S[i] << T[i];
  }
  cout << endl;
}

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

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> target;
    vector<double> probs;
    double prob = 1;
    int preb = 0;
    while(k > 0)
    {
        if(k == preb)
        {
            break;
        }
        target.push_back(k);
        probs.push_back(prob);
        prob /= 2;
        preb = k;
        k = ceil(k/2.0);
    }

    // for(int j = 0; j < (int)target.size(); ++j)
    // {
    //     cout << "target: " << target[j] << endl;
    //     cout << "probs: " << probs[j] << endl;
    // }

    double ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        double p = 0;
        for(int j = 0; j < (int)target.size(); ++j)
        {
            int t = target[j];
            if(t <= i)
            {
                p = probs[j];
                break;
            }
        }
        ans += p / n;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/03/24
 *      Author: londo
 */
/*
 * main.c
 *
 *  Created on: 2019/03/09
 *      Author: londo
 */
#include<stdio.h>

int main(){
	char ch;
	scanf("%c",&ch);
	if(ch == 'A')printf("T\n");
	if(ch == 'T')printf("A\n");
	if(ch == 'G')printf("C\n");
	if(ch == 'C')printf("G\n");

	return 0;
}









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

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  rep (i, n+1) {
    rep (j, m+1) {
      if (i * (m-j) + j * (n-i) == k) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    double tmp = 0;
    rep(i, n) {
        tmp += 1.0/a[i];
    }

    printf("%.10f\n", 1.0/tmp);
}

Measured memory_bytes: 256
s=input()
n=len(s)
w2019=[1]
i=0
for i in range(i,n):
  w2019.append((w2019[-1]*10)%2019)
v=[int(s[-1])]
for i in range(1,n):
  v.append((v[-1]+int(s[-(i+1)])*w2019[i])%2019)
v.sort()
cnt=0
co=0
if v[0]==0: cnt+=1
for i in range(1,n):
  if v[i]==v[i-1]: co+=1
  elif co!=0:
    cnt+=co*(co+1)//2
    co=0
  if v[i]==0: cnt+=1
cnt+=co*(co+1)//2
print(cnt)

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

int main() {
  
  int a, b;
  cin >> a >> b;
 
  if(a==1) a+=13;
  if(b==1) b+=13;
  
  if(a>b) cout << "Alice" << endl;
  else if(a<b) cout << "Bob" << endl;
  else cout << "Draw" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll k;
        cin >> k;
        ll rem = 0;
        for(i = 1; i <= k; i++){
            rem = rem * 10 + 7;
            rem %= k;
            if(rem == 0){
                cout << i;
                return 0;
            }
        }
        cout << -1;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
// use gp_hash_table<int,int,custom_hash> m;
// in place of map
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
// This custom_hash is for unordered_map 
// use map<int, int, custom_hash> mp;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	rep(i,n){
		cout<<s[i]<<t[i];
	}	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    if(a+b >= 10){
        print("error");
    }else{
        print(a+b);
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

class UnionFindTree {
private:
  vector<int> par;
  vector<int> rnk;
  vector<int> siz;

public:
  UnionFindTree(int n) {
    par.assign(n, -1);
    rnk.assign(n, -1);
    siz.assign(n, -1);

    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
      siz[i] = 1;
    }
  }

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

  bool same(int x, int y) { return find(x) == find(y); }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rnk[x] < rnk[y]) {
      par[x] = y;
      siz[y] += siz[x];
    } else {
      par[y] = x;
      siz[x] += siz[y];
      if (rnk[x] == rnk[y])
        ++rnk[x];
    }
  }

  int size(int x) {
    x = find(x);
    return siz[x];
  }
};

void solve(long long N, long long M, std::vector<long long> X,
           std::vector<long long> Y, std::vector<long long> Z) {

  UnionFindTree uf(N + 1);
  rep(m, M) { uf.unite(X[m], Y[m]); }

  set<ll> parents;
  for (ll n = 1; n <= N; n++) {
    parents.insert(uf.find(n));
  }

  print(parents.size());
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> X(M);
  std::vector<long long> Y(M);
  std::vector<long long> Z(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &X[i]);
    scanf("%lld", &Y[i]);
    scanf("%lld", &Z[i]);
  }
  solve(N, M, std::move(X), std::move(Y), std::move(Z));
  return 0;
}


Measured memory_bytes: 8448
import java.util.*;

public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String a = sc.next();
      String b = sc.next();
      String c = sc.next();
      int alen = a.length();
      String al = a.substring(alen-1,alen);
      String bf = b.substring(0,1);
      int blen = b.length();
      String bl = b.substring(blen-1,blen);
      String cf = c.substring(0,1);
      if(al.equals(bf) && bl.equals(cf)){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
  }
}

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

ll func(int i, ll cur, ll sum, const string &s) {
	if (i == s.length()) {
		return sum;
	}
	int d = s[i] - '0';
	ll a = 0;
	if (i + 1 != s.length()) {
		a += func(i + 1, cur * 10 + d, sum, s);
	}
	a += func(i + 1, 0, sum + cur * 10 + d, s);
	return a;
}

int main() {
	string s;
	cin >> s;
	ll ans = func(0, 0, 0, s);
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    // 入力値
    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    bool has_odd = false;
    int count = 0;
    while (true) {
        for (int i = 0; i < N; i++) {
            if (A.at(i) % 2) has_odd = true;
        }

        if (has_odd) break;

        for (int i = 0; i < N; i++) {
            A.at(i) /= 2;
        }
        count++;
    }

    // 出力値
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define bf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double d;
#define MAX 1000001
#define MIN -1
#define mod 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> Vector;
typedef queue<ll > Queue;
typedef stack<ll> Stack;
typedef pair<ll,ll> Pair;
#define mp make_pair
#define pb push_back
vector< pair<ll,ll> > v;
bool vis[MAX];
ll ar[MAX];
int main(){
    bf;
    ll i,j,m,k,s,c,t,n,ans=0,lans=0; 
    cin>>s>>c;
    ans=c/4;
    if(c%4>1&&s>0) ans++;
    if(s<=c/2) {lans+=s; c-=s*2;
        lans+=c/4;
    }
    else{
        lans=c/2;
    }
    ans=max(ans,lans);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;
    int A[N];
    
    rep(ni,N) cin >> A[ni];

    int n1=0;
    int n2=1;
    if(A[n1]<A[n2]){
        n1 = 1;
        n2 = 0;
    }
    for( int ni = 2 ; ni <N ; ni++ ){
        if(A[ni]>A[n1]){
            n2 = n1;
            n1 = ni;
        }else if(A[ni] > A[n2]){
            n2 = ni;
        }
    }
    rep(ni,N){
        if(ni==n1) cout << A[n2] << endl;
        else cout << A[n1] << endl;
    }


}

Measured memory_bytes: 2432
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(0,N-1):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        A[i],A[minj] = A[minj],A[i]
        count += 1
print(*A)
print(count)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
main(){
  long long n;
  long long a[100005]={0};
  cin>>n;
  long long ans=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(a[a[i]]==i){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int ans=INF;
    for(int i=1;i*i<=N;i++){
        if(N%i==0){
            int cx=0;
            int cy=0;
            int x=N/i;
            int y=i;
            while(x>0){
                x/=10;
                cx++;
            }
            while(y>0){
                y/=10;
                cy++;
            }
            int cou=max(cx,cy);
            ans=min(ans,cou);
        }
    }
    cout << ans << endl;




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;
int aray[200005];
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, K; cin >> N >> K;
    ll v = 0, bes = 0; int cnt = 0;
    rep(i, N) {
        cin >> aray[i]; aray[i]++;
        v += aray[i];
        bes = max(bes, v);
        cnt++;
        if(cnt == K) {
            v -= aray[i-K+1];
            cnt--;
        }
    }
    cout << bes/2;
    if(bes%2) cout << ".5";
    cout << endl;
}

Measured memory_bytes: 4396
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

int compress(int n, vector<int>& a, vector<int>& b) {
	vector<int> c;
	for (int i = 0; i < n; i++) {
		c.push_back(a[i]);
		c.push_back(b[i]);
	}
	sort(c.begin(), c.end());
	c.erase(unique(c.begin(), c.end()), c.end());
	for (int i = 0; i < n; i++) {
		a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
		b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
	}
	return c.size();
}

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

void dfs(int x, int y, vector< vector<bool> >& a) {
	int h = a.size(), w = a[0].size();
	a[y][x] = true;
	for (int k = 0; k < 4; k++) {
		int _x = x + dx[k], _y = y + dy[k];
		if (_x >= 0 && _x < w && _y >= 0 && _y < h && !a[_y][_x])
			dfs(_x, _y, a);
	}
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<int> l(n), t(n), r(n), b(n);
		for (int i = 0; i < n; i++)
			cin >> l[i] >> t[i] >> r[i] >> b[i];
		int w = compress(n, l, r), h = compress(n, t, b);
		vector< vector<bool> > a(h * 2 + 1, vector<bool>(w * 2 + 1));
		for (int i = 0; i < n; i++) {
			l[i] = l[i] * 2 + 1; t[i] = t[i] * 2 + 1;
			r[i] = r[i] * 2 + 1; b[i] = b[i] * 2 + 1;
			for (int y = b[i]; y <= t[i]; y++)
				a[y][l[i]] = a[y][r[i]] = true;
			for (int x = l[i]; x <= r[i]; x++)
				a[t[i]][x] = a[b[i]][x] = true;
		}
		/*for (int y = 0; y < h * 2 + 1; y++) {
			for (int x = 0; x < w * 2 + 1; x++)
				cout << (a[y][x] ? '#' : '.');
			cout << endl;
		}*/
		int cnt = 0;
		for (int y = 0; y < h * 2 + 1; y++)
			for (int x = 0; x < w * 2 + 1; x++)
				if (!a[y][x]) {
					cnt++;
					dfs(x, y, a);
				}
		cout << cnt << endl;
	}
}

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

int main(){
	int n,i,c;
	vector<int> vec;
	cin >> n;
	for(i = 0;i < n;i++){
		cin >> c;
		vec.push_back(c);
	}
	sort(vec.begin(),vec.end());
	cout << vec[n-1] - vec[0] << endl;
	return 0;
}


Measured memory_bytes: 256
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	a := sc.i()

	fmt.Println(a + a*a + a*a*a)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 102030405060708090

int main()
{
  int n;cin>>n;
  vector<ll> a(n);
  int i,j,k;
  rep(i,n)cin>>a[i];
  vector<vector<ll>> dp(n,vector<ll>(n,INF));
  vector<ll> sum(n+1,0);
  rep(i,n)sum[i+1]=sum[i]+a[i];
  rep(i,n)dp[i][i]=0;
  for(i=1;i<n;i++)
  {
    rep(j,n-i)
    {
      for(k=j;k<j+i;k++)
      {
        dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+sum[j+i+1]-sum[j]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
}


Measured memory_bytes: 1536
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;



int main()
{



     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

     
ll n;
string s;
cin>>n;
cin>>s;
if(n%2!=0)
{
	cout<<"No"<<endl;
}
else
{
	ll i=0,j=n/2;
	bool flag=true;
	while(i<n/2&&j<n)
	{
		if(s[i]!=s[j])
		{
			flag=false;
			break;
		}
		else
		{
			i++;
			j++;
		}
	}
	if(flag==true)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}



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

     return 0;

}


Measured memory_bytes: 256
#include <iostream>

const int MOD=1000000007;
void extgcd(int a,int b,int *x,int *y) {
	if(a<b) {
		extgcd(b,a,y,x);
	} else {
		if(b==0) {
			*x=1;
			*y=0;
		} else {
			int xk,yk;
			extgcd(b,a%b,&xk,&yk);
			*x=yk;
			*y=xk-(a/b)*yk;
		}
	}
}
int inv(int vl) {
	int xk,yk;
	extgcd(vl,MOD,&xk,&yk);
	if(xk<0) xk+=MOD;
	return xk;
}
int fact[100008];
int comb(int n,int k) {
	if(n<0||k<0||n<k) return 0;
	long long ret=fact[n];
	ret*=inv(fact[k]);
	ret%=MOD;
	ret*=inv(fact[n-k]);
	ret%=MOD;
	return ret;
}
using namespace std;
int main() {
	int n;
	cin>>n;
	int vl[100008];
	int count[100008];
	fact[0]=1;
	for(int i=1;i<=n;i++) {
		count[i]=0;
		fact[i]=((long long)fact[i-1]*i)%MOD;
	}
	int dbl=0;
	for(int i=0;i<=n;i++) {
		cin >> vl[i];
		count[vl[i]]++;
		if(count[vl[i]]>1) dbl=vl[i];
	}
	int lf,rg;
	lf=-1;
	for(int i=0;i<=n;i++) {
		if(vl[i]==dbl) {
			if(lf<0) {
				lf=i;
			} else {
				rg=i;
			}
		}
	}
	for(int k=1;k<=n+1;k++) {
		//zero
		int sol=comb(n-1,k);
		//one
		sol=(sol+comb(n-1,k-1))%MOD;
		if(k>1) {
			sol=(sol+comb(n-1,k-1))%MOD;
			sol=(sol+MOD-comb(lf+n-rg,k-1))%MOD;
		}
		//two
		sol=(sol+comb(n-1,k-2))%MOD;
		cout << sol << endl;
	}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];

  map<i64, i64> sum;
  for (i64 i = 0; i < N; i++)
    sum[(i + 1) - A[i]]++;
  i64 ans = 0;
  for (i64 i = 0; i < N; i++)
    ans += sum[A[i] + (i + 1)];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<17, mod = 1e9 + 7, i2 = (mod+1)/2;
ll n, a, b, h[maxn];
bool can(ll x) {
	ll t = 0;
	for(int i = 0; i < n; i++) t += (max(0ll, h[i] - x*b)+a-1)/a;
	return t <= x;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> a >> b;
	a -= b;
	for(int i = 0; i < n; i++) cin >> h[i];
	int ans = 0;
	for(ll i = 1ll<<50; i>>=1;)
		if(!can(ans+i)) ans += i;
	cout << ans+1;
	return 0;
}


Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#define ll long long
using namespace std;

int main()
{
    ll n,ans=0;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        mp[a[i]]++;
    }
    for(auto x:mp){
        if(x.second%2==1){
            ans++;
        }
    }
    cout << ans << endl;
}


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

using ll = long long;

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

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

int main() {
  ll A, B;
  scanf("%lld%lld", &A, &B);
  ll ans = lcm(A, B);
  printf("%lld", ans);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const ll MAXN = 50 + 5;
const ll MAXK = 1e5 + 10;

int main() {
    ll N, W;
    cin >> N >> W;
    vll weight(N);
    vll value(N);
    for (int i = 0; i < N; ++i) {
        cin >> weight[i] >> value[i];
    }
    vector<vector<ll>> dp(N + 1, vector<ll>(MAXK));
    fill(dp[0].begin(), dp[0].end(), INF);
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < MAXK; ++j) {
            if (j < value[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < MAXK; ++i) {
        if (dp[N][i] <= W) {
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
N=int(input())
#print(A,B)

cond=0
if N>81:
  print('No')
elif N<10:
  print('Yes')
else: 
  for j in range(2,10):
    if N%j ==0 and N//j <=9:
      print('Yes')
      cond=1
      break
  if cond==0:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int main(void){
	int tot = 0,n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		if(e%2==0&&r%2) tot++;
	}
	printf("%d",tot);
	return 0;
}


Measured memory_bytes: 3820
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

def main():
    Q = int(input())
    for _ in range(Q):
        n = input()
        count = 0
        while len(n) > 1:
            if count == 1000000:
                count = -1
                break
            tmp = 0
            for i in range(1,len(n)):
                tmp = max(tmp, int(n[:i])*int(n[i:]))
            count += 1
            n = str(tmp)
        print(count) 

if __name__ == '__main__':
    main()



Measured memory_bytes: 6896
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100010],ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    ans=a[n-1]+a[n-2]-(a[0]*2);
    for(int i=1;i<n/2;i++)ans+=a[n-i-2]+a[n-i]-(a[i]*2);
    if(n%2&&a[n/2+1]-a[n/2]>a[n/2]-a[n/2-1])ans+=a[n/2+1]+a[n/2-1]-(a[n/2]*2);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	bool used[1001];
	int n,m;
	while(cin>>n>>m,n) 
	{
		fill(used,used+1001,0);
		int cnt=0,now=n;
		while(cnt<n-1) 
		{
			int mcnt=0;
			while(mcnt<m)
			{
				now=(now+1)%n;
				if(used[now]) continue;
				mcnt++;
			}
			cnt++;
			//cout<<"cnt="<<cnt<<",now="<<now<<endl;
			used[now]=true;
		}
		for(int i = 1; i <= n; ++i)
		{
			if(!used[i]) 
			{
				cout<<i<<endl;
				break;
			}
		}
	}
  return 0;
}

Measured memory_bytes: 1160
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
i = 0
count = 0
while i < N:
    A = list(map(int, input().split()))
#    print ('A', A)
    j = 1
    ans = C
    while j <= M:
        ans +=  A[j-1] * B[j-1]
        j += 1
#    print (ans)
    if ans > 0:
        count += 1
    i += 1
print (count) 

Measured memory_bytes: 3188
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define curr first
#define prev second 
typedef pair<int, int> P;
typedef vector<bool> vec;
typedef vector<vec> mat;

long long n;
int H, W;

//A*B
mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  REP(i, A.size())
    REP(k, B.size())
    REP(j, B[0].size())
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
  return C;
}

//A^n
mat pow(mat A, long long n){
  mat B(A.size(), vec(A.size()));
  REP(i, A.size())
    B[i][i] = 1;
  while(n > 0){
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

bool check(int N, mat &A, vector<P> &v){
  REP(i, A[0].size()) if(A[0][i] && v[i].curr == N - 1) return true;
  return false;
}

void disp(mat &A, vector<P> &v){
  cout <<"-------" <<endl;
  REP(i, v.size()) cout <<"curr = " <<v[i].curr <<", prev = " <<v[i].prev <<endl;
  REP(i, A.size()) REP(j, A[i].size()) if(A[i][j]) cout <<"(curr = " <<v[i].curr <<", prev = " <<v[i].prev <<") -> " <<"(curr = " <<v[j].curr <<", prev = " <<v[j].prev <<")" <<endl;
  REP(i, A.size()){
    REP(j, A[i].size()) cout <<A[i][j] <<" ";
    cout <<endl;
  }
}

int main() {
  int N, M, Z;
  while(cin >>N >>M >>Z && (N | M | Z)){
    vector< vector<bool> > G(N, vector<bool>(N));
    vector<P> v(M * 2 + 1);
    v[0].curr = 0;
    v[0].prev = -1;
    FOR(i, 1, M + 1){
      cin >>v[i].prev >>v[i].curr;
      v[i].prev--; v[i].curr--;
      v[i + M].curr = v[i].prev;
      v[i + M].prev = v[i].curr;
      G[v[i].prev][v[i].curr] = G[v[i].curr][v[i].prev] = 1;
    }
    mat A(M * 2 + 1, vec(M * 2 + 1, 0));
    REP(i, M * 2 + 1){
      REP(j, M * 2 + 1){
        if(G[v[i].curr][v[j].curr] && v[i].curr == v[j].prev && v[i].prev != v[j].curr) A[i][j] = 1;
      }
    }
    //disp(A, v);
    A = pow(A, Z);
    cout <<(check(N, A, v) ? "yes" : "no") <<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; ll a,b; cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i,0,n) cin >> x[i];
    ll ans = 0;
    rep(i,0,n-1){
        ans += min((x[i+1]-x[i])*a,b);
    }
    cout << ans << endl;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int a, b;
    cin >> a >> b;
    int mn;
    mn = min(a, b);
    if (a == mn)
    {
        rep(i, b)
        {
            cout << a;
        }
        cout << endl;
    }
    else
    {
        rep(i, a)
        {
            cout << b;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,c=0;
    cin>>n;
    ll a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[a[i]]==i)
            c++;
    }
    cout<<c/2<<endl;
}
return 0;
}

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

using namespace std;

int main()
{
    long long int n , i , j , k;
    cin>>n>>k;
    int h[n];
    vector<int> dp(n,INT_MAX);
    for( i = 0 ; i < n ; i++)cin>>h[i];
    dp[0]=0;
    for( i = 0 ; i < n ; i++)
    {   
       // cout<<dp[i]<<endl;
        for( j = i+1 ; j<=i+k ; j++)
        {
           if(j<n) dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024