akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n;
    cin >> n;
    pair<ll,ll> x[n];
    for (ll i=0;i<n;i++){
        ll a;
        cin >> a;
        x[i]=make_pair(i+1,a);
    }
    sort(x,x+n,pairCompareSecond);
    for (ll i=0;i<n;i++){
        cout << x[i].first << " ";
    }
    cout << endl;
    return 0;
}


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

int main(void)
{
	string S; cin >> S;
	int y = stoi(S.substr(0, 4));
	int m = stoi(S.substr(5, 2));
	int d = stoi(S.substr(8, 2));
	if (y <= 2019 && m <= 4 && d <= 30)cout << "Heisei" << endl;
	else cout << "TBD" << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())

ans=0
if n<=9:
  ans=n
elif n<=99:
  ans = 9
elif n<=999:
  ans = 9 + n-100+1
elif n<=9999:
  ans = 9+ 999-100+1
elif n<=99999:
  ans = 9+ 999-100+1 +n-10000 +1
elif n<=999999:
  ans = 9+ 999-100+1 +99999-10000 +1
elif n==100000:
  ans = 9+ 999-100+1 +99999-10000 +1
  
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int main(){
	int n,mi=INF,mx=-1; cin>>n;
	for(int i=1; i<=n; i++){
		int x = read();
		mi = min(x,mi);
		mx = max(x,mx);
	}

	cout << mx - mi << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    string x, y;
    cin >> x >> y;
    if(x > y)cout << ">";
    else if(x == y)cout << "=";
    else cout << "<";
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e6+7;
int n;
vector<pair<int,int>> v;

bool comp(pair<int,int> a, pair<int,int> b)
{
	if(a.first!=b.first)
		return a.first<b.first;
	return a.second<b.second;
}

int32_t main()
{
	fast;

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		v.push_back({b,a});
	}
	sort(v.begin(),v.end(),comp);

	int cur = 0;
	for(int i=0;i<n;i++)
	{
		if((cur+v[i].second)<=v[i].first)
		{
			cur+=v[i].second;
			continue;
		}
		else
			return cout<<"No", 0;		
	}

	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 6000
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
PY_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

## key= int, Number of Prefecture
## value= list, BirthYear of city
pref_dic={}

for p,y in PY_list:
    pref_dic.setdefault(p,[])
    pref_dic[p] += [y]

for k in pref_dic:
    pref_dic[k].sort()

## key= int, BirthYear of city
## value= int, Index of BirthYear-list in each Prefecture
city_dic={}

for k in pref_dic:
    for i,year in enumerate( pref_dic[k] ):
        city_dic.setdefault(year,-1)
        city_dic[year] = i

for m in range(M):
    inum_pref = PY_list[m][0]
    #inum_city = pref_dic[ inum_pref ].index( PY_list[m][1] ) + 1
    inum_city = city_dic[ PY_list[m][1] ] + 1
    print('{0:06}{1:06}'.format(inum_pref, inum_city))


Measured memory_bytes: 52132
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

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

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

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

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

mt19937_64 rnd(0);

const int LOG = 30;
const int N = (int)3e5 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

int n, a[N];

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	map <int, int> cnt;
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		int val = i - a[i];
		ans += cnt[val];
		cnt[i + a[i]]++;
	}
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 21356
N,M = [int(i) for i in input().split(' ')]
H = [int(i) for i in input().split(' ')]
A = []
for i in range(M):
	x,y = [int(j) for j in input().split(' ')]
	if H[x-1] < H[y-1]:
		A.append(x)
	elif H[x-1] > H[y-1]:
		A.append(y)
	else:
		A.append(x)
		A.append(y)

print(N-len(set(A)))
  



Measured memory_bytes: 92884
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<iomanip>
#include<math.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
#define INF 1000000000000000000LL

