akhauriyash/Code-Regression huggingface dataset:
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

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

        if(scan.hasNext())
            n=scan.nextInt();

        if(scan.hasNext())
            m=scan.nextInt();
        String str="";
        char[][] arr=new char[n][m];
        for(int i=0;i<n;i++){
            if(scan.hasNext())
                str=scan.next();
            arr[i]=str.toCharArray();
        }
        boolean flag=false;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(arr[i][j]=='#'){
                    flag=true;
                    break;
                }
            }
            if(flag)
                break;
        }
        if(!flag){
            System.out.println(m+n-2);
            return;
        }
        int max=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(arr[i][j]=='.')
                max=Math.max(max,bfs(arr,i,j));
            }
        }
        System.out.println(max);
    }
    static int bfs(char[][] maze,int i,int j){
        int lev=0;
        boolean[][] brr=new boolean[maze.length][maze[0].length];
        Queue<int[]> q=new ArrayDeque<>();
        q.add(new int[]{i,j,0});

        while(q.size()>0){
            int[] arr=q.poll();
            brr[arr[0]][arr[1]]=true;
            lev=arr[2];
            if(arr[0]-1>=0 && !brr[arr[0]-1][arr[1]] && maze[arr[0]-1][arr[1]]=='.'){
                q.add(new int[]{arr[0]-1,arr[1],arr[2]+1});
            }
            if(arr[0]+1<maze.length && !brr[arr[0]+1][arr[1]] && maze[arr[0]+1][arr[1]]=='.'){
                q.add(new int[]{arr[0]+1,arr[1],arr[2]+1});
            }
            if(arr[1]-1>=0 && !brr[arr[0]][arr[1]-1] && maze[arr[0]][arr[1]-1]=='.'){
                q.add(new int[]{arr[0],arr[1]-1,arr[2]+1});
            }
            if(arr[1]+1<maze[0].length && !brr[arr[0]][arr[1]+1] && maze[arr[0]][arr[1]+1]=='.'){
                q.add(new int[]{arr[0],arr[1]+1,arr[2]+1});
            }
        }
        return lev;
    }
}


Measured memory_bytes: 27604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<int> b(N);
  for(int i=0;i<N-1;++i){
    cin>>b[i];
  }
  b[N-1]=100001;
  
  ll ans=b[0];
  
  for(int i=0;i<N-1;++i){
    ans+=min(b[i],b[i+1]);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define INF 1e9

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

    int X, Y;
    cin >> X >> Y;
    cout << X + Y/2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>

intmax_t f(intmax_t n) {
  // 1 ^ 2 ^ ... ^ n
  switch (n & 3) {
  case 0: return n;
  case 1: return 1;
  case 2: return n+1;
  case 3: return 0;
  }
  assert(false);
}

int main() {
  intmax_t A, B;
  scanf("%jd %jd", &A, &B);

  printf("%jd\n", f(A)^f(B)^A);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long a[n],b[n],c[n],e=1,f=2,g=3;
  for(int i=1;i<=n;i++){
     cin>>a[i]>>b[i]>>c[i]; 
  }
  long long dp1[n+1],dp2[n+1],dp3[n+1];
  dp1[1]=a[1];dp2[1]=b[1];dp3[1]=c[1];
  for(int i=2;i<=n;i++){
      dp1[i]=a[i]+max(dp2[i-1],dp3[i-1]);
      dp2[i]=b[i]+max(dp1[i-1],dp3[i-1]);
      dp3[i]=c[i]+max(dp2[i-1],dp1[i-1]);
  }
  cout<<max(dp1[n],max(dp2[n],dp3[n]))<<endl;
}

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

int main(){
  string s;
  bool a=false, b=false;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]=='A')a=true;
    if(s[i]=='B')b=true;
  }
  if(a==true&&b==true)puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

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

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

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 約数列挙
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

string background_black(string s) { return "\x1b[40m" + s; }
string background_red(string s) { return "\x1b[41m" + s + "\x1b[40m"; }
string background_green(string s) { return "\x1b[42m" + s + "\x1b[40m"; }
string background_yellow(string s) { return "\x1b[43m" + s + "\x1b[40m"; }
string background_bleu(string s) { return "\x1b[44m" + s + "\x1b[40m"; }
string background_white(string s) { return "\x1b[47m" + s + "\x1b[40m"; }

