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

int main()
{
    /* ------- 宣言と入力 ------- */

    int N;

    cin >> N;

    /* ------- 計算 ------- */
    
    int ans = (int)ceil((double)N/2);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <locale>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------

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

  int n, k;
  string s;
  cin >> n >> k >> s;
  std::locale l = std::locale::classic();

  REP(i, n) {
    if(i == k - 1) {
      cout << tolower(s[i], l);
    } else {
      cout << s[i];
    }
  }

  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
int a,b,c,d,e;
  cin>>a>>b>>c;
  d=abs(a-b);
  e=abs(a-c);
  if(d<e){
    cout<<"A\n";
  }else{
    cout<<"B\n";
  }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    vector<string> strs(N);
    for (int i = 0; i < N; i++) {
        cin >> strs[i];
    }

    for (int i = 0; i < N; i++) {
        sort(all(strs[i]));
    }

    // for (int i = 0; i < N; i++) {
    //     for (int j = i+1; j < N; j++) {
    //         if (strs[i].compare(strs[j]) == 0) {
    //             ans++;
    //         }
    //     }
    // }

    map<string, int> mp;
    for (int i = 0; i < N; i++) {
        mp[strs[i]]++;
    }


    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        ll n = itr->second;
        if (n != 1) {
            ans += (n * (n-1)) / 2;
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 18176
class SegmentTreeDual():
    def __init__(self, n, op, id, commutative=False):
        self.n = n
        self.op = op
        self.id = id
        self.commutative = commutative
        self.log = (n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [id] * self.size
        self.lz = [id] * (2 * self.size)

    def build(self, arr):
        for i, a in enumerate(arr):
            self.d[i] = a

    def propagate(self, k):
        if self.lz[k] == self.id: return
        if k < self.size:
            self.lz[2 * k] = self.op(self.lz[k], self.lz[2 * k], )
            self.lz[2 * k + 1] = self.op(self.lz[k], self.lz[2 * k + 1])
        else:
            self.d[k - self.size] = self.op(self.lz[k], self.d[k - self.size])
        self.lz[k] = self.id

    def get(self, p):
        res = self.d[p]
        p += self.size
        for i in range(self.log):
            res = self.op(self.lz[p >> i], res)
        return res

    def range_apply(self, l, r, f):
        if l == r: return
        l += self.size
        r += self.size
        if not self.commutative:
            for i in range(self.log)[::-1]:
                self.propagate(l >> i)
                self.propagate(r >> i)
        while l < r:
            if l & 1:
                self.lz[l] = self.op(f, self.lz[l])
                l += 1
            if r & 1:
                r -= 1
                self.lz[r] = self.op(f, self.lz[r])
            l >>= 1
            r >>= 1

import sys
input = sys.stdin.buffer.readline

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

stx = SegmentTreeDual(N, min, 10**18, True)
sty = SegmentTreeDual(N, min, 10**18, True)

x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]

stx.build(x)
sty.build(y)

res = (N - 2) * (N - 2)

for _ in range(Q):
    q, k = map(int, input().split())
    if q == 1:
        g = stx.get(k - 1)
        res -= g - 1
        sty.range_apply(1, g, k - 1)
    if q == 2:
        g = sty.get(k - 1)
        res -= g - 1
        stx.range_apply(1, g, k - 1)

print(res)

Measured memory_bytes: 101708
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(N: Long){
    if (N.toString() == N.toString().reversed()) println(YES)
    else println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



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

int main(){
    string s;
    int j, c, n, k, tmp=0, ans=0, array[100000]={};
    cin >> n >> k;
    cin >> s;
    c=0;
    array[0] = 1;
    for(int i=1; i<n; i++){
        if(s[i]!=s[i-1]){
            c++;
        }
        array[c]++;
    }
    if(s[0]=='0'){
        for(int i=0; i<=k*2-1; i++){
            if(i<=c){
                tmp+=array[i];
            }
        }
        ans = tmp;
        if(k*2<=c){
            tmp = tmp - array[0] + array[k*2];
            if(k*2+1<=c){
                tmp += array[k*2+1];
            }
            ans = max(ans,tmp);
            j = 3;
        }
    }
    else{
        for(int i=0; i<=k*2; i++){
            if(i<=c){
                tmp+=array[i];
            }
        }
        ans = tmp;
        j = 2;
    }
    int i;
    i = j;
    while(i+k*2-1<=c){
        tmp = tmp - array[i-2] - array[i-1] + array[i+k*2-1];
        if(i+k*2<=c){
            tmp += array[i+k*2];
        }
        ans = max(ans,tmp);
        i += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
fn main() {
    let m = read::<u32>();
    println!("{}", 48 - m);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int[] ABC = in.nextIntArray(3);
            Arrays.sort(ABC);
            if (ABC[0] == ABC[1] && ABC[1] != ABC[2] || ABC[0] != ABC[1] && ABC[1] == ABC[2]) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 23252
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[1000][1000];
ll x[200000] = {};
ll y[200000] = {};
ll x2[200000] = {};
ll y2[200000] = {};

int main() {
	ll h, w, v; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) {
		scanf("%d", &v);
		a[i][j] = v % 2;
	}

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] & 1) {
				a[i][j + 1]++;

				y[cnt] = i + 1;
				x[cnt] = j + 1;
				y2[cnt] = i + 1;
				x2[cnt] = j + 2;
				cnt++;
			}
		}

		if (i != h - 1) {
			if (a[i][w - 1] & 1) {
				a[i + 1][w - 1]++;

				y[cnt] = i + 1;
				x[cnt] = w;
				y2[cnt] = i + 2;
				x2[cnt] = w;
				cnt++;
			}
		}
	}

	printf("%d\n", cnt);
	rep(i, 0, cnt)	printf("%d %d %d %d\n", y[i], x[i], y2[i], x2[i]);

	return 0;
}

Measured memory_bytes: 11776
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=l; i<=r; i++) {
            if(i % d == 0) list.add(i);
        }
        System.out.println(list.size());
    }
}