int main(){
    int n; cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans=1;
    rep(i, n-1){
        ans *= a[i];
        if(a[i+1]>INF/ans){
            cout << -1 << endl;
            return 0;            
        }
    }
    ans *= a[n-1];
    cout << ans << endl;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 998244353;
signed main() {
    int n;
    cin>>n;
    int l = 0, r = n - 1, m;
    string ls, rs, ms;
    cout<<l<<endl<<flush;
    cin>>ls;
    if (ls == "Vacant") return 0;
    cout<<r<<endl<<flush;
    cin>>rs;
    if (rs == "Vacant") return 0;

    while (r - l > 1) {
        m = (l + r) / 2;
        cout<<m<<endl<<flush;
        cin>>ms;
        if (ms == "Vacant") return 0;

        if ((m - l) % 2 == 0 && ms != ls) r = m, rs = ms;
        else if ((m - l) % 2 == 1 && ms == ls) r = m, rs = ms;
        else if ((r - m) % 2 == 0 && ms != rs) l = m, ls = ms;
        else if ((r - m) % 2 == 1 && ms == rs) l = m, ls = ms;
    }
    cout<<l<<endl<<flush;
    cin>>ls;
}

Measured memory_bytes: 852
#!/usr/bin/env python
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

N = int(input())
primes = primes(55555)
primes_five = []
for p in primes:
    if p % 5 == 1:
        primes_five.append(p)

print(*primes_five[:N])

Measured memory_bytes: 3572
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.File;
import java.io.PrintStream;

public class Main {

	public static void main(String[] args) throws IOException {
		
		InputStreamReader reader = new InputStreamReader(System.in);
		int key,i,a[],flag;
		a=new int[100];
		key='.';
		key=reader.read();
		while(true){  //while outside
			//System.out.print((char)key+"-");
			//System.out.print("***");
			i=0;
			a[i]=0;
			
			if(key=='.')
				break;
			while(true){	//while inside
				if(key=='['||key=='('){
					i++;
					a[i]=key;
				}
				else if(key==']'){
					if(a[i]!='['){
						while(key!='.'){
							key=reader.read();
						}
						System.out.println("no");
						break;
					}
					i--;
				}
				else if(key==')'){
					if(a[i]!='('){
						while(key!='.'){
							key=reader.read();
						}
						System.out.println("no");
						break;
					}
					i--;
				}	

				key=reader.read();
				if(key=='.'){
					if(i==0){
						System.out.println("yes");
						break;
					}
					else{
						System.out.println("no");
						break;
					}
				}
			} //while(true) inside
			
			while(key!='\n'){
				key=reader.read();
			}
			//System.out.print((char)key);
			//if(key=='\n'){
			key=reader.read();
			//}
			//key=reader.read();
			
		} //while outside
	} //main
} //class

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int ans=0;
  rep(i,n){
    if(h[i]>=k) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  int n1, n2, n4;
  n1=n2=n4=0;
  rep(i, n){
    int a;cin>>a;
    if(a%4==0)n4++;
    else if(a%2==0)n2++;
    else n1++;
  }
  if(n2==0){
    cout<<(n1<=n4+1?"Yes":"No")<<endl;
  }else{
    cout<<(n1<=n4?"Yes":"No")<<endl;
  }
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main(){
	int N; cin >> N; int dif = 0; 
	for(int i = 1; i <= N; i++){
		int a; cin >> a; 
		if(a != i) dif ++; 
	}
	if(dif <= 2) cout << "YES" << endl; 
	else cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

  int count = 0;
  for (int i = 0; i < n; i++) {
    int item = a[i];
    while (item % 2 == 0) {
      count++;
      item /= 2;
    }
  }

  cout << count << endl;
}

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

signed main() {
    int n, m;
    cin >> n;
    map<string, int> table;
    rep(i, n){
        string s;
        cin >> s;
        table[s]++;  
    }
    cin >> m;
    rep(i, m){
        string t;
        cin >> t;
        table[t]--;
    }

    int ans = 0;
    for(auto i = table.begin(); i != table.end(); i++){
        ans = max(ans, i->second);
    }

    cout << ans << endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

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

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

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

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

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

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec A(N);
  rep(i, N){
    cin >> A[i];
    A[i] -=i+1;
  }
  sort(ALL(A));
  ll b = A[N/2];
  if(N%2==0){
    b = (A[N/2] + A[N/2-1])/2;
  }
  ll ans = 0;
  rep(i, N)ans += abs(A[i] - b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4680
A,B,C=map(int,input().split())
MAX=0

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

ans=list(set(make_divisors(A)) & set(make_divisors(B)))
ans.sort(reverse=True)
print(ans[C-1])

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	ll n, t[100005], x[100005], y[100005], i, z, xx, yy, tt;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}

	if ((x[0] + y[0] > t[0]) || (((x[0] + y[0]) % 2) != (t[0] % 2))) {
		cout << "No" << endl;
		return 0;
	}
	for (i = 1; i < n; i++) {
		xx = abs(x[i] - x[i - 1]);
		yy = abs(y[i] - y[i - 1]);
		tt = t[i] - t[i - 1];
		if ((xx + yy > tt) || (((xx + yy) % 2) != (tt % 2))) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>

void CountingSort(int);

int A[20000000];
int B[20000000];
int C[20000000];

int n;

int main(){

  int i;
  int Max = 0;
  scanf("%d",&n);

  for(i = 1;i <= n;i++){
    scanf("%d",&A[i]);
      
    if(Max < A[i]){ 
      Max = A[i];
    }
  }

  CountingSort(Max);
  
  for(i = 1;i <= n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[i]);
  return 0;
}

void CountingSort(int k){

  int i, j;

  for(i = 0;i <=k;i++){
    C[i] = 0;
  }

  for(j = 1;j <=n;j++){

    C[A[j]]++;
  }

  for(i = 1;i <=k;i++){
    C[i] = C[i] + C[i-1];
  }

    for(j = n;j >=1;j--){

      B[C[A[j]]] = A[j];
      C[A[j]]--;

  }
}

Measured memory_bytes: 21072
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
    scanf("%d %d",&a,&b);
    printf("%d",max(max(a+b,a-b),a*b));

    return 0;
}






Measured memory_bytes: 384
import java.util.Scanner;

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

		long x = c - a - b;
		long y = 0;

		//System.out.println(x);
		if (x < 0) {
			System.out.println("No");
		} else {
			y = x * x - 4 * a * b;
			//System.out.println(y);
			if (y > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vec4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);

int main()
{
     io;
    int T=1;
    //T=gi();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       ll k,cnt=1;
       cin>>k;
        ll mod=7;
       if(~k&1||k%10==5)
       {
           cout<<-1;
           _
       }
       while(mod%k&&cnt<10000007){cnt++;mod=(mod*10+7)%k;}
       if(cnt==10000007)cout<<-1;
      else cout<<cnt;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int abs(int a,int b){
	if(a>b) return a-b;
	else return b-a;
}

int bekia(int a,int b){
	int tempo=1;
	rep(i,b){
		tempo = a * tempo;
	}
	return tempo;
}

int main (){
	int XXX;
	cin >>XXX;
	int beki[11][40]={0};
	int anstemp = 1;
	rep(i,40){
		Rep(j,2,11){
			if(bekia(i+1,j)>1010 ){
				break;
			}
			beki[j][i] = bekia(i+1,j);
		}
	}
	rep(i,40){
		rep(j,11){
			if(XXX>=beki[j][i] && anstemp <=beki[j][i]){
				anstemp = beki[j][i];
			}
		}
	}


	cout << anstemp << endl;
}


Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

s = S()
ans = 0
temp = 0
for i in s:
    if i in 'ACGT':
        temp += 1
    else:
        temp = 0
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 8964
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define cont continue  
#define MOD 998244353
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll INF = 10000000000000001;
const double pi = 3.141592653589793;

int T;

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

  ll A, B, C, K; // 1, 0, -1
  ll ans = 0;

  cin >> A >> B >> C >> K;

  if(A >= K) {
    cout << K << endl;
  }
  else {
    K -= A;
    ans = A;
    if(K <= B) {
      cout << ans << endl;
      return 0;
    }
    else {
      K -= B;
      ans = A;
      cout << ans - K << endl;
      return 0;
    }
  }
  return 0;
}

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

void trace(int V[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << V[i];
    }
    cout << endl;
}

void insertionSort(int A[], int N) {
    for (int i = 1; i < N; i++ ) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j]>v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A,N);
    }
}
int main()
{
    int N{ 0 };
    cin >> N;
    int Array[100];

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

    trace(Array,N);
    insertionSort(Array,N);
}


Measured memory_bytes: 3088
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0003&lang=jp
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

bool ok(int a, int b, int c){
	int arr[3];
	arr[0] = a, arr[1] = b, arr[2] = c;
	sort(arr, arr+3);
	return arr[2]*arr[2] == arr[0]*arr[0] + arr[1]*arr[1];
}


int main(){
	int n;
	cin >> n;
	int a,b,c;
	for(int i=0; i<n; i++){
		cin >> a >> b >>c;
		if(ok(a,b,c)) cout << "YES" << endl;
		else cout <<"NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define loop1(i, start, end) for (int i = start; i < end; i++)
#define loop2(i, start, end) for (int i = end; i >= start; i--)

const int mod = 1000000007;
inline int add(int a, int b)
{
    return a + b >= mod ? a + b - mod : a + b;
}
inline int multi(int a, int b) { return int(a * 1ll * b % mod); }
typedef long long ll;
typedef long double lld;
void solve()
{
    char ch;
    cin >> ch;
    if ((int)ch <= 122 && (int)ch >= 97)
        cout << "a";
    else
    {
        cout << "A";
    }
}
int main()
{
    int t;
    solve();
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    long int people[5], n;
    cin >> n;
    for(int i=0; i<5; i++){
        cin >> people[i];
    }
    
    long int a = n/people[0];
    if(n%people[0]!=0) a++;
    long int ans=a;
    long int tmp1, tmp2;
    int flag=0;
    for(int i=1; i<5; i++){
        tmp1=n/people[flag];
        if(n%people[flag]!=0) tmp1++;
        tmp2=n/people[i];
        if(n%people[i]!=0) tmp2++;
        if(people[flag]<=people[i]){
            ans++;
        }else{
            flag=i;
            ans+=tmp2-tmp1;
            ans++;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
ll cnt;
vector<ll> v,d;
map<ll,ll> m;
void divisor(ll n,ll t)
{
    ll r=1;
    if(n==1)
    {
        rep(i,m[v[n-1]]+1)
        {
            d.pb(t*r);
            r*=v[n-1];
        }
    }
    else
    {
        rep(i,m[v[n-1]]+1)
        {
            divisor(n-1,t*r);
            r*=v[n-1];
        }
    }
}
int main()
{
    ll n,a,ans=0;
    cin>>n;
    a=n;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(a%i==0)
        {
            v.pb(i);
            //cout<<v.back()<<"\n";
        }
        while(a%i==0)
        {
            a/=i;
            m[i]++;
        }
    }
    if(a>1)
    {
        v.pb(a);
        m[a]++;
    }
    //cout<<v.back()<<"\n";
    cnt=v.size();
    divisor(cnt,1);
    //cout<<d.size()<<"e\n";
    rep(i,d.size())
    {
        if(d[i]==1) continue;
        //cout<<d[i]<<"\n";
        ll t=n;
        while(t%d[i]==0) t/=d[i];
        if(t%d[i]==1) ans++;
    }
    a=n-1;
    ll b=1;
    for(int i=2;i<=sqrt(n-1);i++)
    {
        ll k=0;
        while(a%i==0)
        {
            a/=i;
            k++;
        }
        b*=(k+1);
    }
    if(a>1) b*=2;
    cout<<ans+b-1;
}


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    map<ll, ll> mp;

    ll a;
    rep(0, i, N)
    {
        cin >> a;
        mp[a]++;
    }

    ll ans = 0;
    priority_queue<ll> pq;
    for (auto m : mp)
    {
        if (m.second >= 4)
        {
            ans = max(ans, m.first * m.first);
        }
        if (m.second >= 2)
        {
            pq.push(m.first);
        }
    }
    if (pq.empty())
    {
        cout << 0 << endl;
        return 0;
    }
    ll res1 = pq.top();
    pq.pop();
    ll res2 = pq.top();
    ans = max(ans, res1 * res2);

    cout << ans << endl;
}

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


int main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> h(n);
  rep(i,n)cin>>h[i];
  ll dp[n+2];
  rep(i,n+2)dp[i]=INF;
  dp[0]=0;
  rep(i,n){
    rep(j,k){
      if (i+j>=n-1)continue;
      dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(h[i+j+1]-h[i]));
    //  cout<<dp[j]<<"i"<<i<<"j"<<j<<endl;
    }
  }
cout<<dp[n-1];

}


Measured memory_bytes: 4752
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}
ll A, B, X;
bool isOK(ll g,ll X) {
	if (g > X) return true;
	else return false;
}
ll keta(ll a) {
	ll k = 0;
	a = abs(a);
	if (a == 0)return 1;
	while (a > 0) {
		k++;
		a /= 10;
	}
	return k;
}
ll binary_search(ll key,ll A,ll B,ll X) {
	int left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = 1000000000; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(A*mid+B*keta(mid),X)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return left;
}

int main() {
	ll N, P, an = 1;;
	cin >> N >> P;
	for (ll i = 2; i * i <= P; i ++) {
		ll k = 0;
			while (P % i == 0) {
				k++;
				P /= i;
			}
			rep(j, k / N) {
				an *= i;
			}
	}
	if (N == 1) {
		an *= P;
	}
	cout << an << endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i * i < n; i++)
        if (n % i == 0 && i < (n / i - 1))
            ans += n / i - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		scan.close();
		int min_fee;
		if(a>b)min_fee=b;
		else min_fee=a;
		
		System.out.println((c>d)? min_fee+d:min_fee+c);
	}
}


