akhauriyash/Code-Regression huggingface dataset:
using System;

namespace pro
{



    class MainClass
    {
        public static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int kuti = a;
            int count = 1;
            if (b == 1)
            {
                Console.WriteLine(0);
            }
            else if (a >= b)
            {
                Console.WriteLine(1);
            }
            else
            {
                while (kuti < b)
                {
                     kuti+= (a - 1);
                    count++;
                }
                Console.WriteLine(count);
            }
            


        }
    }


}


Measured memory_bytes: 13140
#include<iostream>

using namespace std;




int main(){
	int R,G,B,N;
  	cin >> R >> G >> B >>N;
  	int cont = 0;
	for(int i = 0; i <= N/R; i++){
		for(int j = 0; j <= N/G; j++){
    		if((-R*i-G*j+N)%B==0&&-R*i-G*j+N>=0){
              	cont++;
            	//cout << i << j << endl;
            }
    	}    	
    
    }
  	cout << cont << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair <int,int> P;
int n;
P book[1001];

int solve(){
  int sumf=0,sums=0;
  for(int i=0;i<n;i++)sumf+=book[i].f,sums+=book[i].s;
  if(2*book[0].f<=sumf)return sumf+sums;
  int d=2*book[0].f-sumf,dp[3000]={1},D=d;
  for(int i=1;i<n;i++)
    for(int j=d-book[i].s;j>=0;j--) dp[j+book[i].s]|=dp[j];
  while(!dp[D])D--;
  return sumf+sums+(d-D);
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>book[i].f>>book[i].s;
    sort(book,book+n,greater<P>());
    cout <<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
def sol(_inp=input):
    n=int(_inp())
    words=[_inp() for _ in range(n)]
    ab_in_words=sum(w.count('AB') for w in words)
    ends_A=sum(w.endswith('A') for w in words)
    starts_B=sum(w.startswith('B') for w in words)
    sands=sum((w.endswith('A') and w.startswith('B')) for w in words)
    if ends_A==sands and starts_B==sands and sands>0:
        return str(ab_in_words+sands-1)
    return str(ab_in_words+min(ends_A,starts_B))
print(sol())

Measured memory_bytes: 45784
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [(0,0) for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = (h-1,w-1)

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not (h,w) in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)


Measured memory_bytes: 143076
N,M = map(int, input().split())

a = [int(input()) for i in range(M)]

#初期化
dp=[-1]*N
dp[0]=1

for i in a:
    dp[i-1] = 0

for i in range(1,N):
    if dp[i]==0:
        continue
    elif i==1:
        dp[i]=dp[i-1] + 1
    else:
        dp[i]=dp[i-1]+dp[i-2]

print(dp[N-1]%1000000007)

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

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

  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];

  int c = 0;
  for (int i = 1; i < n - 1; i++) {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
        (p[i - 1] > p[i] && p[i] > p[i + 1]))
      c++;
  }

  cout << c << endl;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)

x = as.first
y = as.inject(:+) - x
ans = (x - y).abs

as[1..n - 2].each do |a|
  x += a
  y -= a
  diff = (x - y).abs

  ans = diff if diff <= ans
end

puts ans


Measured memory_bytes: 27212
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define spc printf(" ");
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}
play
{
    I a,b,i;
    sf(a),sf(b);
    rep(i,b-a+1,b)
    pf(i),spc;
    pf(b),spc;
    rep(i,b+1,b+a)
    pf(i),spc;
    nl;
    out 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

using ll = long long;

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

    ll large = max(a, b);
    ll small = min(a, b);

    a = small;
    b = large;

    vector<ll> al;
    vector<ll> bl;

    for (int i = 1; i <= sqrt(a); i++) {
        if (a % i == 0) {
            al.push_back(i);   
            if (i != sqrt(a)) {
                al.push_back(a / i);
            }
        }

    }
    for (int i = 1; i <= sqrt(b); i++) {
        if (b % i == 0) {
            bl.push_back(i);   
            if (i != sqrt(b)) {
                bl.push_back(b / i);
            }
        }
    }

    sort(al.begin(), al.end());
    sort(bl.begin(), bl.end());

    vector<ll> res;
    ll count = 0;
    for (int i = 0; i < al.size(); i++) {
        ll now = al[i];
        while(bl[count] < now) {
            count++;
            if (count >= bl.size()) {
                break;
            }
        }
        if (count >= bl.size()) {
            break;
        }
        if (bl[count] == now) {
            res.push_back(now);
        }
    }


    ll result = 0;
    for (int i = 0; i < res.size(); i++) {
        // 素数
        bool isSosu = true;
        for (int j = 2; j <= sqrt(res[i]); j++) {
            if (res[i] % j == 0) {
                isSosu = false;
                break;
            }
        }
        if (isSosu) result++;
    }

    cout << result << endl;
}


