akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

	static long m = (long) (1e9 + 7);
	static String arr[];
	static int count = 0;

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = scn.nextInt();
		arr = new String[fact(n)];
		String a = "", b = "";
		int arr1[] = new int[n];
		int arr2[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr1[i] = scn.nextInt();
			a += arr1[i];
		}
		for (int i = 0; i < n; i++) {
			arr2[i] = scn.nextInt();
			b += arr2[i];
		}
		String num = "";
		for (int i = 1; i <= n; i++) 
			num += i;
		StringBuilder s1 = new StringBuilder(num);
		permute(s1, 0, n - 1, arr);
		int k = fact(n);
		Arrays.sort(arr);
		int index1 = 0, index2 = 0;
		for (int i = 0; i < k; i++) {
			if (arr[i].compareTo(a) == 0)
				index1 = i + 1;
			if (arr[i].compareTo(b) == 0)
				index2 = i + 1;
		}
		System.out.println(Math.max(index2, index1) - Math.min(index1, index2));
	}

	static StringBuilder swap(int i1, int i2, StringBuilder s) {
		char temp1 = s.charAt(i1), temp2 = s.charAt(i2);
		s.setCharAt(i1, temp2);
		s.setCharAt(i2, temp1);
		return s;
	}

	static void permute(StringBuilder s, int l, int r, String arr[]) {
		if (l == r) {
			arr[count] = s.toString();
			count++;
		} else {
			for (int i = l; i <= r; i++) {
				s = swap(i, l, s);
				permute(s, l + 1, r, arr);
				s = swap(l, i, s);
			}
		}
	}

	static int fact(int a) {
		if (a == 1 || a == 0)
			return 1;
		return a * fact(a - 1);
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 25740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll n; cin >> n;
    ll dp[n];
    ll a[n];
    for (int i=0;i<n;i++){
        cin >> a[i];
        dp[i]=INF;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for (int i=2;i<n;i++){
        chmin(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        chmin(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout << dp[n-1] << "\n";
}















Measured memory_bytes: 5180
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int K; cin >> K;
	int now = 7;
	FOR(i, 1, K * 10) {
		if (now%K == 0) {
			cout << i << endl;
			return 0;
		}
		now *= 10;
		now += 7;
		now %= K;
	}
	cout << -1 << endl;
	return 0;
}



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

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        Arrays.sort(t);
        String t2 = new StringBuilder(String.valueOf(t)).reverse().toString();
        Arrays.sort(s);
        String s2 = String.valueOf(s);

        System.out.println(s2.compareTo(t2) < 0 ? "Yes": "No");
    }
}


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

// Contest: AtCoder Beginner Contest 143 (https://atcoder.jp/contests/abc143)
// Problem: C

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

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

    int n; string s; cin >> n >> s;
    int c = 0;
    for (int i = 1; i < n; ++i)
        if (s[i - 1] != s[i])
            ++c;
    cout << (c + 1) << '\n';

    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))

cost1, cost2 = 0, 0
base1, base2 = 0, 0
for i in range(n):
    base1 += a[i]
    if i % 2 == 1:
        if base1 < 1:
            cost1 += (1 - base1)
            base1 = 1
    else:
        if base1 > -1:
            cost1 += (base1 + 1)
            base1 = -1

for i in range(n):
    base2 += a[i]
    if i % 2 == 1:
        if base2 > -1:
            cost2 += (base2 + 1)
            base2 = -1
    else:
        if base2 < 1:
            cost2 += (1 - base2)
            base2 = 1

print(min(cost1, cost2))

Measured memory_bytes: 14468
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        if ((A - 2 * B) > 0){
            System.out.println(A - 2 * B);
        }else{System.out.println(0);
          }

    }
}

Measured memory_bytes: 22996
/*author:anshumanc007
  created on:12/01/2019
            */
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
#define MAX 200005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int dp[405][405];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,p,q,r,s,t,x,y,a,b,ans=0,cnt=0,maxi=0,mini=INF,len;
    cin>>n;
    long long int A[n];
    long long int pre[n][n]={0};
   
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
     for(i=0;i<n;i++)
    { k=0;
        for(j=i;j<n;j++)
        {
            k=k+A[j];
            pre[i][j]=k;
        }
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            dp[i][j]=INF;
        }
    }
    for(i=0;i<n;i++)
    {
        dp[i][i]=0;
    }
    for(len=2;len<=n;len++)
    {
        for(i=0;i<=n-len;i++)
        {
            j=i+len-1;
            for(k=i;k<j;k++)
        {
                if(len==2)
                {
                    dp[i][j]=min(A[i]+A[j],dp[i][j]);
                }
                
                else if(k==i)
               {
                dp[i][j]=min(pre[k+1][j]+dp[k+1][j]+A[i],dp[i][j]);
                }
                else if (k==j-1)
                {
                   dp[i][j]=min(pre[i][k]+dp[i][k]+A[j],dp[i][j]) ;
                }
                else
                dp[i][j]=min(pre[i][k]+dp[i][k]+pre[k+1][j]+dp[k+1][j],dp[i][j]);
            }
            
            
            
        }
        
    }
    cout<<dp[0][n-1]<<endl;
    
    
   
}

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

