akhauriyash/Code-Regression huggingface dataset:
N = int(input()) + 1
S = " "+input()
d = [[0]*N for _ in range(N)]
r = 0
for i in range(N):
    for j in range(i-1,0,-1):
        d[i][j] = d[i-1][j-1] + 1 if S[i] == S[j] else 0
        r = max(r, min(d[i][j], i-j))
print(r)


Measured memory_bytes: 229996
import collections
n = int(input())
s = collections.Counter([input() for i in range(n)])
m = int(input())
t = collections.Counter([input() for i in range(m)])

mv = 0
for k,v in s.items():
    if k in t:
        mv = max(mv, v-t[k])
    else:
        mv = max(mv, v)
print(mv)



Measured memory_bytes: 3316
from sys import stdin
import math

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A, B = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    if B/0.1<A/0.08:
        cnt = -1 if (B+1)/0.1<=A/0.08 else math.ceil(A/0.08)
    else:
        cnt = -1 if (A+1)/0.08<=B/0.1 else math.ceil(B/0.1)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38512
#include<stdio.h>

int main(){
  int a[11][11]={};
  int i,j,n,s,t;

  for(;;){
    scanf("%d",&n);
    if(!n)
      break;
    t=0;

    for(i=0;i<n;i++){
      s=0;
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	s+=a[i][j];
      }
      a[i][n]=s;
      t+=s;
    }
    a[n][n]=t;
    for(j=0;j<n;j++){
      s=0;
      for(i=0;i<n;i++){
	s+=a[i][j];
      }
      a[n][j]=s;
    }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	printf("%5d",a[i][j]);
      }
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k,ans=0,a[N];
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)ans+=a[i];
    cout<<ans;
    
    
    
    
    
}


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

int main() {
	long long int ma = 0, mi = 1e9, n, ans = 0;
	vector<long long int> a;
	cin >> n;
	a.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ma = max(ma, a[i]);
		mi = min(mi, a[i]);
	}
	ans = ma - mi;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
S = [0]*N
T = [0]*N
S[0] = A[0]
T[-1] = B[-1]
for k in range(1,N):
    S[k] = A[k] + S[k-1]
    T[-k-1] = B[-k-1] + T[-k]

ans = 0
for k in range(N):
    ans = max(ans,S[k]+T[k])
print(ans)


Measured memory_bytes: 38256
h,w = list(map(int,input().split()))
s=[i for i in range(h)]
for i in range(h):
  s[i] = input()
count = [[0 for i in range(w)]for j in range(h)]
if h==1and w==1:
  if s=="#":
    print("#")
    exit()
  else:
    print(0)
    exit()
  
elif h==1:
  for i in range(w):
    if s[0][i]=="#":
      if i==0:
        count[0][i+1]+=1
      elif i==w-1:
        count[0][i-1]+=1
      else:
        count[0][i-1]+=1
        count[0][i+1]+=1
  ans=""
  for i in range(w):
    if s[0][i]!="#":
      ans+=str(count[0][i])
    else:
      ans+="#"
  print(ans)
  exit()
elif w==1:
  for i in range(h):
    if s[i][0]=="#":
      if i==0:
        count[i+1][0]+=1
      elif i==h-1:
        count[i-1][0]+=1
      else:
        count[i-1][0]+=1
        count[i+1][0]+=1
  
  for i in range(h):
    ans=""
    if s[i][0]!="#":
      ans+=str(count[i][0])
    else:
      ans+="#"
    print(ans)
  exit()