Measured memory_bytes: 512
object Main extends App {

  import scala.io.StdIn._
  val Array(n, r) = readLine.trim.split(' ').map(_.toDouble)
  val points = Array.fill(n.toInt){
    val Array(x, y) = readLine.trim.split(' ').map(_.toDouble)
    Coordinate(x, y)
  }.sortBy(_.x)
  val uft = new UnionFind(n.toInt)
  merge(points.indices.toArray)
  println(points.indices.count(i ⇒ uft.find(i) == i))
  def merge(rest: Array[Int]): Array[Int] = {
    if (rest.length <= 3) {
      for (i ← rest.indices; j ← 0 until i) {
        if (points(rest(i)).distance(points(rest(j))) <= 2 * r) {
          uft.unite(rest(i), rest(j))
        }
      }
      rest.filter(i ⇒ uft.find(i) == i)
    }else {
      val mid = points(rest(rest.length / 2)).x
      val merged = (merge(rest.take(rest.length / 2)) ++ merge(rest.drop(rest.length / 2))).filter(i ⇒ math.abs(points(i).x - mid) <= 1.1 * r).sortBy(i ⇒ points(i).y)
      if (merged.length >= 2) {
        for (i ← merged.indices.tail) {
          if (points(merged(i)).distance(points(merged(i - 1))) <= 2 * r) uft.unite(merged(i), merged(i - 1))
        }
      }
      rest.filter(i ⇒ uft.find(i) == i)
    }
  }
}
class UnionFind(size: Int) {
  private[this] val parent = Array.fill(size){-1}
  def find(a: Int): Int = {
    if (parent(a) < 0) a
    else {
      parent(a) = find(parent(a))
      parent(a)
    }
  }
  def isSame(a: Int, b: Int): Boolean = find(a) == find(b)
  def unite(a: Int, b: Int): Unit = {
    val ar = find(a)
    val br = find(b)
    if (ar != br) {
      if (parent(ar) < parent(br)) {
        parent(ar) += parent(br)
        parent(br) = ar
      }else {
        parent(br) += parent(ar)
        parent(ar) = br
      }
    }
  }
}
case class Coordinate(x: Double, y: Double) {
  def distance(that: Coordinate): Double = math.sqrt((x - that.x) * (x - that.x) + (y - that.y) * (y - that.y))
}


Measured memory_bytes: 482720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long int
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)
const int mod = 1000000007;
bool comp(pair<ll,ll>& a, pair<ll,ll>& b)
{
    if(a.second == b.second)
    return a.first > b.first;
    else
    return b.second < a.second;
}
int main()
{
    fast
    int n;
    cin>>n;
    map<string,int> mp;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    for(string st : {"AC","WA","TLE","RE"})
        {
            cout<<st<<" x "<<mp[st]<<endl;
        }



    return 0;
}


Measured memory_bytes: 3644
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, ans;
    int mod = 10007;
    String s;
    char[] c;
    int[][] dp;


    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    s = sc.next();
	    dp = new int[n+1][8];
	    for(int i=0; i<=n; i++)
		Arrays.fill(dp[i], -1);
	    c = s.toCharArray();

	    for(int i=0; i<8; i++){
		search(n, i);
		ans += dp[n][i];
		if(ans>=mod) ans-=mod;
	    }

	    //show();
	    System.out.println(ans);
	}
    }

    /*
      1. テ・ツスツ禿ヲツ猟・テ」ツ?ョティツイツャテ、ツサツサティツ??」ツ?古」ツ??」ツつ凝」ツ?禿」ツ?ィ
      2. テ・ツ可催ヲツ猟・テ」ツ?ィテ・ツスツ禿ヲツ猟・テ、ツクツ。テヲツ鳴ケテ」ツ?ォテ・ツ渉づ・ツ環?」ツ?療」ツ?ヲテ」ツ??」ツつ凝、ツコツコテ」ツ?古」ツ??」ツつ凝」ツ?禿」ツ?ィ
     */
    void search(int x, int y){
	if(x==0) {
	    if( y!=1 ){ // *1
		dp[x][y]=0;
		return;
	    }
	    dp[x][y] = 1;
	    return;
	}


	int l = c[x-1]=='J' ? 0 : c[x-1]=='O' ? 1 : 2;
	if( ((y>>l)&1) == 0 ){ // *1
	    if(dp[x][y]==-1) dp[x][y]=0;
	    return;
	}
	
	for(int k=0; k<8; k++){ //テヲツ伉ィテヲツ猟・
	    if(dp[x-1][k]==-1) search(x-1, k);
	    if( (y&k) == 0){ // *2
		if(dp[x][y]==-1) dp[x][y]=0;
		continue;
	    }
	    
	    dp[x][y] += dp[x-1][k];
	    if(dp[x][y]>=mod) dp[x][y]-=mod;
	}
    }

    void show(){
	for(int i=0; i<=n; i++){
	    for(int k=0; k<8; k++)
		System.out.printf("%5d ", dp[i][k]);
	    System.out.println();
	}
	System.out.println("-----------------");
    }
}