Measured memory_bytes: 23892
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N, A, B;

int main(){
	cin >> N >> A >> B;
	cout << min(A*N, B) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
vector<vector<int> > nxt;
string s,t;
int n,m;
int pre1[N+5],pre2[N+5];
int main()
{  fast
 cin>>s>>t;
 n=s.size();
 m=t.size();
 for(int i=0;i<n;i++)
 {
 	pre1[i+1]+=pre1[i];
 	if(s[i]=='A')
 	pre1[i+1]++;
 	else
 	pre1[i+1]+=2;
 }
 for(int i=0;i<m;i++)
 {
 	pre2[i+1]=pre2[i];
 	if(t[i]=='A')
 	pre2[i+1]++;
 	else
 	pre2[i+1]+=2;
 }
 int q;
 cin>>q;
 while(q--)
 {
 	int a,b,c,d;
 	cin>>a>>b>>c>>d;
 	if((pre1[b]-pre1[a-1])%3==(pre2[d]-pre2[c-1])%3)
	puts("YES\n");
	else
	puts("NO\n");
 }
}


Measured memory_bytes: 1744
n = int(input())
a = [int(i) for i in input().split()]
if 0 in a:
    print(0)
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

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

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            var (x, n) = IOUtils.Read2Ints();

            if (n == 0) {
                Console.ReadLine();
                System.Console.WriteLine(x);
                return;
            }

            var vals = new HashSet<int>(IOUtils.ReadInts());

            foreach (var diff in Enumerable.Range(0, 101))
            {
                if (diff == 0) {
                    if (!vals.Contains(x)) {
                        System.Console.WriteLine(x);
                        return;
                    }
                    continue;
                }
                var sml = x - diff;
                var lg = x + diff;

                if (!vals.Contains(sml)) {
                    System.Console.WriteLine(sml);
                    return;
                }
                if (!vals.Contains(lg)) {
                    System.Console.WriteLine(lg);
                    return;
                }
            }

        }
    }
    
    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