Measured memory_bytes: 35588
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
  int i, j, tmp; 
  int number[1000]; 
  int n=0; 
  while(1){
  int min=1000000;
  scanf("%d", &n);
  if(n==0) {
      break;
  }
  for (i=0; i<n; i++){ 
    scanf("%d", &number[i]);
    }
  for (i=0; i<n-1; i++) { 
    for (j=i+1; j<n; j++) { 
        if(number[i]>number[j]){
        tmp =  number[i]; 
        number[i] = number[j]; 
        number[j] = tmp; 
        } 
    }
  }
  for(i=0;i<(n-1);i++){
      if(number[i+1]-number[i]<min){
          min=number[i+1]-number[i];
      }
  }
  cout<<min<<endl;
 }
    return 0;
} 
    




Measured memory_bytes: 3208
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    grid = [list(input().rstrip()) for _ in range(n)]

    for i in range(1, n):
        target = [grid[0][(i + j) % n] for j in range(n)]
        if grid[i] != target:
            break
    else:
        print(n ** 2)
        exit()

    res = 0
    for a in range(n):
        grid2 = [[""] * n for _ in range(n)]
        for i in range(n):
            for j in range(n):
                grid2[i][j] = grid[(i + a) % n][j]
        for i in range(n):
            for j in range(n):
                if grid2[i][j] != grid2[j][i]:
                    break
            else:
                continue
            break
        else:
            res += 1
    print(res * n)


if __name__ == '__main__':
    resolve()


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

using namespace std;

#define ll              long long int
#define endl            '\n'

static const int maxn = 5000 + 5;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(12);



      ll n;
      cin >> n;
      ll ans = n * n * n;
      cout << ans << endl;
}


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