Measured memory_bytes: 18992
#include <stdio.h>

int main(){
    int n, a, b;

    char buf[256];
    fgets(buf, 256, stdin);

    sscanf(buf, "%d %d %d", &n, &a, &b);

    if(n*a > b){
        printf("%d", b);
    }else{
        printf("%d", n * a);
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int a,b;
  cin >> a >> b;
  int ans = 0;

  // 1~b-aまでタス
  for (int i= 1; i<= b-a; i++) {
    ans += i;
  }
  ans -=b;
  cout << ans << endl;

}

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





Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
    char s[4];
    int n=0;
    cin>>s;

    for(int i=0;i<3;i++){
        
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            exit(0);
        }
        }
    cout<<"Good"<<endl;
    exit(0);
}

Measured memory_bytes: 256
import heapq

ans=0
n,k=map(int,input().split())
enemy=list(map(int,input().split()))
if k>=len(enemy):
    print(0)
else:
    for  i in range(len(enemy)):
        enemy[i]*=(-1)
    heapq.heapify(enemy)

    for i in range(k):
        heapq.heappop(enemy)


    while len(enemy)>0:
        ans += heapq.heappop(enemy)*(-1)

    print(ans)



Measured memory_bytes: 106836
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286

int main() {
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double mDeg = m/60.0*360;
    double hDeg = (h*60.0+m)/720.0*360;
    //double hDeg = h/12.0*360;
    double deg = abs(hDeg-mDeg);
    double c = a*a + b*b - 2*a*b*cos(deg* PI /180.0);
    c = pow(c,0.5);
    //cout << mDeg << endl;
    //cout << hDeg << endl;
    cout <<fixed << setprecision(30) << c;
}

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

