akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
struct node 
{
      int u,v,w;
      bool used,mark,del;
      node(int x = 0,int y = 0,int z = 0) 
	  {
        u = x;
        v = y;
        w = z;
        mark = del = used = false;
     }
     bool operator<(const node &tmp) const 
	 {
         return w < tmp.w;
     }
 }e[maxn];
 int uf[maxn],n,m,cnt;
 bool flag[maxn];
 int find(int x) {
     return uf[x] = uf[x] == x?uf[x]:find(uf[x]);
 }
 int kruskal(bool &Unique,bool first) {
     int ans = cnt = 0;
     for(int i = 0; i <= n; ++i) uf[i] = i;
     for(int i = 0; i < m; ++i) {
        if(!first && e[i].del) continue;
        int fx = find(e[i].u);
        int fy = find(e[i].v);
       if(fx != fy)
	   {
    	   	uf[fx] = fy;
            ans += e[i].w;
            if(first) 
			{
            e[i].used = true;
            if(e[i].mark) Unique = false;
            }
            if(++cnt == n-1) return ans;
	   }
     }
     return ans;
 }
 int main() {
     int u,v,w;
    // freopen("data.in","r",stdin); 
     while(~scanf("%d %d",&n,&m)) {
         for(int i = 0; i < m; ++i) {
             scanf("%d %d %d",&u,&v,&w);
             e[i] = node(u,v,w);
         }
         memset(flag,false,sizeof(flag));
         sort(e,e+m);
         for(int i = 1; i < m; ++i)
             if(e[i].w == e[i-1].w) e[i].mark = e[i-1].mark = true;
         bool Unique = true;
         int MST = kruskal(Unique,1);
         if(Unique) printf("%d %d\n",cnt,MST);
         else {
             int res1 = 0,res2 = 0;
             for(int i = 0; i < m; ++i) {
                 if(e[i].used && e[i].mark) {
                     e[i].del = true;
                     int mst = kruskal(Unique,0);
                     if(mst == MST && cnt == n-1) flag[i] = true;
                     e[i].del = false;
                 }
               if(e[i].used && !flag[i]) {
                     res1++;
                     res2 += e[i].w;
                 }
             }
             printf("%d %d\n",res1,res2);
        }
     }
     return 0;
 }

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b, c;
  std::cin >> a >> b >> c;
  if (a + b + c <= 21) {
    std::cout << "win" << std::endl;
  } else {
    std::cout << "bust" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
def s(c,d):
    x = c%d
    if x==0:
        return d
    
    else:
        return s(d,x)

a,b,c,d=map(int,input().split())
if c < d:
    c,d=d,c
e = s(c,d)
e = (c//e)*(d//e)*e
print((b-a+1)-(b//c - (a-1)//c)-(b//d - (a-1)//d)+(b//e - (a-1)//e))

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

template <typename T>
class matrix: public std::vector< std::vector<T> >
{
public:
	matrix(int m = 0, int n = 0, const T& v = T()):
		std::vector< std::vector<T> >(m, std::vector<T>(n, v)) {}
	int rows() const {return this->size();}
	int cols() const {return rows() == 0 ? 0 : this->at(0).size();}
};

template <typename T>
std::istream& operator>>(std::istream& is, matrix<T>& M)
{
	for (int i = 0; i < M.rows(); ++i)
		for (int j = 0; j < M.cols(); ++j)
			is >> M[i][j];
	return is;
}

int main()
{
	int m, n;
	while (std::cin >> n >> m && !(m == 0 && n == 0))
	{
		matrix<int> M(m, n);
		std::cin >> M;
		int maxs = 0;
		std::vector<int> s(n);
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
				s[i] += M[j][i];
			if (maxs < s[i])
				maxs = s[i]; 
		}
		std::cout << maxs << '\n';
	}
	return 0;
} 


Measured memory_bytes: 3244
import numpy as np
N=int(input())
s=[]
t=[]
for i in range(N):
  x, y=input().split()
  s.append(x)
  t.append(int(y))
  
X=input()

for i in range(N):
  if s[i]==X:
    a=i
    break
    
if a==N-1:
  print(0)
else:
  print(sum(t[(a+1):]))

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void initComb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long comb(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll pow(ll v, ll n) {
  ll r = 1;
  for (ll i = 0; i < n; i++) {
    r *= v;
    r %= MOD;
  }
  return r;
}

int main() {
  initComb();

  ll N, K;
  scanf("%lld %lld", &N, &K);

  ll red = N - K;

  for (ll i = 1; i <= K; i++) {
    ll places = red + 1;
    ll rest = K - i;

    ll p = comb(places, i);
    ll m = comb(K - 1, i - 1);

    cout << ((p * m) % MOD) << endl;
  }
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }
//重複した要素の取り扱い方がよくわからない
//iでは入れずにjのときだけ入れれば良い？
int main(){
	ll n;cin>>n;
	vector<ll> a(n);
	for(ll i = 0; i < n; i++) {
		cin>>a[i];
	}
	// cout << a.size() << endl;
	sort(ALL(a));
	vector<ll> b(1000005,1);//a[i] = 1ならAの中に自身以外の約数は存在しない
	for(ll i = 0; i < n; i++) {
		ll x = a[i];
		ll mul = 2;
		if(x * mul <= a[n - 1]){
			while(x * mul <= a[n - 1]){
				b[x * mul] = 0;
				mul ++;
			}
		}
	}
	ll ans = 0;
	for(ll i = 0; i < n; i++) {
		if((i > 0 && a[i] == a[i -  1]) || (i < n - 1 && a[i] == a[i + 1])){
			continue;
		}
		else if (b[a[i]])ans++;
	}
	cout << ans << endl;
	for(int i = 0; i < b.size(); i++) {
		// cout << i << " " << b[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 12664
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, w;
    cin >> n >> w;
    vector<pair<int, int>> weights(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> weights[i].first >> weights[i].second;
    vector<vector<int>> dp(2, vector<int>(w + 1));
    for (int i=1; i<=n; i++)
        for (int j=1; j<=w; j++) {
            int t = i&1;
            dp[t][j] = dp[1-t][j];
            if (j >= weights[i].first)
                dp[t][j] = max(dp[t][j], dp[1-t][j - weights[i].first] + weights[i].second);
        }
    cout << dp[n&1].back() << "\n";
}

Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, M;
    cin >> N >> M;
    int K[M];
    vector<int> S[M];
    REP(i, M)
    {
        cin >> K[i];
        REP(j, K[i])
        {
            int tmp;
            cin >> tmp;
            S[i].pb(tmp);
        }
    }
    int P[M];
    REP(i, M) cin >> P[i];

    int ret = 0;
    REP(i, pow(2, N))
    {
        bool swt[N];
        REP(j, N) swt[j] = i >> j & 1;

        REP(j, M)
        {
            int n = 0;
            REP(k, K[j]) n += swt[S[j][k]-1];
            if (n%2 != P[j]) goto esc;
        }
        ++ret;
esc:;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char a[10001];
int main(){
    scanf("%s",a+1);
    int len = strlen ( a+1 ) ;
    for(int i=2;i<len;i++){
        if(a[i-1]==a[i]&&a[i]==a[i+1]){puts("Yes"); exit(0);}
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int[] a = new int[n];
        
        for(int i = 0 ; i < n ; i++){
            a[i] = sc.nextInt();
        }
        int max = a[n-1];
        for(int i = n-1 ; i >= 0 ; i--){
            int tmp = a[i];
            a[i] = max - a[i];
            max = Math.max(max, tmp);
        }
        Arrays.sort(a);
        int num = a[n-1];
        int ans = 0;
        for(int i = n-1; i >= 0 && a[i] == num ; i--){
            ans++;
        }

        System.out.println(ans);
    }
}


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

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

        if(a==1){
                if(b==0)
                        cout << "Close" << endl;
                else
                        cout << "Open" << endl;
        }
        else if(a==0){
                if(b==0){
                        if(c==0)
                                cout << "Close" << endl;
                        else
                                cout << "Open" << endl;
                }
                else
                        cout << "Close" << endl;
        }

        return 0;
}

Measured memory_bytes: 1156
K = int(input())

if K == 1 or K == 7:
    print(1)
    exit()

v = 7
M = set([])
for i in range(1, K + 1):
    v = (v * 10 + 7) % K
    if v == 0:
        print(i + 1)
        exit()
    if v not in M:
        M.add(v)
    else:
        print(-1)
        exit()


Measured memory_bytes: 78084
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int A[]=new int[N];
		int z=0;
		while(z<Q){
			int a=stdIn.nextInt();
			A[a-1]++;
			z++;
		}z=0;
		while(z<N){
			if(A[z]+K<=Q)
				System.out.println("No");
			else
				System.out.println("Yes");
			z++;
		}
	}
}

Measured memory_bytes: 53716
//RUPC-A
#include<stdio.h>
#include<string.h>
char s[10005];
int d[1005],e[1005];
int main(){
	int i,j,len,x,f,ans,r,k;
	scanf("%s",s);
	len=strlen(s);
	x=0;
	for(i=0;i<len;i+=0){
		if(s[i]=='e'){
			d[x]=1;
			i+=3;
		}else{
			d[x]=2;
			i+=7;
		}
		x++;
	}
	//r=f=k=0;
	//f=d[0];
	k=r=1;ans=d[0];
	for(i=1;i<x;i++){
		if(d[i]-d[i-1]==0){
			if(r<k)ans=d[i],r=k;
			k=1;
		}else{
			k++;
		}
	}
	if(r<k)r=k,ans=d[x-1];
	//printf("\n");
	printf("%s\n",(ans==1)?"egg":"chicken");
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	int n,k,ans=0;
	cin>>n>>k;
	int l[n];
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	sort(l,l+n);
	for(int i=n-1;i>=n-k;i--){
		ans+=l[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    ll a, b, c;
    cin >> a >> b >> c;
    int k, d = 0;
    cin  >> k;
    while(b <= a)
        b *= 2, d++;
    while(c <= b)
        c *= 2, d++;
    cout << (d <= k ? "Yes" : "No");
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
vector<int> v;

int main ()
{
	int n, k; cin >> n >> k;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < k; i++)
		sum += v[i];
	cout << sum << '\n';
}


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

int main() {
	int W, a, b;
	int distance,move;

	scanf("%d %d %d", &W, &a, &b);
	
	distance = abs(b - a);
	move = distance - W;
	
	if (move < 0) {
		move = 0;
	}

	printf("%d\n", move);
	return 0;
}

Measured memory_bytes: 128
n, q = map(int, input().split())
s = '_' + input()
t = [0] * (n + 1)
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        t[i] += 1
    t[i+1] += t[i]

for i in range(q):
    l, r = map(int, input().split())
    ans = t[r-1] - t[l-1]
    print(ans)

Measured memory_bytes: 7668
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    vector<int> co(26);
    char c;
    while(cin >> c) {
        if(isalpha(c)) {
            if(isupper(c))
                c = tolower(c);
            co[c - 'a']++;
        }
    }
    rep(i, 26) {
        c = 'a' + i;
        cout << c << " : " << co[i] << endl;
    }
}


Measured memory_bytes: 3104
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k= map(int, sys.stdin.readline().split(' '))
    v=1
    ans=1
    while(v<=n):
        v*=k
        ans+=1
    print(ans-1)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >> n;
  string s;
  cin >>s;
  int g=0;
  int ans=0;
  rep(i,n){
    if(s[i]=='I'){g++;}else if(s[i]=='D'){g--;}
    chmax(ans,g);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int N, D;
	cin >> N;
	cin >> D;
	if (N%(2*D+1)==0)
	{
		cout << N / (2 * D + 1) << endl;
	}
	else
	{
		cout << N / (2 * D + 1)+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys

def hoge(arg):
    if( (arg % 2) ==0):
        return( int(arg/2))
    else:
        return(int(3 * arg + 1))



# s = map(int, input().split())
s = int(input())

x = list()
x.append(s)

for i in range(1000000):
    s = hoge(s)
    #print(x)
    # print(s)
    if(s in x):
        print(len(x)+1)
        break
    x.append(s)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
vector<pii> g[112345];
int edge[112345];

int dfs(int u, int pre, int prec) {
	int nc = 1;
	int res = 0, cur = 0;
	if (prec != -1) cur++;
	
	for (pii e : g[u]) {
		int v = e.fi;
		if (v == pre) continue;
		if (nc == prec) nc++;
		edge[e.se] = nc;
		chmax(res, dfs(v, u, nc));
		nc++;
		cur++;
		
	}
	
	chmax(res, cur);
	return res;
}

int main() {
	cin >> N;
	REP(i, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}
	
	int c = dfs(0, -1, -1);
	cout << c << endl;
	REP(i, N - 1) printf("%d\n", edge[i]);
	
	return 0;
}


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

keys=[[] for _ in range(N)]
dp=[-1]*(2**N)
dp[0]=0

for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a))


def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret

print(rec(2**N-1))

Measured memory_bytes: 77136
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
void exgcd(ll a, ll b, ll& x, ll& y, ll& c)
{
    if(!b) {y = 0; x = 1; c = a; return;}
    exgcd(b, a % b, y, x,c); y -= a / b * x;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll n,x,y,u,v,ans=-1,a,b;
ll solve(ll x,ll y)
{
	ll v,u,d;
	exgcd(x,y,u,v,d);
	if(u>0)u-=y*((u-1)/y+1);
	else u+=y*((-u)/y);
	if(v>0)v-=x*((v-1)/x+1);
	else v+=x*((-v)/x);
	return min(-u*x,-v*y);
}
int main()
{
	scanf("%lld",&n);n=2ll*n;
	ans=n-1;
	for(int i=2;1ll*i*i<=n;i++)
	{
		if(n%i)continue;
		x=i;y=n/i;
		if(gcd(x,y)>1)continue;
		a=solve(x,y),solve(y,x);
		ans=min(a,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1736
n, a, b = [int(i) for i in input().split()]
c = b * (n - 1) + a
d = a * (n - 1) + b

if a > b:
    print(0)
elif n == 1:
    if a != b:
        print(0)
    else:
        print(1)
else:
    print(c-d+1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N;
ll A[200010];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N, greater<ll>());
    ll ans = accumulate(A, A + N / 2, 0LL) + accumulate(A + 1, A + (N + 1) / 2 , 0LL);
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	int t=0;
	if(s[0]=='2') t++;
	if(s[1]=='2') t++;
	if(s[2]=='2') t++;
	if(s[3]=='2') t++;
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=0;
vector<int> v;
int main(){

    GO();
    ll n,k;
    cin>>n>>k;
     n%=k;

    cout<<min(k-n,n)<<"\n";

}




































































































































































































































Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[100010];
int n, ans;
int main() {
	scanf("%s", s + 1);
	ans = n = strlen(s + 1);
	for (int i = 1; i < n; ++i)
		if (s[i] != s[i+1])
			ans = min(ans, max(i, n - i));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int []a=new int[5];
		for(int i=0;i<5;i++) {
			int n=scan.nextInt();
			a[i]=n;
		}
		
		for(int i=0;i<5;i++) {
			if(a[i]==0) {
				System.out.println(i+1);
			}
		}
	}

}


Measured memory_bytes: 35720
#include <stdio.h>
 
int main(void){
    char alpha;
 
    scanf("%c", &alpha);
 
    if((alpha >= 'a') && (alpha <='z')){
      printf("a\n");
    }else if((alpha >= 'A') && (alpha <='Z')){
      printf("A\n");
    }
    return 0;
}

Measured memory_bytes: 1600
#include <iostream>
#include <cmath>
#include <string>

#define START 100

using namespace std;

int main()
{
  int year;
  long x, money, value;

  cin >> x;

  money = START; year = 0;

  while(money < x){
    value = money / 100;
    money += value;
    year++;
  }


  cout << year;

}


Measured memory_bytes: 3612
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk,n;
  vector<int> a;
  bitset<32> m;

  cin >> n;

  for(ii=0;ii<pow(2,n);ii++){
    m = ii;
    cout << ii << ":";

    for(jj=0;jj<n;jj++){
      if(m.test(jj)){
        cout << " " << jj;
      }
    }
    
    cout << endl;
  }

  
  return 0;
}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	char s;cin>>s;
	if(s>='A'&&s<='Z') cout<<"A";
	else cout<<"a";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
#define pii pair< ll , pair<ll,ll> >
const int N = 50+5;
ll n , m , s , cost[N][N*N] , c[N] , d[N] , ans[N];
vector<pii> adj[N];

void dijk()
{
    priority_queue<pii , vector<pii> , greater<pii> > q;
    for(int i=1; i<=n; i++)
    {
        ans[i] = 1e18;
        for(int j=0; j<=2500; j++)
            cost[i][j] = 1e18;
    }
    s = min(s , (ll)2500);
    q.push({0 , {1 , min(s,(ll)2500)}});
    cost[1][s] = 0;

    while(q.size())
    {
        ll node = q.top().s.f , cst = q.top().f , sil = q.top().s.s;
        ans[node] = min(ans[node] , cst);
        q.pop();
        if (cost[node][sil] < cst) continue;

        ll newSil = sil+c[node];
        newSil = min(newSil , (ll)2500);
        if (cost[node][newSil] > cst + d[node])
        {
            cost[node][newSil] = cst+d[node];
            q.push({cost[node][newSil] , {node,newSil}});
        }

        for(auto ch : adj[node])
        {
            if (sil < ch.s.f) continue;
            ll cst2 = ch.s.s , sil2=ch.s.f;
            if (cost[ch.f][sil-sil2] > cst+cst2)
            {
                cost[ch.f][sil-sil2] = cst + cst2;
                q.push({cost[ch.f][sil-sil2] , {ch.f,sil-sil2}});
            }
        }
    }
}

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

    cin >> n >> m >> s;
    for(int i=1; i<=m; i++)
    {
        int v,u,a,b;
        cin >> v >> u >> a >> b;
        adj[v].push_back({u , {a,b}});
        adj[u].push_back({v , {a,b}});
    }
    for(int i=1; i<=n; i++)
        cin >> c[i] >> d[i];

    dijk();

    for(int i=2; i<=n; i++)
        cout << ans[i] << '\n';

    return 0;
}

Measured memory_bytes: 7432
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

//ABC98 D

int main(void) {
	ll n;
	cin >> n;
    vector<ll> a = vector<ll>(n);	
	rep(i, 0, n)cin >> a[i];
	ll l = 0, r = 0;
	ll xorSum = 0;
	ll sum = 0;
	ll ans = 0;
	while (r < n) {
		ll xorSumNew = xorSum ^ a[r];
		ll sumNew = sum + a[r];
		if (xorSumNew == sumNew) {
			ans += r - l + 1;
			r++;
			xorSum = xorSumNew;
			sum = sumNew;
		}
		else {
			xorSum ^= a[l];
			sum -= a[l];
			l++;
		}
	}
	cout << ans << endl;
}

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

int main()
{
    int Number[5];
    int Temp;

    for(int i = 0; i < 5; i++)
    {
        cin >> Number[i];
    }
    {
        for(int x = 0; x < 5; x++)
        {
            for(int z = 0; z < 4; z++)
            {
                if(Number[z] < Number[z+1])
                {
                    Temp = Number[z];
                    Number[z] = Number[z+1];
                    Number[z+1] = Temp;
                }
            }
        }

        for(int y = 0; y < 4; y++)
        {
            cout << Number[y] << " ";
        }
        cout << Number[4] << endl;

    }
    return 0;

}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N, K;
string S;

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

  cin >> N >> K;
  cin >> S;
  int cnt = N;
  if (S[0]=='L') cnt--;
  if (S[N-1]=='R') cnt--;
  int idx = 1;
  rep(i, N){
    if (i<N-1 && S[i] == 'R' && S[i+1] == 'L') cnt--;
    if (i>0 && S[i] == 'L' && S[i-1] == 'R') cnt--;
  }
  cout << min(cnt+2*K, N-1) << "\n";
  return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  int N = S.size();

  bool flag = true;
  REP(i, N){
    char conf = S[i];
    if (i % 2 == 0){
      if (conf != 'R' and conf != 'U' and conf != 'D')
      {
        flag = false;}}
      else{
        if (S[i] != 'L' and S[i] != 'U' and S[i] != 'D')
      {flag = false;}}

    }

  if (flag) {cout << "Yes" << endl;}
  else cout << "No" << endl;



  return 0;
}



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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <ll mod> class modint
{
public:
    modint(ll value = 0) : _value(value >= 0 ? value % mod : (value % mod) + mod) {}

    modint operator+() const { return *this; }
    modint operator-() const { return modint(-_value); }

    modint &operator+=(const modint &rhs) {
        if ((_value += rhs._value) >= mod) _value -= mod;
        return *this;
    }
    modint &operator-=(const modint &rhs) {
        if ((_value += mod - rhs._value) >= mod) _value -= mod;
        return *this;
    }
    modint &operator*=(const modint &rhs) {
        (_value *= rhs._value) %= mod;
        return *this;
    }
    modint &operator/=(const modint &rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }

    modint operator++() { *this += 1; return *this; }
    modint operator--() { *this -= 1; return *this; }
    modint operator++(int) { modint tmp = *this; ++*this; return tmp; }
    modint operator--(int) { modint tmp = *this; --*this; return tmp; }

    bool operator==(const modint &rhs) const { return _value == rhs._value; }
    bool operator!=(const modint &rhs) const { return _value != rhs._value; }

    modint inv() const {
        ll a = _value, b = mod, u = 1LL, v = 0LL;
        while (b > 0) {
            ll tmp = a / b;
            a -= tmp * b; swap(a, b);
            u -= tmp * v; swap(u, v);
        }
        return modint(u);
    }

    modint pow(ll n) const {
        modint e = *this, res = 1;
        while (n) {
            if (n & 1) res *= e;
            e *= e, n >>= 1;
        }
        return res;
    }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m._value;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }

private:
    ll _value;
};
using mint = modint<1000000007>;

mint dp[100002][2];

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

    string s; cin >> s;
    int n = s.length();
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            dp[i + 1][0] = dp[i][0] * 2;
            dp[i + 1][1] = dp[i][0] + dp[i][1] * 3;
        } else {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1] * 3;
        }
    }
    cout << dp[n][0] + dp[n][1] << endl;
    return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
int main(void){
  int a,b,c,d,e;
  scanf("%d",&a);
  if(a<40)
    a=40;
  scanf("%d",&b);
  if(b<40)
    b=40;
  scanf("%d",&c);
  if(c<40)
    c=40;
  scanf("%d",&d);
  if(d<40)
    d=40;
  scanf("%d",&e);
  if(e<40)
    e=40;
  a=a+b+c+d+e;
  printf("%d\n",a/5);
  return(0);
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,dp[100][100];
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j)dp[i][j]=1e18;
        }
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        dp[a][b]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(dp[i][k]==1e18||dp[k][j]==1e18)continue;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        if(dp[i][i]!=0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(dp[i][j]==1e18)cout<<"INF";
            else cout<<dp[i][j];
            if(j!=n-1)cout<<" ";
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3192
n, a, b, c, d = gets.chomp.split.map(&:to_i)
a -= 1; b -= 1; c -= 1; d -= 1;
s = gets.chomp

if s[a..c].scan(/##/).count > 0 || s[b..d].scan(/##/).count > 0
  puts "No"
elsif c < d
  puts "Yes"
else
  puts (s[b - 1..d + 1].scan(/\.\.\./).count > 0)? "Yes" : "No"
end

Measured memory_bytes: 14824
H,W,A,B = map(int,input().split())
import numpy as np
ans = np.array([[0] * W] * H)
for h in range(H):
    for w in range(W):
        if w >= A and h >= B:
            pass
        elif w >= A:
            ans[h,w] = 1
        elif h >= B:
            ans[h,w] = 1
        else:
            pass
for h in range(H):
    a = ans[h].tolist()
    print(*a,sep="")

Measured memory_bytes: 22644
#include<bits/stdc++.h>
using namespace std;
int a,b,n,x,y;
int main(){
  while(1){
    int memo[19][19]={0},check[19][19]={0};
    cin>>a>>b;
    if(a==0 && b==0)break;
    cin>>n;
    memo[0][1]=1;
    for(int i=0;i<n;i++){
      cin>>x>>y;
      check[x][y]=1;
    }
    for(int i=1;i<=a;i++){
      for(int j=1;j<=b;j++){
	if(check[i][j]!=1){
	  memo[i][j]=memo[i-1][j]+memo[i][j-1];
	}
      }
    }
    cout<<memo[a][b]<<endl;
  }
}

Measured memory_bytes: 1160
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int n,m,x,pos,ii,cost1,cost2;
  int cost[101];
  memset(cost,0,sizeof(cost));
  cost1 = 0;
  cost2 = 0;
  
  cin >> n >> m >> x;

  for(ii=0;ii<m;ii++){
	cin >> pos;
	//cout << pos << endl;
	cost[pos] = 1;
  }

  //x→n
  for(ii=x;ii<=n;ii++){
	cost1 += cost[ii];


  }
  //x→0
  for(ii=x;ii>=0;ii--){
	//cout << "ii:" << ii << " " << cost[ii] << endl;
	cost2 += cost[ii];
  }

  if(cost1<=cost2){
	cout << cost1 << endl;
  }

  else{
	cout << cost2 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=l[i]+l[j]
        b=bisect_left(l,a)
        ans+=b-j-1
print(ans)        

Measured memory_bytes: 42972
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int fac[N],ifac[N];
int h,w,a,b;

inline int C(int x,int y){
	return (ll)fac[x+y]*ifac[x]%mod*ifac[y]%mod;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(h,w,a,b);fac[0]=1;
	a=h-a+1;
	if(a==1){puts("0");return 0;}
	for(int i=1;i<=h+w;i++) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[h+w]=exp(fac[h+w],mod-2);
	for(int i=h+w;i;i--) ifac[i-1]=(ll)ifac[i]*i%mod;
	int ans=C(h-1,w-1);
	for(int i=1;i<=b;i++)
		ch(ans,mod-(ll)C(a-2,i-1)*C(h-a,w-i)%mod);
	print(ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
const int INF=0x3f3f3f3f,maxn=10;
//vector<int>v[maxn];
//map<int,string>mp[maxn];
//queue<int>q[maxn];
//int a[naxm],n,m;
int main()
{
	int i,j,k,ans=0;
	cin>>i;
	cout<<i+i*i+i*i*i;
	return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int N;
cin>>N;
long long  cost[N],start[N],f[N];

for(int i=1;i<N;i++){
    cin>>cost[i]>>start[i]>>f[i];
}
long long now=0;
for(int k=1;k<N;k++){
    now =0;

    for(int i=k;i<N;i++){
        now=max(start[i],now);
        if(now%f[i]!=0)now+=(f[i]-(now%f[i]));
        now+=cost[i];
    }
    cout<<now<<endl;
}

cout<<"0"<<endl;


 return 0;
}
/*
3
6 5 1
1 10 1


12
11
0

4
12 24 6
52 16 4
99 2 2

187
167
101
0

4
12 13 1
44 17 17
66 4096 64

4162
4162
4162
0
*/


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long dp[3][200],n,map[3][200];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=2;i++)
	for(int j=1;j<=n;j++)scanf("%lld",&map[i][j]);
	for(int i=1;i<=2;i++)
	for(int j=1;j<=n;j++)
	dp[i][j]=max(dp[i-1][j],dp[i][j-1])+map[i][j];
	printf("%lld\n",dp[2][n]);
}

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

int main(void){
    int N,M,C;
    cin>>N>>M>>C;
    int A[N][M];
    int B[M];
    int cnt=0;

    for(int i=0;i<M;i++)
        cin>>B[i];

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

    for(int i=0;i<N;i++){
        int sum=0;
        for(int j=0;j<M;j++){
            sum+=A[i][j]*B[j];
        }
        sum+=C;
        if(sum>0)
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int cnt[2020];

int main(){
  string S; cin>>S;
  cnt[0]=1;
  ll sum=0,pre=0,x=1;
  for(int i=S.length()-1;i>=0;i--){
    int tmp=(pre+(S[i]-'0')*x)%2019;
    sum+=cnt[tmp];
    cnt[tmp]++;
    pre=tmp;
    x=x*10%2019;
  }
  cout<<sum<<endl;
  return 0;
}

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

int main(){
  int n, t; cin >> n >> t;
  vector<pair<int, int>> p(n + 1);
  vector<vector<int>> dp(n+1, vector<int>(t+1));
  rep(i, n) cin >> p[i + 1].first >> p[i + 1].second;
  sort(p.begin() + 1, p.end());
  rep(i, t + 1) dp[0][i] = 0;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 0; j <= t; j++){
      if(j - p[i].first < 0) dp[i][j] = dp[i - 1][j];
      else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p[i].first] + p[i].second);
    }
    ans = max(ans, dp[i - 1][t - 1] + p[i].second);
  }

  /*for(int i = 0; i <= n; i++){
    for(int j = 0; j <= t; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 38592
#include<cstdio>

#include<cctype>

using namespace std;

int main(){

	char ch;

	while(1){

		scanf( "%c", &ch);       // ch?????\?????? %C ????????£???????????¨??????) //

		if( isalpha( ch) ){      // ??¢??????????????????????????\ //

			if( islower( ch)) printf( "%c", toupper(ch) );  // ??????????°???????????????§???????????´???????????? //

			else printf( "%c", tolower( ch));  // ?????????????????????ch?????§?????????????°????????????´???????????? //

		}

		else printf ( "%c", ch);  // ????????\???????????????????????? //

		if ( ch == '\n') break;  // ????????????????????\????????????????????? //

	}

	return 0;

}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  while(s.size()){
    if(s.substr(0,5)=="maerd"||s.substr(0,5)=="esare"){
      s=s.substr(5,s.size());
    }
    else if(s.substr(0,6)=="resare"){
      s=s.substr(6,s.size());
    }
    else if(s.substr(0,7)=="remaerd"){
      s=s.substr(7,s.size());
    }
    else{
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  vector<bool> dp(k+1, false);
  rep(i,k) if(!dp[i]){
    rep(j,n) if(i + a[j] <= k) dp[i+a[j]] = true;
  }

  cout << (dp[k] ? "First" : "Second") << endl;

  return 0;
}


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

int sum(int a ){
  int ans = 0;
  for(int i =0 ; i < 5 ; i++ ){
    ans += a % 10 ;
    a /= 10 ;
  }
  return ans ;
}

int main () {
  int N , a , b ,ans = 0 ;
  cin >> N >> a >> b ;
  for(int i = 1 ; i <= N ; i++ ){
    int pre = sum (i) ;
    if(pre <= b && pre >= a) ans += i  ;
  }
  cout << ans << endl ;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var num = new Dictionary<int, bool>();
            for (int i = 0; i < N; i++)
            {
                var A = ReadInt();
                if (num.ContainsKey(A))
                {
                    if (num[A]) num[A] = false;
                    else num[A] = true;
                }
                else
                {
                    num.Add(A, true);
                }
            }
            var cnt = 0;

            foreach (var v in num) if (v.Value) cnt++;

            Console.WriteLine(cnt);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 18268
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

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,K = map(int, input().split())
    snukes = [0]*N
    for _ in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for a in A:
            snukes[a-1] += 1
    count = 0
    for snuke in snukes:
        if not snuke:
            count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10520
#include <stdio.h>
#include <string.h>
#define MAX 201
  
int main(void) {
    int i, n;
    char str[MAX], buf[MAX];
    while(scanf("%s", str), strcmp(str, "-")) {
        for(scanf("%d", &i); i--; strcpy(str, buf)) {
            scanf("%d", &n);
            strcpy(buf, str + n), strncat(buf, str, n);
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 600