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

int h,w;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
char s[60][60];

int main(){
  cin >> h >> w;
  
  for (int i=0;i<h;i++) cin >> s[i];
  bool ans = true;
  
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
       if (s[i][j] == '#'){
          bool found = false;//自分(黒マス)の隣に黒マスをfoundしたかどうか
          for (int k=0;k<4;k++){
            int i2=i+dx[k];
            int j2=j+dy[k];
            if (i2>=0&&i2<h&&j2>=0&&j2<w&&s[i2][j2]=='#'){//i2j2というマスがボードの内側かつ黒色
              found = true;
          }
       }
      if (!found) ans = false;//s[i][j]が黒なのにs[i2][j2]が4回回しても見つからなかったらfalse
    }
  }
}
cout << (ans ? "Yes" : "No") << endl;
}
 


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

int main() {
  string S;
  cin>>S;
  vector<int>a(4);
  for(int i=0;i<4;i++){
    a.at(i)=S.at(i);
  }
  for(int i=0;i<8;i++){
    string ans;
    int sum=a.at(0)-'0';
    ans+=a.at(0);
    for(int j=0;j<3;j++){
      if(i&(1<<j)){
        sum+=a.at(j+1)-'0';
        ans+='+';
        ans+=a.at(j+1);
      }
      else{
        sum-=a.at(j+1)-'0';
        ans+='-';
        ans+=a.at(j+1);
      }
    }
    if(sum==7){
      cout<<ans<<"=7"<< endl;
      return 0;
    }
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
constexpr int sign(int n) { return n < 0 ? -1 : n > 0; }

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

  vi A(N);
  rep(i, N)
    cin >> A[i];

  ll ans = 1e18;
  rep(k, 2) {
    ll sum = 0, tmp = 0;
    int SIGN = k*2-1;
    rep(i, N) {
      SIGN *= -1;
      if (sign(sum+A[i]) != SIGN) {
        tmp += abs(SIGN - (sum + A[i]));
        sum = SIGN;
      } else
        sum += A[i];
    }
    if (sum == 0)
      ++tmp;
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
/* ex3-3
    kas056*/

#include<stdio.h>
#include<stdlib.h>

int main(void){
    int i,j;
    int row, column;
    char **ptr;
    int *judge_r, *judge_c;
    scanf("%d %d" ,&row, &column);

    

    //ptrのメモリ確保
    ptr = (char**)calloc(row, sizeof(char*));

    if(ptr == NULL){
        exit(1);
    }
    
    for(i=0; i<row; i++){
        ptr[i] = (char*)calloc(column, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }

    //judge_rのメモリ確保
    judge_r = (int*)calloc(row, sizeof(int));
    if(judge_r == NULL){
        exit(1);
    }

    //judge_cのメモリ確保
    judge_c = (int*)calloc(column, sizeof(int));

    if(judge_c == NULL){
        exit(1);
    }


    for(i=0; i<row; i++){
        for(j=0; j<column; j++){
            scanf(" %c", &ptr[i][j]);
        }
    }

    //＃があるか判定
    for(i = 0; i < row; i++){//まず行を固定して
        for (j = 0; j < column; j++){//その行の各要素に対して
            if(ptr[i][j] == '#'){//＃と一致するものがあったら終了する。
                break;
            }
        }

        if(j == column){//最後まで＃がなかったら
            judge_r[i] = 1;
        }
    }

    for(j = 0; j < column; j++){//列を固定して、行の場合と同様の操作を行う
        for(i = 0; i < row; i++){
            if(ptr[i][j] == '#'){
                break;
            }
        }
        if(i == row){
            judge_c[j] = 1;
        }
    }

    for(i=0; i<row; i++){//ある行において＃があった時、かつ
        if(judge_r[i] == 0){
            for(j = 0; j<column; j++){//その列に＃があったとき、
                if(judge_c[j] == 0){
                    printf("%c", ptr[i][j]);//(i,j)番目の文字を一文字出力
                }
            }//折り返し。これをcolumnの数だけ繰り返す
            printf("\n");//終点で改行
        }
    }//これをrowの数だけ繰り返す

    //逆順に開放
    for(i=0; i<row;i++){
        free(ptr[i]);
    }
    free(ptr);

    free(judge_r);
    free(judge_c);

    return 0;
}

Measured memory_bytes: 1676
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)
x=a.count(m)

for j in a:
    if j==m and x>1:
        print(m)
    elif j==m and x==1:
        print(m2)
    else:
        print(m)

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

long long n, res = 0;

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

    cin >> n;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            int d = __gcd(i, j);
            for(int k = 1; k <= n; ++k) res += __gcd(d, k);
        }
    }
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 3620
/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    in_file     freopen("input.txt", "r", stdin)
#define    out_file    freopen("output.txt", "w", stdout)
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    sp          fixed<<setprecision
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    fora(i,n)   for(int (i)=0; (i) < (n); (i)++)


int Int(){int x;scanf("%d", &x);return x;}
#define    Int         Int()
#define    mx          100010
void dhimanda();
int main()
{
    //fast;
    //in_file;
    //out_file;
    int t=1;
    forr(i,1,t){
        //printf("Case #%d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    ll n;
    cin >> n;
    map <string , int> m;
    map <string , int> :: iterator itr;
    m.clear();
    for(int i=1; i<= n;i++) {
        string tmp;
        cin >> tmp;
        m[tmp]++;
    }
    int mxx= 1;
    set <string > st;
    set <string > :: iterator it;
    st.clear();
    for (auto itr = m.begin(); itr != m.end();++itr){
            if (itr->S > mxx) mxx = itr->S ;
    }
    //cout << mxx ;
    for (auto itr = m.begin(); itr != m.end();++itr){
            if (itr->S == mxx) st.insert(itr->F);
    }
    for (auto it=st.begin(); it != st.end(); ++it) cout << *it <<endl;



}

// Contact : chessdhiman@gmail.com



Measured memory_bytes: 34560
# -*- coding: utf-8 -*-

import sys
import os


s = input().strip()
N = int(input())
for i in range(N):
    lst = input().split()
    command = lst[0]
    if command == 'replace':
        a = int(lst[1])
        b = int(lst[2])
        p = lst[3]
        s = s[:a] + p + s[b+1:]
    elif command == 'reverse':
        a = int(lst[1])
        b = int(lst[2])
        part = s[a:b+1]
        part = part[::-1]
        s = s[:a] + part + s[b+1:]
    elif command == 'print':
        a = int(lst[1])
        b = int(lst[2])
        print(s[a:b+1])
    else:
        print('error')
    #print('s', s)

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

inline void pr(ll n){
    cout << n << endl;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;
    ll m = max({a, b, c});
    ll s = a+b+c;
    if(s%2 == m%2){
        pr((m*3-s)/2);
    }else{
        pr(((m+1)*3-s)/2);
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

s = Array.new(13, 0)
h = Array.new(13, 0)
c = Array.new(13, 0)
d = Array.new(13, 0)

n.times do
  mark, rank = gets.chomp.split
  rank = rank.to_i

  case mark
  when 'S'
    s[rank - 1] = 1
  when 'H'
    h[rank - 1] = 1
  when 'C'
    c[rank - 1] = 1
  when 'D'
    d[rank - 1] = 1
  end
end

s.each_with_index do |s_i, i|
  puts "S #{i + 1}" if s_i == 0
end

h.each_with_index do |h_i, i|
  puts "H #{i + 1}" if h_i == 0
end

c.each_with_index do |c_i, i|
  puts "C #{i + 1}" if c_i == 0
end

d.each_with_index do |d_i, i|
  puts "D #{i + 1}" if d_i == 0
end



Measured memory_bytes: 6876
n = gets.to_i
a = gets.split.map(&:to_i)

def insertion_sort(a, n)
  for i in 1..n-1
    puts a.join(' ')

    v = a[i]
    j = i - 1

    while j >= 0 && a[j] > v
      a[j+1] = a[j]
      j -= 1
    end
    a[j+1] = v
  end
  a
end

puts insertion_sort(a, n).join(' ')


Measured memory_bytes: 6892
n = int(input())
s = input()

l = [0]*n
l[0] = s[1:].count("E")

for i in range(1,n):
    if s[i-1] == "W":
        l[i] += 1
    if s[i] == "E":
        l[i] -= 1
    l[i] += l[i-1]

print(min(l))


Measured memory_bytes: 15520
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(a);

		while (true) {
			if (a[0] == a[n - 1]) {
				out.println(a[0]);
				return;
			}

			for (int i = 1; i < n; i++) {
				a[i] = (a[i] % a[0]);
				if (a[i] == 0)
					a[i] = a[0];
			}
			Arrays.sort(a);

		}

	}

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

}


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

int main(){
    string s;
    cin >> s;
    int st,ed;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            st = i;
            break;
        }
    }
    for(int i = s.size()-1; i >= 0; i--){
        if(s[i] == 'Z'){
            ed = i;
            break;
        }
    }
    cout << ed-st+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum1=0,sum2=0,cost1=0,cost2=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum1+=a[i];
    sum2+=a[i];
    if(i%2==0&&sum1<=0){
      cost1+=1-sum1;
      sum1=1;
    }
    else if(i%2==1&&sum1>=0){
      cost1+=sum1+1;
      sum1=-1;
    }
    if(i%2==0&&sum2>=0){
      cost2+=1+sum2;
      sum2=-1;
    }
    else if(i%2==1&&sum2<=0){
      cost2+=1-sum2;
      sum2=1;
    }
  }
  cout << min(cost1,cost2) << endl;
}

Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 16.11.2019 23:39:30       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int minn = (int) 1e9 + 1;
  int maxx = 0;
  int min2 = (int) 1e9 + 1;
  int max2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) swap(a[i], b[i]);
    minn = min(minn, a[i]);
    maxx = max(maxx, b[i]);
    min2 = min(min2, b[i]);
    max2 = max(max2, a[i]);
  }
  long long ans = (long long) (maxx - min2) * (long long) (max2 - minn);
  vector<pair<int, int>> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = make_pair(a[i], b[i]);
  }
  sort(c.begin(), c.end());
  multiset<int> s;
  for (int i = 0; i < n; i++) {
    s.insert(c[i].first);
  }
  for (int i = 0; i <= n; i++) {
    int x = *s.begin();
    int y = *s.rbegin();
    ans = min(ans, (long long) (y - x) * (maxx - minn));
    if (i < n) {
      s.erase(s.find(c[i].first));
      s.insert(c[i].second);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <cstdlib>
#include <cstring>
int top, S[1000];

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

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

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



Measured memory_bytes: 2744
#include<iostream>
#define _GLIBCXX_DEBUG
using namespace std;
int main(){
    int r, c, x, y,sum;
    sum = 0;
    cin >> r >> c;
    long long data[101][101] = {0};
    for (int i = 0; i < r; i++){ 
        for (int j = 0; j < c; j++){
        cin >> data[i][j] ;
        }
    } 
    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            sum += data[i][j];
        }
        data[i][c] = sum;
        sum = 0;
    }
    for (int i = 0; i < c; i++){
        for (int j = 0; j < r; j++){
            sum += data[j][i];
        }
        data[r][i] = sum;
        sum = 0;
    }
    for (int i = 0; i < c; i++){
        data[r][c] += data[r][i];
    }
    for (int i = 0; i < r+1; i++){
        for (int j = 0; j < c+1; j++){
            if(j == c)cout << data[i][j];
            else if(1)
            cout << data[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

int main() {
	const int mod = 1e9 + 7;
	int n; cin >> n;
	map<int, int> mp;
	bool judge = true;
	ll ans = 1;
	if (n % 2 == 1) {
		Loop(i, n) {
			int x; cin >> x;
			mp[x]++;
			if (x % 2 != 0 || mp[0] > 1 || mp[x] > 2) judge = false;
		}
	}
	else {
		Loop(i, n) {
			int x; cin >> x;
			mp[x]++;
			if (x % 2 == 0 || mp[x] > 2) judge = false;
		}
	}
	if (judge) {
		Loop(i, n / 2) {
			ans = ans * 2 % mod;
		}
	}
	else ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3200
import math
from fractions import Fraction
X = int(input())
n = 360 / X
m = Fraction(360,X)
s = m.denominator
a,b = math.modf(n)
if a == 0.0:
    print(int(n))
elif a != 0.0:
    ans = m * s
    print(int(ans))

Measured memory_bytes: 10472
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    int ans = 0;

    for(int i = 0; i < n; i++){
      int h = sc.nextInt();
      if(h >= k){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 50264
s = input()

n = int(s)

arrays = []

y = n

while y > 0:
    arrays.append(y % 10)
    y = int(y / 10)

sum_num = 0

for i in range(len(arrays)):
    sum_num += arrays[i]

if n % sum_num == 0:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 8988
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

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

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct etree { ll from, to, cost; };
struct people { ll v, k, year; };
bool comp(const etree& e1, const etree& e2) {
	return e1.cost < e2.cost;
}
bool comp2(const people& e1, const people& e2) {
	return e1.year < e2.year;
}
#define ALL(x) (x).begin(),(x).end()

ll FACT[201100] = { 0 }, IFACT[201100] = { 0 };
ll extgcd(ll a, ll b, ll &x, ll &y) {
	ll g = a;
	x = 1;
	y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
ll invMod(ll a, ll m) {
	ll x, y;
	if (extgcd(a, m, x, y) == 1) return (x + m) % m;
	else                         return 0;
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%MOD;
		x = x*x%MOD;
		n >>= 1;
	}
	return res;
}
void inverse(ll N) {
	FACT[0] = 1;
	IFACT[0] = 1;
	for (int i = 1;i <= N;i++) {
		FACT[i] = FACT[i - 1] * i % MOD;
		IFACT[i] = invMod(FACT[i], MOD);
	}
}
ll combi(ll n, ll r) {
	if (n < 0 || r < 0 || r > n)return 0;
	if (r > n / 2)r = n - r;
	return FACT[n] * IFACT[n - r] % MOD*IFACT[r] % MOD;
}


int main() {
	ll n, m, a[100010], b[100010], asum = 0, bsum = 0;
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		asum -= a[i] * (n - 1 - i);
		asum += a[i] * i;
		asum += MOD;
		asum %= MOD;
	}
	for (int i = 0;i < m;i++) {
		cin >> b[i];
		bsum -= b[i] * (m - 1 - i);
		bsum += b[i] * i;
		bsum += MOD;
		bsum %= MOD;
	}
	cout << (asum*bsum) % MOD << endl;

}

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

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, K;
bool used[MAX];
vector<int> G[MAX];

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 順列計算
long long PAM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

int main(){
    cin >> N >> K;
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    COMinit();

    queue<int> q;
    q.push(0);
    used[0] = true;

    int cnt;
    ll ans = K;
    while(q.size()){
        int now = q.front();
        q.pop();
        used[now] = true;

        cnt = 0;
        for(int i : G[now]){
            if(!used[i]){
                q.push(i);
                cnt++;
            }
        }

        if(cnt){
            if(now == 0){
                ans = (ans * PAM(K - 1, cnt)) % MOD;
            }
            else{
                ans = (ans * PAM(K - 2, cnt)) % MOD;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 8952
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int n,i,j,min,a[100],tmp,count=0;
	char input[4001],*p;
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&n);
	
	fgets(input,sizeof input,stdin);
	p=strtok(input," ");
	a[0]=atoi(p);
	
	for(i=1;i<n;i++){
		p=strtok(NULL," ");
		a[i]=atoi(p);
	}
	
	for(i=0;i<n;i++){
		min=i;
		for(j=i;j<n;j++){
			if(a[min]>a[j]){
				min=j;
			}
		}
		if(min!=i){
			tmp=a[i];
			a[i]=a[min];
			a[min]=tmp;
			count++;
		}
	}
	
	
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i!=n-1){
			printf(" ");
		}
	}
	printf("\n%d\n",count);
	
	
	
	
	return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<algorithm>
#include<string>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  int N = S.size();
  int ans = N;
  for(int i = 1; i < N; ++i) if(S[i] != S[i-1]) {
    int m = std::max(i, N-i);
    ans = std::min(ans, m);
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
char s[1005][1005];
int d[1005][1005];
int x[1000005],y[1000005];
int h,w;
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
int main(){
	scanf("%d%d",&h,&w);
	getchar();
	int t=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			scanf("%c",&s[i][j]);
			if(s[i][j]=='.')
				d[i][j]=1e9;
			else{
				d[i][j]=0;
				x[t]=i;
				y[t++]=j;
			}
		}
		getchar();
	}
	int s=0,ans=0;
	while(s<t){
		int xx=x[s],yy=y[s++];
		for(int i=0;i<4;i++){
			int u=xx+dx[i];
			int v=yy+dy[i];
			if(u<1||u>h||v<1||v>w||d[u][v]<=d[xx][yy]+1)
				continue;
			d[u][v]=d[xx][yy]+1;
			ans=max(ans,d[u][v]);
			x[t]=u;
			y[t++]=v;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 12928
#include <stdio.h>

long long d[5001],p[5001];

int main()
{
	int N,A;
	scanf ("%d %d",&N,&A);
	d[2500] = 1;

	for (int i=0;i<N;i++){
		int x; scanf ("%d",&x); x -= A;
		for (int j=0;j<=5000;j++) p[j] = 0;
		for (int j=0;j<=5000;j++) if (d[j]){
			p[j] += d[j];
			p[j+x] += d[j];
		}
		for (int j=0;j<=5000;j++) d[j] = p[j];
	}
	printf ("%lld\n",d[2500]-1);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
  #include <iomanip>
  #include <algorithm>
  #include <cmath>
  #include <queue>
  #include <list>
  #include <limits>
  #include <string>
  #include <vector>
  #include <stack>
  using namespace std;
  typedef unsigned long long ll;

  typedef pair<ll, ll> curr;
  const int MOD = 998244353;


  int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }

  ll calc(int a, int b, int p){
    if(b == 0) return 1;
    if(b % 2 == 0){
      ll d = calc(a, b/2, p);
      return (d*d)%p;
    }else{
      return (a*calc(a, b-1, p))%p;
    }

  }
  ll a[60];
  ll p[60];
  ll f(ll n, ll x){
    if(n == 0) return 0;
    if(x <= 0) return 0;
    if(x <= a[n-1]+1) return f(n-1,x-1);
    if(x == 2 + a[n-1]) return p[n-1]+1;
    if(x && x <= 2+2*a[n-1]) return p[n-1]+1+f(n-1 , x-2-a[n-1]);
    if(x == 3 + 2*a[n-1]) return 2*p[n-1]+1;
  }

  int main(){
    string s;
    ll K,i;
    cin >> s;
    cin >> K;
    for(i=0;i<s.length();i++) {
      if(s[i] != '1') break;
    }
    if(K <= i) cout << '1';
    else cout << s[i];
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	ll x;cin>>x;
	for(ll i=-1000;i<=1000;i++){
		for(ll j=-1000;j<=1000;j++){
			ll a=i*i*i*i*i;ll b=j*j*j*j*j;
			if(x==(a-b)){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3576
N,K = map(int,input().split())
P = list(map(int,input().split()))

# 累積和 
s = [0] * (N+1)
for i in range(N):# O(N)
    s[i+1] = s[i] + P[i]

# [j,j+K) の和の最大値と j を保持 
m = 0
midx = 0
for j in range(N-K+1):# O(N)
    v = s[j+K] - s[j]
    if v > m:
        m = v
        midx = j
        
E = 0
for k in range(midx,midx+K):# O(K)
    x = P[k]
    E += (1/x)*(x*(x+1)/2)
print(E)

Measured memory_bytes: 32276
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

const int mod = 1e9 + 7;
const int nax = 2e5 + 5;
int sum[nax];

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
	int n;
    scanf("%d", &n);
    vector<int> in(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &in[i]);
    }
    int dp = 1;
    for(int i = 0; i < n; ++i) {
        int x = in[i];
        if(i != 0 && in[i] == in[i-1]) {
            continue;
        }
        add_self(sum[x], dp);
        dp = sum[x];
    }
    printf("%d\n", dp);
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
vector<int> G[100100];
bool flag = false;
int vs[100100];

void dfs(int v, int x){
    vs[v] = x;

    for(int w : G[v]){
        if(vs[w] != -1){
            if(vs[w] == x){
                flag = true;
            }

            continue;
        }

        dfs(w, !x);
    }
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    memset(vs, -1, sizeof(vs));
    dfs(1, 0);

    ll res = -1ll;
    if(flag){
        res = 1ll * N * (N - 1) / 2 - M;
        // std::cout << "wa-i" << std::endl;
    }else{
        ll n = 0, m = 0;
        for(int i=1;i<=N;++i){
            if(vs[i] == 0){
                ++n;
            }else{
                ++m;
            }
        }

        res = n * m - M;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
} /*atcoder*/



Measured memory_bytes: 3552
import Control.Applicative

main :: IO ()
main = do
    getLine
    nums <- map (\n -> read n ::Int) . words <$> getLine
    loop nums []
  where
      loop :: [Int] -> [Int] -> IO ()
      loop [] _          = return ()
      loop (x:xs) sorted = do
          let sn = insertion x sorted
          printNums $ sn ++ xs
          loop xs sn
      printNums :: Show a => [a] -> IO ()
      printNums = putStrLn . unwords . map show

insertion :: Int -> [Int] -> [Int]
insertion v []     = [v]
insertion v (x:xs)
  | x < v     = x:(insertion v xs)
  | otherwise = v:x:xs



Measured memory_bytes: 4100
#include <iostream>
#include <math.h>
#include <cmath>
#include <iomanip>


using namespace std;

//-------------------------------------------------------------------------------------
/*2点[(x1,y1),(x2,y2)]を入力し二点を通る直線ax+by+cの(a,b,c)を返す,  */
/*x1==x2ならfalseを返す*/
/*falseならばx=cの形の直線*/
void straight_line_passing_through_the_two_points(double x1, double y1, double x2, double y2, double *a, double *b, double *c){
    *a=(y2-y1);
    *b=-(x2-x1);
    *c=y2*(x2-x1)-x2*(y2-y1);
}

//-------------------------------------------------------------------------------------
/*(x,y)を通るa1x+b1y+c1=0に垂直な直線a2x+b2y+c2=0を返す*/
void vertical_straight_line(double x, double y, double a1, double b1, double c1, double *a2, double *b2, double *c2){
    *a2 = -b1;
    *b2 = a1;
    *c2 = b1*x - a1*y;
}


//-------------------------------------------------------------------------------------
/*2直線 a1x+b1y+c1=0 a2x+b2y+c2=0 の交点 (x,y)を返す*/
/*2直線が平行であるならばfalseを返す*/

bool intersection_and_parallel(double a1, double b1, double c1, double a2, double b2, double c2, double *x, double *y){
    if(a1*b2==a2*b1)return false;//平行の判定
    
    *x = (b1*c2-b2*c1)/(a1*b2-a2*b1);
    *y = (a2*c1-a1*c2)/(a1*b2-a2*b1);
    
    return true;
}


//-------------------------------------------------------------------------------------
/*直線ax+by+c=0に対し　(x1,y1)と線対称な位置(x2,y2)を出力*/
/*vertical_straight_lineを使用*/
/*intersection_and_parallelを使用*/
void line_symmetry(double a, double b, double c, double x1, double y1, double *x2, double *y2){
    //垂直な直線を求める
    double a2,b2,c2;
    vertical_straight_line(x1, y1, a, b, c, &a2, &b2, &c2);
    
    //垂直な直線との交点を求める
    double c_x, c_y;
    intersection_and_parallel(a, b, c, a2, b2, c2, &c_x, &c_y);
    *x2 = x1 + 2*(c_x-x1);
    *y2 = y1 + 2*(c_y-y1);
}



//-------------------------------------------------------------------------------------
/*2点(x1,y1), (x2,y2) の距離*/
double distance_between_the_two_pointss(double x1,double y1, double x2, double y2){
    return  sqrt(fabs((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


//-------------------------------------------------------------------------------------
/* (x1,y1)から(x2,y2)へ伸ばした直線の角度を求める  */
double angle_of_the_line(double x1, double y1, double x2, double y2){
    return atan2(y2-y1, x2-x1);
}



int main(int argc, const char * argv[]){
    double x0,y0,x1,y1,x2,y2;
    cin>>x0>>y0>>x1>>y1;
    
    double angle1 = angle_of_the_line(x0,y0,x1,y1);
    
    int q;
    cin>>q;
    for(int i=0; i<q; i++){
        cin>>x2>>y2;
        double angle2 = angle_of_the_line(x0,y0,x2,y2);
        
        double angle = angle2-angle1;
        
        if(angle<0)angle+=2*M_PI;
        if(x2==x0&&y2==y0)cout<<"ON_SEGMENT"<<endl;
        else if(angle==0||angle==2*M_PI){
            double l1=distance_between_the_two_pointss(x0, y0, x1, y1);
            double l2=distance_between_the_two_pointss(x0, y0, x2, y2);
            if(l1>=l2)cout<<"ON_SEGMENT"<<endl;
            else cout<<"ONLINE_FRONT"<<endl;
        }else if(angle == M_PI)cout<<"ONLINE_BACK"<<endl;
        else if(angle<M_PI)cout<<"COUNTER_CLOCKWISE"<<endl;
        else cout<<"CLOCKWISE"<<endl;
        
        
    }
}

Measured memory_bytes: 1308
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n, minv=0, maxv=-2000000000;
    cin >> n;
    int r[n];
    for(int i=0;i<n;i++){
        cin >> r[i];
    }
    
    minv = r[0];
    for(int i=1;i<n;i++){
        maxv = max(maxv, r[i]-minv);
        minv = min(minv, r[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,pair<int,char>>
#define sorted(a_1) sort(a_1.begin(),a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(),a_1.rend())
#define t1(a_1) cout<<a_1<<endl;
#define t2(a_1) for(auto it_test : a_1) cout<<it_test<<" ";


const int MAX = 1000001;
vector<long long >isprime(MAX , true); 
vector<long long >prime; 
vector<long long >SPF(MAX); 
void Seive(int N) 
{ 
    isprime[0] = isprime[1] = false ; 
   
    for (long long int i=2; i<N ; i++) 
    { 
        if (isprime[i]) 
        { 
            prime.push_back(i);  
            SPF[i] = i; 
        } 
  
        for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) 
        { 
            isprime[i*prime[j]]=false; 
   
            SPF[i*prime[j]] = prime[j] ; 
        } 
    } 
} 

ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0) 
        return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 

void lcs(string& s1, string& s2){
    int n = s1.length();
    int m = s2.length();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0) dp[i][j] = 0;
            else if(s1[i-1]==s2[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    int index = dp[n][m];
    char com[index+1];
    int i = n,j=m;
    com[index]='\0';
    while(i>0 && j>0){
        if(s1[i-1]==s2[j-1]){
            com[index-1] = s1[i-1];
            i--;
            j--;index--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    cout<<com;
}
void solve(){
    string s1,s2;
    cin>>s1;
    cin>>s2;
    lcs(s1,s2);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--){
        solve();
    }

return 0;
}

Measured memory_bytes: 54116
#include "bits/stdc++.h"
using namespace std;
#ifdef _debug
#define out(i) cout << #i << ' ' << i << ' '
#else 
#define out(i) //
#endif
using ll = long long;
using ull = unsigned long long;
const int maxn = 600001;
string s, t;
int f[500001], cnt[4000001];
void build_kmp(const string &w){
	for(int i = 1, q = 0;i < w.size();++i){
		while(q and w[i] != w[q])q = f[q - 1];
		f[i] = q += w[i] == w[q];
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> s >> t;
	while(s.size() < t.size())s += s;
	int s3len = s.size() * 3;
	s += s;
	s += s;
	build_kmp(t);
	ull res = 0;
	for(int i = 0, q = 0;i < s.size();++i){
		while(q and s[i] != t[q])q = f[q - 1];
		q += (s[i] == t[q]);
		if(q == t.size())q = f[q - 1], cnt[i - (int)t.size() + 1] = 1;
	}
	// return 0;
	for(int i = 0;i < s.size();++i){
		if(cnt[i]){
			if(i >= t.size())cnt[i] += cnt[i - t.size()];
			if(cnt[i] > res)res = (i >= s3len - t.size() - 1) ? -1ul : cnt[i];
		}
	}
	cout << (int)res << '\n';
}

Measured memory_bytes: 24760
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

map<ll, ll> prime_factorization(ll n){
    map<ll,ll> ret;
    for(ll i=2;i*i<n;i ++){
        while(n%i==0){
            ret[i] ++;
            n /= i;
        }
    }
    if(n!=1) ret[n]=1;
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    map<ll,ll> divs = prime_factorization(N);
    ll count=0;
    ll Nmax = 1000000000000;
    ll max_e = 1;
    while(Nmax > pow(2, max_e)) max_e++;
    //cerr << max_e << endl;
    vector<ll> dcount = {1, 3, 6, 10, 15, 21, 28, 36, 45};
    for(auto i : divs)
    {
        //cerr << i.first << ":" << i.second << endl;
        //3: 1, 2
        //4: 1, 3
        //5: 1, 4
        //1  2  3   4   5   6   7,  8,  9
        //1, 3, 6, 10, 15, 21, 28, 36, 45
        for(ll d=0;d<dcount.size();d++)
        {
            if(i.second < dcount[d])
            {
                count+=d;
                break;
            }
        }
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s == "Sunny"){
        cout<<"Cloudy"<<endl;
    } else if(s== "Cloudy"){
        cout<<"Rainy"<<endl;
    } else if(s== "Rainy"){
        cout<<"Sunny"<<endl;
    }

    return  0;
}


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

typedef long long ll;
ll a, b, ans;

ll f(ll p, ll q) {
	return p / (q * 2) * q + max(0LL, p % (q * 2) - q + 1);
}

int main()
{
	ll i;
	cin >> a >> b;
	a = max(0LL, a - 1);
	for (i = 1; i <= b; i *= 2) {
		ans += (f(b, i) - f(a, i)) % 2 * i;
	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
ans=0
x=list(map(int,input().split()))
min=float("inf")
for i in range(N):
    a=abs(A-(T-x[i]*0.006))
    if a<min:
        ans=i
        min=a
print(ans+1)

Measured memory_bytes: 3064
from operator import itemgetter

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


a = [list(map(int,input().split())) for i in range(N)]

if N ==1:
    Z = M*a[0][0]
    print(Z)
else:
    a.sort(key = itemgetter(0))
    X = 0 
    D = 0
    var=0
    while M>D:
        D+=a[var][1]
        X+=a[var][0]*a[var][1]
        var+=1
        
    X += a[var-1][0]*(M-D)
    print(X)


Measured memory_bytes: 28968
#include <iostream>
#include <vector>

int main() {
  uint32_t N = 0, Q = 0;
  std::cin >> N >> Q;
  std::vector<uint32_t> A(N);
  for (auto &&a : A) std::cin >> a;
  for (size_t q = 0; q < Q; q++) {
    uint64_t x = 0;
    std::cin >> x;

    uint64_t count = 0;
    for (size_t s = 0, t = 0, sum = 0; s < N; sum -= A[s++]) {
      while (t < N && sum + A[t] <= x) sum += A[t++];
      count += (t - s);
    }
    std::cout << count << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3152
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main(){
	int x,a,b;cin>>x>>a>>b;if(abs(x-a)>abs(x-b))puts("B");else puts("A");
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N, A, B;
  cin >> N >> A >> B;

  int cnt = 0;
  FOR(i,1,N+1){
    if((i/10000%10+i/1000%10+i/100%10+i/10%10+i%10) >= A && B >= (i/10000%10+i/1000%10+i/100%10+i/10%10+i%10)){
      cnt+=i;
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int N, M, A=0, B=0;
  cin >> N >> M;
  for (int i=1; i<N; i++) A+=i;
  for (int i=1; i<M; i++) B+=i;
  cout << A+B << endl;
}


Measured memory_bytes: 256
s = input()
t = input()
q = int(input())

len_s = len(s)
len_t = len(t)

s_counter= [0]*(len_s+1)
s_temp = 0
for i in range(len_s):
	if s[i] == "A":
		s_temp += 1
	s_counter[i+1] = s_temp
	
t_counter= [0]*(len_t+1)
t_temp = 0
for i in range(len_t):
	if t[i] == "A":
		t_temp += 1
	t_counter[i+1] = t_temp

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s_counter[b]-s_counter[a-1]
	y = t_counter[d]-t_counter[c-1]
	print(['NO', 'YES'][((x+b-a+1)-(y+d-c+1))%3==0]) 

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

int main() {
  long long a, b, c, d;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  printf("%lld", max(max(a*c, a*d), max(b*c, b*d)));
  return 0; 
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int k = Integer.parseInt(strlist[0]);
		int s = Integer.parseInt(strlist[1]);
		int count = 0;

		for(int x = 0; x <= k; x++){
			for(int y = 0; y <= k; y++){
				int z = s - x -y;
				if(z >= 0 && z <= k){
					count = count + 1;
					continue;
				}
			}
		}

		System.out.println(count);


	}

}


Measured memory_bytes: 21460
n, l = map(int, input().split())
sa = 1000
sum = 0
for i in range(1,n+1):
    if sa != min(abs(l+i-1), sa):
        sa = min(abs(l+i-1), sa)
        app = l+i-1
    sum += l+i-1

print(sum-app)

Measured memory_bytes: 3064
class Dice:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

    def right(self):
        temp = self.num.copy()
        self.num[2-1] = temp[4-1]
        self.num[4-1] = temp[5-1]
        self.num[5-1] = temp[3-1]
        self.num[3-1] = temp[2-1]

num = list(map(int,input().split()))
dice = Dice(num)
q = int(input())
for _ in range(q):
    top,front = map(int,input().split())
    while not (top == dice.num[0] or front == dice.num[1]): dice.north()
    while top != dice.num[0]: dice.east()
    while front != dice.num[1]: dice.right()
    print(dice.num[2])
        



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

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

    constexpr int64_t MOD = 2019;
    int64_t ans = 0;
    vector<int64_t> num(MOD + 1, 0);
    num[S.front() - '0'] = 1;
    for (int64_t j = 1; j < S.size(); j++) {
        //全部10倍して足す
        vector<int64_t> new_num(MOD, 0);
        for (int64_t i = 0; i < MOD; i++) {
            new_num[((i * 10 + S[j] - '0') % MOD)] += num[i];
        }
        new_num[S[j] - '0']++;

        num = new_num;
        ans += num[0];
    }

    cout << ans << endl;
}

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

int main() {
  while(true){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == -1 &&(b == -1 && c == -1)) return 0;
    if(a == -1 || b == -1) cout << 'F' << endl;
    else if(a+b >= 80) cout << 'A' << endl;
    else if(a+b >= 65) cout << 'B' << endl;
    else if(a+b >= 50 || (a+b >= 30)&& c >= 50) cout << 'C' << endl;
    else if(a+b >= 30) cout << 'D' << endl;
    else cout << 'F' << endl;
  }
}



Measured memory_bytes: 3104