int main() {
  int n;
  cin >> n;
  
  int x;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0; i<n; i++) {
    cin >> x;
    a[i] = x;
    b[i] = x;
  }
  sort(b.rbegin(), b.rend());
  
  for(int i=0; i<n; i++) {
    if(a[i]<b[0]) cout << b[0] << endl;
    else if(a[i]==b[0] && b[0]==b[1]) cout << b[0] << endl;
    else cout << b[1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4844
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	//printf("%c%c%c\n", a[0]+'A'-'a',b[0]+'A'-'a',c[0]+'A'-'a');
	cout << b+b-a << endl;
	//printf((a == 'a' || a == 'i' || a == 'u'||a=='e'||a=='o') ? "vowel\n" : "consonant\n");
}

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

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
                                           	
const int N = 3123, inf = 1e9 + 123, mod = 1e9 + 7;
const ll INF = 1e18;

int dp[N][N];

int main() {
	cin.tie(0);  	
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	s = '#' + s;
	t = '&' + t;
	for (int i = 1; i < s.size(); i++) {
		for (int j = 1; j < t.size(); j++) {
			if (s[i] == t[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int i = s.size() - 1, j = t.size() - 1;
	string ans = "";
	while (i && j) {
		if (s[i] == t[j]) {
			ans += s[i];
			i--, j--;
		} else {
			if (dp[i][j] == dp[i - 1][j]) {
				i--;
			} else {
				j--;
			}
		}
	}
	reverse(all(ans));
	cout << ans;
	return 0;
}                                               

Measured memory_bytes: 37120
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
c = Counter(s)

c = list(c.items())
c.sort(reverse=True, key=lambda x: x[1])
mx = c[0][1]

ans = []
for k, v in c:
    if v == mx:
        ans.append(k)
    else:
        break

ans.sort()
print(*ans, sep="\n")


Measured memory_bytes: 43504
package main

import (
    "fmt"
    "strconv"
    )
func main() {
   var N, M int
   fmt.Scan(&N, &M)
   
   var s, c []int
   for i:=0; i < M; i++ {
       var t1, t2 int
       fmt.Scan(&t1, &t2)
       s, c = append(s, t1), append(c, t2)
   }
   
   fmt.Println(solve(s,c,N,M))
}

func solve(s, c []int, N, M int) int {
    if !first(s,c,N,M) {
        return -1
    }
    pd := padding(N)
    
    for i:=0; i < M; i++ {
        if pd[s[i]-1] != -1 && pd[s[i]-1] != c[i] {
            return -1
        }
        pd[s[i]-1] = c[i]
    }
    
    for i, v := range pd {
        if v == -1 {
          pd[i] =0  
        }
    }
    
    if !second(pd) && N != 1 {
        pd[0] = 1
        var str string
        for i:=0; i < N; i++ {
           str += strconv.Itoa(pd[i])
        }
        re, _ := strconv.Atoi(str)
        return re
    }
    
    
    if pd[0] == 0 && N != 1 {
          pd[0] = 1 
    }
       
    
    
    var str string
    for i:=0; i < len(pd); i++ {
        str += strconv.Itoa(pd[i])
    }
    re, _ := strconv.Atoi(str)
    return re
}

func padding(N int) []int {
    return func() []int {
        var a []int
        for i:=0; i < N; i++ {
            a = append(a, -1)
        }
        return a
    }()
}

func first(s,c []int, N, M int) bool {
    for i :=0; i < M; i++ {
        if s[i] == 1 && c[i] == 0 && N != 1 {
            return false
        }
    }
    return true
}

func second(pd []int) bool {
    var ok bool 
    for _, v := range pd {
        if v != 0 {
            ok = true
        }
    }
    return ok
}

Measured memory_bytes: 512
n,d =map(int, input().split())
L=[]
for i in range(n):
    L.append(list(map(int, input().split())))
ans =0

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis += (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if dis % 1.0 ==0:
            ans +=1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [0] + [int(input()) for _ in range(n)]
pushed = [0]*(n+1)

na = a[1]
cnt = 1
pushed[na] = 1
while True:
    if na == 2:
        break
    na = a[na]
    cnt += 1
    if pushed[na] == 1:
        cnt = -1
        break
    pushed[na] = 1
print(cnt)

Measured memory_bytes: 7852
n, x, y = map(int, input().split())
array = [0]*(n-1)

for i in range(1, n+1):
    for j in range(i+2, n+1):
        array[min(j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j))-1] += 1

print(n)
for k in range(1, n-1):
    print(array[k])

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const ll mod = 1e9 + 7;


int main(){

  int h,w;cin>>h>>w;
  char s[h+10][w+10];
  rep(i,0,h){
    rep(j,0,w){
      cin>>s[i][j];
    }
  }

  rep(i,0,h){
    int c=0;
    rep(j,0,w){
      cout<<s[i][j];
      if(c==0&&j==w-1){
        j=-1;
        c++;
        cout<<endl;
      }
    }
    cout<<endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
    int a[3];
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a, a+3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
constexpr int MAX = 10000;
std::bitset<MAX> fld[MAX];
int memo[MAX];
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int W, H, K, N;
    std::cin >> W >> H >> K >> N;
    for (int i = 0, y, x; i < N; i++) { std::cin >> x >> y, fld[y - 1][x - 1] = 1; }
    const int WNUM = (W + 1) / 2;
    K -= WNUM;
    if (K < 0) { return std::cout << -1 << std::endl, 0; }
    auto ok = [&](const int y, const int x) { return fld[y][x] == 0; };
    int two = 0, ans = 0;
    for (int y = 2; y < H; y += 2) {
        std::fill(memo, memo + MAX, -1);
        auto rec = [&](auto&& self, const int x) {
            if (x == -2) { return 0; }
            if (memo[x] != -1) { return memo[x]; }
            if (x == 0) { return memo[x] = (ok(y - 1, x) ? 1 : 2); }
            return memo[x] = std::min((ok(y - 1, x - 1) ? 2 : 4) + self(self, x - 4), (ok(y - 1, x) ? 1 : 2) + self(self, x - 2));
        };
        const int score = rec(rec, W - 1);
        ans += score, two += score - WNUM;
    }
    const int t = std::min(K, two);
    ans -= 2 * t, K -= t, ans -= K;
    std::cout << std::max(0, ans) << std::endl;
    return 0;
}


Measured memory_bytes: 15772
#include<iostream>
#include<cassert>
using namespace std;

#define N 8
#define FREE -1
#define NOTFREE 1

int row[N],col[N],dpos[2 * N - 1],dneg[2 * N - 1];

bool X[N][N];

void printBoard()
{
    int i,j;

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            if(X[i][j])
            {
                if(row[i] != j) return;
            }
        }
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            cout << ((row[i] == j) ? "Q" : ".");
        }
        cout << endl;
    }
}

void recursive(int i)
{
    int j;

    if(i == N)
    {
        printBoard(); return;
    }

    for(j=0;j<N;j++)
    {
        if(NOTFREE == col[j] || 
           NOTFREE == dpos[i + j] ||
           NOTFREE == dneg[i-j + N-1]) continue;

       row[i] = j;
       col[j] = dpos[i+j] = dneg[i-j + N-1] = NOTFREE;

       recursive(i+1);

       row[i] = col[j] = dpos[i+j] = dneg[i-j + N-1] = FREE;
    }
}

int main()
{
    int i,j,k,r,c;

    for(i=0;i<N;i++)
    {
        row[i] = FREE;
        col[i] = FREE;
    }
    for(i=0;i<2*N-1;i++)
    {
        dpos[i] = FREE;
        dneg[i] = FREE;
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            X[i][j] = false;
        }
    }

    cin >> k;
    for(i=0;i<k;i++)
    {
        cin >> r >>c;
        X[r][c] = true;
    }

    recursive(0);

    return 0;

}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B + C + D == 21 && A * B * C * D == 252) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3608
//Coffee.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String s=sc.next();
        
        if(s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        sc.close();
    }
}	