int main() {
  int T;
  cin >> T;
  while(T--) {
    string s,ans="";
    int k=0;
    cin >> s;
    ans=s[0];
    for(int i=3; i<s.size(); i+=3) {
      if(s[i-1]=='>') k++;
      else k--;
      if(k==ans.size()) ans+=s[i];
      if(k==-1) {
        ans=s[i]+ans;
        k++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3160
n=int(raw_input())
for i in range(n):
    xa,ya,ra,xb,yb,rb=map(float,raw_input().split())
    d=((xa-xb)**2+(ya-yb)**2)**0.5
    if ra+rb<d:
        print 0
    elif ra>=rb:
        print 2 if d+rb<ra else 1
    else:
        print -2 if d+ra<rb else 1

Measured memory_bytes: 6488
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int N, K;
	cin >> N >> K;

	vector<int> vV(N);
	rep(i, N) cin >> vV[i];


	vector<int> leftsum(N+1, 0);
	leftsum[0] = 0;
	for (int i = 1; i != N+1; ++i) {
		leftsum[i] = leftsum[i - 1] + vV[i-1];
	}

	vector<int> rightsum(N+1, 0);
	rightsum[0] = 0;
	for (int i = 1; i != N+1; ++i) {
		rightsum[i] = rightsum[i-1] + vV[N - i];
	}


	int maxsum = 0;
	for (int i = 0; i != min(K+1,N+1); ++i) {
		vector<int> vObtain;
		if (i != 0) {
			rep(a, i) vObtain.push_back(vV[a]);
		}

		for (int j = 0; j != min(K-i+1,N-i+1); ++j) {
			vector<int> vObtain2;
			if (j != 0) {
				rep(b, j) vObtain2.push_back(vV[N-b-1]);
			}
			vObtain2.insert(vObtain2.end(), vObtain.begin(), vObtain.end());
			sort(vObtain2.begin(), vObtain2.end());

			int sum = leftsum[i] + rightsum[j];
			int limit = min(K - i - j, i + j);
			for (int k = 0; k < limit; ++k) {
				if (vObtain2[k] < 0) {
					sum -= vObtain2[k];
				}
			}
			if (sum > maxsum) {
				maxsum = sum;
			}
		}

	}

	cout << maxsum << endl;

	return 0;
}

Measured memory_bytes: 256
class Dice(object):
    def __init__(self, faces):
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]

    def rotate(self, command):
        pre_top = self.top
        if command == 'N':
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = pre_top
        elif command == 'E':
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = pre_top
        elif command == 'W':
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = pre_top
        elif command == 'S':
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = pre_top


def main() -> None:
    *dice_values, = map(int, input().split())
    dice_x = Dice(dice_values)

    commands = input()
    for command in commands:
        dice_x.rotate(command)

    print(dice_x.top)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Pigeonhole principle
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N = parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		Map<Integer, List<Integer>> map = new HashMap<>();

		String ans = "";

		while (st.hasMoreTokens()) {
			int a = parseInt(st.nextToken());
			int m = a % (N - 1);
			map.putIfAbsent(m, new ArrayList<>());
			map.get(m).add(a);
			if (map.get(m).size() > 1) {
				ans += map.get(m).get(0);
				ans += " ";
				ans += map.get(m).get(1);
				break;
			}
		}

		System.out.println(ans);
	}
}




Measured memory_bytes: 24860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, cnt = 0;
void find(ll x) {
	if (x <= n) {
		int t = x;
		int c1 = 0, c2 = 0, c3 = 0;
		while (t > 0) {
			if (t % 10 == 3) c1 = 1;
			if (t % 10 == 5) c2 = 1;
			if (t % 10 == 7) c3 = 1;
			t /= 10;
		}
		if (c1 + c2 + c3 == 3) cnt++;
		find(x * 10 + 3);
		find(x * 10 + 5);
		find(x * 10 + 7);
	}
}

