akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll dsum(ll n) {
  ll ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

double g(ll n) {
  return (double)(n) / dsum(n);
}

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

  vector<ll> res;
  ll base = 1;
  for (int i = 0; i < 15; i++) {
    for (int j = 1; j < 150; j++) {
      res.push_back(base * (j + 1) - 1);
    }
    base *= 10;
  }
  sort(res.begin(), res.end());
  res.erase(unique(res.begin(), res.end()), res.end());

  for (ll i = 0; i < res.size(); i++) {
    for (ll j = i + 1; j < res.size(); j++) {
      if (g(res[i]) > g(res[j])) {
        res.erase(res.begin() + i--);
        break;
      }
    }
  }

  for (ll i = 0; i < K; i++)
    cout << res[i] << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;

int main() {
   long long int N, K;
   cin >> N >> K;
   long long int yakusu = N/K;
   long long int ans = 0;
   if (K%2 == 0) {
      long long int yakusu2 = (N + K/2)/K;
      ans += yakusu2 * yakusu2 * yakusu2;
   } 
   ans += yakusu * yakusu * yakusu;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())

    def num_divisors_table(n):
        table = [0] * (n + 1)

        ans = 0
        for i in range(1, n + 1):
            for j in range(i, n + 1, i):
                table[j] += 1
            ans += table[i] * i
        return ans

    ans = num_divisors_table(N)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 146008
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int l, r, d;
    int count = 0;
    scanf("%d%d%d", &l, &r, &d);
    for (int i = l; i <= r; i++) {
        if (i % d == 0) {
            count++;
        }
    }
    printf("%d \n", count);
    return 0;
}

Measured memory_bytes: 1716
#
import sys
import math
import numpy as np
import itertools

n = int(input())

def factorialization(n):
    a = []
    t = n
    for i in range(2,int(math.sqrt(n))+1):
        if t%i == 0:
            e = 0
            while t%i ==0:
                e += 1
                t = t // i
            a.append([i,e])
    if t > 1:
        a.append([t,1])
    return a

p = factorialization(n)
#print(p)
answer = 0
for i in p:
    k = i[1]
    x = 1
    while k > 0:
        x += 1
        answer += 1
        k -= x
print(answer)



Measured memory_bytes: 27136
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	public static int H,W;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		int SIZE = 55;
		int table[][] = new int[SIZE][SIZE];
		int diff_row[] = {-1,-1,-1,0,0,1,1,1};
		int diff_col[] = {-1,0,1,-1,1,-1,0,1};

		StringBuilder ans = new StringBuilder();

		Queue<Info> Q = new ArrayDeque<Info>();

		while(true){

			W = scanner.nextInt();
			H = scanner.nextInt();

			if(W == 0 && H == 0)break;

			for(int row = 0; row < H; row++){
				for(int col = 0; col < W; col++){

					table[row][col] = scanner.nextInt();
				}
			}

			int num_island = 0;

			for(int row = 0; row < H; row++){
				for(int col = 0; col < W; col++){
					if(table[row][col] == 0)continue;

					num_island++;
					table[row][col] = 0;

					Q.add(new Info(row,col));

					while(!Q.isEmpty()){

						for(int i = 0; i < 8; i++){

							int adj_row = Q.peek().row+diff_row[i];
							int adj_col = Q.peek().col+diff_col[i];

							if(rangeCheck(adj_row,adj_col) == false || table[adj_row][adj_col] == 0)continue;

							table[adj_row][adj_col] = 0;
							Q.add(new Info(adj_row,adj_col));
						}
						Q.poll();
					}
				}
			}
			ans.append(Integer.toString(num_island)).append("\n");
		}
		System.out.print(ans.toString());
	}

	public static boolean rangeCheck(int row,int col){

		return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
	}
}

class Info{

	public int row;
	public int col;

	Info(int arg_row,int arg_col){

		row = arg_row;
		col = arg_col;
	}
}


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

