akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace abc093_a
{
    class program
    {
        static void Main(string[] args)
        {
            ChangeLocalDebugInput();
            string s =Console.ReadLine();
            bool haveA = false, haveB = false, haveC = false;
            for (int i = 0; i < 3; i++)
            {
                if (s[i] == 'a')
                {
                    haveA = true;
                } else if (s[i] == 'b')
                {
                    haveB = true;
                } else if (s[i] == 'c')
                {
                    haveC = true;
                }
            }
            if (haveA && haveB && haveC)
            {
                Console.WriteLine("Yes");
            } else
            {
                Console.WriteLine("No");
            }

            Console.ReadKey();
        }


        [System.Diagnostics.Conditional("LOCAL_DEBUG")]
        static void ChangeLocalDebugInput()
        {
            Console.SetIn(new System.IO.StreamReader("../../stdin.txt"));
        }
    }
}


Measured memory_bytes: 11220
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Place> list = new ArrayList<>();
        for(int i = 0; i < n; i++){
            double x = scanner.nextDouble();
            double y = scanner.nextDouble();
            list.add(new Place(x,y));
        }
        int[] C = new int[n];
        for (int i = 0; i < n; i++) {
            C[i] = i;
        }
        double ans = 0;
        double count = 0;
        do{
            for(int i = 0; i < n-1; i++){
                double tmp = getDistance(list.get(C[i]), list.get(C[i+1]));
                //System.out.println(tmp);
                ans += tmp;
            }
            count++;
        }while(nextPermutation(C));
        System.out.println(ans/count);
    }

    public static double getDistance(Place a, Place b){
        return Math.sqrt(Math.pow((a.x-b.x),2) + Math.pow((a.y-b.y),2));
    }

    static class Place implements Comparable<Place>{
        double x, y;
        public Place(double x, double y){
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object v){
            boolean retVal = false;
            if(v instanceof Place){
                Place ptr = (Place) v;
                retVal = (ptr.x == this.x) && (ptr.y == this.y);
            }
            return retVal;
        }

        @Override
        public int compareTo(Place r){
            return (int)r.x - (int)this.x;
        }
    }

    //【参考URL】
    // http://d.hatena.ne.jp/tomerun/20081203/1228321480
    public static boolean nextPermutation(int[] a) {
    for (int i = a.length - 1; 0 < i; i--) {
      if (a[i - 1] < a[i]) {
        int index = find(a[i - 1], a, i, a.length - 1);
        int temp = a[index];
        a[index] = a[i - 1];
        a[i - 1] = temp;
        Arrays.sort(a, i, a.length);
        return true;
      }
    }
    return false;
  }

    // destより大きい要素の中で最小のもののインデックスを二分探索で探す
    private static int find(int dest, int[] a, int s, int e) {
        if (s == e) {
        return s;
        }
        int m = (s + e + 1) / 2;
        return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);
    }
}



Measured memory_bytes: 23476
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int calc(int N) //0^1^...^N-1
{
    int res=(N/2)%2;
    if(N%2==1) res^=N-1;
    return res;
}

signed main()
{
    int A,B; cin>>A>>B;
    cout<<(calc(B+1)^calc(A))<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, x: "List[int]"):

    xneg = [0]+[xv for xv in x if xv < 0][::-1]
    xpos = [0]+[xv for xv in x if xv >= 0]

    ans = []
    # print(xneg)
    # print(xpos)
    for i in range(K+1):
        if len(xneg) <= i or len(xpos) <= K-i:
            continue
        ans.append(xpos[K-i]-2*xneg[i])
        # print(xpos[K-i], xneg[i])
    for i in range(K+1):
        if len(xpos) <= i or len(xneg) <= K-i:
            continue
        ans.append(2*xpos[i]-xneg[K-i])
        # print(xpos[i], xneg[K-i])

    # print(ans)
    print(min(ans))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20092
(defun getval (s x y)
  (gethash `(,x . ,y) s))
(defun check (s a)
  (let ((x (car a))
        (y (cdr a))
        (dx '(1 0 -1 0))
        (dy '(0 -1 0 1)))
    (unless (eq #\# (getval s x y))
      (return-from check t))
    (dotimes (i 4)
      (when (eq #\# (getval s (+ x (nth i dx)) (+ y (nth i dy))))
        (return-from check t)))
    nil))
(let ((h (read))
      (w (read))
      (s (make-hash-table :test #'equal)))
  (dotimes (y h)
    (let ((str (read-line)))
      (dotimes (x w)
        (setf (gethash `(,x . ,y) s) (char str x)))))
  (format t "~A~%"
          (loop for a being the hash-keys of s
                unless (check s a)
                return "No"
                finally (return "Yes"))))