for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if i==0:
        if j==0:
          count[i+1][j]+=1
          count[i+1][j+1]+=1
          count[i][j+1]+=1
        elif j==w-1:
          count[i][j-1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
        else:
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]  +=1
          count[i+1][j+1]+=1
      elif i==h-1:
        if j==0:
          count[i][j+1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
        elif j==w-1:
          count[i][j-1]+=1
          count[i-1][j-1]+=1
          count[i-1][j]+=1
        else:
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
      else:
        if j==0:
          count[i-1][j]+=1
          count[i-1][j+1]+=1
          count[i][j+1]+=1
          count[i+1][j]+=1
          count[i+1][j+1]+=1
        elif j==w-1:
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i][j-1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
        else:
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
          count[i+1][j+1]+=1

for i in range(h):
  ans=""
  for j in range(w):
    if s[i][j]!="#":
  	  ans+=str(count[i][j])
    else:
      ans+="#"
  print(ans)



Measured memory_bytes: 3320
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
sum = 0
for i in range(N):
  if A[i] == 0:
    ans += sum//2
    sum = 0
  else:
    sum += A[i]
    if i == N-1:
      ans += sum//2
print(ans)

Measured memory_bytes: 7072
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define N 200010
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<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int x,y,a,b,c,p[N],q[N],r[N];
ll ans;
priority_queue<int,vector<int>,greater<int> > q1,q2;
int main(){
	x=read(),y=read(),a=read(),b=read(),c=read();
	for(int i=1;i<=a;++i){
		p[i]=read();
	}
	for(int i=1;i<=b;++i){
		q[i]=read();
	}
	for(int i=1;i<=c;++i){
		r[i]=read();
	}
	sort(p+1,p+a+1,greater<int>());
	sort(q+1,q+b+1,greater<int>());
	sort(r+1,r+c+1,greater<int>());
	for(int i=1;i<=x;++i){
		ans+=p[i],q1.push(p[i]);
	}
	for(int i=1;i<=y;++i){
		ans+=q[i],q2.push(q[i]);
	}
	for(int i=1;i<=c;++i){
		if(q1.top()<q2.top()){
			if(r[i]>q1.top()){
				ans-=q1.top();
			q1.pop();
			ans+=r[i];
			q1.push(r[i]);
			}
			else break;
		}
		else{
			if(r[i]>q2.top()){
				ans-=q2.top();
				q2.pop();
				ans+=r[i];
				q2.push(r[i]);
			}
			else break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2552
n, m = map(int, input().split())
ab = {}
for _ in range(m):
    a, b = map(int, input().split())
    if not a in ab:
        ab[a] = []
    if not b in ab:
        ab[b] = []
    ab[a].append(b)
    ab[b].append(a)

def dfs(i: int, l:list) -> bool:
    if i > 2:
        return False

    ret = False
    for _l in l:
        if _l == n:
            ret = True

        if _l > i:
           ret |= dfs(i+1, ab[_l])

    return ret

print("POSSIBLE" if dfs(1, ab[1]) else "IMPOSSIBLE")


Measured memory_bytes: 50920
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

	/** 置き換えるための正規表現 */
	private static final Pattern PATTERN = Pattern.compile("(A)tCoder\\s([A-Z])[a-z]*\\s(C)ontest");

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.nextLine();
			System.out.println(PATTERN.matcher(s).replaceFirst("$1$2$3"));
		}
	}
}


Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1003,INF=1<<29;
vector<int> tour;
vector<int> G[MAX];
int dis[MAX];

void DFS(int u){
    tour.push_back(u);
    for(int to:G[u]){
        dis[to]=dis[u]+1;
        DFS(to);
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<string> S(N);
    
    for(int i=0;i<N;i++){
        int a;cin>>a;
        a--;
        cin>>S[i];
        
        if(a==-1) continue;
        
        G[a].push_back(i);
    }
    
    dis[0]=0;
    DFS(0);
    
    for(int a:tour){
        for(int i=0;i<dis[a];i++) cout<<'.';
        cout<<S[a]<<endl;
    }
    
}



Measured memory_bytes: 3416
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
    int n, d;
    cin >> n >> d;

    int x[n][d];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }

    double l[n][n];
    for (int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            l[i][j] = 0.0;
        }
    }

    
    for(int i = 0; i < n-1; i++){
         for(int j =i+1; j < n; j++){
            for(int k = 0; k < d; k++){
                if((x[i][k]-x[j][k]) != 0){
                    l[i][j] = l[i][j] + pow((x[i][k]-x[j][k]), 2.0);
                }
            }
         }
    }

    int cnt = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            if(ceil(sqrt(l[i][j])) == floor(sqrt(l[i][j]))){
               cnt++;
            }
        }
    }

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    divs = np.arange(1, n + 1)
    divs2 = n // divs
    divs3 = divs2 * (divs2 + 1) // 2
    divs3 = divs3 * divs
    r = divs3.sum()
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 339812
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int n;
    char s[105];
    scanf("%d",&n);
    scanf("%s",s);
    if(n%2!=0){printf("No\n");return 0;}
    for(int i=0;s[n/2+i]!='\0';i++){
        if(s[i]!=s[n/2+i]){printf("No\n");return 0;}
    }
    printf("Yes");
}


Measured memory_bytes: 128
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    h[0] -= 1
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
        if h[i] < h[i-1]:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); i++)
 
