akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		int N=sc.nextInt();
		
		int t[]=new int[N+1];
		int x[]=new int[N+1];
		int y[]=new int[N+1];
		
		boolean f=true;
		
		for(int i=1;i<=N;i++) {
			t[i]=sc.nextInt();
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
			
			int a=t[i]-t[i-1];
			int b=Math.abs(x[i]-x[i-1])+Math.abs(y[i]-y[i-1]);
			
			int ama=a-b;
			
			if(a<b||ama%2!=0) {
				f=false;
			}
			
			
		}
		if(f)p("Yes");
		else p("No");
		
		
		
		
		
		
		
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++) cin >> d[i];
    
    long long ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout << ans << endl;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n;cin>>n;

  vector<int> A(n), B(n);
  for(int i=0;i<n;i++){
    cin>>A[i]>>B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if(n%2==0){
    cout<<B[n/2] + B[n/2-1]- (A[n/2] + A[n/2-1])+1<<endl;
  }else{
    cout<<B[n/2]-A[n/2]+1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 4764
/*
	---------author:O7Oo7oO7O-------------
*/

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using ll = long long int;



int main()
{
	IOS

	string s;
	cin>>s;
	if(s=="ABC")
		cout<<"ARC\n";
	else
		cout<<"ABC\n";
	return 0;
}

Measured memory_bytes: 3664
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	sum := 0
	for i, v := range s {
		if i%2 == 0 && v == '0' {
			sum++
		}
		if i%2 == 1 && v == '1' {
			sum++
		}
	}
	sum2 := 0
	for i, v := range s {
		if i%2 == 0 && v == '1' {
			sum2++
		}
		if i%2 == 1 && v == '0' {
			sum2++
		}
	}
	if sum < sum2 {
		fmt.Println(sum)
	} else {
		fmt.Println(sum2)
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int p = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
void solve(){
    int n; cin >> n;
    map<string, int> vis;
    string s;
    ll res = 0;
    for(int i = 1; i <= n; ++i){
        cin >> s;
        sort(s.begin(), s.end());
        if(vis.count(s)) res += vis[s], vis[s]++;
        else vis[s] = 1;
    }
    cout << res << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 11136
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], n, m, k;

void solve()
{
     cin >> n;
     int s = 0;
     for (int i = 1; i <= n; i++)
     {
          if ((i % 3 == 0) || (i % 5 == 0))
               continue;
          else
               s += i;
     }
     cout << s;

}

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

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 3800
/**
 * File              : C.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 12.12.2019
 * Last Modified Date: 12.12.2019
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
int const MAXN = 15;
int a[MAXN];
int x[MAXN][MAXN];
int y[MAXN][MAXN];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool ok = true;
        //cout << "BIT: " << bitset<8>(bit) << endl;
        for (int j = 0; j < n; j++) {
            if (!(bit & (1 << j))) continue;
            for (int i = 0; i < a[j]; i++) {
                //cout << bitset<8>(bit >> x[j][i]) << ' ' << y[j][i] << endl;
                //cout << ((bit >> x[j][i]) ^ (y[j][i])) << endl;
                if (((bit >> x[j][i]) & 1) ^ (y[j][i])) ok = false;
            }
        }
        if (ok) {
            //cout << "OK " << endl;
            ans = max(ans, __builtin_popcount(bit));
        } 
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;

Vi tmp;
bool cal(ll id,ll nu = 1){//id番目から引き始める.nu回やる
	if(nu==0)return true;
	ll tp = 1;
	repi(i,id,n){
		tmp[i] -= tp*nu;
		if(tmp[i]<0)return false;
		tp++;
	}
	rep(i,id){
		tmp[i] -= tp*nu;
		if(tmp[i]<0)return false;
		tp++;
	}
	return true;
}

ll sol(ll diffx,ll difn){//そこから1がはじまるパターンが何回?
	ll tp = diffx - difn;
	if(tp%n==0){
		return tp/n;
	}else{
		return INF;
	}
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n;
	a.resize(n);
	rep(i,n){
		cin>>a[i];
	}
	tmp = a;
	Vi dif(n);//dif[i]:=a[i+1]-a[i]
	ll difx=0;//difのmax
	rep(i,n-1){
		dif[i+1] = a[i+1]-a[i];
		chmax(difx,dif[i+1]);
	}
	dif[0] = a[0] - a[n-1];
	chmax(difx,dif[0]);
	Vi ct(n);
	bool ans = true;
	rep(i,n){
		ll tmp = sol(difx,dif[i]);
		if(tmp==INF){
			ans = false;
			break;
		}
		ct[i] = tmp;
	}
	rep(i,n){
		cal(i,ct[i]);
	}
	ll sum = n*(n+1)/2;
	ll pre = tmp[0];
	rep(i,n){
		if(tmp[i]%sum!=0){
			ans = false;
			break;
		}
		if(tmp[i]!=pre){
			ans = false;
			break;
		}
		pre = tmp[i];
	}
	YES(ans);
	return 0;
}

Measured memory_bytes: 3456
def aising19_c():
    from collections import deque

    h, w = (int(x) for x in input().split())
    color = [[s == '#' for s in str(input())] for _ in range(h)]
    used = [[False]*w for _ in range(h)]

    ans = 0
    for i in range(h):
        for j in range(w):
            if used[i][j]: continue
            bk, wt = 0, 0
            que = deque()
            used[i][j] = True
            que.append((i, j))
            while que:
                ci, cj = que.popleft()
                if color[ci][cj]: bk += 1
                else: wt += 1
                for di, dj in ((-1,0),(0,-1),(0,1),(1,0)):
                    ni, nj = ci+di, cj+dj
                    if ni < 0 or h <= ni or nj < 0 or w <= nj: continue
                    if color[ci][cj] == color[ni][nj]: continue
                    if used[ni][nj]: continue
                    used[ni][nj] = True
                    que.append((ni, nj))
            ans += bk * wt
    print(ans)

if __name__ == '__main__':
    aising19_c()

Measured memory_bytes: 11868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

lint app() {
  int n,k;
  cin>>n>>k;

  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }

  vector<lint> c(n);
  rep(i,n){
    cin>>c[i];
  }

  vector<lint> lplen(n,0), lpsum(n);
  rep(i,n){
    if(lplen[i]==0){
      int len=0; lint sum=0;
      int cur=i;
      do{
        cur=p[cur]; len++; sum+=c[cur];
      }while(cur!=i);
      do{
        cur=p[cur]; lplen[cur]=len; lpsum[cur]=sum;
      }while(cur!=i);
    }
  }

  lint ans=-2e9;
  rep(i,n){
    int llen=lplen[i]; lint lsum=lpsum[i];
    int len=0; lint sum=0;
    int cur=i;
    do{
      cur=p[cur]; len++; sum+=c[cur];
      if(len>k) break;
      if(lsum>0){
        chmax(ans,sum+(k-len)/llen*lsum);
      }else{
        chmax(ans,sum);
      }
    }while(cur!=i);

  }

  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3748
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
set<string>st;
int main(){
    ll n;
    cin >> n;
    st.insert("7");
    st.insert("5");
    st.insert("3");
    rep(i,10){
        set<string>s;
        for(auto x:st){
            s.insert(x);
        }
        for(auto x:st){
            s.insert(x+"7");
            s.insert(x+"5");
            s.insert(x+"3");
        }
        swap(st,s);
    }
    int ans = 0;
    for(auto x:st){
        if(stoll(x)<=n){
            bool flag[10] = {};
            rep(i,x.size()){
                flag[x[i]-'0'] = true;
            }
            if(flag[7] and flag[5] and flag[3]){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 32384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    t = sorted([(a[i], i) for i in range(n)])
    r = []
    for _,i in t:
        r.append(i+1)

    return JA(r, " ")


print(main())





Measured memory_bytes: 31100
n,m,k=map(int,input().split())
mod1,mod2=10**9+7,998244353
mod=mod2
MAX=n-1
fact=[1]*(MAX+1)
inv=[1]*(MAX+1)
for i in range(2,MAX+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(MAX,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
ans=0
cor=pow(m-1,n-1-k,mod)
for i in range(k,-1,-1):
    ans=(ans+comb(n-1,i)*cor)%mod
    cor=cor*(m-1)%mod

print(m*ans%mod)

Measured memory_bytes: 24548
object Main extends App {
  def getLine(): (Int, Int) = {
    val input: String = scala.io.StdIn.readLine
    val ary = input.split(" ").map(_.toInt)
    (ary(0), ary(1))
  }

  val (w1, h1) = getLine()
  val (w2, h2) = getLine()

  val answer = (w1 - w2) * (h1 - h2)
  println(answer)
}

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

int main(){
  int N; cin >> N;
  int a,mae=0,seq=1,mahou=0;
  
  for(int i=0; i<N; i++){
    cin >> a;
    if(a==mae){
      seq++;
    }else{
      mahou+=(seq/2);
      seq=1;
    }
    mae=a;
  }
  cout << mahou+seq/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second
 
inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}
 
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char x[1010][1010];
int h,w,dp[1010][1010],md = 1e9 + 7;
int main()
{
	scanf("%d %d",&h,&w);
	for(int i=0;i<h;i++)
	{
		scanf("%s",&x[i]);
	}
	bool stp1=0,stp2=0;
	for(int i=0;i<h;i++)
	{
		if(x[i][0]=='#') stp1 = 1;
		if(x[0][i]=='#') stp2 = 1;
		if(!stp1)
		{
			dp[i][0] = 1;
		}
		if(!stp2)
		{
			dp[0][i] = 1;
		}
	}
	for(int i=1;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(x[i][j]=='.')
			{
				dp[i][j] = dp[i-1][j]%md+dp[i][j-1]%md;
				dp[i][j]%=md;
			}
		}
	}
	printf("%d\n",dp[h-1][w-1]);
	return 0;
}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=sc.Ia;
		StringBuilder sb=new StringBuilder();
		for(int i = s[1];i<s[0];i++) {
			sb.Append((a[i-s[1]]<a[i]?"Yes":"No")+"\n");
		}
		Console.Write(sb);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;

bool has_key(unordered_map<string, ll> &m, string s){
    if (m.find(s) == m.end()){
        return false;
    }
    else{
        return true;
    }
}


bool vector_find(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return true;
  }
  else {
    return false;
  }
}


void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}


void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}


int main() {

  ll X, N;
  cin >> X >> N;

  vector<ll> p(N);
  ll tmp = 100000;
  ll ans;

  for (ll i = 0; i < N; i++) {
    cin >> p.at(i);
  }

  for (ll i = -200; i <= 200; i++) {
    
    if (abs(X-i) < tmp && !vector_find(p, i)) {
      tmp = abs(X-i);
      ans = i;
    } else if (abs(X-i) == tmp && !vector_find(p, i)) {
      tmp = abs(X-i);
      ans = min(i, ans);
    }
  }

  if(N == 0) ans = X;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3000;
const int K = 100000;
const int mod = 998244353;
vector <int> a;
int dx[2] = {1, 0};
int dy[2] = {0, 1};
string s[N];
int used[N][N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    int z = 0;
    for (int i = 0; i < n; i++){
        cin >> s[i];
        for (int j = 0; j < m; j++) if (s[i][j] == 'o') z++;
    }
    mcf_graph <int,int> g(z + n * m + 2);
    int tt = z;
    z = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (s[i][j] == 'o'){
                for (int l = 0; l < n; l++){
                    for (int k = 0; k < m; k++){
                        used[l][k] = 0;
                    }
                }
                queue <pair<int,int>> q;
                q.push({i, j});
                while (!q.empty()){
                    auto x = q.front();
                    q.pop();
                    used[x.F][x.S] = 1;
                    g.add_edge(z, tt + x.S + x.F * m, 1, n * m - x.S - x.F + i + j);
                    for (int l = 0; l < 2; l++){
                        int nx = x.F + dx[l];
                        int ny = x.S + dy[l];
                        if (!used[nx][ny] && nx < n && nx >= 0 && ny < m && ny >= 0 && s[nx][ny] != '#'){
                            q.push({nx, ny});
                            used[nx][ny] = 1;
                        }
                    }
                }
                z++;
            }
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            g.add_edge(z + j + m * i, z + n * m, 1, 0);
        }
    }
    for (int i = 0; i < z; i++){
        g.add_edge(n * m + z + 1, i, 1, 0);
    }
    auto x = g.flow(n * m + z + 1, n * m + z);
    cout << z * n * m - x.S;
}


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

int sn=0;
int s[1000001];

int n,x;
int v[30];
bool p[1000001],dp[1000001];

int main(){
	p[0]=false;p[1]=false;
	for(int i=2;i<=1000000;i++){
		p[i]=true;
		for(int j=0;j<sn;j++){
			if(i%s[j] == 0){
				p[i]=false;
				break;
			}
			if(i<=s[j]*s[j]) break;
		}
		if(p[i]){
			s[sn]=i;
			sn++;
		}
	}

	while(cin>>n>>x,x!=0){
		for(int i=0;i<n;i++) cin>>v[i];
		fill(dp,dp+x,false);dp[0]=true;
		int ans=0;
		for(int i=0;i<=x;i++){
			if(dp[i]){
				for(int j=0;j<n;j++){
					if(i+v[j]<=x) dp[i+v[j]]=true;
				}
				if(p[i]) ans=i;
			}
		}
		if(ans) cout<<ans<<endl;
		else cout<<"NA"<<endl;
	}

	return 0;
}

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

#define rep(i, N) for(int i = 0;i < N;i++)
typedef long long ll;
const int mod = 1e9 + 7;

using namespace std;

template<typename T>
T mpow(T a, T n) {
	if (n == 1)return a;
	T temp = mpow(a, n / 2);
	return ((temp * temp) % mod) * (n % 2 != 0 ? a : 1) % mod;
}

template<typename T>
T mcomb(T n, T r) {
	if (n < 0 || r < 0 || n < r) return 0;
	T X = 1, Y = 1;
	rep(i, r)X = (X * (n - i)) % mod;
	rep(i, r)Y = (Y * (r - i)) % mod;
	T ret = X * mpow<T>(Y, mod - 2);
	return ret%mod;
}

int main(void) {
	ll n, a, b; cin >> n >> a >> b;

	ll total = mpow<ll>(2, n) - 1;
	ll A = mcomb<ll>(n, a);
	ll B = mcomb<ll>(n, b);

	ll ans = total - A;
	ans = ans % mod + (ans < 0 ? mod : 0);
	ans -= B;
	ans = ans % mod + (ans < 0 ? mod : 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
if s[k-1] == "A":
    print(s[:k-1] + "a" + s[k:])
elif s[k-1] == "B":
    print(s[:k-1] + "b" + s[k:])
else:
    print(s[:k-1] + "c" + s[k:])

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int n; cin>>n;
	string str;
	cin >> str;
	int ans = 1;
	rep2(i, 1, n){
		if(str[i-1] != str[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
const MOD: u64 = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().chars().collect();
    let n = s.len();

    let mut dp: Vec<u64> = vec![0; 4];
    dp[0] = 1;
    for i in 0..n {
        let mut next = dp.clone();
        next[0] = dp[0];
        match s[i] {
            'A' => {
                next[1] = (dp[0] + dp[1]) % MOD;
            }
            'B' => {
                next[2] = (dp[1] + dp[2]) % MOD;
            }
            'C' => {
                next[3] = (dp[2] + dp[3]) % MOD;
            }
            _ => {
                next[0] = next[0] * 3 % MOD;
                next[1] = (dp[0] + dp[1] * 3) % MOD;
                next[2] = (dp[1] + dp[2] * 3) % MOD;
                next[3] = (dp[2] + dp[3] * 3) % MOD;
            }
        }
        dp = next;
    }
    println!("{}", dp[3]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 5010
#define INF 1e9
#define F first
#define S second
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
  
int N,K;
pii taxi[MAX];
vector<int> G[MAX];
int cost[MAX][MAX];
 
int dijkstra(){
  priority_queue<piii,vector<piii>,greater<piii> > Q;
  Q.push(piii(pii(0,0),0));
  fill(cost[0],cost[0]+MAX*MAX,INF);
  cost[0][0] = 0;
 
  while(!Q.empty()){
    piii p = Q.top(); Q.pop();
    int v = p.F.S, r = p.S;
    if(cost[v][r] < p.F.F) continue;
 
    if(r > 0){
      for(int i = 0 ; i < (int)G[v].size() ; i++){
        int to = G[v][i];
        if(cost[v][r] < cost[to][r-1]){
          cost[to][r-1] = cost[v][r];
          Q.push(piii(pii(cost[to][r-1],to),r-1));
        }
      }
    }
    pii t = taxi[v];
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      int to = G[v][i];
      if(cost[v][r] + t.F < cost[to][t.S-1]){
        cost[to][t.S-1] = cost[v][r] + t.F;
        Q.push(piii(pii(cost[to][t.S-1],to),t.S-1));
      }
    }
  }
   
  return *min_element(cost[N-1],cost[N-1]+N);
}
 
int main(){
  int C,R,A,B;
  cin >> N >> K;
  for(int i = 0 ; i < N ; i++){
    cin >> C >> R;
    taxi[i] = pii(C,R);
  }
  for(int i = 0 ; i < K ; i++){
    cin >> A >> B; A--; B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  cout << dijkstra() << endl;
  return 0;
}


Measured memory_bytes: 101640
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    ll a[200005];
    ll b[200005];
    ll c[200005];
    int main()
    {
        fastread;
        ll n,i,j,k,l;
        //int n;
        cin>>n;
        for(i=1;i<=n;i++){
        	cin>>a[i];
		}
		ll sum=0;
		for(i=1;i<=n;i++){
			cin>>b[i];
			sum+=b[i];
		}
		for(i=1;i<=n-1;i++)
		cin>>c[i];
		for(i=1;i<=n-1;i++){
			if((a[i+1]-a[i])==1){
				sum+=c[a[i]];
			}
		}
		cout<<sum;
        return 0;
    }

Measured memory_bytes: 2304
N, M = map(int, input().split())
T = []
for i in range(M):
    a, b = map(int, input().split())
    T.append([a, b])

T.sort()
c = 1
s = 1
e = 10**9
for i in range(M):
    a = T[i][0]
    b = T[i][1]
    if a >= e and b > e:
        c += 1
        s = a
        e = b
    elif a > s and b < e:
        s = a
        e = b
    elif a > s:
        s = a
    elif b < e:
        e = b
    else:
        pass
print(c)

Measured memory_bytes: 89156
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int max = Integer.MIN_VALUE, min = sc.nextInt();
        for (int i = 1; i < count; i++) {
            int v = sc.nextInt();
            max = Math.max(max, v - min);
            min = Math.min(min, v);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 99804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return e > p.e;
    }
    ll e;
    int b, l, u;
};

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

    int n, x;
    cin >> n >> x;

    vector<P> p(n);
    ll B = 0;
    for (int i = 0; i < n; i++) {
        int b, l, u;
        cin >> b >> l >> u;

        B += (ll)l * b;
        p[i] = { (ll)l * b + (ll)u * (x - b), b, l, u };
    }
    sort(p.begin(), p.end());

    ll r = 0;
    int i0 = 0;
    for (int i = 0; i < n; i++) {
        ll t = B - p[i].e;
        if (t < 0) break;
        B = t;
        r += x;
        i0 = i + 1;
    }

    //以降は、フルには取らない
    if (B > 0) {
        ll s = x;
        for (int i = i0; i < n; i++) {
            ll t;
            ll y = (ll)p[i].l * p[i].b;
            if (B <= y) {
                t = (B + p[i].l - 1) / p[i].l;
            } else {
                t = (B - y + p[i].u - 1) / p[i].u + p[i].b;
            }
            s = min(s, t);
        }
        for (int i = 0; i < i0; i++) {
            B += p[i].e - p[i0].e;
            ll t;
            ll y = (ll)p[i].l * p[i].b;
            if (B <= y) {
                t = (B + p[i].l - 1) / p[i].l;
            } else {
                t = (B - y + p[i].u - 1) / p[i].u + p[i].b;
            }
            s = min(s, t);
            B -= p[i].e - p[i0].e;
        }
        r += s;
    }

    cout << r << endl;

    //引き分けにするときはどうでもよく、勝つときはuを、負けるときはlを選ぶ
    //青木君が高得点を取るとわかっているテストは捨てるのが普通 しかしlが大きいかもしれない
    //高橋君の点数がb未満のときは1時間勉強する毎にlずつAが増える b以上のときはuずつ増える Xまでしか増やせない
    //X点取ったときの効率を求める X点取るにはX時間の勉強 gainはl*b+u*(X-b)=u*X-b*(u-l) 途中まで取っても効率は上がらない
    //フルに取らない b以下しかとらないならlの大きい順にやればいい 以下はuの領域まで行く必要があるケースを考える
    //bがすごく高いけど、uもすごく魅力的なケースはあるかも lも関係してくる
    //全部は取らないわけだが、長くとるほど効率がよくなる（悪くならない）
    //uまで行くのが2つ以上になるとは思えないが それどころか1つだけになるんじゃ？
    //効率で抜かれたらもう抜き返せないから
    //残りのB以上を得るためにどれか一つを選ぶ
    //全部取るとやりすぎなので、効率の悪い他のテストで全部取るという戦略があるか？いや、メリットがない 勉強時間がXで同じなのでデメリットしかない
    //少しとる効率がすごくいいため全体を取るのは他へゆずるということはあるか？ありそう
    //少しと全体でトレードオフになる 困った とりあえずの解は求まっているのでこれより上を探す
    //フルに取ったやつのどれかを外し、そこから少しだけ取る 答えの上界が求まっているのでフルに取る数が増えることはない
    //

    return 0;
}

Measured memory_bytes: 2560
# Input
h, n = input().split()
a = list(map(int, input().split()))

# Declaring variables
h = int(h)
n = int(n)
sum = 0

# Calculating the sum
for i in range(n):
    sum += a[i]

# Judging if the raccoon can win without using the same move twice or more.
if sum >= h:
    print("Yes")
else:
    print("No")








Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
#define inf (1<<20)
int main(){
	int n;string s;
	cin>>n>>s;
	vector<int> W(n),E(n);
	

	for(int i=0;i<n;++i){
		if(i!=0)W[i]=W[i-1],E[i]=E[i-1];
		if(s[i]=='W'){
			++W[i];
		}else{
			++E[i];
		}
	}

	int ans=inf,c_ans=0;
	for(int i=0;i<n;++i){
		c_ans=W[i-1]+E[n-1]-E[i];
		ans=min(c_ans,ans); 
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 3076
// header {{{
using namespace std;

// C++
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#pragma GCC optimization_level 3

// util {{{
#define print(x)	        cout << (x)
#define printvec(x)       for(int i = 0;i < (x).size();i++)cout << (x).at(i) << " ";cout << endl
#define println(x)	        cout << (x) << endl
#define printn		        cout << endl
#define read(x)	            cin >> (x)
#define readvec(x)        for(int i = 0; i < (x).size();i++)cin >> (x).at(i)

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

#define all(x) 		        (x).begin(),(x).end()
#define vint                vector<int>
#define outif(x,y,z)        if(x) cout<<(y)<<endl; else cout<<(z)<<endl
#define loop 		        while(true)

// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------
void draw(int H,int W){
    rep(i,H){
        rep(i,W){
            print("#");
        }
        printn;
    }
    printn;
}

void solve() {
    vector<pair<int,int>> squares;
    loop{
        int H,W;
        read(H);
        read(W);
        if(H == W && W == 0){
            break;
        }
        pair<int,int> tmp;
        tmp.first=H;
        tmp.second=W;
        squares.push_back(tmp);
    };
    rep(i,squares.size()){
        draw(squares.at(i).first,squares.at(i).second);
    }

}

signed main() {
    solve();
    return 0;
}


Measured memory_bytes: 3216
import numpy as np
from collections import deque
infinity = -10**5
H,W = map(int,input().split())

A = np.zeros((H+1,W+1))

for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            A[i][j] = 1
        else:
            A[i][j] = -1
#print(A)
N = H*W
G=[[] for i in range(N)]

for i in range(H):
    for j in range(W):
        if A[i][j] ==1:
            if A[i+1][j] == 1:
                G[W*(i+1)+j].append(W*i+j)
                G[W*i+j].append(W*(i+1)+j)

            if A[i][j+1] == 1:
                G[W*i+(j+1)].append(W*i+j)
                G[W*i+j].append(W*i+(j+1))

def BFS (s):
    queue = deque()
    d = [infinity]*N
    
    queue.append(s)
    d[s]= 0
    
    while len(queue)!=0:
      u = queue.popleft()
      for v in G[u]:
      	if d[v] == infinity:
        	d[v] = d[u]+1
        	queue.append(v) 	  
  
    return d

ans = 0


for i in range(N):
    I = i//W
    J = i%W
    if A[I][J] == 1:
        d = BFS(i)
        for k in range(N):
            if d[k] == infinity:
                d[k] = -1
        ans = max(ans,max(d))
        
"""

for i in range(H):
    for j in range(W):
        if A[i][j] == 1:
            d = BFS(W*i+j)
        ans = max(ans,max(d))
"""
print(ans)

    


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

int main() {
  int n , r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
  }
  else {
    cout << r + 100 * (10 - n) << endl;
  }
  
}
    
      
  

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

#define MAX 200000
#define SENTINEL (int)2e9

typedef long long ll;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
  int i, j, k;
  ll cnt = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = SENTINEL;
  i = j = 0;
  for (k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
  return cnt;
};

ll mergeSort(int A[], int n, int left, int right) {
  int mid;
  ll v1, v2, v3;
  if (right - left > 1) {
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  } else return 0;
};

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

  ll ans = mergeSort(A, n, 0, n);
  cout << ans << endl;
  return 0;
};



Measured memory_bytes: 4636
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
temp = [-1] * n
ans = -1

for i in sc:
    if temp[i[0]-1] != -1 and temp[i[0]-1] != i[1]:
        print(-1)
        exit()
    temp[i[0]-1] = i[1]

if n == 1:
    mini = 0
    maxi = 10
if n == 2:
    mini = 10
    maxi = 100
if n == 3:
    mini = 100
    maxi = 1000

for i in range(mini,maxi):
    s = str(i)
    ok = True
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            ok = False
    if ok:
        ans = i
        print(ans)
        exit()

print(ans)

Measured memory_bytes: 3064
n=int(input())
l=list(map(int,input().split()))

l=sorted(l)
a=l[0]

for i in range(1,n-1):
  if i==1:
    x=(a+l[i])/2
    l[i]=x
    
  else:
    x=(l[i-1]+l[i])/2
    l[i]=x
    
ans=(l[n-2]+l[n-1])/2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
ll dp[100010][13];
int main( ){
    string s;
    cin>>s;
    ll mod=1e9+7;
    dp[0][0]=1;
    int n=s.size();
    rep(i,0,n){
        if(s[i]=='?'){
            rep(pd,0,13){
                rep(now,0,10){
                    dp[i+1][(pd*10+now)%13]+=dp[i][pd];
                    dp[i+1][(now+pd*10)%13]%=mod;
                    if(dp[i+1][(now+pd*10)%13]<0)dp[i+1][(now+pd*10)%13]+=mod;
                }
            }
        }
        else{
           int now=s[i]-'0';
           rep(pd,0,13){
                dp[i+1][(pd*10+now)%13]+=dp[i][pd];
                dp[i+1][(now+pd*10)%13]%=mod;
                if(dp[i+1][(now+pd*10)%13]<0)dp[i+1][(now+pd*10)%13]+=mod;
           }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}




Measured memory_bytes: 10624
#include <stdio.h>
#include <string.h>
void main()
{
  char s[10],t[10],u[10];
  int m,n;
  scanf("%s %s",s,t);
  scanf("%d %d",&m,&n);
  scanf("%s",u);
  
  if(strcmp(u,s)==0)
    printf("%d %d",m-1,n);
  
  else
    printf("%d %d",m,n-1);
}

Measured memory_bytes: 128
n = int(input())
s = input()

from itertools import accumulate as acc
w = [0] + list(acc([int(i == 'W') for i in s]))
e = [0] + list(acc([int(i == 'E') for i in s[::-1]]))

ans = float('inf')
for i in range(n):
    ans = min(ans, w[i] + e[-i-2])
print(ans)

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

const int maxn=1e5+10;

string S;
int num[maxn];

int main()
{
    cin>>S;
    for(int i=0;i<S.size();)
    {
        if(S[i]=='L')
        {
            i++;
            continue;
        }
        int n=0;
        while(i<S.size()&&S[i]=='R')
        {
            n++;
            i++;
        }
        num[i-1]=n;
    }
    for(int i=S.size()-1;i>=0;)
    {
        if(S[i]=='R')
        {
            i--;
            continue;
        }
        int n=0;
        while(i>=0&&S[i]=='L')
        {
            n++;
            i--;
        }
        num[i+1]=n;
    }

    for(int i=0;i<S.size();i++)
    {
        if(num[i]!=0)
        {
            //cout<<i<<' '<<num[i]<<' '<<num[i+1]<<endl;
            int m=(num[i]+num[i+1])/2;
            //cout<<m<<endl;
            if((num[i]+num[i+1])%2)
            {
                if(num[i]%2)
                {
                    num[i]=m+1;
                    num[i+1]=m;
                }
                else
                {
                    num[i]=m;
                    num[i+1]=m+1;
                }

            }
            else
                num[i]=num[i+1]=m;
            i++;
        }
    }
    for(int i=0;i<S.size();i++)
        cout<<num[i]<<' ';
    return 0;
}



Measured memory_bytes: 1024
import sys


input = sys.stdin.readline


# 高さを変更するかどうかの bool 型配列を作る
def make(i, l):
    if i == N:
        return [l]
    else:
        lc = l[:]
        l.append(False)
        lc.append(True)
        return make(i+1, l) + make(i+1, lc)


def main():
    ans = 15*10**10
    for tf in make(1, [False]):
        peak = A[0]
        count = 1
        cost = 0
        for i in range(1, N):
            if count == K:
                break
            if tf[i]:
                count += 1
                if peak >= A[i]:
                    cost += peak - A[i] + 1
                    peak += 1
                else:
                    peak = A[i]
            else:
                if A[i] > peak:
                    peak = A[i]
                    count += 1
        if count == K:
            ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    main()


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


int main() {
  ll A,B,C,K,ans=0;
  cin >> A >> B >> C >> K;
  ll tmp;
  tmp=min(A,K);
  ans+=tmp;
  K-=tmp;
  if (K==0) {
    cout << ans << endl;
    return 0;
  }
  tmp = min(B,K);
  K-=tmp;
  if (K==0) {
    cout << ans << endl;
    return 0;
  }
  tmp=min(C,K);
  ans-=tmp;
  K-=tmp;
  cout << ans << endl; 
}

Measured memory_bytes: 3624
var input = function()
{

  return require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
};

var out = function(x)
{
  console.log(x);
  return x;
}

var drawRect = function(H,W)
{
  var rect = "";
  for (var i = 0; i < H; i++)
  {
    if (i==0 || i==H-1)
    {
      rect = rect+drawLineFrame(W);
    }
    else
    {
      rect = rect+drawLine(W);
    }

  }
  out(rect);
  return rect;
}

var drawLineFrame = function(W)
{
  var line = "";
  for(i=0;i<W;i++)
  {
    line = line+'#';
  }
  line = line+'\n';
  return line;
}

var drawLine = function(W)
{
  var line = "";
  for(i=0;i<W;i++)
  {
    if(i==0 || i==W-1)
    {
      line = line+'#';
    }
    else
    {
      line = line+'.';
    }
  }
  line = line+'\n';
  return line;
}

var calc = function(x)
{
for (var i = 0; i < x.length; i++) {
  var HW = x[i].split(' ').map(Number);
  if(HW[0]==0 && HW[1] ==0)return;
  drawRect(HW[0],HW[1]);
}
return x;
};

calc(input());

Measured memory_bytes: 10684
N = int(input())
v = [int(x) for x in input().split()]

even = v[::2]
odd = v[1::2]

from collections import Counter
dev = Counter(even).most_common(2)
dod = Counter(odd).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])



Measured memory_bytes: 15900