int main() {
	int n, m, ans=0;
    int k[10], p[10], s[10][10];

    cin >> n >> m;
    for(int i=0; i<m; i++){
      cin >> k[i];
      for(int j=0; j<k[i]; j++){
        cin >> s[i][j];
      }
    }
    for(int i=0; i<m; i++){
        cin >> p[i];
    }

    for(int ii=0; ii<(1<<n); ii++){
        bitset<11> isOnBits(ii);
        string isOn = isOnBits.to_string().substr(11-n);
        for(int i=0; i<m; i++){
            int sum =0;
            for(int j=0; j<k[i]; j++){
                sum += isOn[ s[i][j] -1 ] == '1' ? 1 : 0;
            }
            if(sum%2 != p[i]) break;
            if(i==m-1) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[] Array = new Integer[N];
		for(int i = 0;i < N;i++) {
			Array[i] = sc.nextInt();
		}
		Arrays.sort(Array,Collections.reverseOrder());
		int A = 0,B = 0;
		for(int k = 0;k < N;k++) {
			if(k % 2 == 0) A += Array[k];
			else B += Array[k];
		}
		int ans = A - B;
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 23764
#include<stdio.h>
#define MAX 101
#define INF 2001
#define NIL -1
#define WHITE 0
#define BLACK 1


int n,A[MAX][MAX];



int prim(int n){
  int d[MAX],pi[MAX],color[MAX],u,i,v,sum=0,mincost;
  
  for(u=1;u<=n;u++){
    d[u]=INF;
    pi[u]=NIL;
    color[u]=WHITE;
  }
  d[1]=0;

  while(1){
    mincost=INF;
    u=NIL;
    for(i=1;i<=n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==INF){
      break;
    }

    color[u]=BLACK;

    for(v=1;v<=n;v++){
      if(color[v]!=BLACK && A[u][v]!=NIL){
	if(d[v]>A[u][v]){
	  pi[v]=u;
	  d[v]=A[u][v];
	}
      }
    }
  }

  for(i=1;i<=n;i++){
    if(pi[i]!=NIL){
      sum=sum+d[i];
    }
  }
     
  return sum; 
}

int main(){
  int n,i,j;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      scanf("%d",&A[i][j]);
    }
  }

  printf("%d\n",prim(n));

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int a, b ,c ;
    cin >> a >> b >> c ;
    swap(a, b) ;
    swap(a, c) ;
    cout << a << " " << b << " " << c << endl ;
}
 
int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if ((a + b) >= (c * 2)) {
        int minxy = min(x, y);
        ans += minxy * c * 2;
        x -= minxy;
        y -= minxy;
        // cout << "bought c: " << minxy << endl;
    }
    if (a >= (c*2)) {
        ans += c * 2 * x;
        y -= x;
    } else {
        ans += a * x;
        // cout << "bought a: " << x << endl;
    }
    y = max(0, y);
    if (b >= (c*2)) {
        ans += c * 2 * y;
    } else {
        ans += b * y;
        // cout << "bought b: " << y << endl;
    }

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

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

char grading(int m,int f, int r){
	int ex;

	ex = m+f;

	if(m == -1 || f == -1)
		return 'F';
	else {
	if(ex >= 80)
		return 'A';
	else {
		if (ex >= 65)
			return 'B';
		else {
			if (ex >= 50)
				return 'C';
			else {
				if (ex >= 30){
					if ( r >= 50)
						return 'C';
					else
						return 'D';
				}
				else
					return 'F';
				}
			}
		}
	}
}
int inputdata(int *m, int *f, int *r){
	cin >> *m >> *f >> *r;
	if(*m == -1 && *f == -1 && *r == -1)
		return 0;
	else
		return 1;
}

int main() {
	int i=0,n;
	int m[50],f[50],r[50];

	while(inputdata(&m[i],&f[i],&r[i]) == 1){
		i++;
	}
	n=i;

	for(i=0;i<n;i++){
		cout << grading(m[i],f[i],r[i]) << endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, a,b,c,d; cin >> N >> a >> b >> c >> d;
    string s; cin >> s;
    s = '0' + s;

    if(c < d){

        // check if b can go to d
        bool flg = true;
        for(int i=b+1; i<=d-1; ++i) if(s[i] == '#' && s[i+1] == '#') flg = false;
        
        // when b can go to d, s[b] = '.'
        // and check if a can go to c
        for(int i=a+1; i<=c-1; ++i) if(s[i] == '#' && s[i+1] == '#') flg = false;

        if(flg) cout << "Yes" << endl;
        else cout << "No" << endl;

    }
    else{

        // first, b goes to the point next to which are '.'
        bool flg = false;
        for(int i=b; i<=d; ++i){
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') flg = true;
        }

        // check if a can go to c
        for(int i=a+1; i<=c-1; ++i) if(s[i] == '#' && s[i+1] == '#') flg = false;
        
        if(flg) cout << "Yes" << endl;
        else cout << "No" << endl;

    }

    return 0;
}

Measured memory_bytes: 772
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		int N = nextInt();
		int H = nextInt();

		int[] a = new int[N];
		int[] b = new int[N];
		int aMax=0;
		for(int i=0;i<N;i++) {
			a[i]=nextInt();
			b[i]=nextInt();
			aMax=Math.max(aMax, a[i]);
		}
		int ans = 0;
		Arrays.sort(b);
		for(int i=N-1;i>=0;i--) {
			if(b[i]>aMax) {
				H-=b[i];
				ans++;
				if(H<=0) {
					pw.println(ans);
					return;
				}
			}else {
				break;
			}
		}
		pw.println(ans+(H+aMax-1)/aMax);
	}



	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 47716
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((ll)2e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n;
ll a[MAXN];
ll b[MAXN];

double ans;

double dist(ll x, ll y, ll x2,ll y2)
{
	return sqrt((x-x2)*(x-x2) + (y-y2)*(y-y2));
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; ++i)
		cin >> a[i] >> b[i];

	for (int i = 0; i < n; ++i)
		for (int j = i+1; j < n; ++j)
			ans += dist(a[i],b[i],a[j],b[j]);

	cout << fixed << setprecision(12) << ans * (2) / n << endl;
}

Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map &:to_i
r=a.inject(:+)
j=true
t=n*(n+1)/2
j=false if r%t!=0
b=[a[0]-a[-1]]
(n-1).times do |i|
  b<< a[i+1]-a[i]
end
c=[]
n.times do |i|
  g=r/t-b[i]
  j=false if g%n!=0||g<0
  c<< g/n
end
puts j&&c.inject(:+)==r/t ? :YES : :NO

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

int main()
{
    long long int p,q,r,k;
    cin>>p>>q>>r>>k;
    if(k<=p)
        cout<<k<<endl;
    else if(k<=(p+q))
        cout<<p<<endl;
    else
        cout<<p-(k-p-q)<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main()
{
  int d;

  scanf("%d",&d);
  
  int h;
  h = d / 3600;
  
  int m;
  m = ((d - (3600*h)) / 60);

  int s;
  s = d - ((3600*h) + (m*60));
  printf("%d:%d:%d\n",h,m,s);

  return 0;
}


Measured memory_bytes: 2760
a,b = list(input().split())
c=int(a+b)
i=1
while True:
  if i *i ==c:
    print("Yes")
    exit()
  elif i*i >c:
    print("No")
    exit()
  else:
    i += 1
a,b = list(input().split())
c=int(a+b)
i=1
while True:
  if i *i ==c:
    print("Yes")
    exit()
  elif i*i >c:
    print("No")
    exit()
  else:
    i += 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll x(n),l(n);
  vector<pll> p(n);
  rep(i,n){
    ll x,l;
    cin>>x>>l;
    p[i]=mp(x+l,x-l);
  }
  sort(all(p));
  ll ans=1;
  ll t=p[0].F;
  for(int i=1;i<n;i++){
    if(t<=p[i].S){
      ans++;
      t=p[i].F;
    }
  }
  COUT(ans);
}


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

    int main (){
        int a,b;
        cin >> a >> b;
        if(a<0 && b<0){
        if(abs(a)%2==0 && abs(b)%2==0){
            cout << "Negative" << endl;
        }
        
        if(abs(a)%2==1 && abs(b)%2==1){
            cout << "Negative" << endl;
        }
        
        if(abs(a)%2==1 && abs(b)%2==0){
            cout << "Positive" << endl;
        }
        
        if(abs(a)%2==0 && abs(b)%2==1){
            cout << "Positive" << endl;
        }
        }
        else if(a>0 && b>0){
            cout << "Positive" << endl;
        }
        else{
            cout << "Zero" << endl;
        }

        return 0;
    }

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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

class UnionFind {
public:
    int n;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), par(n), rank(n), sz(n) {
        for (int i=0; i<n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x != y) {
            if (rank[x] > rank[y]) swap(x, y);
            par[x] = y;
            sz[y] += sz[x];
            if (rank[x] == rank[y]) ++rank[y];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }
};

vector<int> makeTable(const string& s) {
    int n = s.size();
    vector<int> ret(n+1);
    ret[0] = -1;
    int j = -1;
    for (int i = 0; i < n; i++) {
        while (j >= 0 && s[i] != s[j]) j = ret[j];
        ret[i+1] = ++j;
    }
    return ret;
}

vector<int> kmp(const string& str, const string& word) {
    vector<int> table = makeTable(word), ret;
    int m = 0, i = 0, n = str.size();
    while (m+i < n) {
        if (word[i] == str[m+i]) {
            if (++i == (int)(word.size())) {
                ret.push_back(m);
                m = m+i-table[i];
                i = table[i];
            }
        } else {
            m = m+i-table[i];
            if (i > 0) i = table[i];
        }
    }
    return ret;
}

int solve(string s, string t) {
    vector<int> pos = kmp(s, t);
    int n = s.size();
    int m = t.size();
    int l = pos.size();

    UnionFind uf(n);
    int mx = 0;
    for (int i=0; i<l; ++i) {
        auto it = lower_bound(pos.begin(), pos.end(), (pos[i]-m+n)%n);
        if (it != pos.end() && *it == (pos[i]-m+n)%n) {
            uf.unite(i, it-pos.begin());
        }
    }
    for (int i=0; i<l; ++i) {
        mx = max(mx, uf.size(i));
    }
    return mx;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    string s, t;
    cin >> s >> t;

    string ss = s+s+s;
    while ((int)ss.size() < (int)t.size()*2) {
        ss += s;
    }

    int ans1 = solve(ss, t);
    int ans2 = solve(ss+ss, t);

    if (ans1 < ans2) {
        cout << -1 << endl;
    } else {
        cout << ans1 << endl;
    }

    return 0;
}

Measured memory_bytes: 62252
#include <bits/stdc++.h>
using namespace std;
const int N=5005;
#define ll long long
bitset < N > f[N],g[N];
int a[N],sum[N];
int n,m;
inline bool in(int l,int r){
	if (l<=0) return sum[r]!=0;
	return (sum[r]-sum[l-1]!=0);
}
inline bool check(int x){
	sum[0]=1;
	for (int i=1;i<=m;i++)
		sum[i]=sum[i-1]+f[x-1][i];
	for (int i=0;i<=m;i++)
		if (g[x+1][i]&&in(m-a[x]-i,m-i-1)) return false;
	return true;
}
int main (){
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf ("%d",&a[i]);
	sort(a+1,a+n+1);
	f[0][0]=1,g[n+1][0]=1;
	for (int i=1;i<=n;i++)
		f[i]=f[i-1]|(f[i-1]<<a[i]);
	for (int i=n;i>=1;i--)
		g[i]=g[i+1]|(g[i+1]<<a[i]);
	int l=0,r=n,ans=0;
	while (l<=r){
		int mid=(l+r)>>1;
		if (check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf ("%d",ans);
	return 0;
}

Measured memory_bytes: 6400
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long fa[100005],ans,a;
int n,q,i;
bool r[100005];
char c;
long long find(long long x)
{
	if(r[x]==1)
		return x;
	return find(fa[x]);
}
int main()
{
	fa[1]=1;
	r[1]=1;
	while(1)
	{
		scanf("%d %d",&n,&q);
		if(n==0||q==0)
			return 0;
		ans=0;
		for(i=2;i<=n;i++)
			r[i]=0;
		for(i=2;i<=n;i++)
			scanf("%lld",&fa[i]);
		for(i=1;i<=q;i++)
		{
			scanf("\n%c %lld",&c,&a);
			if(c=='M')
				r[a]=1;
			if(c=='Q')
				ans=ans+find(a);
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 3448
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){
  while(u != NIL && k != k.key)
    if(k < u.key){
      u = u.left;
    }
    else 
      u = u.right;
  return u;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
     if(z->key <  x->key){
       x = x->left;
     }
     else
       x = x->right;
  }
   z->parent = y;
   if(y == NIL){
     root = z;
   }
   else if(z->key <  y->key){
     y->left = z;
   }
   else
     y->right = z;


  }

void inorder(Node u){
if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
 }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL){
     preorder(u->left);
  }
  if(u->right != NIL){
     preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    /*  if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }*/ 
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*else if ( com[0] == 'd' ){
	scanf("%d", &x);
	treeDelete(treeSearch(root, x));
	}*/
  }

  return 0;
}

 

Measured memory_bytes: 24040
import java.util.*;
public class Main {

	private int intPow(int a, int b){
		if(b == 0){
			return 1;
		}
		int sum = a;
		for(int i=1; i < b; i++){
			sum *= a;
		}
		return sum;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i=0; (n >> i) > 0; i++){

				if(((n >> i ) & 1) == 1){
					list.add(intPow(2, i));
				}
			}
			System.out.print(list.get(0));
			for(int i=1; i < list.size(); i++){
				System.out.print(" " + list.get(i));
			}
			System.out.println("");

		}

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

	}

}

