akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
using namespace std;

int main() {
    string s;
    int x, y, j = 0, k = 0;
    cin >> s >> x >> y;
    list<int> nums[2];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            nums[j].emplace_back(k);
            k = 0;
            j = 1 - j;
        } else {
            k++;
        }
    }
    nums[j].emplace_back(k);
    x -= nums[0].front();
    nums[0].pop_front();
    auto knapsack = [&](list<int>& nums, int target)->bool {
        int mid = max(abs(target), (int)s.size()), size = mid * 2 + 1;
        vector<bool> table(size);
        auto dp = [&](int i)->decltype(auto) {
            return table[mid + i];
        };
        dp(0) = true;
        for (int i : nums) {
            vector<bool> next(size);
            for (int j = 0; j < size; j++) {
                if (j - i >= 0) {
                    next[j] = next[j] || table[j - i];
                }
                if (j + i < size) {
                    next[j] = next[j] || table[j + i];
                }
            }
            swap(next, table);
        }
        return dp(target);
    };
    if (knapsack(nums[0], x) && knapsack(nums[1], y)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int N, M, K;
	int  count[31] = { 0 };

	scanf("%d %d", &N, &M);
	for (int i = 0;i < N;i++)
	{
		scanf("%d", &K);
		for (int j=0;j < K;j++)
		{
			int A;
			scanf("%d", &A);
			--A;
			count[A]++;//j番目の食べ物が好きならcount[j]を+1する
		}
	}
	int ans = 0;
	for (int i = 0;i < M;i++)
	{
		if (count[i] == N)ans++;/*全員i番目の食べ物が好き,つまり
		count[i]==Nならansを+1*/
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream stream)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(stream);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private int N;
    private int[] A;
    private void Scan()
    {
        Scanner scanner = new Scanner(Console.OpenStandardInput());
        N = scanner.NextInt();
        A = scanner.IntArray();
    }

    public void Solve()
    {
        Scan();
        int cnt = 0;
        for (int i = 0;;)
        {
            int type = 0;
            for (int j = i + 1; ; j++)
            {
                if (j >= N)
                {
                    cnt++;
                    Console.WriteLine(cnt);
                    return;
                }
                if (type == -1)
                {
                    if (A[j] > A[j - 1])
                    {
                        cnt+=1;
                        i = j;

                        break;
                    }
                }
                else if (type == 1)
                {
                    if (A[j] < A[j - 1])
                    {
                        cnt++;
                        i = j;
                        break;
                    }
                }
                else
                {
                    type = A[j].CompareTo(A[j - 1]);
                }
            }
        }
    }
}

Measured memory_bytes: 24416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

vll div(ll N)
{
    vll yakusuu;
    for (ll i = 1; i * i <= N; i++)
    {
        if (N % i == 0)
        {
            yakusuu.push_back(i);
            if (i * i != N)
                yakusuu.push_back(N / i);
        }
    }
    return yakusuu;
}
int main()
{
    ll N, tmp, ans = 0;
    cin >> N;

    div(N);
    auto div1 = div(N), div2 = div(N - 1);
    for (auto i : div1)
    {
        tmp = N;
        if (i == 1)
            continue;
        while (tmp % i == 0)
        {
            tmp /= i;
        }
        if ((tmp - 1) % i == 0)
            ans++;
    }
    cout << ans + (int)div2.size() - 1;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int res = 0;

  rep(i, N) {
    int a;
    cin >> a;
    if ((i + 1) % 2 != 0 && a % 2 != 0) res++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn=1e5+20;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int cnt4=0,cnt2=0;
        for(int i=1;i<=n;i++)
        {
            long long a;
            scanf("%lld",&a);
            if(a==0)    continue;
            if(a%4==0)  cnt4++;
            else if(a%2==0) cnt2++;
        }
        if(cnt2>=2) n=n-cnt2+1;
        if(cnt4*2+1>=n)   puts("Yes");
        else              puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)

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

int solve(){
    int n, k, m;
    cin >> n >> k >> m;
    if(n==0) return 1;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[i] = i+1;
    }
    int idx = m-1;
    for(int t=0;t<n-1;t++){
        a.erase(a.begin()+idx);
        int r = a.size();
        idx = (idx+(k-1)%r)%r;
    }
    cout << a[0] << endl;
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}