Measured memory_bytes: 28360
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll H, W, K;
	std::cin >> H >> W >> K;

	vector<string> S(H);
	rep(i, 0, H) {
		std::cin >> S[i];
	}

	ll ans = 0;
	rep(i, 0, (1LL << H)) {
		rep(j, 0, (1LL << W)) {
			ll cnt = 0;
			rep(ii, 0, H) {
				if (i & (1LL << ii)) {
					rep(jj, 0, W) {
						if (j & (1LL << jj)) {
							if (S[ii][jj] == '#') {
								cnt++;
							}
						}
					}
				}
			}
			if (cnt == K) {
				ans++;
			}
		}
	}

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


Measured memory_bytes: 3624
n = int(input())

# head and tailのつもり
h_and_t = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, n + 1):
    s = str(i)
    # 一番左がpで一番右がq、のように1からNまでの数を分類
    # 10と100は同じ、2と22は同じ、など
    # 0から始まる数字はないので、h_and_t[0]はNの値に関わらず[0,0,...0]となる
    h_and_t[int(s[0])][int(s[-1])] += 1

#print(h_and_t)

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        # i=2,j=3なら、(23,32),(23,302)...などが拾える
        # i=3,j=2なら、(32,23),(32,203)...

        # Aの場合の数*Bの場合の数
        ans += h_and_t[i][j] * h_and_t[j][i]