Measured memory_bytes: 0
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
l=[]
for i in range(h):
    a=list(input())
    if a[0]!="." or len(list(set(a)))!=1:
        l.append(a)

i=0
while i<len(l[0]):
    ch=True
    for k in range(len(l)):

        if l[k][i]=="#":
            ch=False
    if ch:
        for k in range(len(l)):
            del l[k][i]
        i-=1
    i+=1
for i in range(len(l)):
    print(*l[i],sep="")

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

const int MAXN=200000; 
vector<int> v[MAXN+5];
int idx[MAXN+5]; 
int Max=0,sum=0;

void DFS(int x,int id)
{
	if(idx[x]!=0) return;
	++sum;
	idx[x]=id;
	for(int i=0;i<v[x].size();++i)	
	{	
		DFS(v[x][i],id);
	}
} 

int main()
{
	//1.输入 
	int n,m;
	scanf("%d%d",&n,&m);
	//2.存图 
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[y].push_back(x);
		v[x].push_back(y);
	} 
	//3.求最大连通块
	int cnt=0;
	for(int i=1;i<=n;++i)
	{
		if(idx[i] == 0) 
		{
			DFS(i,++cnt);
			Max=max(Max,sum);
			sum=0;
		} 
	}
	//4.输出
	printf("%d",Max);
	return 0; 
} 