Measured memory_bytes: 3056
def main():
    d = {"R": 0, "G": 1, "B": 2}
    n = int(input())
    s = [d[i] for i in input()]
    #n = len(s)//3
    mod = 998244353
    fact = 1
    for i in range(2, n+1):
        fact = fact*i % mod

    cnt = 0
    ans = fact
    RGB_list = [0, 0, 0]
    for i in s:
        srt = sorted(RGB_list)[::-1]
        if RGB_list[i] == srt[0]:
            pass
        elif RGB_list[i] == srt[1]:
            ans = ans*(srt[0]-srt[1]) % mod
            cnt += 1
        else:
            ans = ans*cnt % mod
            cnt -= 1
        RGB_list[i] += 1
    print(ans)
main()

Measured memory_bytes: 6044
K,N=map(int, input().split()) 
c=list(map(int, input().split())) 
a = 0
b = 0
for i in range(N):
  if i == 0:
    a = min((c[N-1]-c[0]),K-(c[i+1]-c[0]))
  elif i == N-1:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[0]-c[i]))
    
  else:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[i+1]-c[i]))
    
print(a)
    

Measured memory_bytes: 26444
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		adjmatrix = new int[n+1][n+1];
		for (int i=0; i < n; i++) {
			String[] list = br.readLine().split(" ");

			int u = Integer.parseInt(list[0]);
			adjmatrix[u][0] = u;

			int k = Integer.parseInt(list[1]);
			for (int j=0; j < k; j++) {
				int vi = Integer.parseInt(list[2+j]);
				adjmatrix[u][vi] = 1;
			}
		}

		distance = new int[n+1];
		Arrays.fill(distance, -1);

		distance[1] = 0;
		deq.offer(adjmatrix[1]);

		while( ! deq.isEmpty() ) {
			int[] adjlist = deq.poll();
			int id = adjlist[0];
			for (int i = 1; i <= n; i++) {
				if (adjlist[i] == 1 && distance[i] == -1) {
					distance[i] = distance[id] + 1;
					deq.offer(adjmatrix[i]);
				}
			}
		}

		for (int id=1; id <= n; id++) {
			System.out.println(id + " " + distance[id]);
		}
	}

	static int[][] adjmatrix;

	static int[] distance;

	static ArrayDeque<int[]> deq = new ArrayDeque<>();

//	public static void search(int[][] adjmatrix, int i) {
//
//	}
}

Measured memory_bytes: 24644
use std::collections::HashMap;
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    input.clear();
    io::stdin().read_line(&mut input)?;
    let a_s: Vec<i32> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    input.clear();

    let mut map: HashMap<i32, i32> = HashMap::new();

    let mut result = 0 as i64;
    for x in a_s {
        result += x as i64;
        let count = map.entry(x).or_insert(0);
        *count += 1;
    }

    io::stdin().read_line(&mut input)?;
    let q = input.trim().parse::<i32>()?;
    input.clear();
    for _ in 0..q {
        io::stdin().read_line(&mut input)?;
        let b_c: Vec<i32> = input
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<i32>().unwrap())
            .collect();
        let b = b_c[0];
        let c = b_c[1];
        input.clear();
        let temp = c - b;
        if let Some(&count) = map.get(&b) {
            result += temp as i64 * count as i64;
            *map.entry(c).or_insert(0) += count;
        }
        map.remove(&b);
        println!("{}", result);
    }

    Ok(())
}


Measured memory_bytes: 4800
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