Measured memory_bytes: 6504
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  long double A, B;
  cin >> A >> B;

  long long ans = floor(A * B);

  cout << ans << endl;
}


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

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

    int ans = 0;
    while(true){
        if(*max_element(h.begin(),h.end()) == 0){
            break;
        }
        int i = 0;
        while(i < n){
            if(h[i] == 0){
                i++;
            }
            else{
                ans++;
                while(i<n && h[i]>0){
                    h[i]--;
                    i++;
                }
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int r;
    scanf("%d", &r);
    printf("%d\n", r * r);
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,k,ans,p;
int map[12][6]=
{
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};
int main()
{
    scanf("%d%d",&n,&k);n-=2;
    p=n%11;n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
     for(int j=0;j<5;j++)
      if(map[i][j]==k)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int max(int a, int b) { return a < b ? b : a; }
int board[2010][2010];
int main() {
    int N, K; scanf("%d%d", &N, &K);

    int sum = 0, white = 0;
    for(int i=0; i<N; i++) {
        int x, y; char c; scanf(" %d%d %c", &x, &y, &c);
        x %= 2*K, y %= 2*K;
        if(c == 'B') board[x+1][y+1]++, sum++;
        if(c == 'W') board[x+1][y+1]--, sum--, white++;
    }

    for(int i=1; i<=2*K; i++) {
        for(int j=1; j<=2*K; j++) {
            board[i][j] += board[i][j-1];
        }
    }

    for(int j=1; j<=2*K; j++) {
        for(int i=1; i<=2*K; i++) {
            board[i][j] += board[i-1][j];
        }
    }

    int ma = -(1 << 25);
    for(int i=0; i<=K; i++) {
        for(int j=0; j<=K; j++) {
            int a = board[i][j];
            int b = board[i+K][j+K] - board[i+K][j] - board[i][j+K] + board[i][j];
            int c = board[2*K][j] - board[i+K][j];
            int d = board[i][2*K] - board[i][j+K];
            int e = board[2*K][2*K] - board[2*K][j+K] - board[i+K][2*K] + board[i+K][j+K];
            int tmp = a + b + c + d + e;
            ma = max(ma, max(tmp, sum - tmp));
        }
    }
    ma += white;
    printf("%d\n", ma);
    return 0;
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <stdlib.h>
int main(){
    int hoge;
    int K,A,B;
    hoge = scanf("%d",&K);
    hoge = scanf("%d %d",&A,&B);
    int i;
    int flag=0;
    for(i=A;i<=B;i++){

        if(i%K==0){
            flag = 1;
            break;
        }
    }
    //最終出力
    if(flag==0){
        printf("NG");
    }else{
        printf("OK");
    }
    return 0;
}

Measured memory_bytes: 1724
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		int N = int.Parse(Console.ReadLine());
		int[] a = new int[N];

        for(var i = 0; i < N; i++)
		{
			a[i] = int.Parse(Console.ReadLine()) - 1;
		}
		bool[] btn = new bool[N];
        for(var i = 0; i < N; i++)
		{
			if (i == 0) { btn[i] = true; }
			else { btn[i] = false; }
		}

		long ans = 0;
		int index = 0;

		while (btn[1] == false)
		{
			if (btn[a[index]] == true)
			{
				ans = -1;
				break;
			}
			btn[a[index]] = true;
			index = a[index];
			ans++;
		}

		Console.WriteLine(ans);

		Console.Out.Flush();
	}
}


Measured memory_bytes: 15200
#include<stdio.h>
int main(void){
   long a, b, r, A, B;
   while(scanf("%ld %ld", &a, &b) != EOF){
      A = a;
      B = b;
      if(b > a){
         a = B;
         b = A;
      }
      r = a % b;
      while(r != 0){
         a = b;
         b = r;
         r = a % b;
      }
      printf("%ld\n", b);
   }
   return 0;
}

Measured memory_bytes: 1848
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
 
# abc125_c
import fractions, functools, itertools
 
# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
x = A[0]
y = A[1]
def divisors(n):
     for i in range(1, n+1):
        if i*i > n:
            break
        if n%i == 0:
            yield i
            yield n//i
ds = set(divisors(x)) | set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)
 

Measured memory_bytes: 16068
#include <stdio.h>

int main(){
  int n,k;
  int i,j;
  int ans=0;
  int tmp;
  scanf("%d %d",&n,&k);
  int price[n];
  for(i=0;i<n;i++){
    scanf("%d",&price[i]);
  }

 /*sort*/
  for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (price[i] > price[j]) {
        tmp =  price[i];
        price[i] = price[j];
        price[j] = tmp;
      }
    }
  }

 for(i=0;i<k;i++){
   ans += price[i];
 }
 printf("%d\n",ans);

return 0;
}