print(ans)


Measured memory_bytes: 9200
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {

	const ll mod = 1000000007;
	ll C[200000];
	ll right[200000];
	ll dp[200001];

	ll N;
	cin >> N;

	rep(i, N) {
		cin >> C[i];
		--C[i];
	}

	rep(i, 200000) right[i] = -1;

	dp[N] = 1;
	ford (i, 0, N) {
		dp[i] = dp[i + 1];
		if (right[C[i]] != -1 && right[C[i]] != i + 1) {
			dp[i] += dp[right[C[i]]];
			if (dp[i] >= mod) dp[i] -= mod;
		}

		right[C[i]] = i;
	}

	cout << dp[0] << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long i,j,k,n;
	cin>>n;
	long long arr[n+1];
	for(i=1;i<=n;i++){
	    cin>>arr[i];
	}
	long long dp[n+1][n+1];
	for(i=1;i<=n;i++){
	    dp[i][i]=arr[i];
	}
	for(i=n;i>=1;i--){
	    for(j=i;j<=n;j++){
	        if(i!=j){
	            dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
	        }
	    }
	}
	cout<<dp[1][n];
}

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

typedef pair<int,int> ii;
int n,m,p[1005];
long long dist[1005];
vector<ii> adj[1005];

bool hasNegativeCycle = false;