vector<int> m;
int main(void){
	int N;
	cin >> N;
	REP(i, N){
		int a;
		cin >> a;
		m.push_back(a);
	}
	sort(all(m));
	m.erase(unique(all(m)), m.end());
	cout << m.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fitr(it,it1,itr2) for(auto it=itr1;it!=itr2;++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define PI 3.1415926535897932384626433832795
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll,ll>> vpll;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
const ll MOD=1000000007;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}

int main()
{
  ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
  ll n;
  cin>>n;
  ll cnt=0;
  cnt+=n/11;
  cnt*=2;
  int r=n%11;
  if (r!=0 && r<=6) ++cnt;
  else if (r!=0) cnt+=2;
cout<<cnt;
return 0;
}




Measured memory_bytes: 3636
h, w, a, b = map(int, input().split())

n = 2 * 10 ** 5
k = 2 * 10 ** 5
mod = 10**9 + 7

modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def prepare_binomial_coefficients(n, k):
    for i in range(1,n+1):
        bc_num[i] = i * bc_num[i-1] % mod
    bc_num[0] = 0
    for i in range(1,k+1):
        bc_den[i] = modinv_table[i] * bc_den[i-1] % mod
    return

def binomial_coefficients(n, k):
    if n == 0 and k == 0:
        return 1
    return bc_num[n] * bc_den[k] * bc_den[n-k] % mod

bc_num = [1]*(n+1)
bc_den = [1]*(n+1)
prepare_binomial_coefficients(n, n)

mids = [0]*(w-b)
dis_mid = h - a - 1
for i in range(w-b):
    mids[i] = binomial_coefficients(dis_mid+i+b,i+b)

#print(mids)

mids_down = [0]*(w-b)
dis_mid = a
for i in range(w-b):
    mids_down[i] = binomial_coefficients(dis_mid+w-b-i-1,w-b-i-1)

#print(mids_down)

for i in range(w-b-1):
    mids_down[i] -= mids_down[i+1]

#print(mids_down)

for i in range(w-b):
    mids[i] = (mids[i] * mids_down[i]) % mod

#print(mids)

print(sum(mids)%mod)

Measured memory_bytes: 40268
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
char str[maxn];
int ans[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n;scanf("%d",&n);
    scanf("%s",str);
    bool isok = false;
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=2;j++)
        {
            memset(ans, 0, sizeof(ans));
            ans[n - 1]=i,ans[0]=j;
            for (int k = 0; k < n - 2; k++) {
                int pre = (k - 1 + n) % n;
                int nxt = (k + 1) % n;
                if (ans[k] == 1) {
                    if (str[k] == 'o') {
                        ans[nxt] = ans[pre];
                    } else {
                        ans[nxt] = 3 - ans[pre];
                    }
                } else {
                    if (str[k] == 'x') {
                        ans[nxt] = ans[pre];
                    } else {
                        ans[nxt] = 3 - ans[pre];
                    }
                }
            }
            bool success = true;
            for (int k = 0; k < n; k++) {
                int pre = (k - 1 + n) % n;
                int nxt = (k + 1) % n;
                if (ans[k] == 1) {
                    if (str[k] == 'o' && ans[pre] == ans[nxt]) ;
                    else if (str[k] == 'x' && ans[pre] == 3 - ans[nxt]) ;
                    else {
                        success = false;
                        break;
                    }
                } else {
                    if (str[k] == 'x' && ans[pre] == ans[nxt]) ;
                    else if (str[k] == 'o' && ans[pre] == 3 - ans[nxt]) ;
                    else {
                        success = false;
                        break;
                    }
                }
            }
            if (success) {
                isok = true;
                break;
            }
        }
        if (isok) break;
    }
    if (!isok) return 0 * puts("-1");
    else {
        for (int i = 0; i < n; i++) {
            if (ans[i] == 1) printf("S");
            else printf("W");
        }
    }
    return 0;
}