Measured memory_bytes: 22996
parseInt(x) = parse(Int, x)
function parseMap(x::String)
    x = split(x)
    map(parseInt, x)
end


function main()
    w, h, x, y = readline() |> parseMap
    面積 = w * h / 2
    ans = 0
    ans = w / 2 == x && h / 2 == y ? 1 : 0
    println("$面積 $ans")

end

main()

Measured memory_bytes: 110228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  if (r < 1200)
    cout << "ABC" << endl;
  else if (r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  int n,k;
  cin >> n >> k;
  vint A(n);
  rep(i,0,n){
    cin >> A[i];
    A[i]--;
  }
  vint dist;
  vbool judge(n);
  int now = 0;
  while(1){
    if(!judge[now]){
      judge[now] = true;
      dist.push_back(now);
    }
    else{
      break;
    }
    now = A[now];
  }
  int key = 0;
  rep(i,0,dist.size()){
    if(dist[i] == now){
      key = i;
      break;
    }
  }
  int roop = dist.size()-key;
  // rep(i,0,dist.size()) cout << dist[i] << endl;
  // cout << key << roop << endl;
  if(k < dist.size()){
    cout << dist[k] + 1<< endl;
  }
  else{
    k -= key;
    k %= roop;
    cout << dist[key+k] + 1 << endl;
  }
}

Measured memory_bytes: 6892
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
u=max(max(lis),k)
memo=0
for i in range(45):
    x=(u>>i)%2
    if x==1:
        memo=i
memo+=1
#print(memo)
table=[0 for i in range(memo)]
for i in range(n):
    for j in range(memo):
        x=(lis[i]>>j)%2
        if x==1:
            table[j]+=1
#print(table)
table2=[[0,0] for i in range(memo)]
for i in range(memo):
    table2[i][0]=abs(n-2*table[i])*2**i
    table2[i][1]=i+1
    if n-2*table[i]<0:
        table2[i][1]*=(-1)
#print(table2)
table2.sort(reverse=True)
#print(table2)
#print(sorted(table2,reverse=True))
maxx=0
ans_table=[0 for i in range(memo)]
for i in range(memo):
    if table2[i][1]>0:
        maxx+=2**(table2[i][1]-1)
        if maxx<=k:
            ans_table[table2[i][1]-1]=1
        else:
            ans_table[table2[i][1]-1]=0
            maxx-=2**(table2[i][1]-1)
    else:
        ans_table[abs(table2[i][1])-1]=0
#print(ans_table)
ans=0
for i in range(memo):
    if ans_table[i]==1:
        ans+=(2**i)*(n-table[i])
    else:
        ans+=(2**i)*table[i]
print(ans)

Measured memory_bytes: 20784
// compile option: g++ -std=c++11
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> pos[26];
  REP(i, s.size()) pos[s[i] - 'a'].push_back(i);
  int last = -1;
  ll ans = 0;
  REP(i, t.size()) {
    if (pos[t[i] - 'a'].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto it = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), last);
    if (it == pos[t[i] - 'a'].end()) {
      ans += s.size();
      last = -1;
      it = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), last);
    }
    last = *it;
  }
  cout << ans + last + 1 << endl;
  return 0;
}

Measured memory_bytes: 1216
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	ll n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n) {
		cnt++;
		n/=k;
	}
	cout << cnt;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int a[100010];