Measured memory_bytes: 21752
#include<bits/stdc++.h>
#define ll long long 
#define inf 0x7fffffff
#define infll 0x7fffffffffffffff
#define clr(c) memset(c,0,sizeof(c))
using namespace std;
int mod=998244353;
const int M=2e5+10;
const int N=1e6+10;
inline ll read(){
    ll b=1,sum=0; char c=getchar();
    while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
    while(isdigit(c)){sum=sum*10+c-'0'; c=getchar();}
    return b*sum;
}
int T,n,m,k;
int ans;
int a;
int main()
{
    int i,j;
    T=1;
//	T=read();
	while(T--) {
		ans=0;
		a=read(); //k=read();
//		for(i=1;i<=n;i++) {
//			a[i]=read();
//		}
		ans=a+a*a+a*a*a;
		bool f=0;
		printf("%d",ans);
		puts("");
	}
    return 0;
}


Measured memory_bytes: 3752
//abc076_c.cpp
//Sat May 26 11:19:20 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;

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

	int flag;
	int marker = -1;

	if (t.length()>s.length()){
		cout << "UNRESTORABLE" << endl;
	}else{

	for (int i=0;i<=s.length()-t.length();i++){
		flag = 1;
		for (int j=0;j<t.length();j++){
			if (s[i+j] != '?'){
				if (s[i+j] != t[j]){
					flag = 0;
				}
			} 
		}
		if (flag == 1){
			marker = i;
		}
	}

	if (marker == -1){
		cout << "UNRESTORABLE" << endl;
	}else {
		for (int i=0;i<s.length();i++){
			if (i>=marker && i<marker+t.length()){
				s[i] = t[i-marker];
			}
			if (s[i] == '?'){
				s[i] = 'a';
			}
		}
		cout << s << endl;
	}
}
}