Measured memory_bytes: 768
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String[] a = new String[h];
    int[][] y = new int[h][w];
    int[][] t = new int[h][w];
    for(int i=0;i<h;i++){
      a[i] = sc.next();
    }
    
    for(int i=0;i<h;i++){
      y[i][0]=( a[i].charAt(0)=='.' ? 1 : 0 );
      for(int j=1;j<w;j++){
        y[i][j]=( a[i].charAt(j)=='.' ? y[i][j-1]+1 : 0 );
      }
      for(int j=w-1-1;j>=0;j--){
        y[i][j]=( y[i][j]==0 ? 0 : Math.max(y[i][j+1],y[i][j]) );
      }
    }
    
    for(int i=0;i<w;i++){
      t[0][i]=( a[0].charAt(i)=='.' ? 1 : 0 );
      for(int j=1;j<h;j++){
        t[j][i]=( a[j].charAt(i)=='.' ? t[j-1][i]+1 : 0 );
      }
      for(int j=h-1-1;j>=0;j--){
        t[j][i]=( y[j][i]==0 ? 0 : Math.max(t[j+1][i],t[j][i]) );
      }
    }
    
    int max=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        max=Math.max(y[i][j]+t[i][j],max);
      }
    }
    System.out.println(max-1);
  }
}


Measured memory_bytes: 85652
#include <bits/stdc++.h>
using namespace std;
int main(){
  long L,R;
  cin>>L>>R;
  if(R-L>=2019)cout<<0<<endl;
  else{
    int x=2019;
    for(long i=L;i<R;i++){
      for(long j=i+1;j<R+1;j++){
       int I=i%2019;
        int J=j%2019;
        int l=(I*J)%2019;
        x=min (x,l);
      }
    }
    cout<<x<<endl;
  }
}
  

Measured memory_bytes: 256
import itertools
import math


N = int(input())
P = [[int(x) for x in input().split()] for _ in range(N)]

Plist = list(itertools.permutations(P))
ans=0
for p in Plist:
    for i in range(len(p)-1):
        ans += math.hypot(p[i][0]-p[i+1][0], p[i][1]-p[i+1][1])
print(ans/len(Plist))