int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    adj[a].push_back(ii(b,-c));
  }
  for (int i = 1; i <= n; i++) dist[i] = 1000000000000000007;
  dist[1] = 0;
  for(int i=1;i<=n;i++) p[i]=i;
  for (int i = 0; i < n - 1; i++) { // relax all edges N-1 times
      for (int u = 1; u <=n; u++) { 
          for (auto v : adj[u]) {
            if(dist[u]+v.second<dist[v.first]) p[v.first]=u;
              dist[v.first] = min(dist[v.first], dist[u] + v.second); // node, distance
          }
      }
  }
  set<int> si;
  int cur=n;
  while(cur!=1){
    if(si.find(cur)!=si.end()) break;
    si.insert(cur);
    cur=p[cur];
  }
  for (int u = 1; u <= n; u++) {
    for (auto v : adj[u]) {
        if (dist[v.first] > dist[u] + v.second&&dist[u]!=1000000000000000007&&(si.find(v.first)!=si.end())) {
            hasNegativeCycle = true;
        }
    }
}
  if(hasNegativeCycle==true) printf("inf");
  else printf("%lld",-dist[n]);
}

Measured memory_bytes: 384
import numpy as np
N, M =map(int,input().split())
coeff = np.zeros((M,N)) # M行N列のO行列を作成(行列の添字はそれぞれ０からであることに注意)
for i in range(M):
    input_list = list(map(int, input().split())) # 標準入力をint化し、listに入れる
    for j in input_list[1:]: # jにinput_list内の値をindex=1から代入、[1:]とすることでinputしたリストのサイズが変わっても対応
        coeff[i][j-1] = 1 # i行j-1列の値を1にする
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    vec = [int(num) for num in bin(i)[2:]] # iの２進表示を各桁に分けてベクトルとして保存
    fill = N - len(vec)
    vec = np.append(np.zeros(fill), np.array(vec)) # np.zeronos(fill)で0000, np.array(vec)で101101って感じ
    if(all(np.dot(coeff, vec) % 2 == p)):
        ans += 1
