akhauriyash/Code-Regression huggingface dataset:
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

int n;
vector<vector<pair<int, int>>> axy;

bool judge(int bit) {
    rep(i, n) {
        if(!(bit & (1 << i))) continue;

        for(pair<int, int> xy : axy[i]) {
            int x = xy.first;
            int y = xy.second;

            if(y == 1 && !(bit & (1 << x))) return false;

            if(y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    axy.resize(n);
    rep(i, n) {
        int a;
        cin >> a;
        axy[i].resize(a);
        rep(j, a) {
            cin >> axy[i][j].first >> axy[i][j].second;
            --axy[i][j].first;
        }
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++) {

        if(judge(bit)) {
            int count = 0;
            for(int i = 0; i < n; i++) {
                if(bit & (1 << i)) count++;
            }
            ans = max(ans, count);
        }
    }
    COUT(ans);
}


Measured memory_bytes: 256
n, m = [int(v) for v in input().split()]
l = [0] * m
for _ in range(n):
        k = [int(v) for v in input().split()]
        for i in range(1, len(k)):
                l[k[i] - 1] += 1
ans = 0
for num in l:
        if num == n:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#ITP1-ITP1_5_B
while True:
  h,w = (input().split())
  h = int(h)
  w = int(w)
  if h == 0 and w == 0:
    break
  for a in range(w):
    print("#",end="")
  print("")
  for b in range(h-2):
    print("#","."*(w-2),"#",sep="")
  for a in range(w):
    print("#",end="")
  print("\n")


Measured memory_bytes: 5636
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        var max = 0;
        for (int i = 0; i < s.Length; i++)
        {
            try
            {
                int length = 0;
                while (true)
                {
                    var sub = s.Substring(i, length);
                    if (sub.Except(new char[] { 'A', 'T', 'G', 'C' }).Count() > 0) break;
                    max = Max(max, length);
                    length++;
                }
            }
            catch { }
        }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 13268
import numpy as np
N =int(input())
action = [[int(a) for a in input().split()]]
for n in range(N-1):
    action.append([int(a) for a in input().split()])
action = np.array(action)
dp = np.full((N,3),10**10,dtype=int)
dp[0] = action[0]
for i in range(1,N):
    for a in range(3):
        if a ==0:
            dp[i][0] = action[i][0] + max(dp[i-1][1],dp[i-1][2])
        if a ==1:
            dp[i][1] = action[i][1] + max(dp[i-1][0],dp[i-1][2])
        if a ==2:
            dp[i][2] = action[i][2] + max(dp[i-1][1],dp[i-1][0])

print(max(dp[N-1])) 

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

using ll =  long long;
using pint =  pair<int,int>;

//#define int long long
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}
signed main(void){
    int h,n;cin>>h>>n;
    vector<pint> ab(n);
    rep(i,n)cin>>ab[i].first>>ab[i].second;
    vvint dp(n+10,vint(h+10,INT_MAX));
    dp[0][0]=0;
    rep(i,n){
        rep(j,h+1){
            if(j<ab[i].first) dp[i+1][j]=min(dp[i][j],ab[i].second);
            else dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i].first]+ab[i].second);
        }
    }
    cout << dp[n][h] << endl;
    /*rep(i,n){
        cout << "waza" << i << " : ";
        rep(j,h+1)cout << dp[i][j] << " "; 
        cout << endl;
    }*/
}


Measured memory_bytes: 39808
n, k = map(int, input().split())
mod = 1000000007

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

if k >=n:
  L = 2*n-1
  ansbunsi =1
  for j in range(n-1):
    ansbunsi = ansbunsi*L%mod
    L -= 1
  ansbunbo = 1
  L = n - 1
  for j in range(n-1):
    ansbunbo = ansbunbo*L%mod
    L -= 1
  ansbunbo = modinv(ansbunbo)
  print(ansbunsi*ansbunbo%mod)

else:
  kaijou = [1, 1]
  for j in range(2, n):
    kaijou.append(kaijou[-1]*j%mod)
  
  ans = 0

  for m in range(k+1):
    ansbunsi = (kaijou[n-1]**2)*n%mod
    ansbunbo = kaijou[n-m-1]*kaijou[m]%mod
    ansbunbo = ansbunbo*ansbunbo%mod*(n-m)%mod
    ansbunbo = modinv(ansbunbo)
    ans += ansbunbo*ansbunsi%mod
    ans %= mod
  
  print(ans)
    