int main() {
	int N,R;
  	cin >> N >> R;
  	if (N<10){
    cout << R+(10-N)*100;
    }else{
    cout << R << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	a.at(0) = -1;
	for (int i = 1; i < n; i++) {
		cin >> a.at(i);
	}
	vector<int>count(n,0);
	rep(i, n-1) {
		count.at(a.at(i+1)-1)++;
	}
	rep(i, n)cout << count.at(i) << endl;
	return 0;
}


Measured memory_bytes: 4852
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n : i32 = read();
    let ans = n  / 3;
    println!("{}",ans);
}

Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
}

typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 2e5 + 1, M = 1e3+1, OO = 0x3f3f3f3f;
bool cmp(pair<int,int> a,pair<int,int> b){return a.first<b.first;}
pair<int,int> arr[N];
ll csum[N],ans =0,d,a;
int n;


int main()
{
  scanf("%d%lld%lld",&n,&d,&a);
  d<<=1;
  for(int i=1;i<=n;++i)
  {
    int x,h;
    scanf("%d%d",&x,&h);
    arr[i].first=x,arr[i].second=h;
  }
  sort(arr+1,arr+n+1,cmp); 
  for(int i=1;i<=n;++i)
  {
    int x=arr[i].first,h=arr[i].second;
    csum[i]+=csum[i-1];
    h-=csum[i];
    if(h<=0) continue;

    int idx=upper_bound(arr+1,arr+n+1,make_pair(x+d,-1),cmp)-arr;
    ll req=ceil(h*1.0/a);
    csum[i]+=a*req;
    csum[idx]-=a*req;
    ans+=req;
  }
  printf("%lld\n",ans);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; O << '\n'; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;




void _main() {
        int n; cin >> n;
        string str; cin >> str;
        int ans = 0;
        for (int i = 0; i + 2< n; i++) {
                if (str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C')ans++;
        }
        
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[][] bingo = new int[3][3];
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        bingo[i][j] = sc.nextInt();
      }
    }
    int n = sc.nextInt();
    for(int i = 0; i < n; i++){
      int check = sc.nextInt();
      boolean flag = false;
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          if(bingo[j][k] == check){
            bingo[j][k] = -1;
            flag = true;
            break;
          }
        }
        if(flag){
          break;
        }
      }
    }
    if((bingo[0][0] == -1&&bingo[0][1]==-1&&bingo[0][2]==-1)||(bingo[1][0]==-1&&bingo[1][1]==-1&&bingo[1][2]==-1)||(bingo[2][0]==-1&&bingo[2][1]==-1&&bingo[2][2]==-1)){
      System.out.println("Yes");
      return;
    }
    if((bingo[0][0]==-1&&bingo[1][0]==-1&&bingo[2][0]==-1)||(bingo[0][1]==-1&&bingo[1][1]==-1&&bingo[2][1]==-1)||(bingo[0][2]==-1&&bingo[1][2]==-1&&bingo[2][2]==-1)){
      System.out.println("Yes");
      return;
    }
    if((bingo[0][0]==-1&&bingo[1][1]==-1&bingo[2][2]==-1)||(bingo[0][2]==-1&&bingo[1][1]==-1&&bingo[2][0]==-1)){
      System.out.println("Yes");
      return;
    }
    System.out.println("No");
  }
}

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