Measured memory_bytes: 10016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b,sum = 1,cnt = 0;
  cin >> a >> b;
  while (sum < b){
    sum = sum + (a - 1);
    cnt++; 
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sqr(x) (x)*(x)
#define int long long
using namespace std;

signed main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n, s = 0; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
	if(s > 0) s += n / 2;
	if(s < 0) s -= n / 2;
	s /= n;
	int ans = 0;
	for (int i = 0; i < n; i++) ans += sqr(s - a[i]);
	cout << ans << '\n';
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;

  while(1){
    cin>>n;
    if(n==0)break;
    if(n==1){
      cout<<"deficient number"<<endl;
      continue;
    }
    int sum=1;
    for(i=2;i*i<=n;i++)
      if(n%i==0){
        sum+=i;
        if(i*i<n)sum+=n/i;
      }
    if(sum<n) cout<<"deficient number"<<endl;
    else if(sum==n) cout<<"perfect number"<<endl;
    else cout<<"abundant number"<<endl;
  }
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,k; cin>>n>>k;
  vector<ll> cnt(40);
  rep(i,n){
    ll a; cin>>a;
    rep(d,40) cnt[d]+=(a>>d)&1;
  }
  ll ans=0;
  rep(j,39,-2,-1){ // j 桁目でltをtrueにする(-1のときはx=k)
    if(j!=-1&&!((k>>j)&1)) continue;
    ll res=0;
    rep(d,39,-1,-1){
      if(d>j){
        res+=((k>>d)&1?(n-cnt[d])<<d:cnt[d]<<d);
      }else if(d==j){
        res+=cnt[d]<<d;
      }else{
        res+=max(cnt[d],n-cnt[d])<<d;
      }
    }
    chmax(ans,res);
  }
  cout<<ans<<"\n";
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve(){
    ll a, b, c, k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout<<ans;
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 3636
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		for (; sc.hasNextLine();) {

			String in = sc.nextLine();

			String[] token = in.split(" ");

			LinkedList<Double> stack = new LinkedList<Double>();

			for (int i = 0; i < token.length; i++) {

				if (token[i].toCharArray().length == 0) {

					continue;

				}

				if (token[i].toCharArray().length == 1

						&& !Character.isDigit(token[i].toCharArray()[0])) {

					double b = stack.removeLast();

					double a = stack.removeLast();

					switch (token[i].toCharArray()[0]) {

					case '+':

						stack.addLast(a + b);

						break;

					case '-':

						stack.addLast(a - b);

						break;

					case '*':

						stack.addLast(a * b);

						break;

					case '/':

						stack.addLast(a / b);

						break;

					}

				} else {

					stack.addLast(Double.valueOf(token[i]));

				}

			}

			System.out.println(stack.get(0));

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
  for j in range(i+1, N):
    c += (sum((X[i][p]-X[j][p])**2 for p in range(D))**.5).is_integer()
print(c)

Measured memory_bytes: 9348
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define mkp make_pair
#define maxN 1000000
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
//int arr[maxN];
int32_t main()
{
fastio;
int a;in a;
vector<pair<int,int>> divisors;
int x=0;int y=0;ll ans=1000000000000+10;
for(int i=1;i*i<=a;i++){
    if(a%i==0){
        x=i-1;
        y=(a/i)-1;
        //out x<<" "<<y<<endl;
        ll first=x+y;
        //out first<<endl;
        ans=min((ll)ans,first);
    }
}
out ans;
    return 0;
}


Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T& a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector< T > &v) { rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "b.cpp"

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

  vl cnt(n);
  rep(i, k) {
    ll d;
    cin >> d;
    rep(j, d) {
      ll a;
      cin >> a;
      cnt[a-1]++;
    }
  }

  ll ans = 0;
  rep(i, n) {
    if (cnt[i] == 0) {
      ans++;
    }
  }
  cout << ans << el;
}


Measured memory_bytes: 3652
#include<cstdio>
const int MOD = 998244353;
const int MAXN = 4000;
int C[MAXN + 5][MAXN + 5];
int pw2[MAXN + 5];
void init() {
    C[0][0] = 1; pw2[0] = 1;
    for(int i=1;i<=MAXN;i++) {
        C[i][0] = 1;
        for(int j=1;j<=i;j++) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
        }
        pw2[i] = pw2[i-1] * 2 % MOD;
    }
}
int solve(int x, int y, int z) {
    int ret = 0;
    for(int i=0;i<=z&&i<=x;i++)
        if( y+i-1 >= 0 ) ret = (ret + 1LL*pw2[i]*C[x][i]%MOD*C[z+y-1][y+i-1]%MOD) % MOD;
    return ret;
}
int main() {
    init();
    int N, K;
    scanf("%d%d", &K, &N);
    for(int i=2;i<=2*K;i++) {
        int cnt = 0;
        for(int j=1;j<=K;j++)
            if( 1 <= i-j && i-j <= K ) cnt++;
        if( i % 2 == 0 ) {
            printf("%d\n", (solve((cnt-1)/2, K-cnt, N) + solve((cnt-1)/2, K-cnt, N-1)) % MOD);
        }
        else {
            printf("%d\n", solve(cnt/2, K-cnt, N));
        }
    }
}


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

using namespace std;

int main()
{
    long int a,b,s=0,i,j,k;

    cin>>a>>b;

    for(i=1; i<(b-a); i++)
    {
        s+=i;
    }
    cout<<s-a<<endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - n_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

Measured memory_bytes: 48856
import itertools

h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

divide = list(itertools.product([0, 1], repeat=h-1))

MIN = 10**10
for d in divide:
    SUM = [0]*(sum(d)+1)
    ans = 0
    reset = False
    ok = True

    for i in range(w):
        # start
        now = 0
        for g in range(h-1):
            if d[g] == 0:
                if s[g][i] == '1':
                    SUM[now] += 1

            elif d[g] == 1:
                if s[g][i] == '1':
                    SUM[now] += 1
                now += 1
        if s[-1][i] == '1':
            SUM[-1] += 1
        # end

        for l in SUM:
            if l > k:
                reset = True
                break

        if reset:
            reset = False
            ans += 1
            SUM = [0]*(sum(d)+1)
            # start
            now = 0
            for g in range(h-1):
                if d[g] == 0:
                    if s[g][i] == '1':
                        SUM[now] += 1

                elif d[g] == 1:
                    if s[g][i] == '1':
                        SUM[now] += 1
                    now += 1
            if s[-1][i] == '1':
                SUM[-1] += 1
            # end
            for l in SUM:
                if l > k:
                    ok = False
                    break
        if ok is False:
            break
    if ok:
        MIN = min(MIN, ans+sum(d))

print(MIN)

Measured memory_bytes: 47836
#include<bits/stdc++.h>
  
  
   #define sz(a) int((a).size()) 
  #define pb push_back 
 
  #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
   #define present(c,x) ((c).find(x) != (c).end()) 
   #define cpresent(c,x) (find(all(c),x) != (c).end())
  using namespace std;
  
  typedef long long ll;
  
  int main()
  {
   string s;
   cin>>s;
  
   int l=s.length();
   int i=0;
   while(i!=l-1)
   {
          if(s[i]=='S'&&s[i+1]=='T')
          {
          s.erase(i,2);
          i--;
          }
          else
                  i++;
  
   }
   cout<<s.length();
  }


Measured memory_bytes: 640
num = []
while True:
    try:
        num.append(int(input()))
    except EOFError:
        break

for i in num:
    s = set()
    for a in range(10):
        if i-a > 27:
            continue
        for b in range(10):
            if i-a-b > 18:
                continue
            for c in range(10):
                if i-a-b-c > 9:
                    continue
                elif i-a-b-c < 0:
                    break
                else:
                    s.add(str(a)+str(b)+str(c)+str(i-a-b-c))
    print(len(s))

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

int main() {
	int n,a;
	int ans = 0;
	vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
	}
	for (unsigned i = 0; i < v.size(); i++) {
		if (i == v[v[i]-1]-1)ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 892
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 3001;
const int P = 1e9 + 7;
void add(int& a,int b){
  a += b;
  if(a >= P)
    a-=P;
}
int mul(int a,int b){
  return a * b % P;
}
int n,q;
int t[MAX];
int war[MAX][MAX];
int pol = (P + 1) / 2;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> q;
  R(i,n){
    cin >> t[i];
  }
  int p2 = 1;
  R(i,q)add(p2,p2);
  R(i,n)R(j,n){
    if(t[i] < t[j]){
      war[i][j] = p2;
    }
  }
  R(_,q){
    int a,b;
    cin >> a >> b;
    a--;b--;
    int sum = war[a][b] + war[b][a];
    R(i,n){
      war[a][i] = war[b][i] = mul(war[a][i] + war[b][i], pol);
      war[i][a] = war[i][b] = mul(war[i][a] + war[i][b], pol);
    }
    war[a][a] = war[b][b] = 0;
    war[a][b] = war[b][a] = mul(sum, pol);
  }
  int res = 0;
  R(i,n)R(j,i){
    add(res,war[i][j]);
  }
  cout << res << "\n";
}


Measured memory_bytes: 70656
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m,a,b,c,t;
V M(const V &x,const V &y){
	V z(n*n);
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(x[slice(i*n,n,1)]*y[slice(j,n,n)]).sum()%m;
	return z;
}
V E(const V &x,const int n){
	if(n==1)return x;
	if(n&1)return M(E(x,n-1),x);
	V y=E(x,n>>1);
	return M(y,y);
}
V s,x;
void O(const V &r){
	int i=0;
	for(;i<n;i++)printf(i<n-1?"%d ":"%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		s.resize(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		x.resize(1);
		x.resize(n*n);
		if(t){
			x[0]=b;
			x[1]=c;
			for(i=1;i<n-1;i++){
				x[i*n+i-1]=a;
				x[i*n+i]=b;
				x[i*n+i+1]=c;
			}
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			O(E(x,t));
		}else{
			for(i=0;i<n;i++)x[i*n+i]=1;
			O(x);
		}
	}
}

Measured memory_bytes: 1084
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.println(a + " " + b + " " + c);
            }
            else if (a < c) {
                System.out.println(a + " " + c + " " + b);
            }
            else {
                System.out.println(c + " " + a + " " + b);
            }
        }
        else {
            if (a < c) {
                System.out.println(b + " " + a + " " + c);
            }
            else if (b < c) {
                System.out.println(b + " " + c + " " + a);
            }
            else {
                System.out.println(c + " " + b + " " + a);
            }
        }
    }
}