int main(){ _;
  int n;cin>>n;
  REP(i,n)cin>>a[i];
  bool loop=true;
  int j=0;
  while(loop){
    loop=false;
    sort(a,a+n);
    for(;a[j]==0;j++){}
    for(int i=j+1;i<n;i++){
      a[i]%=a[j];
      if(a[i]!=0)loop=true;
    }
  }
  cout<<a[j]<<endl;
}


Measured memory_bytes: 640
// hhttps://atcoder.jp/contests/apg4b/tasks/APG4b_ca
// g++ -std=c++11 ex22.cpp && ./a.out
#include <vector>
#include <tuple>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdio>

using namespace std;

int main()
{
    int N, R;
    cin >> N;
    cin >> R;

    // int internal;
    // R = (N >= 10) ? internal : internal - 100 * (10 - N);

    if (N >= 10)
    {
        cout << R << endl;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}

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

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    for(int i = a; i <= min(b,a+k-1); i++){
        cout << i << endl;
    }
    for(int i = max(a+k,b-k+1); i <= b; i++){
        cout << i << endl;
    }
}

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

using namespace std;

int main(int argc,char* argv[]){
  string S;
  long countf=0,counta=0;
  cin >> S;
  for(int i=0;i<S.length();i++){
    if(i%2==0){
      if(S[i]=='0') counta++;
      else countf++;
    }else{
      if(S[i]=='1') counta++;
      else countf++;
    }
  }

  cout << min(counta,countf) << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){

  int color[9] = {0};
  int n;
  int min = 0;
  int max = 0;
  scanf("%d",&n);

  int a;
  for(int i = 0; i < n ; ++i){
    scanf("%d",&a);
    if(a <= 399) color[0] = 1;
    else if(a <= 799) color[1] = 1;
    else if(a <= 1199) color[2] = 1;
    else if(a <= 1599) color[3] = 1;
    else if(a <= 1999) color[4] = 1;
    else if(a <= 2399) color[5] = 1;
    else if(a <= 2799) color[6] = 1;
    else if(a <= 3199) color[7] = 1;
    else color[8] += 1;
  }
  for(int i = 0; i < 8 ; ++i){
    min += color[i];
  }

  if(min == 0){
    min = 1;
    max = color[8];
  }else{
    max = min + color[8];
  }

  printf("%d %d", min, max);
  return 0;

}


Measured memory_bytes: 128
N = int(input())
hlis = list(map(int, input().split()))
dp = [-1]*N
dp[0] = 0
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(hlis[i]-hlis[i-1]), dp[i-2]+abs(hlis[i]-hlis[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

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

    dp = []
    for i, h in enumerate(hs):
        if i == 0:
            dp.append(0)
            continue

        max_num = min([len(dp), K])
        cost = min([dp[i-k-1] + abs(hs[i] - hs[i-k-1])
                    for k in range(max_num)])
        dp.append(cost)

    print(dp[-1])


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    vector<int> h;

    cin >> n;
    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        h.push_back(tmp);
    }

    int cnt = 1;
    for(int i = 1; i < h.size(); i++) {
        bool flg = true;
        for(int j = 0; j < i; j++) {
            if(h[j] > h[i]) {
                flg = false;
            }
        }
        if(flg) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  int S = findSumOfDigits(N); 
  if(N % S == 0) cout << "Yes" << endl; 
  else cout << "No" << endl; 
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())

mn = min(n, m)
S = set()
A = []
sum_9 = 0 # sum of pre + cycle

for _ in range(mn):
    if x in S: break
    S.add(x)
    A.append(x)
    sum_9 += x
    x = x*x % m

if len(A) >= mn:
    print(sum_9)
    exit()

pre_len = A.index(x)
cyc_len = len(A) - pre_len
nxt_len = (n - pre_len) % cyc_len

cyc_num = (n - pre_len) // cyc_len

pre = sum(A[:pre_len])
cyc = sum_9 - pre
nxt = sum(A[pre_len: pre_len + nxt_len])

print(pre + cyc * cyc_num + nxt)


Measured memory_bytes: 12964
def main():
    while True:
        H, W = tuple(map(int, input().split()))

        if (H, W) == (0, 0):
            break
        else:
            for i in range(H):
                chessrow = ""
                for j in range(W):
                    chessrow += "#" if (i+j)%2==0 else "."
                print(chessrow)
            print()

if __name__ == '__main__':
    main()



Measured memory_bytes: 5620
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

char c;
char bo[5] = {'a', 'i', 'u', 'e', 'o'};

int main() {
  cin >> c;
  bool isin = false;
  for (int i = 0; i < 5; ++i) if (c == bo[i]) isin = true;
  if (isin) puts("vowel");
  else puts("consonant");
}


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

using namespace std;

typedef long long ll;
const int maxn = 1e5+500;
const int mod = 1e9+7;
int dp[maxn][13];
int main()
{
	string s;
	cin>>s;
	dp[0][0]=1;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<=12;j++){
			if(s[i]!='?'){
				(dp[i+1][((s[i]-'0')+j*10)%13]+=dp[i][j])%=mod;
			}else{
				for(int k=0;k<=9;k++)
					(dp[i+1][(k+j*10)%13]+=dp[i][j])%=mod;
			}
		}
	}
	cout<<dp[s.size()][5]<<endl;
}


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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 3000006;
ll t, n, m, k, q, a, b, x, y, ans, arr[N];
ll mod = 998244353;
string s;
bool vis[N];