int main() {
    string S;
    cin >> S ;
    
    if (S.compare("Sunny") ==0 ) cout << "Cloudy" << endl;
    if (S.compare("Cloudy") ==0 ) cout << "Rainy" << endl;
    if (S.compare("Rainy") ==0  ) cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long int INF = 1000000007;
struct Edge {
	long long vir1;
	long long vir2;
};
void BFS(vector<vector<long long>>&Graph, vector<long long>&Dis, vector<long long>&Point) {
	queue<long long>Q;
	Q.push(0);
	Dis.at(0) = 0;
	Point.at(0) = 0;
	while (!Q.empty()) {
		long long v = Q.front();
		Q.pop();
		for (auto next_v : Graph[v]) {
			if (Dis.at(next_v) != INF) continue;
			Dis.at(next_v) = Dis.at(v) + 1;
			Point.at(next_v) = v;
			Q.push(next_v);
		}
	}
}
int main() {
	long long N, M; cin >> N >> M;
	vector<Edge>A(M);
	vector<vector<long long>>Graph(N);
	for (long long i = 0; i < M; i++) {
		cin >> A.at(i).vir1 >> A.at(i).vir2;
		Graph.at(A.at(i).vir1 - 1).push_back(A.at(i).vir2 - 1);
		Graph.at(A.at(i).vir2 - 1).push_back(A.at(i).vir1 - 1);
	}
	vector<long long>Dis(N, INF), Point(N, INF);
	BFS(Graph, Dis, Point);

	for (long long i = 0; i < N; i++) {
		if (Dis.at(i) == INF) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (long long i = 1; i < N; i++) {
		cout << Point.at(i)  + 1 << endl;
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
using i64 = int_fast64_t;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(15);

    string s; cin >> s;
    if(s == "SUN") cout << 7 << '\n';
    else if(s=="MON") cout << 6 << '\n';
    else if(s=="TUE") cout << 5 << '\n';
    else if(s=="WED") cout << 4 << '\n';
    else if(s== "THU") cout << 3 << '\n';
    else if(s=="FRI") cout << 2 << '\n';
    else if(s=="SAT") cout << 1 << '\n';
}

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

int A, B, C, K;

int main()
{
    cin >> A >> B >> C >> K;
    int N = 0;
    int rest = K;

    if (A < rest)
    {
        N += A;
        rest = rest - A;
    }
    else
    {
        N += rest;
        rest = 0;
    }

    if (rest <= 0)
    {
        cout << N << endl;
        return 0;
    }

    if (B < rest)
    {
        rest = rest - B;
    }
    else
    {
        rest = 0;
    }

    if (rest <= 0)
    {
        cout << N << endl;
        return 0;
    }

    if (C < rest)
    {
        N -= A;
        rest = rest - C;
    }
    else
    {
        N -= rest;
        rest = 0;
    }

    cout << N << endl;

    return 0;
}

Measured memory_bytes: 3624
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

N, M  = getNM()
req = [N for i in range(N)]
for i in range(M):
    l,r = getNM()
    if req[l] > r-1:
        req[l] = r-1
ans = 0
tar = 0
#print(req) #[9, 7, 6, 4, 5, 9, 9, 8, 9] :9 is ignored
req2 = []
cut = N
for i in range(N):
    if (req[N-i-1]) < cut:
        cut = N-i-1
        ans += 1
    else:
        pass


print(ans)

Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long a;
  cin >> a;
  vector<long long> z(a);
 for(int i = 0;i < a;i++){
   cin >> z.at(i);}
  long long ans = 0;
 for(int64_t i = 0;i < 63;i++){
   long long  d = 0;
   long long  e = 0;
   long long  vv = pow(2,i+1); 
   for (int j = 0;j < a;j++){
     
   if(z.at(j) % vv < vv/2){d++;}
     else{e++;}
   }
   long long  powt = 1;
   powt = pow(2,i);
   powt %= 1000000007;
   long long h = d*e;
    h %= 1000000007;
   long long xx = h * powt;
    xx %= 1000000007;
   ans += xx;
   
   ans %= 1000000007;

 }

  ans %= 1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 2560
n, m = [int(s) for s in input().split()]
cake_list = [[int(s) for s in input().split()] for _ in range(n)]

ans_list = [0] * 8
for i in range(8):
    a, b, c = [1 if (i >> j) & 1 == 1 else -1 for j in range(3)]
    temp_list = sorted([a * x + b * y + c * z for x, y, z in cake_list], reverse=True)

    for j in range(m):
        ans_list[i] += temp_list[j]
print(max(ans_list))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 2005;

int n, a[MAXN], b[MAXN], c[MAXN << 1], sum[MAXN], pre[MAXN], suf[MAXN], ans = 1 << 30;
char s[MAXN];
pii e[MAXN];

inline int Sum(int l, int r)
{
	return l > r ? sum[n] - sum[l] + sum[r + 1] : sum[r + 1] - sum[l];
}

inline void Solve()
{
	for (int i = 0; i < n; i ++)
		c[i] = c[i + n] = b[i];
	for (int i = (n << 1) - 1; ~i; i --)
		c[i] = c[i] ? 0 : c[i + 1] + 1;
	for (int i = 0; i < n; i ++)
		suf[i] = c[i];
	for (int i = 0; i < n; i ++)
		c[i] = c[i + n] = b[n - i - 1];
	for (int i = (n << 1) - 1; ~i; i --)
		c[i] = c[i] ? 0 : c[i + 1] + 1;
	for (int i = 0; i < n; i ++)
		pre[i] = c[n - i - 1];
	for (int i = 0; i < n; i ++)
		sum[i + 1] = sum[i] + b[i];
	for (int d = 0; d < n; d ++)
	{
		int ret = 0, tp = 0, cur;
		for (int i = 0; i < n; i ++)
			if (a[i] ^ b[(i + d) % n])
			{
				ret ++;
				if (!Sum(i, (i + d) % n))
					e[++ tp] = mp(pre[i], suf[(i + d) % n]);
			}
		sort(e + 1, e + tp + 1);
		cur = e[tp].xx;
		for (int i = tp, j = 0; i; i --)
			j = max(j, e[i].yy), cur = min(cur, e[i - 1].xx + j);
		ans = min(ans, ret + (cur << 1) + d);
	}
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	scanf("%s", s); n = strlen(s);
	for (int i = 0; i < n; i ++)
		a[i] = s[i] == '1';
	scanf("%s", s);
	for (int i = 0; i < n; i ++)
		b[i] = s[i] == '1';
	bool flag = true;
	for (int i = 0; i < n; i ++)
		if (b[i])
			flag = false;
	if (flag)
	{
		for (int i = 0; i < n; i ++)
			if (a[i])
				return puts("-1"), 0;
		return puts("0"), 0;
	}
	Solve();
	reverse(a, a + n); reverse(b, b + n);
	Solve();
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n);
	LD res = 1;
	LL ans = 1;
	rep(i, 0, n) {
		sll(num);
		res = res * (LD(num));
		ans = (ans * num);
	}
	if(res > 1e18)	puts("-1");
	else			pll(ans), nl;
}


Measured memory_bytes: 3760
from collections import defaultdict
N = int(input())
d = defaultdict(list)
p2n = {}
for n in range(N):
  s, p = input().split()
  d[s].append(int(p))
  p2n[int(p)] = n + 1

for key in sorted(d):
  for p in sorted(d[key],reverse=True):
    print(p2n[p])

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll modinv(ll a, ll p) {
    if (p == 1) return 0;
    ll pp = p, y = 0, x = 1;
    while (a > 1) {
        ll q = a / p, t = p;
        p = a % p, a = t, t = y, y = x - q * y, x = t;
    }
    if (x < 0) x += pp;
    return x;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	ll ans = 1;
	vector<ll> fra(n + 1, 1), inv(n + 1, 1);
	for (int i = 1; i <= n; i++) {
		fra[i] = fra[i - 1] * i % mod;
		inv[i] = modinv(fra[i], mod);
	}
	for (int i = 1; i <= min(n - 1, k); i++) {
		ll tmp = fra[n] * fra[n-1] % mod * inv[i] % mod * inv[i] % mod * inv[n - i] % mod * inv[n - i - 1] % mod;
		ans = (ans + tmp) % mod;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

signed main() {
    int h, w, K;
    cin >> h >> w >> K;

    vector<string> vs;
    repeat(i, h) {
        string s;
        cin >> s;
        vs.push_back(s);
    }

    int ans = INT_MAX;
    repeat(i, 1 << (h - 1)) {
        vector<int> sec;
        sec.push_back(0);
        int c = 0;
        repeat(j, h) {
            if ((i & (1 << j)) > 0) {
                sec.push_back(++c);
            } else {
                sec.push_back(c);
            }
        }

        int res = c;

        vector<int> vw(c + 1, 0);
        bool end = false;
        repeat(j, w) {
            vector<int> vcw(c + 1, 0);
            bool fl = false;
            repeat(k, h) {
                vw[sec[k]] += vs[k][j] - '0';
                vcw[sec[k]] += vs[k][j] - '0';
                if (vw[sec[k]] > K) fl = true;
                if (vcw[sec[k]] > K) end = true;
            }

            if (fl) {
                ++res;
                vw = vcw;
            }
        }
        if (end) continue;

        ans = min(res, ans);
    }

    cout << ans;
}

Measured memory_bytes: 3168
import copy
import itertools
H, W, K = map(int, input().split())

WHITE = 0
BLACK = 1
RED = 2

board = [[WHITE] * W for i in range(H)]

for i in range(H):
    s = input()
    for j, v in enumerate(s):
        if v == '#':
            board[i][j] = BLACK


ans = 0
for rowmask in itertools.product([0, 1], repeat=H):
    for colmask in itertools.product([0, 1], repeat=W):
        cur = copy.deepcopy(board)
        blackCount = 0
        for i, r in enumerate(cur):
            for j, w in enumerate(r):
                if rowmask[i] == 1 or colmask[j] == 1:
                    continue
                if w == WHITE:
                    continue
                blackCount += 1
        if blackCount == K:
            ans += 1

print(ans)


Measured memory_bytes: 9336
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX =1e5+6;
const long long inf=1e18;
vector<int>adj[MAX];
int arr[MAX];
int vis[MAX];
void dfs(int a){
	vis[a]=1;
	for(int i=0;i<adj[a].size();i++){
		if(!vis[adj[a][i]]){
			arr[adj[a][i]]+=arr[a];
			dfs(adj[a][i]);
		}
	}
}
int main(){
	int n;
	cin>>n;
	int a[n+1], b[n+1];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		b[a[i]]=i;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<" ";

}

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


int main(){
    int x, a=0,b=0;
    cin>>x;

    while(1){
        if(x/500==0){
            break;
        }
        else{
            x = x-500;
            a++;
        }
    }
    b = x/5;
    cout << 1000*a+5*b << endl;
}

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

string input;
int p, q, r;

int i;
int fomula();
int inpar();

int add(int left, int right) {
	return max(left, right);
}

int mul(int left, int right) {
	return min(left, right);
}

int no(int value) {
	return 2 - value;
}

int fomula() {
	switch(input[i++]) {	
	case 'P':
		return p;
	case 'Q':
		return q;
	case 'R':
		return r;
	case '0':
		return 0;
	case '1':
		return 1;
	case '2':
		return 2;
	case '-':
		return no(fomula());
	}

	return inpar();
}

int inpar() {
	int left = fomula();
	char ope = input[i++];
	int right = fomula();
	++i;

	switch(ope) {
	case '+':
		return add(left, right);
	case '*':
		return mul(left, right);
	}	
}

int main() {
	while(cin >> input, input[0] != '.') {
		int count = 0;
		for(p=0; p<3; p++)
			for(q=0; q<3; q++)
				for(r=0; r<3; r++)
					if(i=0, fomula() == 2)
						count++;

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
import math
import sys
import numpy as np
from collections import defaultdict, deque, Counter 
from itertools import accumulate, product, permutations,combinations, combinations_with_replacement
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd

max_value = 1000000000
min_value = -1000000000
sys.setrecursionlimit(max_value)

N = int(input())
hs = list(map(int,input().split()))

for i in reversed(range(1,N)):
    if hs[i] >= hs[i-1]:
        continue
    elif hs[i]  == hs[i-1] - 1:
        hs[i-1] -= 1
    else:
        print('No')
        sys.exit()


print('Yes')



Measured memory_bytes: 25008
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

vector<bool> is_prime;
void eratosthenes(int N) {
    is_prime.resize(N+1);
    fill(ALL(is_prime),true);
    is_prime[0]=false;
    is_prime[1]=false;
    REPF(i,2,sqrt(N)+1)
        if(is_prime[i])
            for(int j=2; i*j<=N; j++)
                is_prime[i*j]=false;
}
signed main() {
    eratosthenes(100001);
    vector<int> primes;
    REP(i,100001) if(is_prime[i]) primes.push_back(i);

    while(1) {
        int m,a,b;
        cin>>m>>a>>b;
        if(m+a+b==0) break;
        int ans=0;
        int x=0,y=0;
        REP(i,SZ(primes)) {
            int p=primes[i];
            int l=i,r=SZ(primes)-1;
            while(l<=r) {
                int mid=(l+r)/2;
                int q=primes[mid];
                bool ok=true;
                if(p>q) ok=false;
                if(a*q>b*p) ok=false;
                if(p*q>m) ok=false;

                if(ok) {
                    l=mid+1;
                    if(chmax(ans,p*q)) {
                        x=p;
                        y=q;
                    }
                }
                else {
                    r=mid-1;
                }
            }
        }
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}

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

int main(){
  int N; cin >> N;
  int A,B,C,D; cin >> A >> B >> C >> D; A--;B--;C--;D--;//0-based
  string S; cin >> S;
  
  bool OK = true;
  for(int i = A; i <= max(C,D)-1; i++){
    if(S.at(i) == '#' and S.at(i+1) == '#'){
      OK = false;
    }
  }
  
  if(C > D){
    OK = false;
    for(int i = B-1; i <= D - 1; i++){
      if(S.at(i) == '.' and S.at(i+1) == '.' and S.at(i+2) == '.'){
        OK = true;
        break;
      }
    }
  }
  
  if(OK) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string N; cin >> N;
    cout << (count(N.begin(), N.end(), '7') > 0 ? "Yes" : "No") << "\n";
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1e8
#define ALL(a) a.begin(), a.end()
#define MAXEL max_element
#define MINEL min_element
#define POW (int)pow
#define BIT(i) (int)pow(2, i)

int main() {
  int n, k;
  cin >> n >> k;
  int a;
  REP(i, n) { scanf("%d", &a); }
  cout << ((n - 1) + (k - 1 - 1)) / (k - 1) << endl; // seiling((n-1)/(k-1))
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

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

		System.out.println(a + a * a + a * a * a);

		sc.close();
	}

}


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

int n;
char s[1010][1010];

int main() {
    scanf("%d", &n);
    if (n == 2) {
        printf("-1\n"), exit(0);
    }
    if (n == 5) {
        printf("aabbc\n");
        printf("bb.dc\n");
        printf("..adb\n");
        printf("c.a.b\n");
        printf("cbbaa\n"), exit(0);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            s[i][j] = '.';
        }
    }
    if (!(n % 3)) {
        for (int i = 1, j = 1; i <= n / 3; i++, j += 3) {
            s[j][j] = s[j][j + 1] = 'a';
            s[j + 1][j + 2] = s[j + 2][j + 2] = 'a';
        }
    } else {
        int tmp = n;
        if (n & 1) {
            int m = n - 7; tmp -= 7;
            string tmp[7] = {"aabbaa.", "bbaa..a", "aabb..a",
                "....bab", "....bab", "....aba", "....aba"};
            for (int i = m + 1; i <= n; i++) {
                for (int j = m + 1; j <= n; j++) {
                    s[i][j] = tmp[i - m - 1][j - m - 1];
                }
            }
        }
        s[1][1] = s[1][2] = 'a', s[1][tmp - 1] = 'c', s[1][tmp] = 'd';
        s[2][1] = s[2][2] = 'b', s[2][tmp - 1] = 'c', s[2][tmp] = 'd';
        for (int i = 1, j = 1; i <= tmp / 2 - 1; i++, j += 2) {
            int k = j + 2;
            s[k][j + 2] = s[k][j + 3] = 'a';
            s[k + 1][j + 2] = s[k + 1][j + 3] = 'b';
            s[k][j] = s[k + 1][j] = 'c';
            s[k][j + 1] = s[k + 1][j + 1] = 'd';
        }
    }
    for (int i = 1; i <= n; i++) {
        printf("%s\n", s[i] + 1);
    }
    return 0;
}

Measured memory_bytes: 2176
import atexit
import io
import sys

temp_buffer = io.BytesIO()
sys.stdout = temp_buffer


@atexit.register
def write():
    sys.__stdout__.write(temp_buffer.getvalue())


result = 0
n = int(raw_input())
for i in range(n):
    l, r = map(int, raw_input().split())
    result += (r - l + 1)
print(result)


Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,z,w;
    cin >> n >> z >> w;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    if(n==1)cout << abs(a[0]-w);
    else{
        cout << max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]));
    }
}

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

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

    ll dp[12][10] = {};
    ll s = 0;

    for (int c = 0; c < 10; c++) {
        dp[0][c] = 1;

        if (c != 0) {
            s += 1;
            if (s >= k) {
                cout << c << endl;
                exit(0);
            }
        }
    }
    for (int d = 0; d < 12 - 1; d++) {
        for (int c = 0; c < 10; c++) {
            ll t = dp[d][c];
            if (c != 0) t += dp[d][c - 1];
            if (c != 9) t += dp[d][c + 1];
            dp[d + 1][c] = t;

            if (c != 0) {
                s += t;
                if (s >= k) {
                    while (1) {
                        cout << c;
                        if (d < 0) break;
                        s -= t;
                        for (int i = max(c - 1, 0); i <= min(c + 1, 9); i++) {
                            t = dp[d][i];
                            s += t;
                            if (s >= k) {
                                c = i;
                                d--;
                                break;
                            }
                        }
                    }
                    cout << endl;
                    exit(0);
                }
            }
        }
    }

    return 0;
}

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

int main() {
  int R;
  cin>>R;
  if(R<1200) {
    cout<<"ABC"<<endl;
  }
  if(1200<=R&&R<2800) {
    cout<<"ARC"<<endl;
  }
  if(2800<=R) {
    cout<<"AGC"<<endl;
  }
}


Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		if(N==M) {
			System.out.println("Yes");
			}else {
				System.out.println("No");
			}

	}
}