void solve() {
	cin >> n;
	find(0);
	cout << cnt;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
} s(100010);

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

  for(int i = x;;++i){
    if(s.isPrime(i)){
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 768
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    sa=input()
    sb=input()
    sc=input()
    s=[sa,sb,sc]
    
    n=[-1,-1,-1]
    
    p=0
    while True:
        if n[p]==len(s[p])-1:
            break
        n[p]+=1
        p=ord(s[p][n[p]])-97
        
        
    ans=["A","B","C"]
    print(ans[p])    

main()


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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> V(N + 1);
  for (int i = 1, cnt = 0; i < N; i++) {
    if (S.at(i - 1) == 'A' && S.at(i) == 'C') cnt++;
    V.at(i + 1) = cnt;
  }
  for (int l, r; cin >> l >> r;) cout << V.at(r) - V.at(l) << "\n";
}

Measured memory_bytes: 1408
n,m=map(int,input().split())
reqs = [list(map(int,input().split())) for _ in range(m)]

reqs.sort(key=lambda x:(x[0],x[1]))
query = []
tmp = 0
for req in reqs:
  if tmp == req[0]:
    continue
  else:
    query.append(req)
    tmp = req[0]
    
left = 0
right = n
count = 1
for q in query:
  if left <= q[0] and q[1]-1 <= right:
    left = q[0]
    right = q[1]-1
  elif left <= q[0] <= right:
    left = q[0]
  else:
    count += 1
    left = q[0]
    right = q[1]-1
print(count)

Measured memory_bytes: 37008
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;
lli dp[51][51][2501];

int main(void)
{
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N)cin >> a[i];
	lli even = 0;
	lli sum = a[0];
	if (a[0] <= 0) {
		even = 1 - a[0];
		sum = 1;
	}
	rep(i, 1, N) {
		sum += a[i];
		if (i % 2 == 1 && sum >= 0) {
			even += sum + 1;
			sum = -1;
		}
		if (i % 2 == 0 && sum <= 0) {
			even += 1 - sum;
			sum = 1;
		}
	}

	lli odd = 0;
	sum = a[0];
	if (a[0] >= 0) {
		odd = 1 + a[0];
		sum = -1;
	}
	rep(i, 1, N) {
		sum += a[i];
		if (i % 2 == 0 && sum >= 0) {
			odd += sum + 1;
			sum = -1;
		}
		if (i % 2 == 1 && sum <= 0) {
			odd += 1 - sum;
			sum = 1;
		}
	}

	cout << min(even, odd) << endl;

	return 0;
}

Measured memory_bytes: 640
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 , inf = 1e18 + 20;
int n , e , t , x[N] , dp[N] , p , mn = inf ;

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n >> e >> t ;
	for (int i = 0 ; i < n ; i ++) cin >> x[i] ;

	p = n ;

	dp[n - 1] = e - x[n - 1] + t ;
	for (int i = n - 2 ; ~i ; i --) {
		while (2 * (x[p - 1] - x[i]) > t){
			p -- ;
			mn = min(mn , dp[p + 1] + ((p == n - 1 ? e : x[p + 1]) - x[p]) + 3 * x[p]) ;
		}

		dp[i] = mn - 3 * x[i] ;

		int len = x[p - 1] - x[i] ;
		dp[i] = min(dp[i] , 3 * len + (t - 2 * len) + (p == n ? e - x[n - 1] : x[p] - x[p - 1] + dp[p])) ;
	}

	cout << x[0] + dp[0] << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int V = 1e5;

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

	int x, y;
	cin >> x >> y;
	int res = 0;
	if (x <= 3) res += (4 - x) * V;
	if (y <= 3) res += (4 - y) * V;
	if (x == 1 && y == 1) res += 4 * V;
	cout << res << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k,q,a[N];
int main()
{
    scanf("%d%d%d",&n,&k,&q);
    while(q--)
    {
        int x;scanf("%d",&x);
        if(x>1) a[1]--,a[x]++;
        if(x<n) a[x+1]--,a[n+1]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        a[i]+=a[i-1];
        if(a[i]+k>0) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
        
        long n = Long.parseLong(sc.next());
    
        HashMap<Long, Integer> map = primeFactorization(n);
        int ans = 0;
        for(long l : map.keySet()){
            int i = map.get(l);
            int j = 1;
            while(i >= j){
                ans++;
                i -= j;
                j++;
            }
        }
        System.out.println(ans);
    }
    
    static HashMap<Long, Integer> primeFactorization(long n){
        
        var map = new HashMap<Long, Integer>();
        while(n%2 == 0){
            n /= 2;
            map.put(2L, map.getOrDefault(2L, 0)+1);
        }
        double sqrt = Math.sqrt(n);
        for(long l = 3; l <= sqrt; l += 2){
            while(n%l == 0){
                n /= l;
                map.put(l, map.getOrDefault(l, 0)+1);
            }
        }
        if(n > 1) map.put(n, 1);
        return map;
    }
}