Measured memory_bytes: 90864
#include <iostream>
#include <cstdio>
#include <queue>
#define N 55
using namespace std;

int h, w, c, fh, fw, fc;
bool v[N][N];
//string a[N];
char a[N][N];
queue<int> qh, qw, qc;
int main()
{
	int i, j;
	cin >> h >> w;
//	for (i = 1; i <= h; i++) cin >> a[i], a[i] = ' ' + a[i] + ' ';
//	for (i = 1; i <= w; i++) a[0][i] = a[h + 1][i] = ' ';
	for (i = 0; i <= h + 1; i++) for (j = 0; j <= w + 1; j++) a[i][j] = ' ';
	for (i = 1; i <= h; i++) scanf("%s", &a[i][1]);
	if (a[1][1] == '#') {cout << "-1"; return 0;}
	qc.push(1), qh.push(1), qw.push(1);
	while (!qc.empty()) {
		fc = qc.front(), qc.pop();
		fh = qh.front(), qh.pop();
		fw = qw.front(), qw.pop();
		if (fh == h && fw == w) break;
		if (v[fh][fw]) continue;
		v[fh][fw] = 1;
		if (a[fh][fw - 1] == '.' && !v[fh][fw - 1]) qh.push(fh), qw.push(fw - 1), qc.push(fc + 1);
		if (a[fh][fw + 1] == '.' && !v[fh][fw + 1]) qh.push(fh), qw.push(fw + 1), qc.push(fc + 1);
		if (a[fh - 1][fw] == '.' && !v[fh - 1][fw]) qh.push(fh - 1), qw.push(fw), qc.push(fc + 1);
		if (a[fh + 1][fw] == '.' && !v[fh + 1][fw]) qh.push(fh + 1), qw.push(fw), qc.push(fc + 1);
	}
	if (fh != h || fw != w) {cout << "-1"; return 0;}
	for (i = 1; i <= h; i++) for (j = 1; j <= w; j++) if (a[i][j] == '.') c++;
    cout << c - fc << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool T=false;
int main(){
    int N;cin>>N;
    int ans=0;
    for (int i = 0; i < 11; i++)
    {
        if(i*1000-N<0)continue;
        ans=i*1000-N;
        break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  map<int, int> mp;
  REP(i, 3) {
    int a, b; cin >> a >> b;
    ++mp[a];
    ++mp[b];
  }
  int one = 0, two = 0;
  FOR(i, 1, 5) {
    if (mp[i] == 1) ++one;
    else ++two;
  }
  cout << (one == 2 && two == 2 ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

a, b, c = na()
k = ni()
m = max(a, b, c)
print(a + b + c + m * (2 ** k - 1))

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final int N=sc.nextInt();
    final int K=sc.nextInt();
    final int X=sc.nextInt();
    final int Y=sc.nextInt();
    int answer=0;
    if(N<=K){
      answer=N*X;
    }else{
      answer=K*X+Y*(N-K);
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 20820
s = int(input())
a = [s]
i = 1

f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1

while True:
    a.append(f(a[i-1]))
    i += 1

    if a[-1] in a[:-1]:
        break

print(i)


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{

    public static void main(String[] args){

	Scanner scan = new Scanner(System.in);

	String data = scan.next();

	for(int i = data.length() - 1; i >= 0; i--){
	    System.out.print(data.charAt(i));
	}

	System.out.println();
    }

}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#define MAX 100000
using namespace std;

int n, A[MAX+1], L[MAX];

int lis(){
     L[0] = A[0];
     int length = 1;

     for(int i = 1; i < n; ++i){
          if(L[length-1] < A[i]){
              L[length++] = A[i]; 
          } else {
              *lower_bound(L, L + length, A[i]) = A[i];
          }
     }
     return length;
}


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

    cout << lis() << endl;
    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  char now = S[0];
  int ans = 1;
  for (int i = 1; i < N; i++)
  {
    if (now != S[i])
      ans++;
    now = S[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	r(i,(int)s.size()){
		int p=s[i]-'A';
		char c = ((p+n)%26)+'A';
		s[i]=c;
	}
	cout<<s<<endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,C;
  cin>>N>>M>>C;
  vector<int> B(M);
  for(int i=0;i<M;++i)cin>>B[i];
  int A,sum,res=0;
  for(int i=0;i<N;++i){
    sum=C;
    for(int j=0;j<M;++j){
      cin>>A;
      sum+=A*B[j];
    }
    if(sum>0)res++;
  }
  cout<<res;
  return 0;
}

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

using namespace std;

int main()
{
	int X;
	cin >> X;
	int Y = 0;
	for (int n = X; n != 0; n /= 10) {
		Y += n % 10;
	}
	if (X % Y == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N;
ll A[201000];
map<ll, ll> mp;
ll ans;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        mp[A[i]]++;
    }
    for(auto tmp : mp) {
        ans += tmp.second * (tmp.second-1) / 2;
    }
    for(int i = 0; i < N; i++) {
        ll now = ans;
        now -= mp[A[i]] * (mp[A[i]]-1) / 2;
        now += (mp[A[i]]-1) * (mp[A[i]]-2) / 2;
        cout << now << endl;
    }
    return 0;
}

Measured memory_bytes: 12160
N = int(input())
a = list(map(int, input().split()))

rating = []
s = 0

for i in range(N):
  if a[i] >= 3200:
    s += 1

  if a[i] < 400:
    rating.append('0')
  elif a[i] < 800:
    rating.append('1')
  elif a[i] < 1200:
    rating.append('2')
  elif a[i] < 1600:
    rating.append('3')
  elif a[i] < 2000:
    rating.append('4')
  elif a[i] < 2400:
    rating.append('5')
  elif a[i] < 2800:
    rating.append('6')
  elif a[i] < 3200:
    rating.append('7')

min = len(list(set(rating)))

if min == 0:
  print(1, min + s)
else:
  print(min, min + s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long n,m,i,j,a[100005],b[100005],ans,sum;
vector<int> c1,c2;
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		if (a[i]>b[i]) c1.push_back(a[i]-b[i]);
		if (a[i]<b[i]) {ans++;sum+=b[i]-a[i];}
	}
	sort(c1.begin(),c1.end());
	reverse(c1.begin(),c1.end());
	i=-1;
	if (sum>0) for (i=0;i<c1.size();i++)
	{
		sum-=c1[i];
		if (sum<=0) break;
	}
	if (i>=0&&i>=c1.size()) puts("-1"); else cout<<i+ans+1<<endl;
	return 0;
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int>x(n),y(n),num(n);
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  for(int i=0;i<n;i++)num[i]=i;
  double sum=0;
  do{
    for(int i=0;i<n-1;i++){
      sum+=sqrt( (x[num[i]]-x[num[i+1]])*(x[num[i]]-x[num[i+1]])+(y[num[i]]-y[num[i+1]])*(y[num[i]]-y[num[i+1]]));
    }
  }while(next_permutation(num.begin(),num.end()));
  double waru=1;
  for(int i=2;i<=n;i++){
    waru*=i;
  }
  double kotae=sum/waru;
  cout<<fixed<<setprecision(12)<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t,u;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    cin>>u;
    if(s.compare(u)==0)
    {
        a--;
    }
    else
    {
        b--;
    }
    cout<<a<<" "<<b;
	return 0;
}







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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int k, a, b;
	cin >> k >> a >> b;
	if (a/k == b/k) {
		if (a % k == 0 || b % k == 0)
			cout << "OK";
		else 
			cout << "NG";
	}
	else 
		cout << "OK";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n';

int n, a;
deque <int> v;
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    rep(i, 0, n, 1) {
        cin >> a;
        if (i % 2 == 0) {
            v.pb(a);
        }
        else {
            v.pf(a);
        }
    }
    if (n % 2 == 1) {
        reverse(all(v));
    }
    for(auto it:v) {
        cout << it << ' ';
    }
    time;
}

Measured memory_bytes: 5408
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long X=s.nextLong();
	long year=0;
    long box=100;
    
	for(year=0;box<X;year++){
      box+=(long)(box*0.01);
    }
    System.out.println(year);
  }  
}

Measured memory_bytes: 35756
#include<stdio.h>
#include<math.h>
int main (void){
long long int n,d,a,b,s,i,count;;
s=0;
count=0;
scanf("%lld %lld",&n,&d);
for(i=0;i<n;i++){
    scanf("%lld %lld",&a,&b); 
    s = a*a+b*b;
    if(d*d>=s)count++;
}
printf("%lld",count);
return 0;
}

Measured memory_bytes: 1704
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException, Exception{
		BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
		int[] data1 = getIntArry(st);
		int n = data1[0];
		int k = data1[1];
		int[] data2 = getIntArry(st);
		int ans = 0;
		for(int i=0;i<n;i++) {
			if (data2[i] >= k) {
				ans++;
			}
		}
		anser(ans);
	}

	private static int[] getIntArry(BufferedReader st) throws Exception, IOException {
		String line = st.readLine();
		String[] strData = line.split(" ");
		int[] intData = new int[strData.length];
		for (int i = 0; i < strData.length; i++) {
			intData[i] = Integer.parseInt(strData[i]);
		}
		return intData;
	}

	private static void anser(int num) {
		System.out.println(num);
	}
}

Measured memory_bytes: 35480
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String n = scan.nextLine();
			if(n.equals("0000")){
				break;
			}
			if(n.charAt(0) == n.charAt(1)
					&& n.charAt(0) == n.charAt(2)
					&& n.charAt(0) == n.charAt(3)){
				System.out.println("NA");
				continue;
			}
			int count = 0;
			char[] num;
			int t = 0;
			while(!n.equals("6174")){
				num = n.toCharArray();
				Arrays.sort(num);
				t = Integer.parseInt(""+num[3]+num[2]+num[1]+num[0]) 
						- Integer.parseInt(""+num[0]+num[1]+num[2]+num[3]);
				if(t < 10){
					n = "000" + String.valueOf(t);
				}else if(t < 100){
					n = "00" + String.valueOf(t);
				}else if(t < 1000){
					n = "0" + String.valueOf(t);
				}else{
					n = String.valueOf(t);
				}
				count++;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 59164
import math

def main():
    while True:
        r0,w0,c,r = map(int,input().split())
        if not r0 and not w0 and not c and not r:
            return
        current = r0/w0
        ans = 0
        if c < current:
            ans = 0
        else:
            ans = math.ceil((c*w0-r0)/r)
        
        print(ans)
            

if __name__ == '__main__':
    main()



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

const ll mod=1000000007;
const int lim=56;

ll mw[lim][lim][2];//akt i pre

ll m3[lim][lim];//te beda do potegowanie
ll m4[lim][lim];//do potegowanie

int n,m,akt,pre=1;

void przepisz(){
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++) m3[i][j]=m4[i][j];
}

void wyznacz(int i, int j){
	m4[i][j]=0;
	for(int i2=0;i2<=n;i2++){
		m4[i][j]+=(m3[i][i2]*m3[i2][j])%mod;
		if(m4[i][j]>=mod) m4[i][j]-=mod;
	}
}

void pot(){//poteguj tablice
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			wyznacz(i,j);
		}
	}
}//