string black(string s) { return "\x1b[30m" + s + "\x1b[37m"; }
string red(string s) {return "\x1b[31m" + s + "\x1b[37m"; }
string green(string s) { return "\x1b[32m" + s + "\x1b[37m"; }
string yellow(string s) { return "\x1b[33m" + s + "\x1b[37m"; }
string blue(string s) { return "\x1b[34m" + s + "\x1b[37m"; }
string white(string s) { return "\x1b[37m" + s + "\x1b[37m"; }

const int ten = 10;
const int hundred = 100;
const int thousand = 1000;

typedef long long ll;
typedef unsigned long long ull;

string tolower(string s) {
  string c;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= 'A') && (s[i] <= 'Z')) {
        c.push_back((s[i] + 0x20));
    } else {
        c.push_back(s[i]);
    }
  }
  return c;
}
#include <cstdlib>
string solve() {
  string str = "";
// int->string: to_string, string->int: stoi
//=============================================================================


  int a, b;
  cin >> a >> b;

  str += to_string((a+b)%24);


//=============================================================================
  return str;
}

int main() {	
  std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
  cout << solve() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;

int main(int argc, const char * argv[]) {
    ll n;
    cin >> n;
    map<int, int> mp;
    // count primes
    for(int i = 2; i <= n; i++){
        int x = i;
        for(int j = 2; j <= x; j++){
            while(x % j == 0){
                x /= j;
                mp[j]++;
            }
        }
    }
    
    ll ans = 1;
    for(auto x: mp){
        ans = (ans%MOD) * ((x.second+1)%MOD);
    }
    cout << ans%MOD << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import numpy as np

S = str(input())

divider = ['maerd', 'remaerd', 'esare', 'resare']

S_reverse = S[::-1]
can = 1
i = 0

while i < len(S):
    can2 = 0
    for j in range(4):
        d = divider[j]
        if S_reverse[i:i+len(d)] == d:
            can2 = 1
            i += len(d)
            break
    if can2 == 0:
        can = 0
        break

if can == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 12644
#include <bits/stdc++.h>
using namespace std;
int main(){
  string w;cin>>w;vector<char>a(w.size());
  for(int i=0;i<w.size();i++)a[i]=w[i];
  sort(w.begin(),w.end());
  int count=1;
  bool s=true;
  for(int i=0;i<w.size();i++){
    if(w[i]==w[i+1])count++;
    else{
      if(count%2==1)s=false;
      count=1;
    }
  }
  if(s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}




Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		long a = scanLong(), b = scanLong();
		scanLong();
		long k = scanLong();
		long r = a - b;
		if ((k & 1) != 0) {
			r = -r;
		}
		out.print(r);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 22740
# -*- coding: utf-8 -*-
# 整数の入力
s = list(input())
n = len(s)

# 組合せで出現する全ての数式結果の積算値
total_sum = 0
for i in range(2**(n-1)):
    # print(str(bin(i)))

    sub_sum = 0
    tmp_str = [s[0]]
    for j in range(n-1):
        # 間に+演算子を挟むケース
        if (i >> j) & 1:
            sub_sum += int("".join(tmp_str))
            tmp_str = [s[j+1]]
            # print("True: " + str(sub_sum) + " is added.")
        # 間に+演算子を挟まないケース
        else:
            tmp_str.append(s[j+1])
            # print("False: tmp_str is " + str(tmp_str) + " .")
    sub_sum += int("".join(tmp_str))
    # print("This equation's sum is: " + str(sub_sum))
    total_sum += sub_sum

print(total_sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define SEKAI_NO_OWARI return 0;
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> H(n);
	rep(i, n) {
		scanf("%d", &H[i]);
		H[i]--;
	}

	bool flag = true;
	rep(i, n - 1) {
		if (H[i] <= H[i + 1]) continue;
		else {
			H[i + 1]++;
			if (H[i] > H[i + 1]) {
				flag = false;
			}
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
}

int main(void) {
	solve();
	SEKAI_NO_OWARI
}

Measured memory_bytes: 640
def actual(n, A):
    even_numbers = [x for x in A if x % 2 == 0]

    immigration_status_list = [(x % 3 == 0) or (x % 5 == 0) for x in even_numbers]

    if all(immigration_status_list):
        return 'APPROVED'

    return 'DENIED'


n = int(input())
A = map(int, input().split())

print(actual(n, A))


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

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];
  
  while(scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    }
    else if (s[0] == '-') {
      b = pop();
      a = pop();
      push (a - b);
    }
    else if (s[0] == '*') {
      a = pop();
      b = pop();
      push (a * b);
    }
    else {
      push(atoi(s));
    }
  }
  
  printf("%d\n", pop());
  
  return 0;
}
    
    



Measured memory_bytes: 3224
import java.util.*;

 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int A1 = 0;
    int A2 = 0;
    int A4 = 0;
    int A5 = 0;
    int sum =0;
    for(int i = A ; i <= B; i++){
        A1 = i / 10000 % 10;
        A2 = (i / 1000) % 10;
        A4 = (i /10) % 10;
        A5 = i % 10; 
        if(A1 == A5 && A2 == A4){
            sum = sum +1;
        }
    }
        System.out.println(sum); 
    }
}    



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