Measured memory_bytes: 1704
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>l(m);
  vector<int>r(m);
  rep(i,m)cin>>l[i]>>r[i];

  vector<int>gate(n);
  int lmax=1;
  int rmin=n;
  rep(i,m){
    lmax=max(l[i],lmax);
    rmin=min(r[i],rmin);

  }
  if(lmax>rmin)cout<<0<<endl;
  else cout<<rmin-lmax+1<<endl;
  
    
    
  return 0;
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define inf 100000000
#define _GLIBCXX_DEBUG
typedef vector<int> VI;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<int,int> PII;
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; }
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int main(){
	list<int> L;
	int n,x;
	str cmd;
    cin >>n;
    rep(i,n){
    	cin>>cmd;
    	if (cmd=="insert" or cmd=="delete"){
    		cin>>x;
    		if (cmd=="insert")L.push_front(x);
    		if (cmd=="delete"){
                for (list<int>::iterator it = L.begin(); it != L.end(); it++)
                {
                    if (*it == x)
                    {
                        L.erase(it);
                        break;
                    }}}}
                    else
                    {
                        if (cmd == "deleteFirst")
                        {
                            L.pop_front();
                        }
                        if (cmd == "deleteLast")
                        {
                            L.pop_back();
                        }
                        if (cmd == "delete")
                        {
                            for (list<int>::iterator it = L.begin(); it != L.end(); it++)
                            {
                                if (*it == x)
                                {
                                    L.erase(it);
                                    break;
                                }
                            }
                        }
                    }
    	
    }
        ll i=0;
        for (list<int>::iterator it = L.begin(); it != L.end(); it++){
            // int k =*it;
            // printf("%d",*it);
            // printf("\n");
            if (i++)cout<<' ';
            cout << *it;
        }
        cout<<endl;


}



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

int res, K;
string N;

void func(auto& s, int i, int k)
{
    if (k==K) {
        if (s<=N) {
            ++res;
            //cout<<stoi(s)<<endl;
        }
        return;
    }
    if (i>=N.size()) return;
    s[i]='0';
    func(s, i+1, k);
    for(int j='1'; j<='9'; ++j) {
        s[i]=j;
        func(s, i+1, k+1);
        s[i]='0';
    }
}

int main()
{
    cin>>N>>K;
    string a(N.size(), '0');
    res=0;
    func(a, 0, 0);
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int a[201]={};
		for(int i=0;i<n;i++){
			int x; cin>>x;
			a[x]=1;
		}
		int cnt[2]={n,n};
		for(int t=1,v=0,i;cnt[0]&&cnt[1];t^=1){
			for(i=1;i<=2*n;i++)
				if(a[i]==t && i>v)
					break;
			if(i>2*n){
				v=0;
				continue;
			}
			v=i;
			a[i]=-1;
			cnt[t]--;
		}
		cnt[0]=cnt[1]=0;
		for(int i=1;i<=2*n;i++)
			if(a[i]!=-1)
				cnt[a[i]]++;
		cout<<cnt[0]<<endl;
		cout<<cnt[1]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
<?php
  
fscanf(STDIN,"%d %d %d",$A,$B,$C);
fscanf(STDIN,"%d",$K);


$max = 0;

for($i=0;$i<=$K;$i++){
  //Kの残り
  $k_rest=$K-$i;
  for($j=0;$j<=$k_rest;$j++){
    $max = max(($A*pow(2,$i)+$B*pow(2,$j)+$C*pow(2,($k_rest-$j))),$max);
  }
}

echo $max;

Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}
	
	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int count = 0;

		if(num.get(0) == 7) count += 7;
		if(num.get(0) == 5) count += 5;
		
		if(num.get(1) == 7) count += 7;
		if(num.get(1) == 5) count += 5;
		
		if(num.get(2) == 7) count += 7;
		if(num.get(2) == 5) count += 5;
		
		if(count == 17){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21204
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
before=sum(A)
for i in range(N):
    temp = A[i]
    A[i] = max(0,A[i]-B[i])
    B[i] = max(0,B[i]-temp)
    A[i+1] = max(0,A[i+1]-B[i])
after=sum(A)
print(before-after)

Measured memory_bytes: 18624
a,b,c,k=map(int,input().split())
n=0
if (k-a)>=0:
    n+=a*1
    if (k-a-b)>0:
        if(k-a-b-c)>=0:
            n-=c*1
        else:
            n-=(k-a-b)*1
    else:
        pass
else:
    n+=k*1
print(n)

Measured memory_bytes: 9184
import java.util.*;
import java.io.*;

public class Main {

    void solve() {
	int N = sc.nextInt();
	int a[] = new int[2*N];

	for (int i = 0; i < N*2; i++) {
	    a[i] = sc.nextInt();
	}

	Arrays.sort(a);

	// for (int i = 0; i < a.length; i++) {
	//     System.out.println(a[i]);
	// }
	// System.out.println(" ");

	int ans = 0;
	for (int i = 0; i < a.length; i=i+2) {
	    ans += a[i];
	}
	System.out.println(ans);

    }

    void print(int[] a) {
	out.print(a[0]);
	for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
	out.println();
    }

    public static void main(String[] args) throws Exception {
	new Main().run();
    }

    MyScanner sc = null;
    PrintWriter out = null;
    public void run() throws Exception {
	sc = new MyScanner(System.in);
	out = new PrintWriter(System.out);
	for (;sc.hasNext();) {
	    solve();
	    out.flush();
	}
	out.close();
    }

    class MyScanner {
	String line;
	BufferedReader reader;
	StringTokenizer tokenizer;

	public MyScanner(InputStream stream) {
	    reader = new BufferedReader(new InputStreamReader(stream));
	    tokenizer = null;
	}
	public void eat() {
	    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		try {
		    line = reader.readLine();
		    if (line == null) {
			tokenizer = null;
			return;
		    }
		    tokenizer = new StringTokenizer(line);
		} catch (IOException e) {
		    throw new RuntimeException(e);
		}
	    }
	}
	public String next() {
	    eat();
	    return tokenizer.nextToken();
	}
	public String nextLine() {
	    try {
		return reader.readLine();
	    } catch (IOException e) {
		throw new RuntimeException(e);
	    }
	}
	public boolean hasNext() {
	    eat();
	    return (tokenizer != null && tokenizer.hasMoreElements());
	}
	public int nextInt() {
	    return Integer.parseInt(next());
	}
	public long nextLong() {
	    return Long.parseLong(next());
	}
	public double nextDouble() {
	    return Double.parseDouble(next());
	}
	public int[] nextIntArray(int n) {
	    int[] a = new int[n];
	    for (int i = 0; i < n; i++) a[i] = nextInt();
	    return a;
	}
    }
}