void wyznacz2(int i, int j){
	mw[i][j][pre]=0;
	for(int i2=0;i2<=n;i2++){
		mw[i][j][pre]+=(mw[i][i2][akt]*m3[i2][j])%mod;
		if(mw[i][j][pre]>=mod) mw[i][j][pre]-=mod;
	}
}

void mn(){
   for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			wyznacz2(i,j);
		}
	}
	swap(akt,pre);
}

int a,b;
ll k;
void prep(){
	//m4[n][0]++;
	//m4[0][0]++;
	for(int i=0;i<=n;i++) mw[i][i][akt]=1;
}

ll suma;

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);


	cin>>n>>k;// k++;
	prep();
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
   		 cin>>m4[i][j];
	}
	
	for(int i=0;(1LL<<i)<=k;i++){
		przepisz();
		if((1LL<<i)&k) mn();
		pot();
	}

//	cout<<mw[1][0][akt];
	for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				suma+=mw[i][j][akt];
				if(suma>=mod) suma-=mod;
			}
	}
	cout<<suma;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);

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

  int temp = 1;
  int ans = 0;


  rep(i,N){
    if (a[i] == temp) {
      ans++;
      temp++;
    }
  }

  if (ans == 0) {
    cout << -1 << endl;
  }else{
    cout << N - ans << endl;
  }

}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
//vector<LL>v;
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    for(LL i=0; i<n; i++)
    {
        cin>>a[i];
    }
    LL cnt=0;
    LL mp[n];
    MEM(mp,0);
    mp[0]=0;
    for(LL i=1; i<n; i++)
    {
        if(a[i]<=a[i-1])
            cnt++;
        else
            cnt=0;
        mp[i]=cnt;
    }
    LL mx=0;
    for(LL i=0; i<n; i++)
    {
        mx=max(mx,mp[i]);
//        cout<<mp[i]<<" ";
    }
    cout<<mx;


}