Measured memory_bytes: 26152
(N, M), As = readlines.map{|l| l.split.map(&:to_i)}

a = As.sort
b = [a.pop / 2]
(M - 1).times{b.unshift((!a.empty? && a.last >= b.last ? a.pop : b.pop) / 2)}
puts (a + b).inject(:+)

Measured memory_bytes: 10608
def main():
    A, B, C, D = map(int, input().split())

    if D <= A or B <= C:
        ans = 0
    if C <= A and A <= D:
        ans = D - A
    if C <= B and B <= D:
        ans = B - C
    if A <= C and D <= B:
        ans = D - C
    if C <= A and B <= D:
        ans = B - A
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
import math
input = raw_input

N = int(input())
A = []
for i in range(N):
    A.append((i, int(input())))

A.sort(key = lambda x: x[1])

for xx in range(N):
    if A[-1][0] != xx:
        print(A[-1][1])
    else:
        print(A[-2][1])


Measured memory_bytes: 54768
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define   Y            imag()
#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=10;
int n,A,B;
int main()
{
    cin>>n>>A>>B;
    if((abs(A-B)-1)%2==0)
      cout<<"Borys"<<endl;
    else
       cout<<"Alice"<<endl;

}




Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  while (0 < A && 0 < C) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }

    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


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

using namespace std;