bool isPrime[N];
vector<ll> primes;

void sieveAtkin() {
	int root = ceil(sqrt(N));
	for (int i = 1; i <= root; ++i) {
		for (int j = 1; j <= root; ++j) {
			int n = (4 * i * i) + (j * j);
			if (n <= N && (n % 12 == 1 || n % 12 == 5))
				isPrime[n] ^= true;
			n = (3 * i * i) + (j * j);
			if (n <= N && n % 12 == 7)
				isPrime[n] ^= true;
			n = (3 * i * i) - (j * j);
			if (i > j && n <= N && n % 12 == 11)
				isPrime[n] ^= true;
		}
	}
	for (int i = 5; i <= root; ++i)
		if (isPrime[i])
			for (int j = i * i; j < N; j += i * i)
				isPrime[j] = false;
	primes.push_back(2ll);
	primes.push_back(3ll);
	for (int i = 5; i < N; ++i) {
		if (isPrime[i])
			primes.push_back(1ll * i);
	}
}

ll get(ll x) {
    ll cur = 0;
    for (int i = 1; i < 100; ++i) {
        cur += i;
        if (cur > x)
            return i - 1;
    }
    return -1;
}

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        sieveAtkin();
        cin >> n;
        for (int i = 0; i < primes.size(); ++i) {
            if (n % primes[i])
                continue;
            int cur = 0;
            while (n % primes[i] == 0)
                ++cur, n /= primes[i];
            ans += get(cur);
        }
        if (n != 1)
            ++ans;
        cout << ans << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


Measured memory_bytes: 8240
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


typedef vector<pair<int, string> > pisv;
string ans;

bool rec(pisv  n)
{
	if(n.size() == 1)
	{
		if(n[0].first == 10)
			ans = n[0].second;

		return n[0].first == 10;
	}

	bool res = false;
	pisv a;

	rep(i, n.size()-1)
	{
		// +
		{
			pisv aa = a;
			aa.push_back(mp(n[i].first + n[i+1].first, "(" + n[i].second + " + " + n[i+1].second + ")"));
			REP(j, i+2, n.size())
				aa.push_back(n[j]);

			res = res || rec(aa);
		}

		// -
		{
			pisv aa = a;
			aa.push_back(mp(n[i].first - n[i+1].first, "(" + n[i].second + " - " + n[i+1].second + ")"));
			REP(j, i+2, n.size())
				aa.push_back(n[j]);

			res = res || rec(aa);
		}
		
		// *
		{
			pisv aa = a;
			aa.push_back(mp(n[i].first * n[i+1].first, "(" + n[i].second + " * " + n[i+1].second + ")"));
			REP(j, i+2, n.size())
				aa.push_back(n[j]);

			res = res || rec(aa);
		}

		a.push_back(n[i]);
	}

	return res;
}