Measured memory_bytes: 256
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int[][] bingo =new int[3][3];
		boolean[][] isHit=new boolean[3][3];
		for (int i=0;i<3;i++) {
			for (int j=0;j<3;j++) {
				bingo[i][j] =sc.nextInt();
				isHit[i][j]=false;
			}
		}
		int n=sc.nextInt();
		for (int k=0;k<n;k++) {
			int drawnCard =sc.nextInt();
			for (int i=0;i<3;i++) {
				for (int j=0;j<3;j++) {
					if (drawnCard==bingo[i][j]) {
						isHit[i][j]=true;
					}
				}
			}
		}
		boolean isBingo =false;
		for (int i=0;i<3;i++) {
			if(isHit[0][i]&&isHit[1][i]&&isHit[2][i]) {
				isBingo =true;
			}
		}
		for (int i=0;i<3;i++) {
			if(isHit[i][0]&&isHit[i][1]&&isHit[i][2]) {
				isBingo =true;
			}
		}
		if (isHit[0][0]&&isHit[1][1]&&isHit[2][2]) {
			isBingo=true;
		}
		if (isHit[0][2]&&isHit[1][1]&&isHit[2][0]) {
			isBingo=true;
		}
		if (isBingo) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
			//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		}
		//----------------------------------------
		//置き場
		
		//----------------------------------------
	}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