int main(){
    string S;
    cin >> S;


    int count = 0;
    long long ans = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] == 'W'){
            ans += i - count;
            count ++;   
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e,f,i;
	scanf("%d",&a); scanf("%d",&b); scanf("%d",&c); scanf("%d",&d); scanf("%d",&e); scanf("%d",&f);
	a=a*1;
	b=b*5;
	c=c*10;
	d=d*50;
	e=e*100;
	f=f*500;
	i=a+b+c+d+e+f;
	if(i>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


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

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	
	char s[n];
	scanf("%s", s);

	int l, r;
	int ret = 0;
	
	/* "AC"カウント */
	int score[n];
	score[0] = 0; /* 探索文字列分０に初期化 */
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == 'A' && s[i] == 'C') {
			score[i] = score[i - 1] + 1;
			// i++;	/* 探索文字列分スキップ */
		} else {
			score[i] = score[i - 1];
		}
	}
	
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &l, &r);
		
		ret = score[r - 1] - score[l - 1];
		printf("%d\n", ret);
	}

	
	
	return 0;
}

Measured memory_bytes: 1280
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int A, K, B;
    cin >> K;
    cin >> A >> B;
    int i;
    for(i=A;i<=B;i++){
        if(i % K == 0){cout << "OK" << endl; return 0;}
    }
    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MOD 1000000007

int main(void){
	long long  n, k;
	scanf("%lld%lld",&n ,&k);
	long long sum = 0;
	long long s;
	while(k<=n+1){
		s = k*n + k - k*k + 1;
		s = s%MOD;
		if(s<0)
		printf("%lld\n",s);
		sum += s;
		sum = sum%MOD;
		k++;
	}
	printf("%lld\n",sum);
    return 0; 
}


Measured memory_bytes: 1732
s = input()
t = input()
count = 0
stock = 0
check = 0

for i in t:
    if check==0:
        if i in s:
            stock = s.index(i)
            check = 1
        else:
            count = -1
            break
    else:
        if i in s:
            if stock==len(s)-1:
                count += 1
                stock = s.index(i)
                continue
            if i in s[stock+1:]:
                stock = s[stock+1:].index(i) + stock + 1
                continue
            else:
                count += 1
                stock = s.index(i)
                continue
        else:
            count = -1
            break
        
if count==-1:
    print(count)
else:
    print(count*len(s)+stock+1)


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

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var S = Console.ReadLine();

            Console.WriteLine(S == "ABC" ? "ARC" : "ABC");

#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


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