Measured memory_bytes: 8148
num = int(input())
al = input()

newal = ""
alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(len(al)):
  if(alp.index(al[i])+num>25):
    newal = newal + alp[(alp.index(al[i])+num)-26]
  else:
    newal = newal + alp[alp.index(al[i])+num]
  
print(newal)

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

using namespace std;

int n, k;
int r, s, p;
string t;
 
char get_char(char ch) {
    if (ch == 'r') return 'p';
    else if (ch == 'p') return 's';
    else return 'r';
}

int get_score(char ch) {
    if (ch == 'r') return r;
    else if (ch == 's') return s;
    else return p;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    int len = (int)t.size();
    vector <char> vec;
    vec.clear();
    int sum = 0;
    for (int i = 0; i < k; i++) {
        char temp = get_char(t[i]);
        vec.push_back(temp);
        sum += get_score(temp);
    }
    for (int i = k; i < len; i++) {
        int ind = i % k;
        char temp = get_char(t[i]);
        if (temp != vec[ind]) {
            vec[ind] = temp;
            sum += get_score(temp);
        } else {
            vec[ind] = '*';
        }
    }
    cout << sum << "\n";
    return 0; 
}

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

#include <bits/stdc++.h>

#define int long long

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

const int N = 2000 + 20 , inf = 3e18 + 20  ;
int n , x , a[N] , b[N] , ans = inf ;

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

	cin >> n >> x ;
	for (int i = 0 ; i < n ; i ++) cin >> a[i] , b[i] = a[i] ;

	for (int t = 0 ; t <= n ; t ++) {
		for (int i = 0 ; i < n ; i ++) b[i] = min(b[i] , a[(i - t + n) % n]) ;

		int sum = 0 ;
		for (int i = 0 ; i < n ; i ++) sum += b[i] ;

		ans = min(ans , sum + x * t) ;
	}

	cout << ans << '\n' ;
}


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

using namespace std;

using ll = long long int;

int main(void) {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[12][12];
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }

    vector<int> prices;
    for (int i = 0; i < (1 << n); ++i) {
        ll sum = 0;
        vector<int> rikai(m, 0);
        int j = 0;
        while (i >> j) {
            if ((i >> j) & 1) {
                for (int k = 0; k < m; ++k) {
                    rikai[k] += a[j][k];
                }
                sum += c[j];
            }
            j++;
        }
        if (*min_element(rikai.begin(), rikai.end()) >= x) prices.push_back(sum);
    }

    cout << (prices.size() > 0 ? *min_element(prices.begin(), prices.end()) : -1) << endl;
}

Measured memory_bytes: 3632
# A
N = list(map(int, input().split()))

a = [1, 9, 7 ,4]
flg = [0, 0, 0, 0]

for i in N:
    for j in range(len(a)):
        if i == a[j]:
            flg[j] = 1
            
if sum(flg) == 4:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll pow_mod(ll n,ll p,ll m){
    ll res = 1;
    while(p>0){
        if(p%2==1) res = (res * n) % m;
        n = (n * n) % m;
        p /= 2;
    }
    return res;
}

ll inv_mod(ll n,ll mod){
    return pow_mod(n,mod-2,mod);
}

ll factrial_mod(ll n,ll k,ll mod){
    ll x=1,y=1;
    rep(i,k){
        x = (x*(n-i)) % mod;
        y = (y*(i+1)) % mod;
    }
    return x*inv_mod(y,mod)%mod;
}

int main(){
    ll x,y;
    cin >> x >> y;
    if((x+y)%3!=0){
        cout << 0 << endl;
    }else{
        int b = (2*x - y) / 3;
        int a= x - 2 * b;
        if(a<0 || b<0) cout << 0 << endl;
        else cout << factrial_mod(a+b,b,MOD) << endl;
    }
}

Measured memory_bytes: 256
from collections import deque