Measured memory_bytes: 35768
#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, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];

  int left = 0, right = k;
  for (int i = k + 1; i <= n; ++i) {
    cout << (a[left] < a[right] ? "Yes" : "No") << endl;
    ++left, ++right;
  }
  return 0;
}


Measured memory_bytes: 4400
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
cnt = [0,0,0]
ans = 1
for a in A:
    idx = []
    for i in range(3):
        if cnt[i] == a:
            idx.append(i)
    if len(idx)==0:
        print(0)
        exit()
    cnt[idx[0]]+=1
    ans *= len(idx)
    ans %= MOD
print (ans)

Measured memory_bytes: 14020
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int N; cin >> N;
    int A[N]={};
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A,A+N);
    int alice=0,bob=0;
    for(int i=N-1; i>=0; i-=2){
        alice+=A[i];
        if(i-1>=0) bob+=A[i-1];
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long int 

int main(){
   ll i,j,k,n,m,t;
   ll pre=0;
  cin>>n;
  ll f=1;
  while(n--){
   cin>>k;
    if(k<pre) {
     f=0; 
    }
    if(k-1>=pre) pre=k-1;
    else pre=k;
  }
  if(f) cout<<"Yes\n";
  else cout<<"No\n";
}

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

int main() {
  long long n,k;
  cin>>n>>k;
  long long ans;
  if(n<=k){
    ans=min(n,k-n);
  }
  else{
    long long a=(n-k)/k;
    ans=n-k*a;
    long long anse=ans-k;
    ans=min(ans,anse);
    ans=min(ans,k-anse);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int bl,re;
int main(){
  string h;
  cin>>h;
  for(int i=0;i<h.length();++i){
    if(h[i]=='0'){++re;}
    else{++bl;}
  }
  cout<<2*min(bl,re)<<endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int st[31],student;
  for(int i=1;i<31;i++){
    st[i]=0;
  }
  for(int i=1;i<29;i++){
    cin>>student;
    st[student]=1;
  }
  for(int i=1;i<31;i++){
    if(st[i]==0){
      cout<<i<<endl;
    }
  }
  return 0;
}

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

int main(){
	int H[300], W[300];
	int s = 0;
	for (;;){
		cin >> H[s] >> W[s];
		if (H[s] == 0 && W[s] == 0)break;
		s++;
	}
	for (int t = 0; t < s; t++){
		for (int i = 0; i < W[t]; i++){
			cout << "#";
		}
		cout << endl;
		for (int i = 1; i < H[t] - 1; i++){
			cout << "#";
			for (int i = 1; i < W[t]-1;i++){
				cout << ".";
			}
			cout << "#" << endl;
		}
		for (int i = 0; i < W[t]; i++){
			cout << "#";
		}
		cout << endl;
		cout << endl;
	}
	return 0;
}


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

int n;
long long c;
long long arr[200005];
long long memo[200005];
int proc;
pair<long long,long long> p;
deque<pair<long long,long long> > dq;

long double intersect(pair<long long,long long> l1,pair<long long,long long> l2){
	return (long double)(l2.second-l1.second)/(long double)(l1.first-l2.first);
}

bool redundant_front(){ //intersection of first 2 < x
	return (intersect(dq[0],dq[1])<arr[proc]);
}

bool redundant_back(){ //intersection of new and second last < intersection of last 2
	int s=dq.size();
	return (intersect(p,dq[s-2])<=intersect(dq[s-1],dq[s-2]));
}

void insert(){
	p=make_pair(-2*arr[proc],arr[proc]*arr[proc]+memo[proc]);
	int s=dq.size();
	while(s>=2&&redundant_back()){
		dq.pop_back();
		s--;
	}
	dq.push_back(p);
}

long long query(){
	int s=dq.size();
	while(s>=2&&redundant_front()){
		dq.pop_front();
		s--;
	}
	return dq[0].first*arr[proc]+dq[0].second;
}

int main(){
	scanf("%d%lld",&n,&c);
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	proc=0;
	memo[0]=0;
	insert();
	for(int i=1;i<n;i++){
		proc=i;
		memo[i]=query()+arr[i]*arr[i]+c;
		insert();
	}
	printf("%lld",memo[n-1]);
}


Measured memory_bytes: 5632
#include <iostream>

using namespace std;

int main() {

	while (true) {

		int a, b;
		char op;
		cin >> a;
		cin >> op;
		cin >> b;

		if (op == '+') {
			cout << a + b << endl;
		}
		else if (op == '-') {
			cout << a - b << endl;
		}
		else if (op == '*') {
			cout << a * b << endl;
		}
		else if (op == '/') {
			cout << a / b << endl;
		}
		else if (op == '?') {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3080
# a, b = (map(int, input().split()))
str_a = input()
str_b = input()

for i in range(len(str_a)):
    if str_a == str_b:
        print('Yes')
        exit()
    b = str_a[-1]
    c = str_a[:-1]
    str_a = b + c

print('No')


Measured memory_bytes: 2940
#include<iostream>
//#include<algorithm>
#include<cmath>
#include<string>
//#include<set>
//#include<vector>
#include<iomanip>
using namespace std;
int main(){

    string s,t;
    cin>>s>>t;
    int ls=s.length() , lt=t.length(),x=t.length();
    for(int i=0,y=0;i<=(ls-lt);i++,y=0){
        for(int j=0; j<lt;j++){
            if(t[j]!=s[j+i]){y++;}
        }
        if(y<x){x=y;}
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

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

		char[] s = in.next().toCharArray();

		int idx = 0;
		while ( idx < s.length ) {
			// Rの個数をカウント
			int cntR = 0;
			while ( idx < s.length && s[idx] == 'R' ) {
				cntR++;
				idx++;
			}

			// Rの連続がLに移行したポイントを記録 s[changePoint -1] = R, s[changePoint] = L,
			int changePoint = cntR;
			// System.out.println("cp is " + changePoint);

			// Lの個数をカウント
			int cntL = 0;
			while ( idx < s.length && s[idx] == 'L' ) {
				cntL++;
				idx++;
			}

			// System.out.println("(cntR + cntL) % 2 =" + (cntR + cntL) % 2);

			// 表示
			if ( (cntR + cntL) % 2 == 0 ) {
				for ( int i = 0; i < cntR + cntL; i++ ) {
					if ( i == changePoint - 1 || i == changePoint ) {
						System.out.print((cntR + cntL) / 2 + " ");
					} else {
						System.out.print(0 + " ");
					}
				}
			} else {
				for ( int i = 0; i < cntR + cntL; i++ ) {
					if ( i != changePoint - 1 && i != changePoint ) {
						System.out.print(0 + " ");

					} else
					// R	
					if ( i != changePoint - 1 ) {

						if ( (changePoint - 1) % 2 == (cntR + cntL) % 2 ) {
							System.out.print(((cntR + cntL) / 2 + 1) + " ");
						} else {
							System.out.print((cntR + cntL) / 2 + " ");
						}
					} else
					// L	
					if ( i != changePoint ) {

						if ( (changePoint) % 2 == (cntR + cntL) % 2 ) {
							System.out.print(((cntR + cntL) / 2 + 1) + " ");
						} else {
							System.out.print((cntR + cntL) / 2 + " ");
						}
					}
				}
			}
		}

		in.close();

	}
}

Measured memory_bytes: 38928
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int H1, M1, H2, M2;
  cin >> H1 >> M1 >> H2 >> M2;
  int K;
  cin >> K;

  int HM1 = H1 * 60 + M1, HM2 = H2 * 60 + M2;
  int ans = HM2 - HM1 - K;
  cout << ans << endl;
}

Measured memory_bytes: 3648
import numpy as np
n, m = list(map(int,input().split()))
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)

position = 0
counter_ = 0
checker_ = 0
for b,c in bc:
    while  position-counter_ < b and position < n:
        if a[position] < c:
            a[position] = c
            position += 1
        else:
            checker_ = 1
            break
    if checker_:
        break
    counter_ = position
print(sum(a))

Measured memory_bytes: 41836
import java.util.Scanner;

public class Main {
	
	static int step(int n) {
		if(n==1) {
			return 1;
		}
		if(n==2) {
			return 2;
		}
		if(n==3) {
			return 4;
		}
		return step(n-1)+step(n-2)+step(n-3);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if(n==0) break;
			System.out.printf("%d\n",step(n)/3650+1);
		}
		
		
	}
}



Measured memory_bytes: 26480
package main

import (
	"fmt"
	"strings"
)

func main() {
	var W string
	var ans int
	fmt.Scan(&W)
	for {
		var T string
		fmt.Scan(&T)
		if strings.ToLower(T) == W {
			ans++
		}
		if T == "END_OF_TEXT" {
			break
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 1112
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k])yn
	}

	return 0;
}


Measured memory_bytes: 4044
from math import sqrt
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def prime_factors(n):
    i = 2
    result = []
    while i * i <= n:
        if n % i == 0:
            n //= i
            result.append(i)
        else:
            i += 1
    if n > 1:
        result.append(n)
    return result

def solve(n):
    primes = sorted(prime_factors(n))
    used = set()
    result = 0
    i = 0
    while n > 1 and i < len(primes):
        curr = primes[i]
        while curr in used:
            i += 1
            if i == len(primes):
                return result
            if primes[i - 1] != primes[i]:
                curr = primes[i]
            else:
                curr *= primes[i]
        n //= curr
        used.add(curr)
        result += 1
        i += 1
    return result

if __name__ == "__main__":
    n = int_in()
    out(solve(n))

Measured memory_bytes: 79904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 7;
const int infint = (int)1e9;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, a[MAXN], p[MAXN], part[MAXN], fen[MAXN];
void add(ll idx, ll t)
{
	for (; idx <= 2 * n; idx += idx & -idx)
		fen[idx] += t;
}
ll get(ll idx)
{
	ll sum = 0;
	for (; idx; idx -= idx & -idx)
		sum += fen[idx];
	return sum;
}
ll check(ll mid)
{
	for (int i = 0; i < n; i++)
		if(a[i] <= mid)
			p[i] = 1;
		else
			p[i] = -1;
	for (int i = 1; i < n; i++)
		p[i] += p[i - 1];
	ll cur = 0;
	for (int i = 0; i < n; i++)
		p[i] += n + 1;
	memset(fen, 0, sizeof fen);
	add(n + 1, 1);
	for (int i = 0; i < n; i++)
	{
		cur += get(p[i] - 1);
		add(p[i], 1);
	}
	return cur;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll l = 0, r = 1e9 + 1;
	ll kol = n * (n + 1) / 2;
	kol = kol / 2 + 1;
	while(r - l > 1)
	{
		ll mid = (l + r) >> 1;
		if(check(mid) >= kol)
			r = mid;
		else
			l = mid;
	}
	cout << r;
}


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

using namespace std;

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

  int n;
  cin >> n;
  map<string, int> cnt;
  while (n--) {
    string s;
    cin >> s;
    ++cnt[s];
  }
  int mx = 0;
  for (auto it : cnt) {
    mx = max(mx, it.second);
  }
  for (auto it : cnt) {
    if (it.second == mx) {
      cout << it.first << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 23808
n = int(input())
list = []
for i in range(n):
    #print("a")
    li=[int(i) for i in input().split()]
    list.append(li)
#print(list)
count = 0
for i in range(n-1):
    for j in range(n-i-1):
        #print(((list[i][0]-list[i+j+1][0])**2+(list[i][1]-list[i+j+1][1])**2)**0.5)
        count += ((list[i][0]-list[i+j+1][0])**2+(list[i][1]-list[i+j+1][1])**2)**0.5

#print(count)

nc2 = n*(n-1)//2

print(count*(n-1)/nc2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if((a + b + c) >= 22)
    {
        cout << "bust";
    }
    else
    {
        cout << "win";
    }
    
    return 0;
}

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


int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
 
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int n, a, b;
signed main() {
	cin >> n >> a >> b;
	int p = (mod_pow(2, n, mod) - 1 + mod) % mod;
	int q = (comb(n, a) + comb(n, b)) % mod;
	cout << (p - q + mod) % mod << endl;
}


Measured memory_bytes: 256
import sys
N,M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

def check(i, j):
    # from (i, j) to (i+M, j+M)
    ret = True
    for h in range(M):
        for w in range(M):
            if A[h+i][w+j] != B[h][w]:
                ret = False

    return ret
                
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i, j):
            print("Yes")
            sys.exit()
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int N = Integer.parseInt(input.nextLine());
		int W = Integer.parseInt(input.nextLine());
		
		int[] v = new int[N];
		
		for(int i = 0; i < N; i++) v[i] = i;
		
		for(int i = 0; i < W; i++) {
			String[] s = input.nextLine().split("[,]");
			int a = Integer.parseInt(s[0]) - 1;
			int b = Integer.parseInt(s[1]) - 1;
			
			int tmp = v[a];
			v[a] = v[b];
			v[b] = tmp;			
		}
		for(int i = 0; i < N; i++) {
			System.out.println(v[i] + 1);			
		}
		System.exit(0);
	}
}

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

using namespace std;

int main(){
    int H,W;
    cin>>H>>W;
    char A[H+1][W+1];
    long long int dp[H+1][W+1];
    long long int power = 1000000007;

    for(int i=1; i <= H; i++){
        for(int j=1; j <= W; j++){
            cin>>A[i][j];
        }
    }

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

    for(int i=1; i <= H; i++){
        for(int j=1; j <= W; j++){
            if(i == 1 && j == 1){
                dp[i][j] = 1;
            }
            else if(A[i][j] == '#'){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = ((dp[i-1][j] % power) + (dp[i][j-1] % power)) % power;
            }
        }
    }
    cout<<dp[H][W];

    return 0;
}


Measured memory_bytes: 12400
n, t = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()

a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)