Measured memory_bytes: 5164
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int A ,B, K;
    cin >> A >> B >> K;
    if (K<=A) {
        A=A-K;
    } else if ((K-A)<=B){
        K=K-A;
        A=0;
        B=B-K;
    } else {
        A=0;
        B=0;
    }
        
   
    
    cout << A << ' ' << B;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> s;
	int ma = 0, cur = 0;
	FOR(i, n) {
		if (s[i] == 'I') cur++;
		else cur--;
		ma = max(ma, cur);
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i],a[i]--;
  ll now = 0;
  ll res = -1;
  ll k = 0;
  map<ll,ll> mp;
  while(1){
    mp[now]++;
    k++;
    now = a[now];
    if(mp[now] >= 1)break;
    if(now == 1){
      res = k;
      break;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 10300
N = gets.to_i
X = gets.split().map(&:to_i)
M = gets.to_i
A = gets.split().map(&:to_i)

A.each do |i|
  next_position = X[i-1] + 1
  next if X.include?(next_position) || next_position > 2019
  X[i-1] = next_position
end

X.each do |i|
  puts i
end


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

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

    int arr[k];
    bool ac=false;
    int mn=1000000,mx=0;

    for (int i=0;i<k;i++)
    {
        cin>>arr[i];
        if (arr[i]<mn)
            mn = arr[i];
        if (arr[i]>mx)
            mx = arr[i];
    }

    int a = mx - mn;
    int mn1 = 0;
    int m;
    for (int i=0;i<k-1;i++)
    {
        if (abs(arr[i+1]-arr[i])>mn1)
        {
            mn1 = abs(arr[i+1]-arr[i]);

        }
    }
    int b = n-mn1;

    if (a>b)
        cout<<b<<endl;
    else
        cout<<a<<endl;


}


Measured memory_bytes: 1024
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

x,y = map(int, input().split())

g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]