Measured memory_bytes: 23764
N = int(input())
A = map(int, input().split())
B = map(int, input().split())
diff = [a - b for a, b in zip(A, B)]
upper = sorted([x for x in diff if x > 0])
lower = sorted([x for x in diff if x < 0])
ans = N - len([x for x in diff if x == 0])
while upper and lower:
    rest = upper.pop()
    while lower:
        tgt = lower.pop()       # negative value
        if rest + tgt >= 0:
            rest += tgt
        else:
            lower.append(tgt + rest)
            break
if lower:
    print(-1)
else:
    print(ans - len(upper))

Measured memory_bytes: 21428
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long lint;
using namespace std;

const int MOD = 1e9+7;
lint dp[2][4];

int main() {
    string S;
    cin >> S;
    const int N = S.size();
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        const int cur = i%2;
        const int tar = cur^1;
        // そのまま
        for (int j = 0; j < 4; j++) {
            dp[tar][j] = ((S[i] == '?' ? 3 : 1) * dp[cur][j]) % MOD;
        }
        // 追加
        if (S[i] == 'A') {
            (dp[tar][1] += dp[cur][0]) %= MOD;
        } else if (S[i] == 'B') {
            (dp[tar][2] += dp[cur][1]) %= MOD;
        } else if (S[i] == 'C') {
            (dp[tar][3] += dp[cur][2]) %= MOD;
        } else {
            for (int j = 0; j < 3; j++) {
                (dp[tar][j+1] += dp[cur][j]) %= MOD;
            }
        }
    }
    cout << dp[N%2][3] << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int h,w,K;
  cin >> h >> w >> K;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i,h)rep(j,w) cin >> s[i][j];
  vector<vector<int>> ans(h, vector<int>(w,0));

  int pre=-1;
  int p=0;
  rep(i,h){
    int cnt=0;
    rep(j,w)if(s[i][j]=='#') cnt++;
    if(cnt==0){ 
      if(pre==-1) pre=i; 
      continue; 
    }

    p++;
    bool F = false;
    rep(j,w){
      if(s[i][j]=='#' && F == true) p++;
      if(s[i][j]=='#' && F == false) F=true;
      ans[i][j] = p;
    }

    if(pre!=-1){
      for(int k=pre; k<i; k++){ ans[k] = ans[i]; }
      pre = -1;
    }
  }
  
  if(pre!=-1){
    for(int k=pre; k<h; k++){ ans[k] = ans[pre-1]; }
  }

  rep(i,h){
    rep(j,w){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdint>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	if ((K & 1) == 0) cout << (int64_t)(N / K) * (N / K) * (N / K) + (int64_t)((N + (K >> 1)) / K) * ((N + (K >> 1)) / K) * ((N + (K >> 1)) / K);
	else cout << (int64_t)(N / K) * (N / K) * (N / K);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、aを決め打つ
この時、a+bはKの倍数であるからb=nK-a、c=mK-aとなる
ここでb+cがKの倍数であるから、nK+mK-2aもまたKの倍数であるので、2aがKの倍数である必要がある
逆に、この時にnとmは任意に値を取れるので、はい
*/

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def f(ss):
    return ss


def main():
    s = input()

    rcount = 0
    lcount = 0
    l = "R"
    lastindex = 0
    res = []
    result = []
    for i, c in enumerate(s):
        if l == "L" and c == "R":  # end
            rr = (rcount + 1) // 2 + (lcount // 2)
            ll = rcount + lcount - rr
            res.append(s[lastindex:i])
            result.extend([0 for _ in range(rcount - 1)])
            result.append(rr)
            result.append(ll)
            result.extend([0 for _ in range(lcount - 1)])
            lastindex = i
            rcount = 0
            lcount = 0
        if c == "R":
            rcount += 1
        if c == "L":
            lcount += 1
        l = c
    res.append(s[lastindex:])
    rr = (rcount + 1) // 2 + (lcount // 2)
    ll = rcount + lcount - rr
    # res.append(s[lastindex:i])
    result.extend([0 for _ in range(rcount - 1)])
    result.append(rr)
    result.append(ll)
    result.extend([0 for _ in range(lcount - 1)])

    # print(res)
    print(*result)

    # N = int(input())
    # H = [int(a) for a in input().split()]
    # H = [
    #     int(input())
    #     for _ in range(N)
    # ]
    # A = [int(a) for a in input().split()]


if __name__ == '__main__':
    main()


Measured memory_bytes: 9812