dp = [[0 for j in range(t+1)] for i in range(n+1)]
prev = [[(0, 0) for j in range(t+1)] for i in range(n+1)]

for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
                prev[i+1][j+a[i]] = (i, j)
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
            prev[i+1][j] = (i, j)

happy = dp[n][t-1]
i = n
j = t-1


used = set([])
while i > 0 or j > 0:
    pi, pj = prev[i][j]
    if dp[pi][pj] != dp[i][j]:
        used.add(pi)
    i = pi
    j = pj

unused = []
for i in range(n):
    if i not in used:
        unused.append(b[i])

if len(unused) == 0:
    ans = happy
else:
    ans = happy + max(unused)

print(ans)





Measured memory_bytes: 394756
n = gets.chomp.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
min = 1000000
ind = -1
h.each_index do |i|
  diff = (t - h[i] * 0.006 - a).abs
  if diff < min
    min = diff
    ind = i
  end
end
puts ind+1


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>

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

using namespace std;

long double x[20];
string u[20];

int main(){
    long double ans = 0;
    int N; cin >> N;

    for(int i = 0; i < N; i++){
        cin >> x[i];
        cin >> u[i];
        if(u[i] == "BTC") x[i] *= 380000.0;

        ans += x[i];
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
using ll = long long;

const int MW = 10100;
const ll MD = 1e9+7;
ll dp[MW];
int main() {
    int n, W;
    cin >> n >> W;
    int sm = 0;
    int w[n];
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sm += w[i];
    }
    if (sm <= W) {
        cout << 1 << endl;
        return 0;
    }

    sort(w, w+n, greater<int>());

    dp[0] = 1;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int nw = w[i];
        sm -= w[i];

        int mi = max(0, W-sm-w[i]+1);
        int ma = W-sm;
        for (int j = mi; j <= ma; j++) {
            ans += dp[j]; ans %= MD;
        }

        for (int j = W; j >= nw; j--) {
            dp[j] += dp[j-nw]; dp[j] %= MD;
        }

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

Measured memory_bytes: 3208
#include <cstdio>
#include <cmath>
 
#define MAX 100000

bool prime[MAX + 1];
int count[MAX + 1];
int N, L, R;

int main() {
  // 素数配列をエラトステネスの篩を使って生成
  // 素数であれば false, 素数でなければ true
  int const limit = sqrt(MAX);
  for (int i = 2; i < limit; ++i)
    if (!prime[i])
      for (int j = i + i; j <= MAX; j += i)
        prime[j] = true;

  // N と (N + 1) / 2 が素数である要素配列を生成
  // 条件が成立すれば 1、成立しなければ 0
  for (int i = 3; i<= MAX; i += 2)
    if (!prime[i] && !prime[(i + 1) >> 1])
      count[i] = 1;

  // 累積和を生成
  for (int i = 3; i<= MAX; ++ i)
    count[i] += count[i - 1];

  scanf("%d", &N);
  while (N --) {
    scanf("%d%d", &L, &R);
    printf("%d\n", count[R] - count[L - 1]);
  }

  fflush(stdout);
  return 0;
}


Measured memory_bytes: 2212
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;//输入 字符串 
    int len=s.size();//提取字符串长度 
    for(int i=0;i<=len;i++)//前面 
    {
        if(s[i]=='C')//前面的C 
        {
            for(int j=i;j<=len;j++)//后面 
            {
                if(s[j]=='F')//后面的F 
                {
                    cout<<"Yes"<<endl;//输出 
                    return 0;//结束 
                }
            }
        }
    }
    cout<<"No"<<endl;//没有C和F 输出 
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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 (b<a) { a=b; return true; } return false; }

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,c;
    cin>>n>>c;

    VV d(c,Vec(c,0));
    rep(i,c){
        rep(j,c){
            cin>>d[i][j];
        }
    }

    Vec g0(c);
    Vec g1(c);
    Vec g2(c);

    rep(i,n){
        rep(j,n){
            ll x;
            cin>>x;
            x--;
            if((i+j)%3==0){
                g0[x]++;
            }
            if((i+j)%3==1){
                g1[x]++;
            }
            if((i+j)%3==2){
                g2[x]++;
            }
        }
    }

    ll ans=INF;
    rep(i,c){
        rep(j,c){
            if(j==i)continue;
            rep(k,c){
                if(k==i)continue;
                if(k==j)continue;

                ll tmp = 0;
                rep(l,c){
                    tmp += d[l][i] * g0[l];
                }
                rep(l,c){
                    tmp += d[l][j] * g1[l];
                }
                rep(l,c){
                    tmp += d[l][k] * g2[l];
                }
                chmin(ans,tmp);
            }
        }
    }



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


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

using ll = 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 ); }

