akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

int main() {
  int n, q;
  cin >> n;
  vec<ll> S(n);
  REP(i, n) { cin >> S[i]; }
  cin >> q;
  vec<ll> T(q);
  REP(i, q) { cin >> T[i]; }
  ll answer = 0;
  REP(i, q) { answer += (binary_search(ALL(S), T[i]) ? 1 : 0); }
  cout << answer << endl;
  return 0;
}



Measured memory_bytes: 4016
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],br[N];
string s,s1;
//Variables End

int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		cin>>n>>k;    
		vi cost(n,0),dp(n,inf);
		rep(i,0,n)cin>>cost[i];
		dp[0]=0;
		rep(i,1,n)
		{
			rep(j,1,k+1)
			if(i-j>=0)
			{
				dp[i]=min(dp[i],dp[i-j]+abs(cost[i]-cost[i-j]));
			}
		}

		cout<<dp[n-1]<<endl;
    }
    return 0;
        
}

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

def f(x,m):
    return x%m

memo=[0 for i in range(M)]

A=[0 for i in range(100001)]
A[1]=X
memo[0]=1
memo[X]=1
b=0
s=1
for i in range(2,100001):
    A[i]=f(A[i-1]**2, M)
    if memo[A[i]]:
        memo[A[i]]=2
        b=A[i]
        s=i
        break
    else:
        memo[A[i]]=1

#周期突入前の部分を取得
mae=[]
m=0
while True:
    if A[m]==b and m!=0:
        break
    else:
        mae.append(A[m])
        m+=1
#print(mae)

#周期部分を取得
shuuki=A[len(mae):s]
if shuuki==[]:
    shuuki=[0]
#print(shuuki)

#print(b,s)


#周期数とあまりで答えを調整

ans=0
#1 周期に入る前におわるパターン
if N<=s-1:
    ans=sum(A[:N+1])
else:
    ans+=sum(mae)
    N-=len(mae)-1
    kai=N//len(shuuki)
    amari=N%len(shuuki)
    ans+=kai*sum(shuuki)
    ans+=sum(shuuki[:amari])

print(ans)

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

using namespace std;

int main() {
	bool accepted = true;
	int capitals = 0;
	int c_count = 0;
    string s = "";
    cin >> s;

	// Get the total number of capital letters
		for(int i = 0; i < s.length(); i++) {
			 if(s[i] >= 'A' && s[i] <= 'Z') {
			 	capitals++;
			 }
		}
		// Get the number of 'C's between the 3rd and 2nd to last
		for(int i = 2; i < s.length() - 1; i++) {
			 if(s[i] >= 'A' && s[i] <= 'Z') {
			 	c_count++;
			 }
		}

		/* Rules
		// First char must be 'A'
		// All chars other than 'A' and 'C' must be lowercase
		// One 'C' between the 3rd char and the second to last char */
		if(s[0] != 'A' || capitals != 2 || c_count != 1) {
			cout << "WA";
		}
		else {
			cout << "AC";
		}
    return 0;
}


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