print(ans)


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

const int MAXN = 1e5 + 21;

int a[MAXN];
int n, m, cnt;
int u, v;
long long ans;
vector<int> adj[MAXN], t[MAXN];
bool vis[MAXN];

void dfs(int root);

int main() {
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	for (int i = 1; i <= m; i++) {
		cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	
	for (int i = 1; i <= n; i++)
		if (!vis[i]) {
			cnt++; 
			dfs(i);
		}
	
	for (int i = 1; i <= n; i++)
		vis[i] = false;
	
	for (int i = 1; i <= cnt; i++) {
		for (auto y: t[i])
			vis[y] = true;

		for (auto y: t[i])
			if (vis[a[y]])
				ans++;
		
		for (auto y: t[i])
			vis[y] = false;
	}
	
	cout << ans << '\n';
	return 0;
}

void dfs(int root) {
	t[cnt].push_back(root);

	vis[root] = true;

	for (auto y: adj[root])
		if (!vis[y])
			dfs(y);
}


Measured memory_bytes: 12156
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
#include <cmath>
using namespace std;
typedef pair<long long int,long long int> pll;
int main(int argc, char const *argv[])
{
	long long int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	b-=a;
	for (int i = 0, j = 1 - n; i <= n - 1; ++i, ++j)
	{
		long long int v1 = c*i + d*j;
		long long int v2 = c*j + d*i;
		if(v1 > v2)
			swap(v1,v2);
		if(v1 <= b && b <= v2)
		{
			cout<<"YES\n";
			return 0;
		}
	}
	cout<<"NO\n";
	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 100;
  int a[101];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];

  int ans = 0;
  for(int i = 0; i < n; i++){
    if(a[i] % 2 == 1 && (i+1) % 2 == 1) ans ++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
import java.util.*;

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

    while (true) {
      a = sc.nextInt();
      b = sc.nextInt();

      if (a == 0 && b == 0) {
        break;
      }

      if (a > b) {
        int temp = a;
        a = b;
        b = temp;
      }
      System.out.println(String.format("%d %d", a, b));
    }
  }
}

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

const Int INF = 1e18;

Int power(Int a, Int n) {
    Int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    Int N;
    cin >> N;
    vector<Int> A(N+1), cap(N+1), B(N+1, 0);
    rep(i,N+1) cin >> A[i];

    if (N == 0) {
        if (A[0] != 1) {
            cout << -1 << endl;
            return 0;
        }
        else {
            cout << 1 << endl;
            return 0;
        }
    }

    cap[0] = 1 - A[0];
    if (N > 0) {
        rep1(i,N) {
          if (2 * cap[i-1] < A[i]) {
              cout << "-1" << endl;
              return 0;
          }
          cap[i] = min(2 * cap[i-1] - A[i], INF);
        }
    }

    //rep(i,N+1) cout << cap[i] << endl;

    B[N] = 0;
    for (Int i = N-1; i>=0; i--) {
      if (2 * cap[i] < B[i+1] + A[i+1]) {
        cout << -1 << endl;
        return 0;
      }
      else {
          B[i] = min(cap[i],B[i+1] + A[i+1]);
      }
    }

    Int ans = 0;
    rep(i,N+1) ans += A[i] + B[i];

    cout << ans << endl;
}