namespace MyProgram{
    class AtCoder{
        static void Main(){
            var A = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = A[0];
            long M = A[1];
            var X = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            if(N>=M){
                Console.WriteLine("0");
                return;
            }
            Array.Sort(X);
            var dist = new long[M-1];
            for(var i=1;i<M;i++){
                dist[i-1] = X[i] - X[i-1]; 
            }
            Array.Sort(dist);
            long sum = 0;
            for(var i=0;i<M-N;i++){
                sum += dist[i];
            }
            System.Console.WriteLine(sum);
        }
    }
}


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

int H, N;
vector<int> A(100001);

void solve(){
    for(int i = 1; i <= N; ++i){
        H -= A[i];
    }
    if(H <= 0) cout << "Yes";
    else cout << "No";
}
int main(){
    cin >> H >> N;
    for(int i = 1; i <= N; ++i){
        cin >> A[i];
    }
    solve();
    return 0;
}

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

int main()
{
    int t=1;
    //cin>>t;
    
    while(t--)
    {
        long long int n, ans;
        cin>>n;
        
        long long int a[n], b[n];
        cin>>a[0];
        
        ans=a[0];
        
        for(int i=1;i<n;i++)
        {
            cin>>a[i];
            ans = ans ^ a[i];
        }
        
        for(int i=0;i<n;i++)
        {
            b[i] = a[i] ^ ans;
            cout<<b[i]<<" ";
        }
        
    }    
    return 0;
}

Measured memory_bytes: 6708
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//NIL is NULL
#define NIL NULL
//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;

//root           
Nodepointer root;

//function insert 
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  //make memory
  z=new struct Node();

  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  }

  z->parent=y;

  if(y==NIL) root=z;

  else if(z->key<y->key) y->leftc=z;
  else y->rightc=z;


}

//function search
Nodepointer find(Nodepointer now,int data){
  if(now==NIL||data==now->key) return now;
  if(data<now->key) return find(now->leftc,data);
  else return find(now->rightc,data);
}

//function treeminimum
Nodepointer treeminimum(Nodepointer x){
  while(x->leftc!=NIL){
    x=x->leftc;
  }
  return x;
}
//function treesuccerssor
Nodepointer treesuccessor(Nodepointer x){
  Nodepointer y;
  if(x->rightc!=NIL) return treeminimum(x->rightc);
  y=x->parent;
  while(y!=NIL && x==x->rightc){
    x=y;
    y=y->parent;
  }
  return y;
}
//function treedelete
void treedelete(Nodepointer z){
  Nodepointer x,y;
  if(z->leftc==NIL ||z->rightc==NIL)y=z;
  else y=treesuccessor(z);

  if(y->leftc!=NIL)x=y->leftc;
  else x=y->rightc;
  
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL) root=x;

  else if(y==y->parent->leftc) y->parent->leftc=x;

  else y->parent->rightc=x;
 
  if(y!=z) z->key=y->key;
  
  delete y;
}

//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}

void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}


int main(){

  int n,i,j,data;
  Nodepointer del;
  char str[10];
  //load n
  scanf("%d",&n);
  //load commnad and key
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //find
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    //delete
    else if(strcmp(str,"delete")==0){
      scanf("%d",&data);
      del=find(root,data);
      treedelete(del);
     
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 10000
#include <iostream>
#include <algorithm>
using namespace std;
int n, i, x, y;
int main(){
cin>>n;
int a[n];
for(i=0; i<n; i++){
  cin>>a[i];
  if(a[i]%2==0)
    x++;
}
for(i=0; i<n; i++){
if(a[i]%2==0)
  if((a[i]%3==0) || (a[i]%5==0))
    y++;
}
if(x==y) 
  cout<<"APPROVED";
else
  cout<<"DENIED";
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int s;

int main(void) {
    cin>>s;

    Int x,y;
    const Int v = 1000000000;
    x = (v - s % v) % v;
    y = (s+x) / v;

    cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int box[4];
    int check =0;
    
    for(int i=0;i<4;i++)
    {
        box[i] = N%10;
        N=N/10;
    }
    
    for(int i=0;i<4;i++)
    {
        if(box[i] == 2)
        {
            check++;
        }
    }
    
    cout << check << endl;
}

Measured memory_bytes: 256