int main()
{
	string S;
	ll cnt = 0;
	ll ans = 0;

	cin >> S;

	for ( ll i = S.size() - 1; i >= 0; i-- ) {
		if ( S[i] == 'B' ) {
			cnt++;
			ans += ((ll)S.size() - i) - cnt;
		}
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

vector<vector<int>> G;

void dfs(int s, int cnt, vector<int> &d){
    if(d[s] != -1) return;
    d[s] = cnt;
    for(int t : G[s]){
        dfs(t, cnt+1, d);
    }
}

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

    int N;
    cin >> N;
    G.resize(N);
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> fen(N, -1);
    vector<int> snu(N, -1);
    dfs(0, 0, fen);
    dfs(N-1, 0, snu);

    int cnt0 = 0;
    for(int i=0; i<N; i++){
        if(fen[i] <= snu[i]) cnt0++;
    }
    int cnt1 = N - cnt0;
    if(cnt0 > cnt1) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;



    return 0;
}

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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e6 + 7;
const int M = 22;
const int mod = 1e9 + 7;

int ar[N];

void solve1()
{
	string a;
	cin >> a;
	if(a[2] == a[3] && a[4] == a[5])
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=[[] for _ in range(N)]
    for i in range(N):
        a[i]=LI()
    
    #dp[S]は状態Sから何通りあるか？男性は1から順に，女性マッチング情報がS   
    M=pow(2,N) 
    dp=[0]*M
    dp[0]=1
    
    def bit_cnt(num):
        cnt=0
        for i in range(N+3):
            if num&1:
                cnt+=1
            num=num>>1
        return cnt

    
    for S in range(M-1):
        if dp[S]==0:
            continue
        man=bit_cnt(S)
        for i in range(N):
            if (S>>i)&1==0:#i桁目が立っていない
                if a[man][i]==1:
                    dp[S+(1<<i)]+=dp[S]
                    dp[S+(1<<i)]%=mod
                        
        
    
    print(dp[-1])

                    
                    
    
        
    

main()


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

using namespace std;

int counter[26];

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

  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      counter[line[j] - 'a']++;
    }
  }

  int div4 = 0, div2 = 0, div1 = 0;
  for (int i = 0; i < 26; i++) {
    div4 += counter[i] / 4 * 4;
    counter[i] %= 4;
    div2 += counter[i] / 2 * 2;
    counter[i] %= 2;
    div1 += counter[i];
  }

  if ((h & 1) && (w & 1)) {
    int corners = h * w - h - w + 1;
    if (div4 >= corners && div2 + div4 >= h * w - 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else if (h & 1) {
    if (div4 >= h * w - w && div2 + div4 >= h * w) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else if (w & 1) {
    if (div4 >= h * w - h && div2 + div4 >= h * w) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else {
    if (div4 == h * w) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&x);
	
	if(a>x||a+b<x) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 128
S = str(input())

ans_one_start = ''
for i in range(len(S)):
    if i % 2 == 0:
        ans_one_start += '0'
    else:
        ans_one_start += '1'
        
ans_zero_start = ''
for i in range(len(S)):
    if i % 2 == 0:
        ans_zero_start += '1'
    else:
        ans_zero_start += '0'

diff_one = 0
diff_zero = 0

for i in range(len(S)):
    s_i = S[i]
    diff_i = ans_one_start[i]
    if s_i != diff_i:
        diff_one += 1
        
for i in range(len(S)):
    s_i = S[i]
    diff_i = ans_zero_start[i]
    if s_i != diff_i:
        diff_zero += 1
    
print(min(diff_one, diff_zero))


Measured memory_bytes: 3316