if (x in g1 and y in g1):
    print("Yes")
elif (x in g2 and y in g2):
    print("Yes")
elif (x in g3 and y in g3):
    print("Yes")
else:
    print("No")




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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int main(){
	int n=read(),a=read(),b=read();
	int d=b-a-1;
	if(d%2==1) puts("Alice");
	else puts("Borys");


	return 0;
}


Measured memory_bytes: 256
/*
 * AOJ1142_mizo0203.cpp
 *
 *  Created on: 2011/08/18
 *      Author: Satoki
 */
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int iM;
string str;
set<string> s;

void init() {
  scanf("%d", &iM);
}

bool input() {
  if (!iM--) return false;
  s.clear();
  cin >> str;
  return true;
}

void manage() {
  int i;
  string a, b;
  for (i = 1; i < (int)str.length(); i++) {
    a = str.substr(0, i);
    b = str.substr(i);
    s.insert(a + b);
    s.insert(b + a);

    reverse(a.begin(), a.end());
    s.insert(a + b);
    s.insert(b + a);

    reverse(b.begin(), b.end());
    s.insert(a + b);
    s.insert(b + a);

    reverse(a.begin(), a.end());
    s.insert(a + b);
    s.insert(b + a);
  }
  printf("%d\n", s.size());
}

int main() {
  init();
  while (true) {
    if (!input()) break;
    manage();
  }
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


int M,T,P,R;
class Team{
public:
	int id;int sc;
	vector<int> wts;
	int time;
	Team(int id,int sc,int time):id(id),sc(sc),time(time){
		wts=vector<int>(P);
	}

	bool operator < (const Team& r) const{
		if(sc!=r.sc)return sc<r.sc;
		else if(time!=r.time)return time>r.time;
		return id<r.id;
	}

	bool operator > (const Team& r) const{
		if(sc!=r.sc)return sc>r.sc;
		else if(time!=r.time)return time<r.time;
		return id>r.id;
	}
};

class Main{
public:
	
	typedef string::const_iterator Cursor;

	ll parse(Cursor &c){
		if(*c=='['){
			c++;// [
			vector<ll> vs;
			while(*c!=']'){
				vs.push_back(parse(c));
			}
			c++; // ]
			sort(ALL(vs));
			int N=(1+vs.size())/2;
			ll res=0;REP(i,N)res+=vs[i];
			return res;
		}else{
			int v=number(c);
			return (1+v)/2;			
		}
	}

	int number(Cursor &c){
		stringstream ss;
		while(isdigit(*c)){
			ss << *c;
			c++;
		}
		int ret;
		ss >> ret;
		return ret;
	}


	void run(){
		int Q;cin >> Q;
		REP(q,Q){
			string str;cin >> str;
			Cursor c=str.begin();
			cout << parse(c)<<endl;
		}
	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

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

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s,t;
    cin>>s;
    cin>>t;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            count++;
        }
    }
    cout<<count<<"\n";
}