Measured memory_bytes: 5636
#include <stdio.h>

int main(){
int N;
scanf("%d",&N);
int i;
int ans = 0;
int prev = 0;
for(i=0;i<N;i++){
int now;
scanf("%d ",&now);
if(now<prev){
ans+=prev-now;
}
prev=now;
}
printf("%d\n",ans+prev);
return 0;
}

Measured memory_bytes: 128
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
    for j in range(i + 2,N):
        cnt += min(j - bisect.bisect_left(L,L[j] - L[i] + 1), j - i - 1)
print(cnt)

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

using namespace std;

typedef long long ll;

// 隣接リストで使う辺を表す型
struct Edge {
  ll to, cost;  // 辺の接続先頂点, 辺の重み
  Edge(ll to, ll cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
                // graph[v][i]は頂点vから出るi番目の辺Edge

const ll INF = 1e15;

vector<ll> dist; // 最短距離

// 戻り値がtrueなら負の閉路を含む
int bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
  dist = vector<ll>(n, INF);
  dist[s] = 0; // 開始点の距離は0
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        Edge e = graph[v][k];
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          if (i == n - 1) return e.to; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }
  return -1;
}

vector<vector<Edge>> rg;
set<int> st;

void dfs(int u){
	for(Edge e: rg[u]){
		if(st.count(e.to) == 0){
			st.insert(e.to);
			dfs(e.to);
		}
	}
}

// 使い方
int main() {
  ll n, m, p;
  cin >> n >> m >> p;

  vector<vector<Edge>> g(n);
  rg.resize(n);

  for (int i = 0; i < m; i++) {
    ll from, to, cost;
    cin >> from >> to >> cost;
	from--;
	to--;
    g[from].push_back(Edge(to, -(cost - p)));
	rg[to].push_back({from, cost});
  }
  
  st.insert(n-1);
  dfs(n-1);
  graph = AdjList(n);
  rep(i, n){
	for(Edge e : g[i]){
		if(st.count(e.to) == 1){
			graph[i].push_back(e);
		}
  	}
  }
  
  int x = bellman_ford(n, 0);
  if(x > -1 && st.count(x) == 1){
	  cout << -1 << endl;
	  return 0;
  }
  
  if(dist[n - 1] > 0) {
	cout << 0 << endl;
  }else{
	cout << -dist[n - 1] << endl;
  }
}


Measured memory_bytes: 1024
using System;
namespace OJ_C_Sharp {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[,] f = new int[n, 10];
            int[,] p = new int[n, 11];
            for (int i = 0; i < n; i++) {
                var input_f = Console.ReadLine().Split(' ');
                for (int j = 0; j < 10; j++) {
                    f[i, j] = int.Parse(input_f[j]);
                }
            }
            for (int i = 0; i < n; i++) {
                var input_p = Console.ReadLine().Split(' ');
                for (int j = 0; j < 11; j++) {
                    p[i, j] = int.Parse(input_p[j]);
                }
            }
            int max = int.MinValue;
            for (int i = 1; i < 1024; i++) {
                int pro = 0;
                for (int j = 0; j < n; j++) {
                    int c = 0;
                    for (int k = 0; k < 10; k++) {
                        if (((i >> k & 1) == 1) && (f[j, k] == 1)) {
                            c++;
                        }
                    }
                    pro += p[j, c];
                }
                if (max < pro) {
                    max = pro;
                }
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 13140