def main():
    input()
    A = list(enumerate(input().split()))
    size = len(A)
    b = deque()
    for i, a in A:
        if i % 2 == 0:
            if size % 2 == 0:
                b.append(a)
            else:
                b.appendleft(a)    
        else:
            if size % 2 == 0:
                b.appendleft(a)
            else:
                b.append(a)

    print(" ".join(list(b)))

main()

Measured memory_bytes: 47172
import sys 
input = sys.stdin.readline
n = int(input())
data = []
class UnionFind:
    def __init__(self, n):
        #親ノードの番号を格納
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)
    def find(self, x):
        #根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        #同じかどうかの確認
        return self.find(x) == self.find(y)
    def union(self, x, y):
        #統合する
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
        else:
            self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
    def getsize(self, x):
        p = self.find(x)
        return self.size[p]
x = []
y = []
for i in range(n):
    a,b = map(int, input().split())
    x.append([a,i+1])
    y.append([b,i+1])
x.sort(key = lambda x: x[0])
y.sort(key = lambda x: x[0])
edge = []
for i in range(n-1):
    edge.append([x[i+1][0] - x[i][0],x[i+1][1],x[i][1]])
    edge.append([y[i+1][0] - y[i][0],y[i+1][1],y[i][1]])
#edge[i][0] = cost, [1] -> [2]でつながっている辺
edge.sort(key = lambda x: x[0])
UF = UnionFind(n)
ans = 0
for i in range(len(edge)):
    cost,a,b = edge[i]
    if UF.same_check(a,b):
        continue
    else:
        ans += cost
        UF.union(a,b)
print(ans)





Measured memory_bytes: 126172
def resolve():
    x, y = map(int, input().split())
    if (x, y) == (1, 1):
        print(1000000)
        return
    ans = 0
    for i in (x, y):
        if i < 4:
            ans += 100000 * (4 - i)
    print(ans)


if __name__ == '__main__':
    resolve()


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


int main(){
    ll x1, x2, y1, y2, x3, y3 ,x4 ,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    
    x4 = (x2 - x1) * 0 - (y2 - y1) * 1 + x1;
    y4 = (x2 - x1) * 1 + (y2 - y1) * 0 + y1;

    x3 = (x1 - x2) * 0 - (y1 - y2) * -1 + x2;
    y3 = (x1 - x2) * -1 + (y1 - y2) * 0 + y2;


    cout << x3 <<" "<< y3 <<" "<< x4 <<" "<< y4 << endl; 



}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1e5;
ll w[105], v[105];
ll dp[105][100005];
int main(){
	int n;
	cin >> n;
	string s;
	string t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		cout << s[i];
		cout << t[i];

	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
long long n,x;
cin >> n;
long double i=n;
for(;;i--)
{
x=sqrt(i);
if(x%1==0)
{
cout << x*x << endl;
break;
}
}
system("pause");
return 0;
}

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

int N;

bool judge(int K, vector<int>& A) {
    map<int, int> mp;
    int temp = A[0];
    for (int i = 1; i < N; i++) {
        int prev = temp;
        temp = A[i];
        if (prev >= temp) {
            if (K == 1) return false;
            auto itr = mp.lower_bound(temp);
            if (itr != mp.end()) {
                mp.erase(itr, mp.end());
            }
            int j = temp - 1;
            while (mp[j] == K - 1) {
                mp.erase(j);
                j--;
                if (j < 0) return false;
            }
            mp[j]++;
        }
    }
    return true;
}

int binary(vector<int>& A, int left, int right) {
    if (left == right) {
        return left;
    }
    
    int mid = (left + right) / 2;
    
    if (judge(mid, A)) {
        return binary(A, left, mid);
    } else {
        return binary(A, mid + 1, right);
    }
}