int main() {
    string S;
    cin >> S;

    char odd, even;
    even = S[0];
    odd = even == '1' ? '0' : '1';

    int l, m;
    l = S.length();
    m = 0;

    for (int i = 1; i < l; i++) {
        if (i % 2 == 1) {
            if (S[i] != odd) m ++;
        } else {
            if (S[i] != even) m ++;
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 512
x = int(input())
n = x//100 + 1
 
for i in range(n):
  for j in range(n):
     for k in range(n):
         for l in range(n):
             for m in range(n):
                 c = 100*i + 101*j + 102*k + 103*l + 104*m
                 if x >= c:
                    t = x-c
                
                    if t%105 == 0:
                        print(1)
                        exit()
                    
print(0)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToString();
            var counter = 0;
            foreach (var item in s)
            {
                if(counter %2 == 0)
                {
                    Console.Write(item);

                }
                counter++;
            }

        }
    }
}

Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const string NAME = "dp_g";
const int N = 101010;
typedef pair<int, int> ii;
int n, m;
vector<int> G[N], topo, vis;

void dfs(int u)
{
    vis[u] = 1;
    for (auto v : G[u])
        if (vis[v] == 0)
            dfs(v);
    topo.push_back(u);
}

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        G[u].emplace_back(v);
    }
    //toposort: luu danh sach dinh da sap xep vao vector topo
    //u xep truoc v trong topo neu co canh v --> u
    vis.resize(n + 1, 0);
    for (int i = 1; i <= n; i++)
        if (vis[i] == 0)
            dfs(i);
    //dp[i] la do dai duong di bat dau tai dinh i
    vector<int> dp(n + 1, 0);
    for (int i = 1; i < n; i++)
    {
        int u = topo[i];
        for (auto v : G[u])
            dp[u] = max(dp[u], dp[v] + 1);
    }
    cout << *max_element(dp.begin(), dp.end());
    return 0;
}

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  rep(i, n) cin >> x.at(i);
  vector<int> y(m);
  rep(i, m) cin >> y.at(i);
  mint xs = 0, ys = 0;
  rep(i, n){
    xs += (ll)x.at(i) * (i - (n-i-1));
  }
  rep(i, m){
    ys += (ll)y.at(i) * (i - (m-i-1));
  }
  cerr << xs.x << " " << ys.x << endl;
  mint ans = xs * ys;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b; cin >> a >> b;
    if(a < b) cout << "a < b";
    if(a > b) cout << "a > b";
    if(a == b) cout << "a == b";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int n,m;
	cin >> n >> m;
	int ans = (n-m)*100+m*1900;
	for(int i=0; i<m; i++)ans*=2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int b[1000];
int c[1000];
int d[1000];
int e[1000];
int main(){
    int a;
    while(scanf("%d",&a),a){
        for(int i=0;i<a;i++)scanf("%d%d%d%d",b+i,c+i,d+i,e+i);
        int p,q,r,s;
        scanf("%d%d%d%d",&p,&q,&r,&s);
        bool ok=false;
        for(int i=0;i<a;i++){
            if(c[i]<=p&&d[i]<=q&&e[i]<=r&&4*c[i]+9*d[i]+4*e[i]<=s){
                ok=true;
                printf("%d\n",b[i]);
            }
        }
        if(!ok)printf("NA\n");
    }
}

Measured memory_bytes: 3192
N = int(input())

def search_ans(max,min):
    if max - min <= 4:
        for i in range(min,max+1):
            if (1+i)*i/2 >= N: #n問目まで全てOKだったときの合計得点… (1+n)*n/2 
                return i
                
    else:
        mid = int((max+min)//2)

        if (1+mid)*mid/2 < N:
            min = mid
        else:
            max = mid
            
        return search_ans(max,min)
    
ans_max = search_ans(N,1) #最大値を探す

for i in range(ans_max,0,-1):
    if N - i >= 0:
        print(i)
        N -= i

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

using namespace std;

const int N = 12;
int dp[N][10];

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

  fill(dp[1], dp[1] + 10, 1);
  for (int i = 1; i < N - 1; ++i) {
    for (int j = 0; j <= 9; ++j) {
      for (int k = j - 1; k <= j + 1; ++k) {
        if (0 <= k and k <= 9) {
          dp[i + 1][k] += dp[i][j];
        }
      }
    }
  }
  int tot = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      tot += dp[i][j];
    }
  }
  //cout << tot << endl;
  int k;
  cin >> k;
  for (int i = 1; i < N; ++i) {
    int cur = 0;
    for (int j = 1; j < 10; ++j) {
      cur += dp[i][j];
    }
    if (cur >= k) {
      for (int j = 1; j < 10; ++j) {
        if (dp[i][j] < k) {
          k -= dp[i][j];
        } else {
          string ans;
          ans += j + '0';
          int lst = j;
          for (--i; i >= 1; --i) {
            for (j = lst - 1; j <= lst + 1; ++j) {
              if (j < 0 or j > 9) {
                continue;
              }
              if (dp[i][j] < k) {
                k -= dp[i][j];
              } else {
                lst = j;
                ans += j + '0';
                break;
              }
            }
          }
          //reverse(ans.begin(), ans.end());
          cout << ans;
          return 0;
        }
      }
    } else {
      k -= cur;
    }
  }
  assert(false);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