Measured memory_bytes: 3780
#include<stdio.h>
#include<string.h>
int main()
{
	long long a,b,k,i;
	scanf("%lld %lld %lld",&a,&b,&k);
	for(i = 1;i <= k;i++)
	{
		if(i % 2 != 0)
		{
			if(a % 2 == 0)
			{
				b = b + a / 2;
				a = a / 2;
			}
			else
			{
				a = (a - 1) / 2;
				b = b + a;
			}
		}
		else
		{
		    if(b % 2 == 0)
			{
				a = a + b / 2;
				b = b / 2;
			}
			else
			{
				b = (b - 1) / 2;
				a = a + b;
			}
		}
	}
	printf("%lld %lld\n",a,b);
	return 0;
}

	


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<string.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define N 102
// int a[3][N],road[3][N],n;

int main()
{

    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    if((x-a)>=0)
    {
      printf("%d\n",(x-a)%b);
    }
    return 0;
}


Measured memory_bytes: 128
S = list(input())
AC = True
if S[0] != "A" or S.count("C") != 1 or not 2 <= S.index("C") <= len(S)-2:
    AC = False
else:
    count = 0
    for i in range(1, len(S)):
        if "A" < S[i] < "Z":
            count += 1
            if count == 2:
                AC = False

if AC:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
map<string,int>price;
map<string,vector<string> >rec;
int R(string o){
	int m=0,i;
	if(rec[o].size()){
		for(i=0;i<rec[o].size();i++)
			m+=R(rec[o][i]);
	}else
		m=price[o];
	if(price[o]&&price[o]<m)
		m=price[o];
	return m;
}
int main(){
	int n,m;
	string s,t;
	for(;cin>>n,n;){
		price.clear();
		rec.clear();
		for(;n--;){
			cin>>s;
			cin>>price[s];
		}
		cin>>n;
		for(;n--;){
			cin>>s>>m;
			for(;m--;){
				cin>>t;
				rec[s].push_back(t);
			}
		}
		cin>>s;
		cout<<R(s)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=505;
LL n,a[N][N],b[N][N],dp[N][N];
inline LL geta(int s1,int s2,int t1,int t2) {
    if(s1>s2 || t1>t2) return 0;
    return a[s2][t2]-(s1?a[s1-1][t2]:0)-(t1?a[s2][t1-1]:0)+((s1&&t1)?a[s1-1][t1-1]:0);
}
inline LL getb(int s1,int s2,int t1,int t2) {
    if(s1>s2 || t1>t2) return 0;
    return b[s2][t2]-(s1?b[s1-1][t2]:0)-(t1?b[s2][t1-1]:0)+((s1&&t1)?b[s1-1][t1-1]:0);
}
inline LL trans(int x,int y,int z) {
    LL sum=getb(1,x,y+2,z+1);
    sum+=getb(x+1,y,z+1,z+1);
    sum+=geta(y+1,z,y+2,z);
    return sum;
}

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<i;j++) cin>>b[j][i];
        for(int j=i+1;j<=n;j++) cin>>a[i][j];
    }
    for(int i=1;i<=n+1;i++)
        for(int j=1;j<=n+1;j++)
            a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+a[i][j], b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+b[i][j];
    
    memset(dp,0x3f,sizeof(dp));
    for(int i=1;i<n;i++) {
        dp[i][0]=trans(0,0,i);
        for(int p=0;p<i;p++)
            for(int j=i+1;j<n;j++)
                dp[j][i]=min(dp[j][i],trans(p,i,j)+dp[i][p]);
    }
    
    LL ans=trans(0,0,n);
    for(int i=1;i<n;i++)
        for(int p=0;p<i;p++)
            ans=min(ans,dp[i][p]+trans(p,i,n));
    cout<<ans<<'\n';
}


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

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int& i : B) cin >> i;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int sum = C;
		for (int j = 0; j < M; ++j) {
			int A;
			cin >> A;
			sum += B[j] * A;
		}
		if (sum > 0) ++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