int mul(int a,int b,int MOD) {return (1ll*a*b)%MOD;}

int power(int a,int b,int MOD)
{
	int num=a,ans=1;
	while(b)
	{
		if(b&1) ans=mul(ans,num,MOD);
		b>>=1;
		num=mul(num,num,MOD);
	}
	return ans;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    string in;
    cin >> in;
    int ones = count(in.begin(), in.end(), '1');
    int cnt_a = ones+1, cnt_b = ones-1;
    int mod_a = 0, mod_b = 0;
    // all zeros
    if(cnt_b==-1) {
        for(int i=0;i<n;i++) cout << "1\n";
        return 0;
    }

    // compute mod of the numbers when a flip occur
    for(int i=n-1,p=1;i>=0;i--,p=(p<<1)%cnt_a) {
        if(in[i]=='1') mod_a+=p;
        mod_a%=cnt_a;
    }
    for(int i=n-1,p=1;i>=0&&cnt_b;i--,p=(p<<1)%cnt_b) {
        if(in[i]=='1') mod_b+=p;
        mod_b%=cnt_b;
    }

    for(int i=0;i<n;i++) {
        if(in[i]=='0') {
            int num=mod_a;
            num=(num+power(2,n-1-i,cnt_a))%cnt_a;
            int res=1, cntone=__builtin_popcount(num);
            while(num) {
                res++;
                num%=cntone;
                cntone=__builtin_popcount(num);
            }
            cout << res << "\n";
        } else {
            if(cnt_b==0) {
                cout << "0\n";
                continue;
            }
            int num=mod_b;
            num=(num-power(2,n-1-i,cnt_b)+cnt_b)%cnt_b;
            int res=1,cntone=__builtin_popcount(num);
            while(num) {
                res++;
                num%=cntone;
                cntone=__builtin_popcount(num);
            }
            cout << res << "\n";
        }
    }
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  rep(i,5) cout << s[i];
  cout << " ";
  for(int i = 6;i<=12;i++) cout << s[i];
  cout << " ";
  for(int i = 14;i<s.size();i++) cout << s[i];
    
  return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  vector<P<int,int>> vp;
  ll n,k; cin >>n >>k;
  for(int i = 0; i < n; ++i){int a,b; cin >> a >> b; vp.push_back({a,b}); }
  sort(vp.begin(), vp.end());
  ll cnt = 0;
  ll ans = 0, idx = 0;
  while(cnt < k){
    ans = vp[idx].first;
    cnt += vp[idx].second;
    idx++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int r,c;cin>>r>>c;
	int t=r*c;
	if(r==1 or c==1){
		cout<<1;
		return;
	}
	if(t%2==0){
		cout<<t/2;
	}
	else{
		cout<<t/2+1;
	}
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int n,s=0,ans=0;
	char a;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='I') s++;
		else s--;
		if(s>ans) ans=s;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
    a.append(input().rstrip())
for i in range(m):
    b.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define rep(a) for(int i = 0; i < a; ++i)
int main(){
  int N;
  cin >> N;
  int a[210];
  rep(N) cin >> a[i];
  int res = 100;
  rep(N){
    int sum = 0;
    while(a[i]%2 == 0){
      a[i] /= 2;
      sum++;
    }
    if(res > sum){
      res = sum;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import bisect

n = int(input())

in_ar = [0 for _ in range(n)]
in_ar = [int(s) for s in input().split()]
in_ar.sort()
res = 0
#print(in_ar)
for i in range(n):
    for j in range(i,n):
        if(i == j):
            continue

        a = in_ar[i]
        b = in_ar[j]
        st = bisect.bisect_left(in_ar, abs(a-b))
        en = bisect.bisect_left(in_ar, abs(a+b))
        #print(a,b,j,en)
        res += en - j - 1
        '''
        if(abs(a-b) < a):
            res -= 1
        if(abs(a-b) < b):
            res -= 1
        '''

print(res)


Measured memory_bytes: 50012
s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s))*k//2)
    exit()

first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:  # 最初に続く文字数をカウント (a)
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:  # s単体のとき必要な操作回数を求める (cnt)
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
    if i == len(s) -1:  # 最後に続く文字数を取得 (b)
        b = tmp_cnt
        cnt += (tmp_cnt // 2)

if first != last:  # sの最初の文字と最後の文字が違う場合
    ans = cnt * k
else:  # sの最初の文字と最後の文字が同じ場合
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)

print(ans)

Measured memory_bytes: 3064
h, w, k = map(int, input().split())
c = [input() for i in range(h)]
a = 0
for i in range(2**h):
    for j in range(2**w):
        b = 0
        hb = format(i, '12b')
        wb = format(j, '12b')
        for m in range(h):
            for l in range(w):
                if hb[-m-1] == '1' and wb[-l-1] == '1' and c[m][l] == '#':
                    b += 1
        if b == k:
            a += 1
print(a)

Measured memory_bytes: 74056
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 10000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int calc(int a, int b, int c, int d) {
	return max(0, min(b, d) - max(a, c));
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector< vector<int> > ti(1000), to(1000);
		while (n--) {
			int M, D, h, m, p; char e;
			scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &e, &p);
			int t = ((M * 31 + D) * 24 + h) * 60 + m;
			if (e == 'I') ti[p].push_back(t);
			else if (e == 'O') to[p].push_back(t);
		}
		vector<int> sum(1000);
		for (int p = 1; p < 1000; p++)
			for (int i = 0; i < ti[p].size(); i++)
				for (int j = 0; j < ti[0].size(); j++)
					sum[p] += calc(ti[p][i], to[p][i], ti[0][j], to[0][j]);
		int ans = 0;
		for (int p = 1; p < 1000; p++)
			ans = max(ans, sum[p]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1348
import numpy as np
from numpy.fft import rfft,irfft

def main():
    n,m=map(int,input().split())
    A=np.array(list(map(int,input().split())))
    F=np.bincount(A)
    fft_len=2*10**5+1
    Ff=rfft(F,fft_len)
    G=np.rint(irfft(Ff*Ff,fft_len)).astype(np.int64)
    G_acc=G.cumsum()
    remove_cnt=n**2-m
    border=np.searchsorted(G_acc,n**2-m)
    x=n**2-m-G_acc[border-1]
    remove_sum=(G[:border]*np.arange(border)).sum()+border*x
    ans=A.sum()*2*n-remove_sum
    print(ans)
    
if __name__=='__main__':
    main()

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

int main(){
    int n;
    cin >> n;
    const int MAX = 1e+5;
    P range[MAX];
    rep(i, n){
        int x, l;
        scanf("%d %d", &x, &l);
        range[i] = P(x + l, x - l);
    }
    sort(range, range + n);
    int ans = 0;
    int back = -1e+9-1;
    for(int i = 0; i < n; i++){
        if(back <= range[i].second){
            ans++;
            back = range[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
S = input()

count = [S[1:].count('E')]
for i in range(1, N):
    check = count[i-1]
    if S[i-1] == 'W':
        check += 1
    if S[i] == 'E':
        check -= 1
    count.append(check)

print(min(count))


Measured memory_bytes: 15564
N=int(input())
A=[int(i) for i in input().split()]
def Check(K):
  stack=[]
  n=A[0]
  for i in range(1,N):
    if A[i-1]<A[i]:
      n=A[i]
    else:
      if K==1:
        return False
      n=A[i]
      while True:
        l=0
        if stack:
          l=stack[-1][0]
        if l>n:
          stack.pop()
        else:
          break       
      k=n
      while k>=1:
        if not stack:
          stack.append([k,1])
          break
        if stack[-1][0]==k:
          if stack[-1][1]==K-1:
            if k!=1:
              stack.pop()
              k-=1
            else:
              return False
          else:
            stack[-1][1]+=1
            break
        else:
          stack.append([k,1])
          break
  return True
l,r=1,N
while l<r:
  m=(l+r)//2
  if Check(m):
    r=m
  else:
    l=m+1
print(l)
          
          
          
      

Measured memory_bytes: 88276
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

uint lps(const vector<vector<uint>>& E, vector<int>& LP, const uint v) {
	if(LP[v] >= 0) return LP[v];

	uint d = 0;
	for(auto nv : E[v]) {
		d = max(d, lps(E, LP, nv) + 1);
	}
	
	LP[v] = d;
	return d;
}

int main() {
	uint N, M;
	cin >> N >> M;

	vector<vector<uint>> E(N, vector<uint>());
	for(uint i=0; i<M; i++) {
		uint x, y;
		cin >> x >> y;
		E[x-1].push_back(y-1);
	}

	vector<int> V(N, -1);

	uint ans = 0;
	for(uint i=0; i<N; i++) { // start node
		ans = max(ans, lps(E, V, i));
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    // if sort is required
    sort(res.begin(), res.end());
    return res;
}

void Main() {
	ll N; cin >> N;
	auto res = divisor(N);
	int ans = 20;
	for (auto v : res) {
		ll tmp = max(v, N / v);
		ans = min(ans, (int)to_string(tmp).size());
	}
	cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;

namespace AtCoderer
{
    public class App
    {
        public static void Solve()
        {
            int a = int.Parse(Console.ReadLine());
            if (a == 0)
                Console.WriteLine("0");
            else
            {
                string[] hu = new string[]{"10","11","00","01"};
                string output = "";
                int integer = a;
                while (integer != 0)
                {
                    int tmp = integer % 4;
                    integer /= 4;
                    if (tmp >= 2)
                    {
                        tmp -= 4;
                        integer++;
                    }
                    if (tmp <= -3)
                    {
                        tmp += 4;
                        integer--;
                    }
                    output = (hu[tmp+2]) + output;
                }
                Console.WriteLine(string.Join("",output.TrimStart('0')));
            }
        }
        public static void Main(string[] args)
        {
            Solve();
            Console.ReadKey();
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
       for(int j=i+1;j<=i+2;j++)
       {
           if(j<n)
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
       }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    ll n = s.size();

    // 左に白、右に黒を安全ソートする移動回数
    ll ans = 0, w = 0;
    rep(i, n) if(s[i] == 'W') ans += i-w, w++;
    cout << ans << endl;
}

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

int main()
{
  int A,B,sum;
  scanf("%d %d",&A,&B);
  if (A<=B){
    sum=B;
    B--;
  }
  else{
    sum=A;
    A--;
  }
  if (A<=B){
    sum=sum+B;
    B--;
  }
  else{
    sum=sum+A;
    A--;
  }
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    ll N, M, K; cin >> N >> M >> K;
    vector<ll> A(N); rep(i,N) cin >> A[i];
    vector<ll> B(M); rep(i,M) cin >> B[i];
    A.emplace_back(MOD);
    B.emplace_back(MOD);
    int idxA = 0, idxB = 0;
    ll t = 0;
    ll ans = 0;
    ll cnt = 0;
    while(idxA < N && t+A[idxA] <= K){
        t += A[idxA];
        idxA++;
        cnt++;
    }
    ans = cnt;
    if(idxA >= 0) idxA--;

    while(1){
        while(idxA >= 0 && t+B[idxB] > K){
            t -= A[idxA];
            idxA--;
            cnt--;
        }
        while(idxB < M && t+B[idxB] <= K){
            t += B[idxB];
            idxB++;
            cnt++;
        }
        ans = max(ans, cnt);
        if(idxA < 0 || idxB >= M) break;
    }

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


Measured memory_bytes: 8016
A, B, K = map(int, input().split())

ans = []
maxAnsNum = A
if A > B:
  maxAnsNum = B

for i in range(1,maxAnsNum+1)[::-1]:
  if A % i == 0 and B % i == 0:
    ans.append(i)

print(ans[K-1])

Measured memory_bytes: 3060
import sys

X,N=map(int,input().split())

if N == 0:
    print(X)
    sys.exit(0)

p_list=list(map(int,input().split()))

for i in range(200):
    a=X-i
    b=X+i

    if a not in p_list:
        print(a)
        sys.exit(0)
    
    if b not in p_list:
        print(b)
        sys.exit(0)


Measured memory_bytes: 61688
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 255

char G[MAX+2][MAX+2];
int n, T[MAX+2][MAX+2][4];

void solve(){
    for ( int i = 0; i < n + 2; i++ ){
	for ( int j = 0; j < n + 2; j++ ){
	    for ( int k = 0; k < 4; k++ ) T[i][j][k] = 0;
	}
    }

    static const int di[4] = {-1, -1, -1, 0};
    static const int dj[4] = {1, 0, -1, -1};

    int maxv = 0;

    for ( int i = 0; i <= n; i++ ){
	for ( int j = 0; j <= n; j++ ){
	    if ( G[i][j] == '1' ){
		for ( int k = 0; k < 4; k++ ){
		    T[i][j][k] = T[i+di[k]][j+dj[k]][k] + 1;
		    maxv = max( maxv, T[i][j][k] );
		}
	    }
	}
    }

    cout << maxv << endl;
}

main(){
    while(cin >> n, n){
	for ( int i = 1; i <= n; i++ ){
	    for ( int j = 1; j <= n; j++ ) cin >> G[i][j];
	}
	solve();
    }
}

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

typedef long long ll;
typedef long double ld;

ll niz[1000005];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    ll res = 0;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
        res += max(0LL, niz[i]-niz[i-1]);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
# Python3 Program to convert decimal to 
# any given base 

# To return char for a value. For example 
# '2' is returned for 2. 'A' is returned 
# for 10. 'B' for 11 
def reVal(num): 

    if (num >= 0 and num <= 9): 
        return chr(num + ord('0')); 
    else: 
        return chr(num - 10 + ord('A')); 

# Utility function to reverse a string 
def strev(str): 

    len = len(str); 
    for i in range(int(len / 2)): 
        temp = str[i]; 
        str[i] = str[len - i - 1]; 
        str[len - i - 1] = temp; 

# Function to convert a given decimal 
# number to a base 'base' and 
def fromDeci(res, base, inputNum): 

    index = 0; # Initialize index of result 

    # Convert input number is given base 
    # by repeatedly dividing it by base 
    # and taking remainder 
    while (inputNum > 0): 
        res+= reVal(inputNum % base); 
        inputNum = int(inputNum / base); 

    # Reverse the result 
    res = res[::-1]; 

    return res; 

# Driver Code 
inputNum,base = map(int,input().split()) 
res = ""; 
print(len(str(fromDeci(res, base, inputNum)))) 

# This code is contributed by mits 



Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    sort(a.begin(), a.end(), greater<int>());

    int sum_a = 0;
    rep(i, n) sum_a += a.at(i);

    if(a.at(m-1)>=sum_a/4.0/m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
V = list(map(int, input().split()))
M = 10 ** 5 + 1
V0 = defaultdict(int)
V1 = defaultdict(int)
ma01, ma02 = 0, 0
ma11, ma12 = 0, 0
for i in range(N):
    if i % 2 == 0:
        V0[V[i]] += 1
    else:
        V1[V[i]] += 1

rec0 = []
rec1 = []
for i, k in V0.items():
    rec0.append((i, k))

for i, k in V1.items():
    rec1.append((i, k))

rec0 = sorted(rec0, key=lambda x: x[1], reverse=True)
rec1 = sorted(rec1, key=lambda x: x[1], reverse=True)

if rec0[0][0] != rec1[0][0]:
    print(N - rec0[0][1] - rec1[0][1])
else:
    if len(rec0) == 1 and len(rec1) == 1:
        print(N // 2)
    elif len(rec0) == 1:
        print(N // 2 - rec1[0][1])
    elif len(rec1) == 1:
        print(N // 2 - rec0[0][1])
    else:
        s = rec0[1][1]
        t = rec1[1][1]
        num = min(N - rec0[1][1] - rec1[0][1], N - rec0[0][1] - rec1[1][1])
        print(num)

Measured memory_bytes: 21532
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	from := make([][]int, n)
	for i := range as {
		var up, dp int
		for j := i + 1; j < n; j++ {
			d := as[j] - as[i]
			if abs(d) <= k {
				if d > 0 {
					if up == 0 {
						up = j
					}
				} else if d < 0 {
					if dp == 0 {
						dp = j
					}
				} else {
					if up == 0 {
						up = j
					}
					if dp == 0 {
						dp = j
					}
				}
			}
			if up != 0 && dp != 0 {
				break
			}
		}
		if up != 0 {
			from[up] = append(from[up], i)
		}
		if dp != 0 {
			from[dp] = append(from[dp], i)
		}
	}
	dp := make([]int, n)
	for i := n - 1; i > 0; i-- {
		for _, f := range from[i] {
			dp[f] = max(dp[f], dp[i]+1)
		}
	}
	var mx int
	for i := range dp {
		mx = max(mx, dp[i])
	}
	fmt.Println(mx + 1)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 22896
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    bool p = false;
    while (n) {
        if (n%10 == 9) {
            p = true;
            break;
        }
        n /= 10;
    }

    p ? cout << "Yes\n" : cout << "No\n";    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    int n;cin>>n;
    vector<ll> p(n);cin>>p;
    vector<ll> b(n);
    vector<ll> a(n);
    repsg(i,0,n){
        b[i] = (n+1)*(n+1-i-1);
        a[i] = (n+1)*(i+1);
    }
    rep(i,n){
        a[p[i]-1]-=(n-i);
    }
    cout<<a<<endl;
    cout<<b<<endl;
    return 0;
}




Measured memory_bytes: 1152
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	count := 0
	res := 0
	fmt.Scan(&n)
	cities := make([]int, n + 1)
	for i := 0; i < n + 1; i++ {
		fmt.Scan(&cities[i])
	}
	heros := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&heros[i])
	}
	for i := 0; i < n; i++ {
		if cities[i] < heros[i] + res {
			count += cities[i]
			res = heros[i] - int(math.Max(float64(cities[i] - res), 0.0))
		} else {
			count += heros[i] + res
			res = 0
		}
	}
	if cities[n] < res {
		count += cities[n]
	} else {
		count += res
	}
	fmt.Println(count)
}


Measured memory_bytes: 5504
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int n, m, P, vis[3000 + 5], cir[3000 + 5], dis[3000 + 5], ban[3000 + 5];
queue<int > q;
vector<int > G[3000 + 5], val[3000 + 5];
/*int dfs(int u) {
	vis[u] = 1;
	if (u == n) return 1;
	int gg = 0;
	for (int i = 0; i < G[u].size(); ++i) {
		int v = G[u][i];
		if (!vis[v]) {
			int fl = dfs(v);
			gg |= fl;
		} else {
			if (v != u && !ban[v]) gg |= 1;
		}
	}
	ban[u] = !gg;
}*/
void dfs(int u) {
	vis[u] = 1;
	for (int i = 0; i < G[u].size(); ++i) {
		int v = G[u][i];
		if (!vis[v]) dfs(v);
	}
}
int main() {
	cin >> n >> m >> P;
	for (int x, y, z, i = 1; i <= m; ++i) {
		scanf("%d%d%d", &x, &y, &z);
		G[x].push_back(y);
		val[x].push_back(z - P);
	}
	for (int u = 1; u <= n; ++u) {
		ms(vis, 0);
		dfs(u);
		if (!vis[n]) ban[u] = 1;
	} 
	//dfs(1);
	q.push(1);
	ms(dis, -0x3f), ms(vis, 0);
	dis[1] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		vis[u] = 0;
		for (int i = 0; i < G[u].size(); ++i) {
			int v = G[u][i];
			if (ban[v]) continue ;
			if (dis[v] < dis[u] + val[u][i]) {
				dis[v] = dis[u] + val[u][i];
				if (!vis[v]) vis[v] = 1, cir[v]++, q.push(v);
				if (cir[v] >= n + 1) {
					return puts("-1"), 0;
				}
			}
		}
	}
	
	printf("%d\n", max(0, dis[n]));
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int maxsum(int *seq, int len);
int seqsum(int *seq, int i, int j);


int main(void){
	int n, i, seq[5000];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i =0; i<n; i++){
			scanf("%d",&seq[i]);
		}
		printf("%d\n",maxsum(seq,n));
	}
	return 0;
}

int maxsum(int *seq, int len){
	int sum = seq[0], i, j;
	for(i=0; i<len; i++){
		int tmpsum=0;
		for(j=i; j<len; j++){
			tmpsum += seq[j];
			if(tmpsum > sum) sum = tmpsum;
		}
	}
	return sum;
}

Measured memory_bytes: 616
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        const int NUM = (int)1e5 + 1;
        var bo = new bool[NUM];bo[1] = true;
        var li = new bool[NUM];
        for(var i=2;i<NUM;i++)
            if (!bo[i])
            {
                li[i] = bo[(i + 1) / 2];
                for (var j = 2 * i; j < NUM; j += i)
                    bo[j] = true;
            }
        var sum = new int[NUM];
        for (var i = 3; i < NUM; i++)
            sum[i] = sum[i - 1] + ToInt32(!bo[i]&&!li[i]);
        var q = Input.num;
        var res = new int[q];
        for(var i = 0; i < q; i++)
        {
            var lr = Input.ar;
            res[i] = sum[lr[1]] - sum[lr[0] - 1];
        }
        WriteLine(string.Join("\n", res));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 18880
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main() {
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N=input()
    K,=pin()

    #degit DP
    #dp_table["index"][smaller][cond]=cond:=ちょうどK個の数がある を満たす総数
    
    rb=(0,1)
    dp_table=[[[0 for cnd in range(K+1)]for sml in rb]for ind in range(len(N)+1)]
    dp_table[0][0][0]=1
    #print(dp_table)
    #print("degit,sml,k,prove,l,x<n,dp_table[degit-1][sml][k]")#
    for degit in range(len(N)+1):
        n=int(N[degit-1])
        for sml in rb:
            t=10 if sml else int(N[degit-1])+1
            for k in range(K+1):
                for prove in range(t):
                    x=prove
                    try:#Indexerror
                        #print(degit,sml,k,prove,"l",x<n,dp_table[degit-1][sml][k])
                        #if  sml==False  and x==n:print(n,":") 
                        dp_table[degit][sml or x<n][k+(x!=0)]+=dp_table[degit-1][sml][k]
                    except :pass

    print(dp_table[-1][0][K]+dp_table[-1][1][K])
    #print(dp_table)
#%%submit!
resolve()


Measured memory_bytes: 3064
n,s = map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for i in range(1,n+1):
    x = a[i-1]
    for j in range(s+1):
        dp[i][j] = dp[i-1][j] * 2
        if dp[i][j] >= mod:
            dp[i][j] %= mod
    for j in range(x,s+1):
        if j >= x:
            dp[i][j] += dp[i-1][j-x]
            if dp[i][j] >= mod:
                dp[i][j] %= mod

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

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

int main(){
    int d,e;
    while(cin>>d>>e, d|e){
        double res=INF;
        rep(i,d/2+1){
            int x=i, y=d-i;
            res = min(res, fabs(sqrt(x*x+y*y)-e));
        }
        printf("%.5lf\n", res);
    }

    return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

#define N 200000

double f(int n) {
	return (double) (n * (n + 1) / 2) / n;
}

int main() {
	static int pp[N];
	int n, k, i, j;
	double x, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]);
	x = 0;
	for (i = 0; i < k - 1; i++)
		x += f(pp[i]);
	ans = 0;
	for (i = 0, j = k - 1; j < n; i++, j++) {
		x += f(pp[j]);
		if (ans < x)
			ans = x;
		x -= f(pp[i]);
	}
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define MAXN 105
map<string,int>cnt;
int N,M;
string a[MAXN],b[MAXN];
string temp;
vector<int>ans;
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++) 
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	scanf("%d",&M);
	for(int i=1;i<=M;i++) 
	{
		cin>>b[i];
		cnt[b[i]]--;
	}
	map<string,int>::iterator it=cnt.begin();
	int maxx=0;
	while(it!=cnt.end())
	{
		maxx=max(maxx,it->second);	
		it++;
	}
	printf("%d\n",maxx);
	/*for(int i=1;i<=N;i++)
		ans.push_back(cnt[a[i]]);
	for(int i=1;i<=M;i++)
		ans.push_back(cnt[b[i]]);
	sort(ans.begin(),ans.end());
	printf("%d\n",ans.back());*/
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
	register long long x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register long long x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
long long n,m,cnt,sum;
int main(){
	n=read();m=read();
	n=n%m;
	print(min(n,m-n));
}


Measured memory_bytes: 256