ll N, Q;
string S;
vector<ll> K;

void input() {
    cin >> N >> S >> Q;
    K.resize(Q);
    for (auto &v : K)
        cin >> v;
}

void solve() {
    
    for (auto k : K) {
        ll cD = 0;
        ll cM = 0;
        ll cDM = 0;
        ll count = 0;
        for (int i = 0; i < N; i++) {
            auto r = S[i];
            if (r == 'D') {
                cD++;
            } else if (r == 'M') {
                cM++;
                cDM += cD;
            } else if (r == 'C') {
                count += cDM;
            }
            if (i - k + 1 >= 0) {
                auto l = S[i - k + 1];
                if (l == 'D') {
                    cD--;
                    cDM -= cM;
                } else if (l == 'M') {
                    cM--;
                }
            }
        }
        cout << count << endl;
    }
}


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



Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int b=s.size();
  int d=1;
  for(int i=0;i<b;i++)
  {
  if(s.at(i)=='L' && i%2==0) d=0;
    if(s.at(i)=='R' && i%2==1) d=0;
  }  
  if(d==0)  cout<<"No";
  else if(d==1) cout<<"Yes";
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
struct UnionFind {
	vector<int> par;
	UnionFind(int N) : par(N) { rep(i, 0, N)par[i] = i;}
	int root(int x) { return par[x] == x ? x : par[x] = root(par[x]);}
	void unite(int x, int y) {if (!same(x, y)) par[root(x)] = root(y); }
	bool same(int x, int y) {return root(x) == root(y);}
};
int main()
{
	int H, W;
	ll ans = 0;
	cin >> H >> W;
	vector<string> S(H);
	UnionFind tree(W * H);
	rep(i, 0, H)cin >> S[i];
	rep(i, 0, H) {
		rep(i2, 0, W) {
			if (i != H - 1 && S[i][i2] != S[i + 1][i2]) {
				tree.unite(i * W + i2, i * W + W + i2);
			}
			if (i2 != W - 1 && S[i][i2] != S[i][i2 + 1]) {
				tree.unite(i * W + i2, i * W + 1 + i2);
			}
		}
	}
	map<int, pair<int, int>>mp;
	rep(i, 0, H * W) {
		if(S[i / W][i % W] == '#')mp[tree.root(i)].first++;
		else mp[tree.root(i)].second++;
	}
	for (auto m : mp) {
		ans += (ll)m.second.first * m.second.second;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 12592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>


int main()
{
    long N,R;
    std::cin >> N >> R;
    if(N<10){
        std::cout << R+100*(10-N) << std::endl;
    }else{
        std::cout << R << std::endl;
    }
    return 0;
}

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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

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

    int a, cnt = 0;
    rep(0, n) {
        cin >> a;

        if (a % 2 == 0) {
            if (a % 3 == 0 || a % 5 == 0) cnt++;
        } else {
            cnt++;
        }
    }

    cout << (cnt == n ? "APPROVED" : "DENIED") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] nums = br.readLine().split(" ");
		int a = Integer.parseInt(nums[0]);
		int b = Integer.parseInt(nums[1]);

		System.out.println(a < 9 && b < 9 ? "Yay!" : ":(");

	}

}