int H, N;
vector<int> A, B;
int memo[1001][10001];

int solve(int i, int hp) {
  if (hp <= 0) return 0;
  if (i >= A.size()) return (1 << 30);
  if (memo[i][hp] != -1) return memo[i][hp];
  
  int res = solve(i, hp - A[i]) + B[i];
  res = min(solve(i + 1, hp - A[i]) + B[i], res);
  res = min(solve(i + 1, hp), res);

  return memo[i][hp] = res;
}

int main(void) {
  cin >> H >> N;
  A.resize(N);
  B.resize(N);
  rep(i, N) {
    int a, b; cin >> a >> b;
    A[i] = a;
    B[i] = b;
  }
  rep(i, 1001) rep(j, 10001) memo[i][j] = -1;
  cout << solve(0, H) << endl;
  return 0;
}


Measured memory_bytes: 39808
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

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

L = sorted(L)

ans = 0
for i in range(N-2):
    for j in range(N-1):
        if j > i:
            c = L[i] + L[j]
            ma = bisect.bisect_left(L[j+1:], c)
            ans += ma

print(ans)


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 1;
    sort(a.begin(), a.end());
    ll sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    sum -= a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        if (2 * sum < a[i + 1]) break;
        sum -= a[i];
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size() <= k) cout<<s<<endl;
    else
    {
        cout<<s.substr(0,k)<<"..."<<endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll res = 0;
    res += N - K +2;
    res = (res + MOD) % MOD;
    res += ((N+1) * ((N+1)*(N+2) - (K-1)*K) / 2) % MOD;
    res = (res + MOD) % MOD;
    res -= ((N+1)*(N+2)*(2*N+3) / 6) % MOD;
    res = (res + MOD) % MOD;
    res += ((K-1)*K*(2*K-1) / 6) % MOD;
    res = (res + MOD) % MOD;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3592
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int N;
int a;
int c[100007];
int main(){
	ios::sync_with_stdio(false);
	int i;
	cin >> N;
	for (i = 0; i<N; ++i){
		cin >> a;
		++c[a];
		++c[a + 1];
		++c[a + 2];
	}
	cout << *max_element(c, c + 100002) << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
	ll X,Y;
	cin>>X>>Y;
	ll ans=-1;
	ll N=X;
	ll i=1;
	if(X%Y!=0){
		while(X*i<=1e18){
			if(X*i%Y!=0){
				ans=X*i;
				break;
			}
			i++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	int ca = 0, cb = 0, cc = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'a') ++ca;
		if (s[i] == 'b') ++cb;
		if (s[i] == 'c') ++cc;
	}
	cout << (max({ ca, cb, cc }) - min({ ca, cb, cc }) <= 1 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1144
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<deque>
#include<functional>
#include<ctime>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;
typedef vector<int> vi;

template<class T> bool uin(T &a, T b){ return (a > b ? a = b, true : false); }
template<class T> bool uax(T &a, T b){ return (a < b ? a = b, true : false); }

/////////////////////////////////
int const N = 141;

int a[2][N], d[2][N];
int n;

int main(){
#ifdef LOCAL_DEFINE
	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, 2) fj(0, n) scanf("%d",&a[i][j]), d[i][j] = a[i][j];
	fi(0, 2) fj(0, n){
		if(i + 1 < 2){
			uax(d[i+1][j], d[i][j] + a[i+1][j]);
		}
		if(j + 1 < n){
			uax(d[i][j+1], d[i][j] + a[i][j+1]);
		}
	}		
	printf("%d\n",d[1][n-1]);

	
#ifdef LOCAL_DEFINE
	fprintf(stderr, "ELAPSED TIME: %.3lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 256
N,X,M=map(int,input().split())
a = X
hist = [a]
indices = [-1]*M
indices[a] = 0
flag=0
for i in range(1,min(10**6,N)):
  a = a**2 % M
  if indices[a] != -1:
    idx = indices[a]
    flag=1
    break
  hist.append(a)
  indices[a] = i
  
if flag==0:
  print(sum(hist))
  exit()
  
cycle = hist[idx:]
margin = hist[:idx]
q,r = divmod((N-len(margin)),len(cycle))
print(sum(margin)+sum(cycle)*q+sum(cycle[:r]))

Measured memory_bytes: 14020
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  string S;
  cin >> S;
  
  if(S == "Sunny")
    cout << "Cloudy";
  else if (S == "Cloudy")
    cout << "Rainy";
  else
    cout << "Sunny";
}

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

using ll = long long;

int main(int argc, char **argv)
{
	int n, q;
	cin >> n >> q;
	string str;
	cin >> str;

	vector<int> l(q+1), r(q+1);
	for (int i = 0; i < q; ++i)
		cin >> l[i] >> r[i];

	vector<int> a(n-1, 0);
	for (int i = 0; i < n-1; ++i)
	{
		if (str[i] == 'A' && str[i+1] == 'C')
			a[i] = 1;
	}
	vector<int> cum_sum(n, 0);
	for (int i = 0; i < n-1; ++i)
		cum_sum[i+1] = cum_sum[i] + a[i];

	for (int i = 0; i < q; ++i)
	{
		int left = l[i]-1;
		int right = r[i]-1;
		std::cout << cum_sum[right] - cum_sum[left] << std::endl;
	}
}

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


int main(){
    int a,b;
    string s;
    vector<char> lst(10);
    cin>>a>>b>>s;
    bool ans=true;
    // for(int i=0;i<s.size();i++){
    //     cin>>lst.at(i);
    // {
        
    for(int i=0;i<s.size();i++){     
        if (i!=a && s[i]=='-'){
            ans=false;
            break;
        }
        if (i==a && s[i]!='-'){
            ans=false;
            break;
        }
    }
    if(ans==true){
        cout<<"Yes"<<endl;    
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
N, T = input().split()
N = int(N)
T = int(T)

import numpy as np

c = np.zeros(N)
t = np.zeros(N)

for i in range(N):
  c[i], t[i] = input().split()
  c[i] = int(c[i])
  t[i] = int(t[i])
  if t[i] > T :
    c[i] = 1001

if min(c) == 1001:
  print('TLE')
  
else:
  print(int(min(c)))
  

Measured memory_bytes: 27116
#include<stdio.h>
#include<string.h>
void mozi_sort(char str[], int length) {
	int tmp[10000] = {};
	int memo = 0;
	for (int i = 0; i < length; i++) {
		tmp[(int)str[i]]++;
	}
	for (int i = 0; i < 256; i++) {
		while (tmp[i] > 0) {
			str[memo] = (char)i;
			memo++;
			tmp[i]--;
		}
	}
}
//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}
int main() {
	long long int n, m, num[2000][2] = {}, result=0;
	char str[200005];
	scanf("%s",str);
  	n = strlen(str);
	mozi_sort(str,n);
  	if(str[0]!='a'){printf("a");return 0;}
	for (int i =1; i < n; i++) {
		if (str[i] == str[i - 1] || (int)str[i] == (int)str[i-1] + 1) {
			continue;
		}
		else {
			printf("%c",(str[i-1]+1));
          return 0;
		}
	}	
  		
  		if(str[n-1]!='z'){printf("%c",(str[n-1]+1));return 0;}
		printf("None");	
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    double a, b, x;
    cin >> a >> b >> x;
    if (x > a*a*b/2.0) {
        cout << atan(2.0*(a*a*b-x)/(a*a*a)) * 180 / M_PI << endl;
    } else {
        cout << atan(a*b*b/(2*x)) * 180 / M_PI << endl;
    }
}


Measured memory_bytes: 4064