int main()
{
	pisv v(4);

	while(cin >> v[0].first && v[0].first)
	{
		rep(i, 3)
			cin >> v[i+1].first;

		rep(i, 4)
			v[i].second = v[i].first + '0';

		bool res = false;
		
		sort(ALL(v));

		do	res = res || rec(v);
		while(next_permutation(ALL(v)));

		cout << (res ? ans : "0") << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

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

    int n = 50;

    cout << n << endl;
    for (int i = 0; i < n; i++) {
        if (k == 0) {
            cout << (i == 0 ? "" : " ") << i;
        } else if (i <= (k - 1) % n) {
            cout << (i == 0 ? "" : " ") << i - (k - 1) % n + n + (k - 1) / n;
        } else {
            cout << (i == 0 ? "" : " ") << i - (k - 1) % n - 1 + (k - 1) / n;
        }
    }
    cout << endl;
}


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

using namespace std;

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

    long long a, b;
    cin >> a >> b;
    if (a == 1 || b == 1) {
        cout << 1 << endl;
        return 0;
    }
    cout << (a*b+1)/2 << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
    a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
    b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0
num = m

for i in range(n+1):
    
    if a_sum[i] > k:
        break
    while (k - a_sum[i]) < b_sum[num]:
        num -=1
        #print(i, num)
        if num == -1:
            break
    total = max(i+num, total)
    
    
print(total)

Measured memory_bytes: 60444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
 
int main() {
  //int n, i, j, c, a, b, d, e, f, suma=0, sum;
  //cin >> n;
  string s;
  //vector<int> A(n);
  //for(i=0; i<n; i++) cin >> A[i];
  cin >> s;
  int t = 0, i, n;
  if(s == "hi") cout << "Yes" << endl;
  else if(s == "hihi") cout << "Yes" << endl;
  else if(s == "hihihi") cout << "Yes" << endl;
  else if(s == "hihihihi") cout << "Yes" << endl;
  else if(s == "hihihihihi") cout << "Yes" << endl;
  
    
    
  
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
const int N = 1 << 20;
const int MOD = 1e9 + 7;
typedef long long int ll;
priority_queue< pair< int, int > > pq;
vector< pair<int,int> >vp;
#define f(a, n) for(int i = a; i  < n ; i++) 
//#define endl "\n" 
//#define sort(v) sort(v.begin() , v.end())
#define print(v) for(int i = 0 ; i < v.size() ; i++) cout << v[i] << ' '  
map< int, int > mp, mpp;
vector< int>v;
int visit[N] ;
//push_back
//insert 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main () 
{ 
    char ch ; 
    cin >> ch ; 
    if(ch >= 'A' and ch <= 'Z') cout << 'A' ;
    else cout << 'a' ; 
    
}
/*






*/


Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int countKeyword(vector<int>* x, vector<int>* oi) {
	int count = 0;
	for (int i = 0; i < x->size(); i++) {
		std::vector<int>::iterator iter = std::find(oi->begin() , oi->end(), x->at(i) + 1);
		if (iter != oi->end()) count++;
	}
	return count;
}

void calc(const char* str) {
	vector<int> posI;
	vector<int> posJ;
	vector<int> posOI;

	for (int i = 0; str[i] != '\0'; i++) {
		if (str[i] == 'J') {
			posJ.push_back(i);
		} else if (str[i] == 'O' && str[i+1] == 'I') {
			posOI.push_back(i);
		} else if (str[i] == 'I') {
			posI.push_back(i);
		}
	}
	
	cout << countKeyword(&posJ, &posOI) << endl;
	cout << countKeyword(&posI, &posOI) << endl;
}

int main()
{
	vector<string> strList;
	char x[10000];
	while (cin >> x) {
		strList.push_back(x);
	}

	for (int i = 0; i < strList.size(); i++) {
		calc(strList[i].c_str());
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int ans=1;
    for(int i=1;i<=x;i++){
        for(int j=2;j<6;j++){
            int a=(int)pow(i,j);
            if(a<=x){
                ans=max(ans,a);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
    char s[2];

    scanf("%s", s);

    if(s[0]=='A') printf("%c\n", 'T');
    else if(s[0]=='T') printf("%c\n", 'A');
    else if(s[0]=='G') printf("%c\n", 'C');
    else if(s[0]=='C') printf("%c\n", 'G');

    

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int m,d,ans=0;
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			if(j>9&&j<100){
			    int a,b;
				a=j/10;
				b=j%10;
			    if(a*b==i&&a>1&&b>1){
					ans++;
				}	
			}
		}	
	} 
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from itertools import accumulate

MOD = 10**9 + 7

N = int(input())
A = [0] + list(map(int, input().split()))
C = list(accumulate(A))

ans = 0
for i in range(1, N):
    ans += A[i] * (C[-1] - C[i])

ans %= MOD
print(ans)


Measured memory_bytes: 29312
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
}
  
LL MOD = 998244353;

LL fact[300005];

LL comb(LL n, LL k) {
    LL ret = fact[n];
    ret *= Number::mod_inv(fact[k], MOD);
    ret %= MOD;
    ret *= Number::mod_inv(fact[n - k], MOD);
    ret %= MOD;
    return ret;
}

int main() {
    LL n, a, b, k;
    cin >> n >> a >> b >> k;
    fact[0] = 1;
    for (LL i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    LL ans = 0;
    for (LL x = 0; x <= n && k - x*a >= 0; x++) {
        if ((k - x * a) % b == 0) {
            LL y = (k - x * a) / b;
            if (y > n) {
                continue;
            }
            ans += (comb(n, x) * comb(n, y) % MOD);
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5916