Measured memory_bytes: 21204
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 30;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int f[1000][2000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int x;
    cin >> x;
    cout << !x << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>


int main (void){
 
 int h=-1 , w=-1 , i , j;
 
 while(1){
     
     scanf("%d %d", &h, &w);
     if(h + w == 0) break;
     
     for(i=0; i < h; i++){
         
        if(i % 2 ==0){
            if(w % 2 == 0){ 
                for(j=0; j < w/2; j++){
                    printf("#."); 
                }
                puts("");
            }else{
                for(j=0; j < w/2; j++){
                    printf("#.");
                }
                printf("#");
                puts("");
            }
        }else{
            if(w % 2 == 0){ 
                for(j=0; j < w/2; j++){
                    printf(".#"); 
                }
                puts("");
            }else{
                for(j=0; j < w/2; j++){
                    printf(".#");
                }
                printf(".");
                puts("");
            }            
            
            
            
            
            
            
            
        }
        
        
        
     }
     
     puts("");
 }
 return 0;
 
}

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

using namespace std;

int64_t m = 2019;

int main()
{
    int64_t l,r;
    cin>>l>>r;
    if(l==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    int64_t gap= r - l + 1 ;

    if(gap>=2019)
    {
        cout<<"0"<<endl;
        return 0;
    }
    else
    {
        int64_t ans=0x3f3f3f3f;
        for(int64_t i=l;i<=r;i++)
        {
            for(int64_t j=i+1;j<=r;j++)
            {
               ans=min(ans,i*j%2019);
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	list := []int{a, b, c}
	sort.Sort(sort.IntSlice(list))

	diff := 0
	if a%2 == 0 || b%2 == 0 || c%2 == 0 {
		diff = 0
	} else {
		diff = list[0]*list[1]*(list[2]/2+1) - list[0]*list[1]*(list[2]/2)
	}
	fmt.Println(diff)

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
    int a, b , c;
    cin>>a>>b>>c;
    int t;
    t=b;
    b=a;
    a=t;
    t=a;
    a=c;
    c=t;
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 256
h,w,k = list(map(int, input().split()))
masu = [input() for _ in range(h)]
ans = 0

def count_num(m, target, goal):
    for i in range(h):
        count = sum(map(lambda x: x.count(target), m))
    
    return count == goal

def change_row(m, i_row_0):
    m[i_row_0] = 'r'*w    
    return m

def change_col(m, j_col_0):
    for i in range(h):
        if j_col_0 < w:
            m[i] = m[i][:j_col_0]+'r'+ m[i][j_col_0+1:]
    return m




for idx_h in range(2**h):
    for idx_w in range(2**w):
        m = masu.copy()
        for i_row, row in enumerate(m):
            if idx_h & (2 ** i_row) > 0:
                m = change_row(m, i_row)

            for j_col, col in enumerate(row):
                if idx_w & (2 ** j_col) > 0:
                    m = change_col(m, j_col)
        
        #print(m)
        if count_num(m, '#', k):
            ans += 1
        
print(ans)

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

using namespace std;

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
string s, t;
int z[6 * N];
vector<int> g[N];
int dp[N], state[N];

bool read() {
    if (!(cin >> s >> t))
        return false;

    return true;
}

bool dfs(int v) {
    state[v] = 1;

    for (auto to : g[v]) {
        if (state[to] == 0) {
            if (!dfs(to))
                return false;
        } else if (state[to] == 1) {
            return false;
        }

        dp[v] = max(dp[v], dp[to] + 1);
    }

    state[v] = 2;
    return true;
}

void solve() {
    n = s.size();
    m = t.size();

    for (t += "#"; t.size() - m - 1 <= n + m; t += s) { }
    swap(t, s);

    for (int i = 1, l = 0, r = -1; i < m + n + n; ++i) {
        for (z[i] = i < r ? min(z[i - l], r - i) : 0; i + z[i] < s.size() && s[z[i]] == s[i + z[i]]; ++z[i])
            if (i + z[i] > r)
                l = i, r = i + z[i];

        if (i > m && i <= m + n && z[i] == m)
            g[i - m - 1].emplace_back((i - 1) % n);
    }

    auto flag = 1;

    for (int i = 0; i < n; ++i)
        if (state[i] == 0)
            flag &= dfs(i);

    if (!flag)
        cout << "-1\n";
    else
        cout << *max_element(dp, dp + n) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 64220
using System;
using System.Collections.Generic;
using System.Linq;

namespace _523_CardGame
{
	class Program
	{
		static void Main ( string[] args )
		{
			while (true)
			{
				//input
				int cardCount = int.Parse (Console.ReadLine ());

				if (cardCount == 0)
				{
					break;
				}

				List<int> playerCardList = new List<int> (cardCount);
				List<int> enemyCardList = new List<int> (cardCount);

				for (int lp = 0; lp < cardCount; lp++)
				{
					int item = int.Parse (Console.ReadLine ());
					playerCardList.Add (item);
				}

				IEnumerable<int> array = Enumerable.Range (1, cardCount * 2).Except (playerCardList);
				enemyCardList.AddRange (array);

				//process
				playerCardList.Sort ();
				enemyCardList.Sort ();

				var turnPlayer = playerCardList;
				int fieldCard = 0;

				while (playerCardList.Count != 0 && enemyCardList.Count != 0)
				{
					//??????????????¢?´¢??????
					bool existCard = true;
					int index = 0;
					while (turnPlayer[index] < fieldCard)
					{
						index++;
						if (turnPlayer.Count <= index)
						{
							existCard = false;
							break;
						}
					}

					//???????????????????????´???
					if (existCard)
					{
						//??????????????????????????£??????????????°????????´??°??????
						fieldCard = turnPlayer[index];
						turnPlayer.RemoveAt (index);
					}
					//??????????????????????????´???
					else
					{
						//??????
						//nothing

						//?????£??????????????°??????0?????????
						fieldCard = 0;
					}

					//??????????????????????§????
					if (turnPlayer == playerCardList)
					{
						turnPlayer = enemyCardList;
					}
					else
					{
						turnPlayer = playerCardList;
					}
				}

				//output
				Console.WriteLine (enemyCardList.Count);
				Console.WriteLine (playerCardList.Count);
			}
		}
	}
}

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

using namespace std;

int main(){
  int n, l;
  cin >> n >> l;
  int tot = 0, mn = INT_MAX, vl;
  for(int i = 1; i <= n; i++){
    tot += (l+i-1);
    if( abs(l+i-1) < mn )
      mn = abs(l+i-1), vl = l+i-1;
  }
  tot -= vl;
  cout << tot << endl;
  return 0;
}

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

const int maxn = 2000 + 7;

int n, k;
vector<int> e[maxn];

int dfs(int u, int pre, int d, int limit) {
    int rt = 0;
    if (d > limit) rt++;
    for (auto &v : e[u])
        if (v != pre) rt += dfs(v, u, d + 1, limit);
    return rt;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int ans = n;
    for (int i = 1; i <= n; i++) {
        ans = min(ans, dfs(i, -1, 0, k / 2));
    }
    for (int i = 1; i <= n; i++) {
        for (auto &v : e[i]) {
            if (v > i) continue;
            ans = min(ans, 
                dfs(i, v, 0, (k - 1) / 2) + dfs(v, i, 0, (k - 1) / 2));
        }
    }
    cout << ans << endl;
    return 0;
}

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

ans = 0
for i in range(N):
  cnt = 0
  l = list(set(S[:i]))
  r = list(set(S[i:]))
  for ll in l:
    if(ll in r):
      cnt += 1
  ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    var min = Int.MAX_VALUE
    var ans = 0
    repeat (N) { i ->
        if (min > A[i]) min = A[i]
        if (A[i] == min) ans += 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 82568
#include <iostream>
#define MAX 10000
using namespace std;

int main() 
{
    int n;
    unsigned short *A, *B;
    int C[MAX+1];
    cin >> n;
    A = new unsigned short[n];
    B = new unsigned short[n];
    for (int i = 0; i <= MAX; ++i) C[i] = 0;
    for (int i = 0; i < n; ++i) 
    {
        B[i] = 0;
        cin >> A[i];
        C[A[i]] ++;
    }
    for (int i = 1; i <= MAX; ++i) C[i] = C[i] + C[i-1];
    for (int i = n-1; i >= 0; --i) 
    {
        B[--C[A[i]]] = A[i];
    }
    for (int i = 0; i < n; ++i) 
    {
        if (i) cout << " ";
        cout << B[i];
    }
    cout << endl;
}


Measured memory_bytes: 10860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll N, K;
	cin >> N >> K;
	
	N %= K;
	
	cout << min(N, K - N) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from math import factorial

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    X = [int(i) for i in input().split()]
    MOD = 10**9 + 7
    ans = 1
    stack = 0

    for x in X:
        stack += 1
        if x < 2*(stack - 1) + 1:
            ans *= stack
            ans %= MOD
            stack -= 1

    ans *= (factorial(stack) % MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 14180
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  [a, b] <- readString
  putStrLn $ f a b


f a b | a == "H"             = b
      | a == "D" && b == "H" = "D"
      | otherwise            = "H"


Measured memory_bytes: 380
from collections import deque
S = input()
Q = int(input())
 
alpha_map = {chr(i):i for i in range(97,123)}
alpha_map_inv = {i:chr(i) for i in range(97,123)}
a = deque()
for s in S:
  a.append(s)
reversed = False
 
for _ in range(Q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    if reversed:
      reversed = False
    else:
      reversed = True
  else:
    if (query[1] == '1')&(not reversed):
      a.appendleft(query[2])
    elif (query[1] == '2')&(reversed):
      a.appendleft(query[2])
    else:
      a.append(query[2])
if reversed:
  a.reverse()
print(''.join(list(a)))

Measured memory_bytes: 8692
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    D,G = readInts()
    P = []
    C = []
    res = float('inf')
    for i in range(D):
        p,c = readInts()
        P.append(p)
        C.append(c)
    # bit全探索
    for bit in range(1 << D):
        SUM = 0
        NUM = 0
        for i in range(D):
            if bit & (1 << i):
                SUM += P[i]*(1+i)*100 + C[i]
                NUM += P[i]
        if SUM >= G:
            res = min(res,NUM)
        else:
            for i in range(D-1,-1,-1):
                if bit & (1 << i):
                    continue
                else:
                    for j in range(P[i]):
                        if SUM >= G:
                            break
                        SUM += 100*(i+1)
                        NUM += 1
            #print(NUM)
            res = min(res,NUM)
    print(res)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string A,B,C;
  cin >> A >> B >> C;
  if(A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)==C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO"  << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int ans;
  ans = r/d - (l-1)/d;
  cout << ans << endl;
}

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

int toNum(string s){
    int time = 0;
    time += (s[0] - '0') * 10 * 3600;
    time += (s[1] - '0') * 3600;
    time += (s[3] - '0') * 10 * 60;
    time += (s[4] - '0') * 60;
    time += (s[6] - '0') * 10;
    time += (s[7] - '0');
    return time;
}

int main(){
    int n;
    while(cin >> n && n){
        vector<int> time(86401);
        for(int i = 0; i < n; i++){
            string s, t;
            cin >> s >> t;
            int start = toNum(s), goal = toNum(t);
            time[start]++;
            time[goal]--;
        }
        int ans = 0;
        for(int i = 1; i < 86401; i++){
            time[i] += time[i-1];
            if(ans < time[i]) ans = time[i];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3396
import math
a, b, x = input().split()
a=int(a)
b=int(b)
x=int(x)
volume = a * a * b
if x<(volume/2):
    state=-1 #반보다 적을때
else:
    state=1 #반이상

if state==-1:
    angle=90-math.degrees(math.atan(x/(b*b*a/2)))
else:
    angle=math.degrees(math.atan((volume-x)/(a*a*a/2)))
print(angle)


Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline unsigned getMaxEffectiveBit(ull a)
{
	ll index = 0;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}



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

	ll A, B, Q;
	cin >> A >> B >> Q;

	vector<ll> ss(A);
	for (ll i = 0; i < A; ++i)
	{
		cin >> ss[i];
	}
	vector<ll> ts(B);
	for (ll i = 0; i < B; ++i)
	{
		cin >> ts[i];
	}
	ll x;
	for (ll i = 0; i < Q; ++i)
	{
		cin >> x;
		auto s_iter = upper_bound(ss.begin(), ss.end(), x);
		auto t_iter = upper_bound(ts.begin(), ts.end(), x);

		ll res = 0x7FFFFFFFFFFFFFFF;
		if (s_iter != ss.begin() && t_iter != ts.begin())
		{
			res = min(res, max(x - *(s_iter - 1), x - *(t_iter - 1)));
		}
		if (s_iter != ss.begin() && t_iter != ts.end())
		{
			res = min(res, 
				min( (x - *(s_iter - 1)) * 2 + (*t_iter - x),
				(x - *(s_iter - 1)) + (*t_iter - x) * 2)
			);
		}
		if (s_iter != ss.end() && t_iter != ts.begin())
		{
			res = min(res, 
				min( ( *s_iter - x ) * 2 + ( x - *(t_iter - 1) ),
				(*s_iter - x) + (x - *(t_iter - 1)) * 2)
			);
		}
		if (s_iter != ss.end() && t_iter != ts.end())
		{
			res = min(res, max(*s_iter - x, *t_iter - x));
		}
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 2944
sx, sy, tx, ty=map(int,input().split())

nx=tx-sx
ny=ty-sy

root_1='U'*ny+'R'*nx
root_2='R'+'D'*(ny+1)+'L'*(nx+1)+'U'
root_3='R'*nx+'U'*ny
root_4='U'+'L'*(nx+1)+'D'*(ny+1)+'R'

print(root_1+root_2+root_3+root_4)

Measured memory_bytes: 3060
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		int x = 1;
		int i = 1;
		try (Scanner sc = new Scanner(System.in)) {
			while(x != 0) {
				x = sc.nextInt();

			if(x == 0)break;
			System.out.println(String.format("Case %d: %d",i,x));
			i++;
			}
		}
	}
}




Measured memory_bytes: 61524
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// // Container コンテナ型, map以外
// template< template<class ...> class Ctn,class T>
// std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
//   // ここでストリームに obj を書き込みます。
//   auto itr=v.begin();
//   while(itr!=v.end()){
//     if(itr!=v.begin())cout << " ";
//     cout << *(itr++);
//   }
//   return os;
// }


int main(){
  string s,t; cin >>t;
  int flag=0;
  rep(i,t.size()){
    if(flag and t[i]=='C'){
      s.push_back('D');
      flag=0;
    }else{
      if(flag) s.push_back('B');
      if(t[i]=='B') flag=1;
      else {
        s.push_back(t[i]);
        flag=0;
      }
    }
  }
  if(flag) s.push_back('B');
  if(df) print(s);
  li cnt=0,ans=0;
  rep(i,s.size()){
    if(s[i]=='A'){
      cnt++;
    }else if(s[i]=='D'){
      ans+=cnt;
    }else cnt=0;
  }
  print(ans);
}



Measured memory_bytes: 776
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
//        sc.useDelimiter("\n");
//        DecimalFormat df = new DecimalFormat("0.00000000");
        
        long n = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        long ans = n % k;
        n = Math.abs(ans - k);
        pw.println(Math.min(ans, n));
        
        pw.flush();
    }
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    int v[n], c, xy;
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++) {
        cin >> c;
        xy = v[i] - c;
        if(xy > 0) {
            ans += xy;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll n;cin >> n;
    ll k;cin >> k;
    ll ret = 0;
    if(k==0){
        cout << n*n << endl;
        return 0;
    }
    for(ll i=k+1;i<=n;++i){
        ret += (i-k)*((n-k+1)/i);
        ll nokori = (n-k+1)%i;
        if(i-k>nokori) ret += nokori;
        else ret += i-k;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "test"
using namespace std;
const ll N = 100 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
ll dx[2] = {0,1};
ll dy[2] = {1,0};
ll dp1[N][N],dp2[N][N];
ll n,m,i,j;
char a[N][N];
bool chk(ll x,ll y){
    return (x <= n&&y <= m);
}
ll f1(ll x,ll y){
    if (x == n&&y == m) return 0;
    if (dp1[x][y] != -1) return dp1[x][y];
    ll ans = inf;
    for (ll i = 0;i < 2;i++){
        ll p = x + dx[i],q = y + dy[i];
        if (chk(p,q)){
            if (a[p][q] == a[x][y]) ans = min(ans,f1(p,q));
            else{
                if (a[p][q] == '#') ans = min(ans,1 + f1(p,q));
                else ans = min(ans,f1(p,q));
            }
        }
    }
    return dp1[x][y] = ans;
}
ll f2(ll x,ll y){
    if (x == n&&y == m) return 0;
    if (dp2[x][y] != -1) return dp2[x][y];
    ll ans = inf;
    for (ll i = 0;i < 2;i++){
        ll p = x + dx[i],q = y + dy[i];
        if (chk(p,q)){
            if (a[p][q] == a[x][y]) ans = min(ans,f2(p,q));
            else{
                if (a[p][q] == '.') ans = min(ans,1 + f2(p,q));
                else ans = min(ans,f2(p,q));
            }
        }
    }
    return dp2[x][y] = ans;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n>>m;
    for (i = 1;i <= n;i++){
        for (j = 1;j <= m;j++) cin>>a[i][j];
    }
    memset(dp1,-1,sizeof(dp1)); memset(dp2,-1,sizeof(dp2));
    ll p = f1(1,1),q = f2(1,1); q++;
    if (a[1][1] == '#') p++;
    else q++;
    cout<<min(p,q);
}


Measured memory_bytes: 512
object Main extends App {
  @scala.annotation.tailrec
  def gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)

  val sc = new java.util.Scanner(System.in)
  val X = sc.nextInt()
  println(360 / gcd(X, 360))
}


Measured memory_bytes: 55168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << min(a, b) + min(c,d) << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N);
    rep(i, N) {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2.0;
    }
    vector<double> ac(N, 0.0);
    double sm = 0.0;
    rep(i, K) sm += p[i];
    ac[K - 1]  = sm;
    double ans = sm;
    for (int i = K; i < N; i++) {
        ac[i] = ac[i - 1] - p[i - K] + p[i];
        ans   = max(ans, ac[i]);
    }
    cout << fixed << setprecision(9);
    cout << ans << endl;
}

Measured memory_bytes: 3328
(N, M, X, Y) = map(int, input().split())
x = map(int, input().split())
y = map(int, input().split())

ans = "War"

max_x = max(x)
min_y = min(y)

if X+1 > max_x+1:
    min_z = X+1
else:
    min_z = max_x+1

if Y < min_y:
    max_z = Y
else:
    max_z = min_y

if min_z <= max_z:
    ans = "No War"

print(ans)



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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  cin >> N;
  vector<pair<ll,ll>> work(N);
  for(ll i = 0LL; i < N; i++) {
    cin >> work[i].second >> work[i].first;
  }
  sort(work.begin(), work.end());
  ll time = 0LL;
  bool can = true;;
  for(ll i = 0LL; i < N; i++) {
    time+=work[i].second;
    if(time>work[i].first){
      can = false;
      break;
    }
  }
  if(can)cout<<"Yes"<<endl;
  if(!can)cout<<"No"<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int factorial(int n)
{
    int ans = 1;
    for(int i = n; i >= 1; i--)
    {
        ans *= i;
    }
    //cout << "factorial : " << n << " = " << ans << endl;
    return ans;
}
int combination(int a, int b)
{
    //cout << "combination : " << a << "," << b << " = " << factorial(a) / (factorial(b) * factorial(a - b)) << endl;
    int start = a - b + 1;
    int son = 1;
    for(int i = start; i <= a; i++)
    {
        son *= i;
    }
    int ans = son / factorial(b);
    //cout << "combination : " << a << "," << b << " = " << ans << endl;
    return ans;
}
int main()
{
    int n,m;
    cin >> n >> m;
    int ans = 0;
    ans = combination(n, 2) + combination(m, 2);
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  ll n;
  cin >> n;
  ll A[n];
  for(int i=0;i<n;i++) A[i]=i+1;
  for(int i=0;i<n;i++){
    if(A[i]%3==0||A[i]%5==0) A[i]=0;
  }
  ll sum=0;
  for(int i=0;i<n;i++) sum+=A[i];
    cout << sum << endl;
}



Measured memory_bytes: 11400
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = 0;

    char c;
    rep(i,n){
        cin >> c;
        if (c == 'Y') ok = 1;
    }
    if (ok) PRINT("Four");
    else PRINT("Three");
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main() {
	int n = in(), l = in();
	vector<string>s(n);
	REPC(&i, s)i = in<string>();
	sort(ALL(s));
	REPC(i, s) cout << i;
	cout << endl;
}

Measured memory_bytes: 256