int main() {
  int A, B, C, D, E;
  cin >> A;
  B = A/1000;
  C = A/100 - 10*B;
  E = A % 10;
  D = (A % 100 - E ) /10;
  
  if ( B == C && C==D ) {
    cout << "Yes" << endl;
  }
   else if ( D == E && C==D ) {
    cout << "Yes" << endl;
   }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0) break;
    for(i=0;i<H;i++){
      if(i==0||i==(H-1))
	for(j=0;j<W;j++)
	  printf("#");	
      else{
	printf("#");
	for(j=1;j<(W-1);j++)
	  printf(".");
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return(0);
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

struct Data{
  int a,b,c,d;
  Data(){}
  Data(int a,int b, int c,int d):
    a(a),b(b),c(c),d(d){}
  friend istream& operator>>(istream&is,Data&dt){
    is >> dt.a >> dt.b >> dt.c >> dt.d;
    dt.a--;dt.b--;
    return is;
  }
};

int n,m,q;
vector<Data> v;

int Rec(int i,vector<int>&ar){
  if(i == n){
    int sum = 0;
    for(auto e:v){
      auto [a,b,c,d] = e;
      if(ar[b] - ar[a] == c)sum += d;
    }
    return sum;
  }
  int j = (i == 0 ? 1 : ar[i-1]);
  int ret = 0;
  for(int k = j; k <= m; ++k){
    ar[i] = k;
    ret = max(ret,Rec(i+1,ar));
  }
  return ret;
}

int main(){
  cin >> n >> m >> q;
  v.resize(q); cin >> v;
  vector<int> ar(n,0);
  cout << Rec(0,ar) << endl;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a == b){
            System.out.println(c);
        } else if (a == c) {
            System.out.println(b);

        } else {
            System.out.println(a);

        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23252
N = int(input())
A = list(map(int, input().split()))
B = [[] for i in range(N)]
for i in range(N):
  B[i] = [A[i], i+1]
B.sort()
ans = [0 for i in range(N)]
for i in range(N):
  ans[i] = B[i][1]
print(*ans)

Measured memory_bytes: 98804
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> odd, even;
    rep(i,n){
        int a;
        cin >> a;
        if(i%2 == 0) even[a]++;
        else odd[a]++;
    }
    int modd = 0, meven = 0, m2odd = 0, m2even = 0, odd_num = -1, even_num = -1;
    for(auto p : odd){
        if(p.second > modd){
            m2odd = modd;
            modd = p.second;
            odd_num = p.first;
        }
        else if(p.second > m2odd){
            m2odd = p.second;
        }
    }
    for(auto p : even){
        if(p.second > meven){
            m2even = meven;
            meven = p.second;
            even_num = p.first;
        }
        else if(p.second > m2even){
            m2even = p.second;
        }
    }
    int ans;
    if(odd_num != even_num){
        ans = n - modd - meven;
    }
    else{
        ans = n - m2odd - meven;
        chmin(ans, n - modd - m2even);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
using namespace std;


int main()
{
	int nW, nH;
	while (cin >> nW >> nH)
	{
		if (0 == nW && 0 == nH)
		{
			break;
		}
		for (int i = 0; i < nW; ++i)
		{
			for (int j = 0; j < nH; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;

	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 3048
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a[]=new int [3];
		a[0]=scanner.nextInt();
		a[1]=scanner.nextInt();
		a[2]=scanner.nextInt();
		Arrays.sort(a);
		
		System.out.println((a[2]-a[1])+a[1]-a[0]);
	}
}


Measured memory_bytes: 21844
import heapq

if __name__ == '__main__':
    X, Y, Z = list(map(int, input().split()))
    A = []
    B = []
    C = []
    N = X + Y + Z
    for i in range(N):
        tmp_a, tmp_b, tmp_c = list(map(int, input().split()))
        A.append(tmp_a)
        B.append(tmp_b)
        C.append(tmp_c)

    gold_minus_silver = [(a - b, a, b, c) for (a, b, c) in zip(A, B, C)]
    gold_minus_silver.sort()
    # print(gold_minus_silver)

    # 左側
    left_side = []
    for i in range(0, Y):
        heapq.heappush(left_side, (
            gold_minus_silver[i][2] - gold_minus_silver[i][3], gold_minus_silver[i][2], gold_minus_silver[i][3]))

    left_max = [0 for i in range(Z + 1)]
    for i in range(0, Y):
        left_max[0] += left_side[i][1]
    left_bronze = []
    for K in range(1, Z + 1):
        heapq.heappush(left_side, (gold_minus_silver[K + Y - 1][2] - gold_minus_silver[K + Y - 1][3],
                                   gold_minus_silver[K + Y - 1][2],
                                   gold_minus_silver[K + Y - 1][3]))
        left_max[K] = left_max[K - 1] + gold_minus_silver[K + Y - 1][2]
        bronze = heapq.heappop(left_side)
        left_max[K] += (bronze[2] - bronze[1])


        # print(left_max)
    # 右側
    right_side = []
    for i in range(Y + Z, N):
        heapq.heappush(right_side, (gold_minus_silver[i][1] - gold_minus_silver[i][3], gold_minus_silver[i][1],
                                    gold_minus_silver[i][3]))
    right_max = [0 for i in range(Z + 1)]
    for i in range(0, X):
        right_max[Z] += right_side[i][1]
    right_bronze = []
    for K in range(Z - 1, -1, -1):
        heapq.heappush(right_side, (gold_minus_silver[K + Y][1] - gold_minus_silver[K + Y][3],
                                    gold_minus_silver[K + Y][1],
                                    gold_minus_silver[K + Y][3]))
        right_max[K] = right_max[K + 1] + gold_minus_silver[K + Y][1]
        bronze = heapq.heappop(right_side)
        right_max[K] += (bronze[2] - bronze[1])

    # print(right_max)

    ans = 0
    for i in range(0, Z + 1):
        if ans < left_max[i] + right_max[i]:
            ans = left_max[i] + right_max[i]

    print(ans)


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

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  long long int a,b,c;
  cin>>a>>b;
  c=a*b;
  cout<<c<<endl;
    
    
    
return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
  
ll mod=1000000007;
  
ll add(ll a,ll b){
  return (a+b+mod+mod)%mod;
}
ll mul(ll a,ll b){
  return (a*b)%mod;
}
  
ll dp[51][51][21][27];
int n;
bool f[50][21];
char t[50][21];
  
ll rec(int ay,int by,int x,char ch){
  //    cout<<ay<<' '<<by<<' '<<x<<' '<<ch<<endl;
 
  if(ay==by)return 1;

  bool flag=true;
  for(int i=ay;i<by;i++)
    if(f[i][x]==true)
      flag=false;
  
  if(flag){
    if(ay+1==by)return  1;
    else return 0;
  }
  
  for(int i=ay+1;i<by;i++){
    if(f[i][x]==false)return 0;
  }

  if(f[ay][x]==false){
    return rec(ay+1,by,x,ch);
  }

  //cout<<'a'<<endl;  
  if(ch>'z')return 0;

  int CH=ch-'a';
  if(dp[ay][by][x][CH]!=-1)return dp[ay][by][x][CH];




  ll res=rec(ay,by,x,ch+1);
  
  
  int next=ay;
  for(int i=ay;i<by;i++){
    if(t[i][x]==ch)next=i;
  }
    
  for(int i=ay;i<next;i++){
    if(t[i][x]!=ch&&t[i][x]!='?')
      return 0;
  }
  
  for(int i=next;i<by;i++){
    if(t[i][x]!='?'&&t[i][x]!=ch)break;
    res=add(res, mul( rec(ay,i+1,x+1,'a') , rec(i+1,by,x,ch+1)) );
  }
 
 
  //  if(res>0){
  // cout<<ay<<' '<<by<<' '<<x<<' '<<CH<<endl;
	//  }
  return dp[ay][by][x][CH]=res;
}
  
  
  
int main(){
  for(int i=0;i<51;i++)
    for(int j=0;j<51;j++)
      for(int k=0;k<21;k++)
	for(int l=0;l<27;l++)
	  dp[i][j][k][l]=-1;
    
  for(int i=0;i<50;i++){
    for(int j=0;j<21;j++){
      t[i][j]='a';
      f[i][j]=false;
    }
  }
  string str;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    for(int j=0;j<(int)str.size();j++){
      t[i][j]=str[j];
      f[i][j]=true;
    }
  }

  //cout<<rec(1,3,0,'b')<<'-'<<endl;

  cout<<rec(0,n,0,'a')<<endl;
  return 0;
}

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

#define pi acos(-1.0)
#define pii pair<int, int>
#define mod 1000000007
#define MAX 1000000
#define pb push_back
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define dbg1(a) printf("yo is %d\n",a)
#define dbg2(a, b) printf("yo is %d %d\n",a ,b)
#define mem(ara,val) memset(ara,val,sizeof(ara))

using namespace std;
typedef long long ll;
typedef vector<int> vi;

int a[100010];

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k;
    cin>>n>>k;
    int idx;
    FOR(i, 1, n)
    {
        scanf("%d", &a[i]);
        if(a[i]==1)
        {
            idx = i;
        }
    }
    int res = 0;
    for(int i=1; i<n;)
    {
        i += k;
        i--;
        res++;
    }
    printf("%d\n", res);
   // main();
    return 0;
}




Measured memory_bytes: 640
N = int(input())
H = list(map(int, input().split()))

tmp = 0
ans = -1
for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0

ans = max(ans, tmp)

print(ans)

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

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

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  string s;
  cin >> s;

  int ans = 0;
  int a = 0;
  REP(i, s.size()) {
    if (s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T')
      a++;
    else {
      ans = max(a, ans);
      a = 0;
    }
  }

  cout << max(ans, a) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

void solve(double a, double b, double c, double d, double p, double q, double *x, double *y){
    *x = (p * d - b * q) / (a * d - b * c);
    *y = (a * q - p * c) / (a * d - b * c);
}

int main(){
    int n;
    double x1, y1, x2, y2, x3, y3, xp, yp, r, d12, d23, d31;
    
    std::cin >> n;
    for(int i=0; i<n; i++){
        std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        solve(2 * (x1 - x2), 2 * (y1 - y2), 2 * (x1 - x3), 2 * (y1 - y3),
            pow(x1, 2) + pow(y1, 2) - pow(x2, 2) - pow(y2, 2),
            pow(x1, 2) + pow(y1, 2) - pow(x3, 2) - pow(y3, 2), &xp, &yp);
        d12 = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
        d23 = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
        d31 = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2));
        r = d12 * d23 * d31 / sqrt((d12 + d23 + d31)*(-d12 + d23 + d31)*(d12 - d23 + d31)*(d12 + d23 - d31));
        std::cout << std::fixed << std::setprecision(3)
            << xp << ' ' << yp << ' ' << r << std::endl;
    }
}

Measured memory_bytes: 1292
import sys
import math
n, m = map(int, input().split())

if abs(n - m) > 1:
    print(0)
    sys.exit()

large = max(n, m)
small = min(n, m)

if large == small:
    ans = 2 * large**2 * math.factorial(large - 1)**2 % (10**9 + 7)
else:
    ans = large * math.factorial(small)**2 % (10**9 + 7)

print(ans)

Measured memory_bytes: 4740
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=11e4,M=N<<1;

int f[N],fa[N];
int ne[M],lb[M],la[N];
int n,oo;

inline void llb(int a,int b)
{ne[++oo]=la[a]; la[a]=oo; lb[oo]=b;}
 
inline int read()
{
	int o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+ch-48;
	return o;
} 

void dfs(int o)
{
	int u=0;
	for(int y=la[o];y;y=ne[y])
	if(!fa[lb[y]]){
		fa[lb[y]]=o,dfs(lb[y]);
		u|=(f[o]&f[lb[y]]);
		f[o]|=f[lb[y]];
	}
	int k=1;
	while(k<=u||(f[o]&k)>0)f[o]^=(k&f[o]),k<<=1;
	f[o]^=k;
}

int main()
{
	cin>>n; int a,b;
	fo(i,1,n-1)a=read(),b=read(),llb(a,b),llb(b,a);
	fa[1]=-1; dfs(1);
	int k=1,p=0;
	while(k<=f[1])k<<=1,++p;
	cout<<p-1;
}

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

using namespace std;

#define MAX 100010

int main(){
  int N,W,H;
  int X[MAX],Y[MAX];
  for(int i = 0 ; i < MAX ; i++){
    X[i] = Y[i] = 0;
  }
  cin >> N >> W >> H;
  for(int i = 0 ; i < N ; i++){
    int x,y,w;
    cin >> x >> y >> w;
    X[max(0,x-w)]++;
    Y[max(0,y-w)]++;
    X[min(W,x+w)]--;
    Y[min(H,y+w)]--;
  }
  for(int i = 0 ; i < W ; i++){
    X[i+1] += X[i];
  }
  for(int i = 0 ; i < H ; i++){
    Y[i+1] += Y[i];
  }
  bool can = false, f = true;
  for(int i = 0 ; i < W ; i++){
    if(X[i] == 0){
      f = false;
      break;
    }
  }
  can |= f; f = true;
  for(int i = 0 ; i < H ; i++){
    if(Y[i] == 0){
      f = false;
      break;
    }
  }
  can |= f;
  cout << (can ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 1936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,c;
	while(cin>>a>>b>>c)
	{
		if(a==b)cout<<c<<endl;
		else if(a==c)cout<<b<<endl;
		else if(b==c)cout<<a<<endl;
	}
	return 0;
}


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

using ll = int_fast64_t;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repr(i,n) for(int i{n};i-->0;)

signed main(){

  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  vector<int> win(3e5);
  rep(i,k){
    if(win[i])continue;
    for(auto ai:a)win[i+ai] = 1;
  }
  cout<<(win[k]?"First":"Second")<<endl;

}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] W = new int[N];
            for(int i = 0; i < N; i++)
            {
                W[i] = int.Parse(str[i]);
            }

            int min = int.MaxValue;
            int sum = W.Sum();

            for(int i = 1; i < N; i++)
            {
                //int[] a = new int[i];
                //int[] b = new int[N - i];
                
                int asum = 0;
                int bsum = 0;

                for (int j = 0; j < i; j++)
                {
                    asum += W[j];
                }

                bsum = sum - asum;

                int score = Math.Abs(asum - bsum);
                if (min > score)
                {
                    min = score;
                }
                else
                {
                    break;
                }
            }

            Console.Write(min);
        }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

class Node{
	int Hcover;
	int Lcover; 
	int min;
	Node parent;
	Node left;
	Node right;
	public Node(){
		parent=null;
		left=null;
		right=null;
	}
	
	public Node(int l,int h,int m){
		Hcover=h;
		Lcover=l;
		min=m;
		parent=null;
		left=null;
		right=null;
	}

	public boolean between(int a){
		return (Lcover<=a)&&(a<=Hcover);
	}
}

public class Main {
	static Node table[]=new Node[100001];

	public static Node cousei(Node n,int l,int h,int m){
		Node mob=new Node(l,h,m);
		mob.parent=n;
		if(h>l){
			mob.left=cousei(mob,l, (h+l)/2, m);
			mob.right=cousei(mob,(h+l)/2+1, h, m);
		}
		if(h==l) table[h]=mob;
		return mob;
	}

	public static int find(Node n,int l,int h){
		//System.out.println("f:"+n.Lcover+"to"+n.Hcover+":"+n.min+"::"+l+"to"+h);
		if(n.Lcover==l&&n.Hcover==h)return n.min;

		if(n.left.between(l)&&n.left.between(h)){
			return find(n.left, l, h);
		}else if(n.right.between(l)&&n.right.between(h)){
			return find(n.right, l, h);
		}else{
			return Math.min(find(n.left, l, n.left.Hcover), find(n.right, n.right.Lcover,h));
		}
	}

	public static void update(Node n,int p,int x,int bef){
		//int i=0;
		for(Node it=n;it!=null;it=it.parent){
			//i++;
			//System.out.println(i+"??????");
				it.min=Math.min(it.left.min, it.right.min);
		}
	}
	public static void prin(Node n){
		//System.out.println(n.Lcover+"to"+n.Hcover+":"+n.min);
		if(n.Hcover==n.Lcover)return;
		prin(n.left);
		prin(n.right);
	}

	public static void main(String[] args) {
		Node root=new Node();
		int n;
		int q;
		Scanner stdin=new Scanner(System.in);
		n=stdin.nextInt();
		q=stdin.nextInt();
		root.min=(1<<31)-1;
		root.Hcover=n;
		root.Lcover=1;
		root.parent=null;
		root.left=cousei(root,1,(n+1)/2,root.min);
		root.right=cousei(root,(n+1)/2+1,n,root.min);
		for(int XXX=0;XXX<q;XXX++){
			int com=stdin.nextInt();
			int x=stdin.nextInt();
			int y=stdin.nextInt();
			x++;
			if(com==0){
				// update
				int m=table[x].min;
				table[x].min=y;
				update(table[x].parent, x, y,m);
				//prin(root);
			}else{
				// find
				y++;
				System.out.println(find(root, x, y));
			}
		}
		stdin.close();
	}

}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

const ll MOD = 1e9+7;

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

  int N;
  cin >> N;
  vector<ll> C(N);
  for(int i = 0; i < N; i++) cin >> C[i];

  sort(C.rbegin(), C.rend());

  ll ans = 0;
  for(int i = 0; i < N; i++){

    ans = (ans + (i+2) * C[i]) % MOD;

  }

  ans = (ans * modpow(4, N-1, MOD)) % MOD;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

int main(void){
    int A, B, H, M;
    scanf("%d %d %d %d", &A, &B, &H, &M);
    double kA, kB;
    kA = 0.5 * (60 * H + M);
    kB = 6 * M;
    double kgap;
    kgap = kA > kB ? kA - kB : kB - kA;
    kgap = 180 < kgap ? 360 - kgap : kgap;
    kgap = M_PI / 180 * kgap;
    double x = cos(kgap);
    
    double answer = A * A + B * B - 2 * A * B * x;
    answer = sqrt(answer);
    printf("%5.9f", answer);
    
    return 0;

}


Measured memory_bytes: 2580
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

int n,a;
map <int,int> ma;

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		if(ma[a]==0)ma[a]++;
		else{
			printf("NO");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 9600
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = ii()
    B = ii()
    C = ii()
    X = ii()
    print(len([1 for a in range(A+1) for b in range(B+1) for c in range(C+1) if 500*a+100*b+50*c == X]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)


using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;


int main(){
	fast_io; cout_precision;
	int a,b,c;	cin  >> a >> b >> c;
	if(a-b>c)	c=0;
	else	c-=(a-b);
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    int n,d;
    cin >> n>>d;
    int ans = 0;
    rep(i,n) {
        double x,y;
        cin >> x >> y;
        double dd = sqrt(x*x+y*y);
        if(dd<=d)ans++; 
    }
    cout << ans << endl;
  return 0; 
}



Measured memory_bytes: 3840
#!/usr/bin/ruby
def dfs(q,z,c)
	r=[0,0,c]
	G[c].each{|e|
		next if e==z
		t=dfs(q,c,e)
		a=[t[0]+1,t[1]+(G[c].size==2 ? 1 : 0)]
		if a[q]>r[q]
			r=[*a,t[2]]
		end
	}
	r
end
N=gets.to_i
D=[0]*N
G=N.times.map{[]}
(N-1).times{
	a,b=gets.split.map(&:to_i)
	D[a-1]+=1
	D[b-1]+=1
	G[a-1]<<b-1
	G[b-1]<<a-1
}
x=dfs(1,-1,0)
x=dfs(1,-1,x[2])
p x[1]+D.count{|e|e==1}

Measured memory_bytes: 12668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	int a, b;
	cin >> a >> b;

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}

    return 0;
}

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

long long a[100054];
int b[100054];

int main() {
	int i, n = 0, m, x; long long s = 0, ans = LLONG_MAX; char op[4];
	for (scanf("%d%lld", &m, a); --m; )
		scanf("%s%d", op, &x), *op == 43 ? a[n] += x : (++n, a[n] = b[n] = x);
	for (++n, i = 1; i <= n; ++i) ans = std::min(ans, s + a[i]), s += b[i];
	printf("%lld\n", std::accumulate(a, a + n, -2 * ans));
	return 0;
}

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


int main() {
  ll n;
  cin >> n;
  vector<ll> A;
  for  (ll i = 2; i*i <= n; ++i) {
    if (n%i == 0) {
      A.push_back(i);
      if (i*i < n) {
        A.push_back(n/i);
      }
    }
  }

  auto f = [&](ll a, ll b) {
    while(a%b == 0) a /= b;
    if (a%b == 1) return 1;
    else return 0;
  };

  int ans = 1;
  for (ll x: A) {
    ans += f(n, x);
  }
  for  (ll i = 1; i*i <= n-1; ++i) {
    if ((n-1)%i == 0) {
      ++ans;
      if (i!=1 && i*i!=(n-1)) ++ans;
      if (i==1 && i*i==(n-1)) --ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 110

int n, W, w[MAXN], v[MAXN], dp[MAXN][MAXN][3 * MAXN], m, ans;

signed main()
{
    cin >> n >> W;
    for(int i = 0; i < n; i++){
        scanf("%lld %lld", w + i, v + i);
        if(i == 0){
            m = w[i];
        }
        w[i] -= m;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k <= 3 * n; k++){
                if((j + 1) * m + k > W){
                    dp[i + 1][j + 1][k] = 0;
                }
                else if(k < w[i]){
                    dp[i + 1][j + 1][k] = dp[i][j + 1][k];
                }
                else{
                    dp[i + 1][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k - w[i]] + v[i]);
                }
            }
        }
    }
    for(int j = 0; j <= n; j++){
        for(int k = 0; k <= 3 * n; k++){
            ans = max(ans, dp[n][j][k]);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 28544
inf=10**10
def knapsackBottomUp(wt,price,c,n,m):
    dp=[[inf for x in range(m+1)] for y in range(n+1)]
    for l in range(n+1):
        dp[l][0]=0


    for i in range(1,n+1):
        wi=wt[i];vi=price[i]
        for V in range(1,m+1):
            if vi <= V:
                dp[i][V]=min(wi+dp[i-1][V-vi],dp[i-1][V])
            else:
                dp[i][V]=dp[i-1][V]

    res=0
    for i in range(m+1):
        if dp[n][i]<=c:
            res=i
    print(res)
n,c=map(int,input().split())
wt=[]
price=[]
wt.append(0)
price.append(0)
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
max_val=sum(price)
knapsackBottomUp(wt,price,c,n,max_val)

Measured memory_bytes: 170992
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    if p[i]>p[i-1] and p[i]-1<p[i+1]:
        ans +=1
    elif p[i] > p[i + 1] and p[i] - 1 < p[i - 1]:
        ans +=1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1000001; 
  
int factor[MAX] = { 0 }; 
  
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    for (int i = 3; i * i < MAX; i++) { 
        if (factor[i] == i) { 
            for (int j = i * i; j < MAX; j += i) { 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
    int dup = factor[n]; 
    int c = 1; 
    int j = n / factor[n]; 
  
    while (j != 1) { 
        if (factor[j] == dup) 
            c += 1; 
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
        j = j / factor[j]; 
    } 
    ans = ans * (c + 1); 
  
    return ans; 
} 
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    generatePrimeFactors();
    int n;
    cin>>n;
    long long ans = 0;
    for(int i = 1; i < n; i++){
        ans += calculateNoOFactors(i);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7568
#include <stdio.h>
#include <stdlib.h>

int main()
{
	long int a, b, c, d;
	scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
    long max=0;
    /* printf("%ld", a);
    printf("%ld", b);
    printf("%ld", c);
    printf("%ld", d); */

    max=a*c;
    if(max<(a*d)) max=(a*d);
    if(max<(b*c)) max=(b*c);
    if(max<(b*d)) max=(b*d);
    
    printf("%ld", max);

}

Measured memory_bytes: 1732
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define UNVISITED -1

int cnt;
int tatami[20][20];

void solve(int r,int c,int now){
  int y=now/c,x=now%c;
  if ( r*c == now){
    cnt++;
    return;
  }

  if( tatami[y][x]!=UNVISITED){
    solve(r,c,now+1);
    return;
  }

  if (y != 0 && x>0){
    if ( tatami[y-1][x-1] != tatami[y-1][x] &&
	 tatami[y-1][x-1] != tatami[y][x-1])return;
  }

  if (y != r-1 ){
    tatami[y][x]=tatami[y+1][x]=now;
    solve(r,c,now+1);
    tatami[y][x]=tatami[y+1][x]=UNVISITED;
  }
  
  if ( x !=c-1 && tatami[y][x+1]==UNVISITED){
    tatami[y][x]=tatami[y][x+1]=now;
    solve(r,c,now+2);
    tatami[y][x]=tatami[y][x+1]=UNVISITED;
  }
  return;
}

main(){
  int r,c;
  while(cin>>r>>c && r){
    rep(i,r)rep(j,c)tatami[i][j]=-1;
    cnt=0;
    solve(r,c,0);
    cout << cnt << endl;
  }
}

Measured memory_bytes: 872
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void mmax(T &m, const T q) { if (m < q) m = q; }
template<typename T> void mmin(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    lint N;
    cin >> N;
    vector<lint> h(N + 1);
    REP(i, N){ cin >> h[i + 1]; }

    int ans = 0;
    REP(i, N) ans += max(h[i + 1] - h[i], 0LL);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010];
    ll b[100010];
    b[0]=1;
    rep2(i,1,100010){
        b[i]=b[i-1]*2;
        b[i]%=MOD;
    }
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    if(n%2==0){
        bool ok=true;
        for(ll i=1;i<n;i+=2){
            if(mp[i]!=2) ok=false;
        }
        if(ok) cout<<b[n/2]<<endl;
        else cout<<0<<endl;
    }
    else{
        bool ok=true;
        for(ll i=0;i<n;i+=2){
            if(i==0){
                if(mp[0]!=1) ok=false;
            }
            else if(mp[i]!=2) ok=false;
        }
        if(ok) cout<<b[n/2]<<endl;
        else cout<<0<<endl;
    }

    return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

ll K;
int N, nxt[maxn], b[maxn], vis[maxn];

int main() {
	
	// freopen("in.in", "r", stdin);
	scanf("%d%lld", &N, &K);
	for (int i = 1; i <= N; i++) scanf("%d", &nxt[i]);
	int pre = 0, st = 1, cir, len, lenc;
	for (int i = st; ; i = nxt[i]) {
		if (vis[i]) {
			cir = i;
			lenc = vis[pre] - vis[i] + 1;
			len = vis[i] - 1;
			break;
		}
		vis[i] = vis[pre] + 1;
		pre = i;
	}
	if (K <= len) {
		for (int i = nxt[st]; ; i = nxt[i]) 
			if (!--K) return printf("%d\n", i), 0;
	} else {
		K -= len;
		K %= lenc;
		if (!K) K = lenc;
		for (int i = nxt[cir]; ; i = nxt[i]) {
			if (!--K) return printf("%d\n", i), 0;
		}
	}

	return 0;
}		


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

int ketanowa(int n){
  int sum = 0;
  while(n>0){
  sum += n % 10;
  n /= 10;
  }
  return sum ;
}


int main() {
 int N ;
  cin >> N ;
  if (N % ketanowa(N) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

int n,m,a[1001],b[1001];
vector<int> c[1001];
string str;
int ans=0;
priority_queue<P ,vector<P>,greater<P> > que;
set<P> st;
int s=0;
ll dp[4100][1001];
ll reg(int s,int x){
	if(dp[s][x]!=-1){
		return dp[s][x];
	}
	if(x==m){
		if(s==(1<<n)-1)return 0;
		return INF;
	}
	int d=s;
	for(int i=0;i<b[x];++i){
		int e=c[x][i];
		d=d|(1<<e);
	}
	ll res=min(reg(d,x+1)+a[x],reg(s,x+1));

	return dp[s][x]=res;

}
int main() {
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	rep(i,0,m){
		cin>>a[i]>>b[i];
		int k;
		rep(j,0,b[i]){
			cin>>k;
			c[i].push_back(k-1);
		}
	}
	if(reg(0,0)==INF){
		cout<<-1<<endl;
		return 0;
	}
	cout<<reg(0,0)<<endl;
	return 0;
}


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

const int mod=1e9+7;

signed main()
{
   int H,W,K; cin>>H>>W>>K;

   K--;

   vector<vector<int> > dp(H+1,vector<int>(W));
   dp[0][0]=1;

   for(int h=0;h<H;h++){
      for(int S=0;S<(1<<(W-1));S++){
         bool ok=true;
         for(int i=0;i<W-2;i++){
            if((S>>i&1) and (S>>(i+1)&1)) ok=false;
         }
         if(!ok) continue;

         vector<int> perm(W);
         for(int i=0;i<W;i++) perm[i]=i;

         for(int i=0;i<W-1;i++){
            if(S>>i&1) swap(perm[i],perm[i+1]);
         }

         for(int i=0;i<W;i++){
            (dp[h+1][perm[i]]+=dp[h][i])%=mod;
         }
      }
   }
   cout<<dp[H][K]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

int f[15][1100];
int p[15],c[15];
int main()
{
	int n,G,mmin=999999999;
	scanf("%d%d",&n,&G);
	for(int i=1;i<=n;i++)scanf("%d%d",&p[i],&c[i]);
	
	memset(f,0,sizeof(f));
	for(int i=1;i<=p[1];i++)
	{
		f[1][i]=100+f[1][i-1];
		if(i==p[1])f[1][i]+=c[1];
		
		if(f[1][i]>=G)mmin=min(mmin,i);
	}
	
	int sum=p[1];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=sum+p[i];j++)
		{
			int add=0;
			for(int k=0;k<=min(j,p[i]);k++)
			{
				f[i][j]=max(f[i][j],f[i-1][j-k]+add);
				add+=i*100;if(k==p[i]-1)add+=c[i];
			}
			if(f[i][j]>=G)mmin=min(mmin,j);
		}
		sum+=p[i];
	}
	printf("%d\n",mmin);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    if(n%2==0)
    {
        cout << "-1" << endl;
        return 0;
    }
    long long int k = 7;
    long long int cnt = 1;
    while(1)
    {
        if(k%n==0)
        {
            cout << cnt << endl;
            break;
        }
        if(cnt>n)
        {
            cout << "-1" << endl;
            break;
        }
        k = (k%n)*10 + 7;
        cnt++;
    }

}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) cout << "error" << endl;
    else cout << a + b << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var N, M int
	var S, T string
	fmt.Scan(&N, &M)
	fmt.Scan(&S, &T)
	m := make(map[int]string, 0)
	L := lcm(N, M)
	for i := 0; i < N; i++ {
		m[i*(L/N)+1] = string(S[i])
	}
	good := true
	for i := 0; i < M; i++ {
		if val, ok := m[i*(L/M)+1]; ok {
			if string(T[i]) != val {
				good = false
				break
			}
		}
	}
	if good {
		fmt.Println(L)
	} else {
		fmt.Println(-1)
	}

}


Measured memory_bytes: 8704
n=int(input())
rec=[]
for i in range(n):
    a,b=input().split()
    rec.append([a,int(b),i+1])
rec=sorted(rec, reverse=True, key=lambda x: x[1]) 
rec=sorted(rec, key=lambda x: x[0]) 
for i in rec:
    print(i[2])

Measured memory_bytes: 9076
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if X == 500 * a + 100 * b + 50 * c:
        count += 1
        
print(count)

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

ll mod = 1e9+7;

int st[123456];

void build(vector <int> &t) {  // build the tree
  int n = t.size()/2;
  for (int i = n - 1; i > 0; --i) t[i] = t[i<<1] + t[i<<1|1];
}

void modify(vector <int> &t, int p, int value) {  // set value at position p
  int n = t.size()/2;
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = t[p] + t[p^1];
}

int query(vector <int> &t, int l, int r) {  // sum on interval [l, r)
  int res = 0;
  int n = t.size()/2;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res += t[l++];
    if (r&1) res += t[--r];
  }
  return res;
}

vector <int> order(vector<int> &heights, vector<int> &infronts) {
    // Do not write main() function.
    // Do not read input, instead use the arguments to the function.
    // Do not print the output, instead return values as specified
    // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
    vector <pair<int,int> > vec1;
    for(int i = 0; i < heights.size(); i++){
        vec1.push_back({heights[i], infronts[i]});
    }
    sort(vec1.begin(), vec1.end());
    int n = heights.size();
    vector <int> vec(n);
    vector <int> t(2*n);
    for(int i = 0; i < n; i++) t[i] = 0;
    for(int i = n; i < 2*n; i++) t[i] = 1;
    build(t);
    modify(t,0, 0);
    for(int i = 0; i < heights.size(); i++){
        int start = 0, end1 = n-1;
        int mid;
        while(start <= end1){
              mid = (start+end1)/2;
              int ind = query(t, 0, mid+1);
              cout << mid << " " << ind << "|" << vec1[i].second << endl;
              int ind1 = query(t, 0, mid);
              if(ind == vec1[i].second && ind1 != vec1[i].second) break;
              if(ind <= vec1[i].second) start = mid+1;
              else end1 = mid-1;
        }
        cout << mid << endl;
        modify(t,mid, 0);
        vec[mid] = vec1[i].first;
    }
    return vec;
}

int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    //cin.sync_with_stdio(false);
    //cin.tie(0); cout.tie(0);
    string s;
    getline(cin >> ws, s);

    map <char, int> mp;
    for(int i = 0;i < s.size(); i++) mp[s[i]]++;

    map <char, int> :: iterator it;

    ll ans = (s.size())*(s.size()+1)/2;

    for(it = mp.begin(); it != mp.end(); it++){
        ll cnt = (*it).second;
        ans -= (cnt)*(cnt-1)/2;
        ans -= cnt;
    }
    cout << ans+1;

}


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

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

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

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

    int cnt=0, sum=0;

    for(int i=0; i<N; i++){
        if((vec.at(i)+sum)<=x){
            cnt++;
            sum+=vec.at(i);
        }
        else break;
    }
  
  	if(sum!=x && cnt==N) cnt--;

    cout << cnt << endl;
}

Measured memory_bytes: 256
let rec lenN n =
  if n <= 0 then 1
  else 3 + 2 * lenN (n - 1)

let rec lenB n =
  if n <= 0 then 0
  else 2 + 2 * lenB (n - 1)

let lenP n =
  lenN n - lenB n

let rec calc n x =
  if n = 0 && x <=0 then 0
  else if n = 0 && x > 0 then 1
  else if x <= 1 + lenN (n-1) then
    calc (n-1) (x-1)
  else
    1 + lenP (n-1) + calc (n-1) (x- lenN (n - 1) - 2)

let () =
  Scanf.scanf "%d %d" (fun n x ->
      let ans =
        calc n x
      in
      Printf.printf "%d" ans
    )


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
// double power(double num, double g) {
// 	if (g == 0)return 1;
// 	if (g % 2 == 1)return (num * power((num * num), g / 2));
// 	return power( (num * num) , g / 2);
// }

int main(){
	ll x;
	cin >> x;
	for (int a = -150; a <= 150; a++){
		for (int b = -150; b <= a; b++){
			if (pow(a, 5) - pow(b, 5) == x){
				cout << a << " " << b;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 4100