n, *x = map(int, open(0).read().split())
mod = 10 ** 9 + 7
fac = [1] * n
for i in range(1, n):
    fac[i] = fac[i - 1] * i % mod

ans = 0
p = 0

for i in range(n - 1):
    p = (p + pow(i + 1, mod - 2, mod))
    ans = (ans + p * (x[i + 1] - x[i])) % mod

print(ans * fac[n - 1] % mod)


Measured memory_bytes: 20056
//ABC0116A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = min({a*b,b*c,c*a})/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
#include<iostream>
using namespace std;
int main() {
	int x=0, o=0, i, num, xo=0, g=0;
	char m[1000001];
	scanf("%d", &num);

	cin >> m;
	
	for (i = 0; i < num-1; i++) {
		if (m[i] == 'X' && m[i + 1] == 'O' || m[i] == 'O' && m[i + 1] == 'X') {
			xo++;
			i++;
		}
	}
	
	printf("%d\n", xo);
	return 0;
}



Measured memory_bytes: 3320
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;
LL K;

LL ans = 0;

void solve(){
    int N = S.size();//桁数
    vector<vector<vector<LL>>> dp;
    dp = vector<vector<vector<LL>>>(N+1,vector<vector<LL>>(K+1,vector<LL>(2,0)));
    //dp[i][j][k]:
    //上からi桁目まで決めて、j個の非0を使う
    //k:0 そこまでの桁はNと一致
    //k:1 そこまでの桁ですでにN以下なことが確定
    //そのときの条件を満たす数値の個数
    dp[0][0][0] = 1;//なにも桁を決めていない状態で、0でない数字が0個、そこまでの桁が一致
    //配るイメージのDP
    for(int i=0;i<N;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<2;k++){
                int nd = S[i]-'0';
                for(int d=0;d<10;d++){
                    int ni = i+1;//i桁目まで決めて、
                    int nj = j;//j個の非0を使う
                    int nk = k;
                    if(d!=0) nj++;//nj個の非0を使う
                    if(nj>K) continue;//非0の数はK個が最大
                    if(k==0){//上からi桁目までの桁がNと一致するとき
                        if(d > nd) continue;
                        if(d < nd) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }
    ans = dp[N][K][0] + dp[N][K][1];
}
 
int main(){
    cin >> S >> K;
 
    solve();

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

Measured memory_bytes: 256
from itertools import combinations

N = int(input())
syogens = []
for i in range(N):
    a = int(input())
    syogen = []
    for j in range(a):
        x,y= map(int,input().split())
        syogen.append((x,y))
    syogens.append(syogen)
#人Aiの証言はsyogens[i]
#j番目の証言は　syogens[i][j]
# print(syogens)

for k in reversed(range(N)): #kにんの正直者がいると仮定
    # print(k)
    comb = combinations(range(N),k+1)
    # print(*comb)
    for pattern in comb: #(0,3,5,6)
        l = [-1]*N
        b=1
        syogen = []
        for i in range(N):
            if i in pattern:
                l[i] = 1
            else:
                l[i] = 0

        # print(l)
        #発言を検証していく
        for person in pattern:
            syogen = syogens[person]
            for s in syogen:
                # print(s)
                target = s[0]
                value = s[1]
                if value != l[target-1]:
                    b = 0
        if b == 1:
            print(k+1)
            exit()

print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 a; std::string b; cin >> a >> b;
	b.erase(begin(b) + 1);
	i64 c = std::stoi(b);
	
	printf("%lld\n", a * c / 100);
	return 0;
}


Measured memory_bytes: 3724
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, M, *A = map(int, read().split())
    ans = sum(A)
    if ans > N:
        ans = -1
    else:
        ans = N - ans
    print(ans)
    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 27484
#include<stdio.h>
int main(void)
{ 
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(a+c==b){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else if(a>b){	
		if(b+c==a){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		if(a+b==c) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

long long A, B, C, D;


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

long long lcm( long long m, long long n ){
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	return ((m / gcd(m, n)) * n); 
}


int main(){
	cin >> A >> B >> C >> D;
	long long ans = B-A+1;
	A--;
	ans -= (B/C) - (A/C);
	ans -= (B/D) - (A/D);
	ans += (B/lcm(C,D)) - (A/lcm(C,D));
	cout << ans << endl;
}

Measured memory_bytes: 256
s = input()

i_A = 0
i_Z = 0
for i in range(len(s)):
  if s[i] == 'A':
    i_A = i
    break

for i in range(len(s)-1, -1, -1):
  if s[i] == 'Z':
    i_Z = i
    break

print(i_Z-i_A+1)

Measured memory_bytes: 3512
from collections import Counter
N, P = map(int, input().split())
S = input()

ans = 0
if P == 2:
    for i, s in enumerate(S, start=1):
        if int(s) % 2 == 0:
            ans += i
elif P == 5:
    for i, s in enumerate(S, start=1):
        if s in "05":
            ans += i
else:
    T = [0] * (N+1)
    d = 1
    for i, s in enumerate(S[::-1], start=1):
        s = int(s) * d + T[i - 1]
        T[i] = s % P
        d *= 10
        d %= P
    c = Counter(T)
    ans = sum(x * (x - 1) // 2 for x in c.values())

print(ans)


Measured memory_bytes: 12012
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, M;
	cin >> N >> M;

	vector<bool> accept(N, false);
	vector<int> panalty_cnt(N, 0);

	int correct = 0;
	int panalty = 0;

	for (int i = 0; i < M; i++)
	{
		int p;
		cin >> p;

		string S;
		cin >> S;

		if (accept[p - 1])
		{
			continue;
		}
		else if (S == "AC")
		{
			accept[p - 1] = true;
			correct++;
			panalty += panalty_cnt[p - 1];
		}
		else
		{
			panalty_cnt[p - 1]++;
		}
	}

	cout << correct << " " << panalty;

	return 0;
}


Measured memory_bytes: 640
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    ll m = inp1;
    ll d = inp1;

    ld term;
    if (d == 0) {
        term = 1.0L / n;
    } else {
        term = 2.L * (n-d) / n / n;
    }

    ld ev = term * (m-1);
    cout << fixed << setprecision(20) << ev << endl;
    
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Char

find ::String -> String -> Bool
find s p 
  | length s < length p    = False
  | take (length p) s == p = True
  | otherwise              = find (drop 1 s) p

main = do
    s <- getLine
    p <- getLine
    let s' = s ++ take (length p - 1) s
    let o = if find s' p then "Yes" else "No"
    putStrLn $ o
    

Measured memory_bytes: 3492
#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>

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


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#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 a,b,c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		outn("bust");
	}
	else {
		outn("win");
	}
	
	return 0;

}


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

class Main {
	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int a[], b[];
		a = new int[7];
		b = new int[7];
		int h;
		
		boolean flag = false;
				
		for(int i = 1; i < 7; i++){
			
			a[i] = scan.nextInt();
			
		}
		
		for(int i = 1; i < 7; i++){
			
			b[i] = scan.nextInt();
			
		}
		

		for(int i = 0; i < 6; i++){
			for(int j = 0; j < 4; j++){
				if(flag == true)break;
					h = a[2];
					a[2] = a[3];
					a[3] = a[5];
					a[5] = a[4];
					a[4] = h;
					flag = Arrays.equals(a,b);

			}
			if(i == 0 || i == 4){
				h = a[1];
				a[1] = a[3];
				a[3] = a[6];
				a[6] = a[4];
				a[4] = h;
			}else{
				h = a[1];
				a[1] = a[2];
				a[2] = a[6];
				a[6] = a[5];
				a[5] = h;
			}
		}
		
		if(flag == true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26344
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int p, q;
bool check(int m, int n) {
  int B = m*m+n*n;
  if ( (m*p + n*q) % B == 0 && (m*q - n*p) % B == 0) return 1;
  return 0;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    cin >> p >> q;
    int A = p*p+q*q;
    int cnt = 0;
    for (int m=0; m*m<=A; ++m) {
      for (int n=0; m*m+n*n<=A; ++n) {
        if (m*m+n*n == 0) continue;
        if (check(m,n)) cnt++;
        if (n) if (check(m,-n)) cnt++;
        if (m) if (check(-m,n)) cnt++;
        if (m&&n) if (check(-m,-n)) cnt++;
      }
    }
    if (cnt == 8) puts("P");
    else puts("C");
  }
}

Measured memory_bytes: 1116