int main() {
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    cout << binary(A, 1, N) << endl;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
if N%2==0:
  print(A[0]+2*sum(A[1:(N-2)//2+1]))
else:
  print(A[0]+2*sum(A[1:(N-2)//2+1])+A[(N-2)//2+1])

Measured memory_bytes: 31428
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < P.length; i++) {
            P[i] = sc.nextInt();
        }
        int[] Q = new int[N];
        for (int i = 0; i < Q.length; i++) {
            Q[i] = sc.nextInt();
        }
        System.out.println(Math.abs(num(P) - num(Q)));
        sc.close();
    }

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

    static int num(int[] a) {
        int res = 0;
        for (int i = 0; i < a.length; i++) {
            int[] copy = new int[a.length - i];
            for (int j = 0; j < copy.length; j++) {
                copy[j] = a[i + j];
            }
            Arrays.sort(copy);
            int index = -1;
            for (int j = 0; j < copy.length; j++) {
                if (copy[j] == a[i]) {
                    index = j;
                }
            }
            res += fact(copy.length - 1) * index;
        }
        return res;
    }
}

Measured memory_bytes: 21844
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 0, mod = (int) 0;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            string x;
            cin >> x;
            if (x == "snuke") {
                cout << char('A' + j) << i + 1 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int F[105][105];
int xg,yg,w,h;
  
  
void DFS(int Y,int X,int c){
  if(F[Y][X] != c){
    return;
  }
  
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
  
  
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<102; i++){
      for(int j=0; j<102; j++){
        F[i][j] = 10;
      }
    }
      
    cin >> xs >> ys >> xg >> yg >> n;
  
  
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;

      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
  
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3616
#include <iostream>
#include <math.h>
using namespace std;
int DivideMul(int N,int a){
  int L=N%(int)pow(10,a);
  int U=(N-L)/pow(10,a);
  return L*U;
}

int Next(int N){
  int n=0;
  double s=log(N)/log(10);
  for(int i=1;i<s;++i){
      n=max(n,DivideMul(N,i));
  }
  return n;
}


int main(){
  int T;
  cin >> T;
  for(int i=0; i<T; ++i){
    
    int N;
    cin >> N;
    if(N==0){
      cout << 0 << endl;;
      break;
    }

    int j=0;
    for( j=0; N>9 ; ++j){
      N=Next(N);
      //cout <<N<<endl;
    }
   
    cout << j << endl;;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
	
using namespace std;
inline void FAST_IO(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

template<class F, class S> ostream& operator<<(ostream& os, pair<F, S> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template<class T, class S> ostream& operator<<(ostream& os, map<T, S> &v) {
	os << "{";
	for(auto &i : v) cout << "{" << i.first << "," << i.second << "}";
	os << "}";
	return os;
}

template<class T> ostream& operator<<(ostream& os, set<T> &v) {
	os << "{";
	for(auto &i : v) cout << i << ",";
	os << "}";
	return os;
}
 
template<class T> ostream& operator<<(ostream& os, vector<T> &v) {
	os << "[";
	if(v.size()) os << v[0];
	for(int i = 1; i < v.size(); ++i) os << "," << v[i];
	os << "]";
	return os;
}

/*----------------------------------------------------------------------------*/

class UF{
public:
	int *a, *sz;
	int n;

	UF(int n){
		sz = new int[n];
		a = new int[n];
		this->n = n;
		
		for(int i =0 ; i < n; i++)
			a[i] = i, sz[i] = 1;
	}
	
	~UF(){
		delete sz;
		delete a;
	}
	
	int root(int p){
		while(a[p] != p) {
			a[p] = a[a[p]];
			p = a[p];
		}
		return p;
	}
	
	void merge(int p, int q){
		int i = root(p);
		int j = root(q);
		
		if(i == j) return;
		
		if(sz[i] > sz[j]) a[j] = i, sz[i] += sz[j];
		else a[i] = j, sz[j] += sz[i];
	}
	
	bool find(int p, int q){
		return root(p) == root(q);
	}	
};

int main (){
	// FAST_IO();

	int n,m;
	cin >> n >> m;
	UF uf(n+1);

	int resp = 1;
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);

		if (!uf.find(a,b)) {
			uf.merge(a,b);
			resp = max(resp, uf.sz[uf.root(a)]);
		}
	}

	cout << resp << endl;

	return 0;
}


Measured memory_bytes: 4836
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------
int h,w;

int diff(int a, int b, int c){
    if (a > b) swap(a,b);
    if (b > c) swap(b,c);
    if (a > b) swap(a,b);

    return c - a;
}
signed main(){
    I(h); I(w);
    int hi = h/3;
    int wi = w/3;

    if (h%3 == 0 || w%3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    int ret = min(h,w);
    cerr << ret << endl;

    //   |  B
    // A |----
    //   |  C

    int a = hi * w;
    int bcs = (h-hi) * (w/2);
    int bcb = (h-hi) * (w - w/2);
    ret = min(ret, diff(a, bcs, bcb));
    cerr << ret << endl;
    hi++;
    a = hi * w;
    bcs = (h-hi) * (w/2);
    bcb = (h-hi) * (w - w/2);
    ret = min(ret, diff(a, bcs, bcb));
    cerr << ret << endl;
    hi--;

    a = wi*h;
    bcs = (w-wi) * (h/2);
    bcb = (w-wi) * (h - h/2);
    ret = min(ret, diff(a, bcs, bcb));
    cerr << ret << endl;
    wi++;

    a = wi*h;
    bcs = (w-wi) * (h/2);
    bcb = (w-wi) * (h - h/2);
    ret = min(ret, diff(a, bcs, bcb));

    cout << ret << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<queue>
#include<vector>
#define MM 210000000000000000
using namespace std;
typedef pair<long long,int> P;
typedef pair<int,int> P1;
int flg[100001];
long long leng[100001],aa;
vector<int> mati[100001];
int main(void)
{
	int i,j,n,m,k,s,p,q,a,b,c,x,y;
	priority_queue<P,vector<P>,greater<P> > que;
	queue<P1> qu1;
	P1 qq;
	P ppp;
	scanf("%d %d %d %d",&n,&m,&k,&s);
	scanf("%d %d",&p,&q);
	for(i=1;i<=n;i++)	flg[i]=0;
	for(i=0;i<k;i++)	{
		scanf("%d",&c);
		flg[c]=2;
		qu1.push(P1(0,c));
	}
	for(i=0;i<m;i++)	{
		scanf("%d %d",&a,&b);
		mati[a].push_back(b);
		mati[b].push_back(a);
	}
	while(qu1.size()!=0)	{
		qq=qu1.front();
		qu1.pop();
		if(qq.first==s)	break;
		x=qq.second;
		for(i=0;i<mati[x].size();i++)	{
			y=mati[x][i];
			if(flg[y]==0)	{
				flg[y]=1;
				qu1.push(P1(qq.first+1,y));
			}
		}
	}
//	for(i=1;i<=n;i++)	printf(" %d",flg[i]);	printf("\n");
	for(i=1;i<=n;i++)	leng[i]=MM;
	que.push(P(0,1));
	while(que.size()!=0)	{
		ppp=que.top();	que.pop();
		aa=ppp.first;	b=ppp.second;
		if(aa<leng[b])	{
			leng[b]=aa;
			if(b==n)	break;
			for(i=0;i<mati[b].size();i++)	{
				if(flg[mati[b][i]]!=2)	{
					if(flg[mati[b][i]]==1)	x=q;
					else x=p;
	//				printf("mati=%d flg=%d x=%d leng=%lld\n",mati[b][i],flg[mati[b][i]],x,aa+x);
					que.push(P(aa+x,mati[b][i]));
				}
			}
		}
	}
//	for(i=1;i<=n;i++)	printf(" %lld",leng[i]);	printf("\n");	
	if(flg[n]==1)	x=q;
	else x=p;	
	printf("%lld\n",leng[n]-x);
	return 0;
}




Measured memory_bytes: 10744
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

int main() {
  int a, cnt = 0, ret = 0;
  cin >> a;
  REP(j, a) {
    ll hoge = j + 1;
    if (hoge % 2 == 0) {
      continue;
    }
    REP(i, a + 100) {
      if (hoge % (i + 1) == 0) {
        cnt++;
      }
    }
    if (cnt == 8) {
      ret++;
    }
    cnt = 0;
  }
  cout << ret << endl;
}

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


int main() {
  string s;
  cin >> s;
  
  int hui=0, ans=0;
  for(int i=0; i<s.size(); ++i) {
    if (s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
      ++hui;
    }
    else{
      ans=max(ans,hui);
      hui=0;
    }
  }
  cout << max(ans,hui)<<'\n';
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  let y = read::<i64>();
  let z = read::<i64>();

  println!("{}", (x - z) / (y + z));
}



Measured memory_bytes: 4352
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
l = list(sorted(l))

tar = []
for x in C, B, A:
    if x in l:
        l.remove(x)
    else:
        tar.append(x)

if not tar:
    print(0)
    exit()

ans = float('inf')
for j in range((len(tar) + 1) ** len(l)):
    vvv = [[] for _ in range(len(tar) + 1)]
    for i in sorted(range(len(l)), reverse=True):
        idx, j = divmod(j, (len(tar) + 1) ** i)
        vvv[idx].append(l[i])
    if any(len(vvvv) == 0 for vvvv in vvv[:-1]):
        continue
    else:
        bbb = 0
        # print(tar, vvv)
        for k in range(len(tar)):
            bbb += 10 * (len(vvv[k]) - 1)
            bbb += abs(sum(vvv[k]) - tar[k])
        ans = min(ans, bbb)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD=1000000007;

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

    ll n, m;
    cin >> n >> m;

    vector< vector<ll> > arr(n);

    ll a, b;
    REP(i, m){
        cin >> a >> b;
        a--;
        b--;
        arr[a].push_back(b);
        arr[b].push_back(a);
    }

    REP(i, arr[0].size()){
        REP(j, arr[arr[0][i]].size()){
            if(arr[arr[0][i]][j] == n-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

int main() {
    int h,w;
    cin>>h>>w;
    std::vector<std::vector<char> > v(h,std::vector<char>(w));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>v[i][j];
    std::vector<std::vector<long> > s(h,std::vector<long>(w,0));
    for(int i=0;i<w;i++){if(v[0][i]=='.')s[0][i]=1;else break;}
    for(int i=0;i<h;i++){if(v[i][0]=='.')s[i][0]=1;else break;}
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(v[i][j]=='.'){
                s[i][j]=(s[i][j-1]+s[i-1][j])%1000000007;
            }
        }
    }
    cout<<s[h-1][w-1];


}

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    int sum = 0;
    for(int i = 0;i < N;i++){
        if(S.at(i) == 'I'){
            sum++;
        }
        else{
            sum--;
        }
        ans = max(ans,sum);
    }
    cout << ans;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
# for use in beginner level contests where speed is key
import bisect

_,_,k = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))

cs = 0
cc = [0]
for a in aa:
    cs += a
    # print(cs)
    cc.append(cs)

cs = 0
dd = [0]
for b in bb:
    cs += b
    # print(cs)
    dd.append(cs)

# print(cc)
# print(dd)

res = 0
for i,d in enumerate(dd):
    if k-d < 0:
        continue
    j = bisect.bisect_right(cc, k-d)-1
    # if dd[i] + cc[j] > k:
    #     continue
    # print(i,j,k-d,dd[i],cc[j])
    res = max(res, i+j)
print(res)




Measured memory_bytes: 131316
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Increment Decrement
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int x = 0, maxx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') x++;
    else x--;

    if (maxx < x) maxx = x;
  }

  printf("%d\n", maxx);
  return 0;
}


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

string s;

int dp[10009][2][100],p,d;


int dfs(int idx,int z,bool tight){
  if(idx==s.size())return !z;
  int &res=dp[idx][tight][z];
  if(~res)return res;
  res=0;
  int x=s[idx]-'0';
  int r=(tight?9:x);
  for(int i=0;i<=r;i++){
    res+=dfs(idx+1,(z+i)%d,tight||i<r);
    res%=1000000007;
  }
  return res;
}

int main(){
  memset(dp,-1,sizeof dp);
  cin>>s>>d;
  cout<<(dfs(0,0,0)-1+1000000007)%1000000007<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 8832
n=int(input())
d=list(map(int,input().split()))
q=[0]*(max(d)+1)
#from collections import Counter
#q=Counter(d)


for i in range(len(d)):
    q[d[i]]+=1
    
if q[0]!=1 or d[0]!=0:
    print(0)
    exit()

ans=1
for i in range(1,max(d)+1):
    ans*=q[i-1]**q[i]
    if ans == 0:
        break
print(ans%998244353)

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
   string s;cin >> s;
   rep(i,3){
   if(s[i]=='9') s[i]='1';
   else s[i]='9';
   }
   cout << s<< endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

s = sum(A) // (4 * M) if not sum(A) % (4 * M) else sum(A) // (4 * M) + 1
c = sum([1 for a in A if a >= s])
print("Yes") if c >= M else print("No")


Measured memory_bytes: 3060
import java.io.*;
  import java.util.*;

  class Main{
    public static void main(String[] args)throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String[] t=s.split("");
        long count=0;
        for(int i=0;i<s.length();i++){
          count+=Integer.parseInt(t[i]);
        }
        long n=Long.parseLong(s);
        if((n%count)==0)
         System.out.println("Yes");
         else
          System.out.println("No");
      }
    }

Measured memory_bytes: 20820
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

l = 0
r = 1000000000

def judge(m):
    k = 0
    for i in range(N):
        if A[i]%m==0:
            k+=A[i]//m-1
        else:
            k+=A[i]//m
    return k<=K

while r-l>1:
    if judge((l+r)//2):
        r = (l+r)//2
    else:
        l = (l+r)//2
print(r)

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

int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(j,D) rep(i,26) cin >> s[j][i];

    vector<int> t(D);
    vector<vector<int>> last(26, vector<int>(1,-1));
    Int manzoku = 0;

    rep(j,1) {
        int maxs = 0;
        rep(i,26) maxs = max(maxs, s[j][i]);
        vector<int> v(0); //s[j][i]が最も大きくなるようなiを入れる
        rep(i,26) {
            if (s[j][i] == maxs) {
                v.push_back(i+1);
            }
        }
        if (v.size() == 1) {
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
        else { //仮
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
    }
    int i = t[0]-1;
    rep1(j,D-1) {
        i = (i + 1) % 26;
        t[j] = i+1;
        last[t[j]-1].push_back(j);
    }


    rep(i,26) last[i].push_back(D);

    vector<int> nums(26,0);
    rep(i,26) nums[i] = last[i].size();

    int M = 10000;
    rep(k,M) {
        int d, q;
        vector<pair<int,int>> vp(26);
        rep(i,26) vp[i] = make_pair(c[i] - 10 * nums[i],i);
        sort(vp.begin(),vp.end());
        reverse(vp.begin(),vp.end());
        q = vp[0].second + 1;
        int p;
        for (int j = 25; j>=0; j--) {
            p = vp[j].second;
            if (last[p].size() == 2) continue;
            else {
                break;
            }
        }
        if (last[p].size() <= 2) continue;
        int lpsz = last[p].size();
        d = last[p][(lpsz/2)] + 1;
        manzoku = 0;

        manzoku -= s[d-1][t[d-1]-1];
        manzoku += s[d-1][q-1];

        auto iteold = find(last[t[d-1]-1].begin(), last[t[d-1]-1].end(), d-1);
        int old_last = *(iteold-1);
        manzoku -= c[t[d-1]-1] * (d-1 - old_last) * (*(iteold+1) - (d-1));

        auto itenew = upper_bound(last[q-1].begin(), last[q-1].end(), d-1);
        int new_last = *(itenew-1);
        manzoku += c[q-1] * (d-1 - new_last) * (*itenew - (d-1));

        if (manzoku > 0) {
            //更新したほうがよいならこれをやる
            last[t[d-1]-1].erase(iteold);
            last[q-1].insert(itenew,d-1);
            t[d-1] = q;
            nums[t[d-1]-1]--;
            nums[q-1]++;
        
        }

        //cout << manzoku << endl;
    }

    rep(j,D) cout << t[j] << endl;
}

Measured memory_bytes: 3680