akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
/////////////////// 
//

#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a;
  cin >> a;
  pri((a-2+1)/2);
  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[][] data=new int[101][2];
		ArrayList<Integer> resulth=new ArrayList<Integer>();
		ArrayList<Integer> resultw=new ArrayList<Integer>();
		int j=0;
		
		while(true){
			data[j][0]=sc.nextInt();
			data[j][1]=sc.nextInt();
			if(data[j][0]==0&&data[j][1]==0)break;
			j++;
		}
		
		for(int i=0;i<j;i++){
			int[] renum=new int[2];
			renum=forfor(data[i][0],data[i][1]);
			resulth.add(renum[0]);		
			resultw.add(renum[1]);		
		}
		for(int i=0;i<resulth.size();i++)System.out.println(""+resulth.get(i)+" "+resultw.get(i));
	}
	public static int[] forfor(int h,int w){
		int[] re=new int[2];
		int hh=h*h;
		int ww=w*w;
		int now=hh+ww;
		int minlen=150;
		int minum=150*149;
		for(int i=1;i<=150;i++){
			for(int k=1;k<i;k++){
				int ii=i*i;
				int kk=k*k;
				int num=ii+kk;
				if((num>now&&minlen>k&&minum>=num)||(num==now&&k>h)){
					re[0]=k;
					re[1]=i;
					minlen=k;
					minum=num;
				}	
			}
				
		}
		return re;
	}
}

Measured memory_bytes: 20520
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define int long long
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

signed main(){
	int n;
	cin>>n;
	int a;
	map<int,int> mp;
	rep(i,n){
		cin>>a;
		if(mp.find(a)!=mp.end())mp[a]++;
		else mp[a]=1;
	}
	vector<p> vec;
	for(map<int,int>::iterator i=mp.begin();i!=mp.end();i++){
		vec.pb(p(i->first,i->second));
	}
	sort(all(vec));
	int cnt=0;
	int len[2]={0,0};
	rep(i,vec.size()){
		if(vec[vec.size()-1-i].second<2)continue;
		while(vec[vec.size()-1-i].second>=2 && cnt<2){
			len[cnt]=vec[vec.size()-1-i].first;
			vec[vec.size()-1-i].second-=2;
			cnt++;
		}
		if(cnt>=2)break;
	}
	cout<<len[0]*len[1]<<endl;
	return 0;
}

Measured memory_bytes: 8696
import java.util.Scanner;

class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (c >= a && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
    long long a, b; int k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            a /= 2;
            b += a;
        } else {
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, x;
	cin >>n >>x;
	
	VL a(n);
	rep(i, n) cin >>a[i];
	rep(i, n) a[i] -=x;
	
	auto gcd = [](auto f, ll x, ll y)->ll{ return y? f(f, y, x%y): x; };
	ll z = 0;
	rep(i, n){
		z = gcd(gcd, z, abs(a[i]));
	}
	cout << z <<"\n";;
	return 0;
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    mt19937_64 mt(random_device{}());
    uniform_int_distribution<long> uid(-2000000, 2000000);
    unsigned long ans{0};
    for(unsigned long i = 0; i < 500; ++i){
        long x{uid(mt)}, y{uid(mt)};
        long a{0}, b{0};
        for(const auto& engine : eng){
            if(x * engine.first + y * engine.second >= 0){
                a += engine.first;
                b += engine.second;
            }
        }
        if(ans < a * a + b * b)ans = a * a + b * b;
    }
    printf("%.12Lf\n", sqrt(static_cast<long double>(ans)));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool edges[100][100];
int n, m;
vector<int> mt;
vector<char> used;
 
bool try_kuhn (int v) {
	if (used[v])  return false;
	used[v] = true;
	for (int i=0; i < n; i++) {
		if (!edges[v][i]) continue;
		if (mt[i] == -1 || try_kuhn (mt[i])) {
			mt[i] = v;
			return true;
		}
	}
	return false;
}
vector<int> find_matching(){
	mt.assign(n, -1);
	for (int v=0; v<n; ++v) {
		used.assign (n, false);
		bool res = try_kuhn (v);
		assert(res);
	}
	vector<int> res(n);
	for (int i=0; i < n; i++) res[mt[i]] = i;
	return res;
}
signed main() {
	#ifdef LOCAL
		freopen("H_input.txt", "r", stdin);
		//freopen("C_output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    int matrix[n][m];
    for (int i=0; i < n;i++) for (int j=0; j < m; j++) cin >> matrix[i][j];
    for (int i=0; i < n;i++) for (int j=0; j < m; j++) matrix[i][j]--;
    int groups[n][m];
	for (int i=0; i < n; i++) for (int j=0; j < m; j++) groups[i][j] = matrix[i][j]/m;
	bool taken[n][m];
	for (int i=0; i < n; i++) for (int j=0; j < m; j++) taken[i][j] = false;
	int ans[n][m];
	for (int i=0; i < m; i++){
		for (int j=0; j < n; j++) for (int k=0; k < n; k++) edges[j][k] = false;
		for (int j=0; j < n; j++){
			for (int k=0; k < m; k++){
				if (taken[j][k]) continue;
				edges[j][groups[j][k]] = true;
			}
		}
		vector<int> res = find_matching();
		for (int j=0; j < n; j++){
			for (int k=0; k < m; k++){
				if (taken[j][k] || groups[j][k] != res[j]) continue;
				ans[j][i] = matrix[j][k];
				taken[j][k] = true;
				break;
			}
		}
	}
	for (int i=0; i < n; i++){
		for (int j=0; j < m; j++)cout << ans[i][j]+1 << " ";
		cout << "\n";
	}
	for (int j=0; j < m; j++){
		for (int i=0; i < n; i++){
			int G = ans[i][j] / m;
			matrix[G][j] = ans[i][j];
		}
	}
	for (int i=0; i < n; i++){
		for (int j=0; j < m; j++)cout << matrix[i][j]+1 << " ";
		cout << "\n";
	}
}

Measured memory_bytes: 512
#include <stdio.h>
#include<string.h>
int main()
{
long long int n[25]={0},k,x,y,sum=0,i,flag=0;
char a[1000];
gets(a);
flag=0;
for(i=0;i<strlen(a);i++)
{
    n[a[i]-97]++;
}
for(i=0;i<26;i++)
{
    if(n[i]%2!=0 && n[i]>=1)
    {
       flag=1;
    }
}
if(flag==1)
{
    printf("No");
}else{
    printf("Yes");
}
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner; 

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

        int N = sc.nextInt();
        int a = 0;
        int b = 0;
        int c = 0;
        int d = 0;

        for(int i = 0; i<N ;i++){
            String e = sc.next();
            if(e.equals("AC")) a++;
            if(e.equals("WA")) b++;
            if(e.equals("TLE")) c++;
            if(e.equals("RE")) d++;
        }

        System.out.println("AC x "+a);
        System.out.println("WA x "+b);
        System.out.println("TLE x "+c);
        System.out.println("RE x "+d);       

    }
}

Measured memory_bytes: 58796
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

int main()
{
	ll N = 0;
	ll even = 0;
	ll ret = 0;

	cin >> N;
	vector<ll> a(N, 0);
	Rep(i, N) {
		cin >> a[i];
		if (a[i] % 2 == 0) even++;
	}

	ret = pow(3, N) - pow(2, even);
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7

N, M = map(int,input().split())
ok = [1] * N
H = list(map(int,input().split()))
for m in range(M):
    a, b = map(int,input().split())
    a-=1
    b-=1
    if H[a] < H[b]:
        ok[a] = 0
    elif H[a] > H[b]:
        ok[b] = 0
    else:
        ok[a] = 0
        ok[b] = 0

print (sum(ok))
    

Measured memory_bytes: 85544
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

class Point
{
private:
  int m_x;
  int m_y;
public:
  void setX(int x);
  void setY(int y);
  int getX();
  int getY();

  Point(int x, int y) {
    setX(x);
    setY(y);
  }
};

void Point::setX(int x) {
  m_x = x;
}

void Point::setY(int y) {
  m_y = y;
}

int Point::getX() {
  return m_x;
}

int Point::getY() {
  return m_y;
}

int main() {
  int N, n, d, max_x, min_x, max_y, min_y;
  while (cin >> N, N) {
    vector<Point> tiles;
    tiles.pb(Point(0, 0));
    while (--N) {
      cin >> n >> d;
      Point t = tiles[n];
      if (d == 0) tiles.pb(Point(t.getX()-1, t.getY()));
      if (d == 1) tiles.pb(Point(t.getX(), t.getY()-1));
      if (d == 2) tiles.pb(Point(t.getX()+1, t.getY()));
      if (d == 3) tiles.pb(Point(t.getX(), t.getY()+1));
    }
    max_x = -INF;
    min_x = INF;
    max_y = -INF;
    min_y = INF;
    for (int i = 0; i < tiles.size(); i++) {
      if (tiles[i].getX() > max_x) max_x = tiles[i].getX();
      if (tiles[i].getX() < min_x) min_x = tiles[i].getX();
      if (tiles[i].getY() > max_y) max_y = tiles[i].getY();
      if (tiles[i].getY() < min_y) min_y = tiles[i].getY();
    }
    cout << max_x-min_x+1 << " " << max_y-min_y+1 << el;
  }
}

Measured memory_bytes: 1204
n = int(input())
l0 = 2
l1 = 1
if n == 0:
    print(l0)
elif n == 1:
    print(l1)
elif n>= 2:
    ll = [l0, l1] + [0 for _ in range(n-1)]
    for i in range(2,n+1):
        ll[i] = ll[i-1] + ll[i-2]
    print(ll[n])


Measured memory_bytes: 3060
K = int(input())
X,Y = map(int,input().split())

def dist(x,y,z=X,w=Y):
    return abs(z-x)+abs(w-y)

def shot(x,y):
    k = K
    if abs(Y-y)<=K:
        k -= abs(Y-y)
        y = Y
    elif Y>y:
        y += K
        k -= K
    else:
        y -= K
        k -= K
    if k>0:
        if X>x:
            x += k
        else:
            x -= k
    return x,y

x = 0
y = 0
ans = []
if (x+X+y+Y)%2==1 and K%2==0:
    print(-1)
else:
    while x!=X or y!=Y:
        if dist(x,y)==K:
            ans.append([X,Y])
            x,y = X,Y
        elif dist(x,y) > 2*K:
            x,y = shot(x,y)
            ans.append([x,y])
        else:
            if (x+X+y+Y)%2==0:
                cand = [[(x+X+y-Y)//2+K,(x-X+y+Y)//2],[(x+X+y-Y)//2-K,(x-X+y+Y)//2],[(x+X+y-Y)//2,(x-X+y+Y)//2+K],[(x+X+y-Y)//2,(x-X+y+Y)//2-K],
                [(X+x+Y-y)//2+K,(X-x+Y+y)//2],[(X+x+Y-y)//2-K,(X-x+Y+y)//2],[(X+x+Y-y)//2,(X-x+Y+y)//2+K],[(X+x+Y-y)//2,(X-x+Y+y)//2-K]]
                for a,b in cand:
                    if dist(a,b,x,y)==K and dist(a,b)==K:
                        ans.append([a,b])
                        ans.append([X,Y])
                        x,y = X,Y
                        break
            else:
                x,y = shot(x,y)
                ans.append([x,y])
    print(len(ans))
    for x,y in ans:
        print(x,y)

Measured memory_bytes: 72192
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a,b;
	for(int i=0;i<n;i++){
		int ta;
		cin>>ta;
		a.pb(ta);
	}
	for(int i=0;i<n;i++){
		int ta;
		cin>>ta;
		b.pb(ta);
	}
	int ans = 0;
	priority_queue<pair<int,int> > que;
	for(int i=0;i<n;i++){
		if(b[i]<a[i]){
			cout<<-1<<endl;
			return 0;
		}
		if(b[i]>a[i]){
			int lef = (i+n-1)%n;
			int rig = (i+n+1)%n;
			int su = b[lef]+b[rig];
			if( b[i] > su ) que.push(mp(b[i],i));
		}
	}
	while(!que.empty()){
		pair<int,int> tp = que.top();que.pop();
		int idx = tp.second;
		int lef = (idx+n-1)%n;
		int rig = (idx+n+1)%n;
		int su = b[lef]+b[rig];
		int det = max(a[idx],b[idx]%su);
		ans +=  ( b[idx]-det )/su;
		b[idx] -= ( b[idx]-det )/su *su;
		int nidx = lef;
		if(b[nidx]>a[nidx]){
			int le = (nidx+n-1)%n;
			int ri = (nidx+n+1)%n;
			int sus = b[le]+b[ri];
			if( b[nidx] > sus ) que.push(mp(b[nidx],nidx));
		}
		nidx = rig;
		if(b[nidx]>a[nidx]){
			int le = (nidx+n-1)%n;
			int ri = (nidx+n+1)%n;
			int sus = b[le]+b[ri];
			if( b[nidx] > sus ) que.push(mp(b[nidx],nidx));
		}
	}
	bool fl = true;
	for(int i=0;i<n;i++){
		if(a[i] != b[i])fl=false;
	}
	if(fl)cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}

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

using namespace std;

//#define MD 100010

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    
    long int ans=0,sum=0;
    for(int i=-100;i<=100;i++){
        sum=0;
        for(int j=0;j<n;j++){
            sum+=(abs(i-v[j])*abs(i-v[j]));
        }
        if(i==-100){
            ans=sum;
        }else{
            ans=min(ans,sum);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val cnt = Array(26) { Int.MAX_VALUE }
        for (i in 0 until n) {
            val s = sc.next()
            val tmp = Array(26) { 0 }
            for (j in s.indices) {
                tmp[s[j] - 'a']++
            }
            for (j in 0 until 26) {
                cnt[j] = Math.min(cnt[j], tmp[j])
            }
        }

        val ans = StringBuilder()
        for(i in 'a'..'z'){
            ans.append(i.toString().repeat(cnt[i-'a']))
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 37956
object Main{

def main(args: Array[String]): Unit = {
  val arr1 = io.StdIn.readLine().split(' ')
  val N = arr1(0).toInt
  val D = arr1(1).toInt
  
  val xList = (1 to N).map{
    i =>
    val x = io.StdIn.readLine().split(' ')
    x.map(_.toInt)
  }
  
  val bool = (0 until N - 1).map{
    i =>
    (i + 1 until N).map{
      j => 
      val x1 = xList(i)
      val x2 = xList(j)
      
      val dist2 = (0 until D).map{
        k => 
        (x1(k) - x2(k)) * (x1(k) - x2(k))
      }.sum
      
      val dist = math.sqrt(dist2)
      if(math.floor(dist) == math.ceil(dist)) {true}else{false}

    }
  }.flatten.filter(it => it)
  
  println(bool.length)
  
}
}

Measured memory_bytes: 27316
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto &__VA_ARGS__:(c))
using namespace std;
using ll = long long;

int const MD=int(1e9)+7;

int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}
int mpow(int x,int p) {
	int res=1;
	while (p>0) {
		if (p%2) res=mmul(res,x);
		x=mmul(x,x);
		p/=2;
	}
	return res;
}
int minv(int x) {
	return mpow(x,MD-2);
}
int mdiv(int x,int y) {
	return mmul(x,mpow(y,MD-2));
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	vector<int> a(N);
	fore(a,i) cin>>i;

	sort(a.begin(),a.end());
	int p=1,res=0;
	rep(i,K-1,N) {
		res=madd(res,mmul((a[i]+MD)%MD,p));
		p=mmul(p,i+1);
		p=mdiv(p,i-K+2);
	}
	reverse(a.begin(),a.end());
	p=1;
	rep(i,K-1,N) {
		res=msub(res,mmul((a[i]+MD)%MD,p));
		p=mmul(p,i+1);
		p=mdiv(p,i-K+2);
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define OUT(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const ll INF = 1e15;
const int MAX_N = 405;

int N;
int A[MAX_N];
ll dp[MAX_N][MAX_N];
ll sum[MAX_N];
ll solve(int s, int t) {
  if (dp[s][t] != INF)
    return dp[s][t];
  if (s + 1 >= t)
    return dp[s][t] = 0;
  if (s + 2 >= t)
    return dp[s][t] = sum[t] - sum[s];

  ll ans = INF;
  FOR(i, s + 1, t)
    ans = min(ans, (sum[t] - sum[s]) + solve(s, i) + solve(i, t));

  return dp[s][t] = ans;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> N;

  sum[0] = 0LL;
  REP(i, N) {
    cin >> A[i];
    sum[i+1] = (ll)sum[i] + A[i];
  }

  REP(i, MAX_N) REP(j, MAX_N)
    dp[i][j] = INF;

  OUT(solve(0, N));

  return 0;
}




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

using namespace std;

int main(void) {
	int k, a, b; cin >> k >> a >> b;

	bool flag = false;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			flag = true;
			break;
		}
	}


	if (flag) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	return 0;
}

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

using ll = int;
using namespace std;

int main(){
    ll n,cost;
    cin >> n >> cost;
    vector<vector<ll>> dp(10001,vector<ll>(cost+1,-1));
    dp.at(0).at(0) = 0;

    for(ll i=0; i<n; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        for(ll j=10000; j>=0; j--){
            for(ll k=cost; k>=0; k--){
                if(dp.at(j).at(k) == -1) continue;
                if(k+c > cost)continue;
                if(j+a <= 10000) dp.at(j+a).at(k+c) = max(dp.at(j+a).at(k+c), dp.at(j).at(k) + b);
                if(j+b <= 10000) dp.at(j+b).at(k+c) = max(dp.at(j+b).at(k+c), dp.at(j).at(k) + a);
            }
        }
    }
    ll ans = -1;
    for(ll j = 0; j<10001; j++){
        for(ll k=0; k<cost+1; k++){
            ans = max(ans, min(j, dp.at(j).at(k)));
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 7108
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, next_val, ans = 1; cin >> N;
    vector<int> buttons, flags(N, 0);
    rep (i, 0, N) {
        int in; cin >> in;
        buttons.push_back(in);
    }

    flags[0] = 1;
    next_val = buttons[0];
    while (true) {
        if (next_val == 2) break;
        if (flags[next_val - 1] == 1) {
            cout << -1 << endl;
            return 0;
        }
        flags[next_val - 1] = 1;
        next_val = buttons[next_val - 1];
        ans += 1;
    }
    cout << ans << endl;
}

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

double operator *( pair<double,double> p1,pair<double,double> p2){
    return p1.first*p2.second-p2.first*p1.second;
}
int main(){
    double x[3],y[3],xp,yp;
    while(cin>>x[0]>>y[0]){
        for(int i=1;i<3;i++)
            cin>>x[i]>>y[i];
        cin>>xp>>yp;
        pair<double,double>vec[3];
        for(int i=0;i<3;i++)
            vec[i]=make_pair(x[(i+1)%3]-x[i],y[(i+1)%3]-y[i]);
        pair<double,double>tes[3];
        for(int i=0;i<3;i++)
            tes[i]=make_pair(xp-x[i],yp-y[i]);
        int suc=1;
        for(int i=0;i<3;i++){
            if((vec[i]*vec[(i+1)%3])*(vec[i]*tes[(i+1)%3])<0){
                suc=0;
                break;
            }
        }
        if(suc==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }

}

Measured memory_bytes: 1216
N,M=map(int,input().split())
edge=[list(map(int,input().split())) for i in range(M)]
inf=10**20
c=[[] for i in range(N*3)]
for i,j in edge:
    c[i-1].append(N+j-1)
    c[N+i-1].append(N+N+j-1)
    c[N+N+i-1].append(j-1)
S,T=map(int,input().split())
from collections import deque
def bfs(c,N,S):
    d=[inf]*N
    d[S]=0
    q=deque([S])
    x=1
    while len(q)>0:
        q2=deque()
        for i in q:
            for j in c[i]:
                if d[j]>x:
                    d[j]=x
                    q2.append(j)
        q=q2
        x+=1
    return d
d=bfs(c,N*3,S-1)
print(d[T-1]//3 if d[T-1]<inf else -1)

Measured memory_bytes: 79896
// https://atcoder.jp/contests/abc146/tasks/abc146_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int ans = 0;
    if (s == "SUN") {
        ans = 7;
    } else if (s == "MON") {
        ans = 6;
    } else if (s == "TUE") {
        ans = 5;
    } else if (s == "WED") {
        ans = 4;
    } else if (s == "THU") {
        ans = 3;
    } else if (s == "FRI") {
        ans = 2;
    } else if (s == "SAT") {
        ans = 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;

/// Equivalent to std::lowerbound and std::upperbound in c++
pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
    fn upper_bound(&self, &T) -> usize;
}
 
impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
 
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
 
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
 
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}
 
 
 
 
 
 
pub static MOD:i64 = 998244353;
fn main(){
    input!{
        n:i64,
        k:i64,
    }
    println!("{}", n-k+1);
}



Measured memory_bytes: 4352
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = sc.nextInt();  //書かれている整数の数
		int shorui[] = new int[sum];  //書類に書かれてる整数が入ってる配列
 
		for(int i=0 ; i<sum ; i++) {
			shorui[i] = sc.nextInt();
            //偶数で、3でも5でも割り切れなかったらその時点で終了
			if(shorui[i]%2==0 && shorui[i]%3!=0 && shorui[i]%5!=0) {
				System.out.println("DENIED");
				return;
			}
		}
		System.out.println("APPROVED");
	}
}

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

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b) swap(a,b);
    if(2*a+(b-a)*2>16) puts(":(");
    else puts("Yay!");
    return 0;
}


Measured memory_bytes: 128
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);
int c[200005],dp[200005],ans[200005];
vi v;
signed main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n,i;
	 cin>> n;
	rep(i,n){
		cin>>c[i];
	}		
	v.pb(c[0]);
	f(i,1,n){
		if(c[i]!=c[i-1]){
			v.pb(c[i]);
		}
	}
	n=v.size();
	dp[n-1]=1;
	ans[v[n-1]]=1;
	fd(i,n-2,0){
		ans[v[i]]+=dp[i+1];
		ans[v[i]]%=mod;
		dp[i]=ans[v[i]];
	}
	cout<<dp[0]<<endl;
	return 0;
} 
	

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

string arr[200];

int main()
{
    int n,l;
    scanf("%d%d",&n,&l);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr,arr+n);
    for(int i = 0; i < n; i++) {
        cout << arr[i];
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


signed main() {
	ll a, b;
	cin >> a >> b;
	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		if (i % 2) {
			if (b & 1) {
				b--;
			}
			a += b / 2;
			b /= 2;
		} else {
			if (a & 1) a--;
			b += a / 2;
			a /= 2;
		}
	}

	cout << a << ' ' << b NL;

	return 0;
}



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

int main() {
    int x, y;
    cin >> x >> y;
    int a[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1,0, 1, 0};
    if(a[x-1]==a[y-1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Pi = pair < int , int >;

template < typename T > 
struct BIT
{
	vector < T > dat;

	BIT (int n)
	{
		dat.assign(n + 1, 0);
	}
	
	void add(int k, T x)
	{
		k++;
		while ( k <= dat.size() ) {
			dat[k] += x;
			k += k & -k;
		}
	}

	T query(int k)
	{
		T sum = 0;
		k++;
		while ( k > 0 ) {
			sum += dat[k];
			k -= k & -k;
		}
		return ( sum );
	}

	int lower_bound(T x)
	{
		int l, r;
		l = -1, r = dat.size();
		while ( l + 1 < r ) {
			int m = (l + r) / 2;
			if ( query(m) >= x ) r = m;
			else l = m;
		}
		return ( r );
	}
};

int main()
{
	int N;
	int A[100005];
	Pi dat[100005];

	map < Pi , int > idx;
	cin >> N;

	for ( int i = 0; i < N; i++ ) {
		cin >> A[i];
		dat[i] = Pi(A[i], -i);
	}
	sort(dat, dat + N);
	
	for ( int i = 0; i < N; i++ ) {
		idx[dat[i]] = i;
	}
	
	BIT < int > tree(N);	
	int ans = 0;
	for ( int i = 0; i < N; i++ ) {
		int pos = idx[Pi(A[i], -i)];
		int value = tree.query(pos);
		
		if ( value == 0 ) {
			ans++;
		} else {
			tree.add(tree.lower_bound(value), -1);
		}
		tree.add(pos, 1);
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 8064
#include <iostream>
using namespace std;
int H,W,ans;
char f[100][100];
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};
void paint(int x,int y){
	int a,b,c;
	c=f[x][y];
	f[x][y]='-';
	for(int i=0;i<4;i++){
		a=x+dx[i];
		b=y+dy[i];
		if(0<=a&&a<W&&0<=b&&b<H&&f[a][b]==c){
			paint(a,b);
		}
	}
}
int main()
{
	while(true){
		cin>>H>>W;
		if(!H&&!W)break;
		ans=0;
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++)cin>>f[j][i];
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++){
				if(f[j][i]!='-'){
					paint(j,i);
					ans++;
				}
		}
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 1632
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;
  int C[VMAX+1];
  int n,i,j;
  int max=0;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

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

  for(i=0;i<=VMAX;i++){
    C[i] = 0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);
  
  return 0;
}





Measured memory_bytes: 9588
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<pair<int, int>>> edges(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, k});
    vector<char> visited(n);
    vector<ll> lens(n, MLL);
    while(pq.size()){
        auto e = pq.top(); pq.pop();
        if(visited[e.second]){ continue; }
        visited[e.second] = true;
        lens[e.second] = e.first;
        for(auto edge : edges[e.second]){
            pq.push({e.first + edge.second, edge.first});
        }
    }
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << lens[x] + lens[y] << '\n';
    }
    return 0;
}


Measured memory_bytes: 10096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class BPalindromicNumbers {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int res = 0;
            for (int i = a; i <= b; i++) if (i / 10000 == i % 10 && i / 10 % 10 == i / 1000 % 10) res++;
            out.println(res);
        }

    }
}



Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(){
	string str;
	bool flag=false;

	cin>>str;

	int s=str.length();
	if(s==2){
		if(str[0]==str[1]){
			cout<<"1 2"<<endl;
			flag=true;
		}
	}else{
		for(int i=0; i<s-2; i++){
			if(str[i]==str[i+1] || str[i+1]==str[i+2] || str[i+2]==str[i]){
				cout<<i+1<<" "<<i+2+1<<endl;
				flag=true;
				break;
			}
		}
	}

	if(!flag){
		cout<<"-1 -1"<<endl;
	}

	return 0;

}

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

int main() {
	int N;
	scanf("%d", &N);
	if (N==3) {
		printf("2 5 63\n");
		return 0;
	}
	long long sum=0;
	for (int i=2; i<=30000; i++) {
		if (i%2==0||i%3==0) {
			printf("%d ", i);
			sum+=i;
			N--;
		}
		if (N==2) {
			bool found=false;
			for (int j=i+1; j<=30000; j++) {
				for (int k=j+1; k<=30000; k++) {
					if ((j+k+sum)%6==0 && (j%2==0||j%3==0) && (k%2==0||k%3==0)) {
						printf("%d %d\n", j, k);
						found = true;
						break;
					}
				}
				if (found) break;
			}
			break;
		}
	}
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    ll N, K;
    cin >> N >> K;

    ll ans = (N / K) * (N / K) * (N / K);

    if (K % 2 == 0) {
        ll n = (N + K / 2);
        ll tmp = (n / K) * (n / K) * (n / K);
        ans += tmp;
    }

    cout << ans << endl;

    return 0;
}


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

int N, S, W, Q;
vector<int> A;

void solve(){
    vector<int> S(N+1);
    int k = 1;
    for(int i=N-1; i>=0; i--){
        S[i] = (k*A[i] + S[i+1]) % Q;
        k = k*10 % Q;
    }
    
    int ans = 0;
    if(Q != 2 && Q != 5){
        map<int, int> mp;
        for(int i=0; i<=N; i++){
            ans += mp[S[i]];
            if(A[i]) mp[S[i]]++;
        }
//        for(int i=0;i<N;i++){
//            if( A[i] ) mp[S[i]]++;
//            ans += mp[ S[i+1] ];
//        }
    }else{
        int cnt = 0;
        for(int i=0; i<N; i++){
            if(A[i]) cnt++;
            if(A[i] % Q == 0)
                ans += cnt;
        }
    }
    cout << ans << endl;
}

signed main(){
    while (cin >>N>>S>>W>>Q, N|S|W|Q) {
        A.clear(); A.resize(N);
        int g = S;
        for(int i=0; i<N; i++) {
            A[i] = (g/7) % 10;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 7600
import java.util.Scanner;
public class Main {

  public static void main(String[] args) {
    String result = "War";
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int X = scanner.nextInt();
    int Y = scanner.nextInt();

    int xMax = -100;
    int yMin = 100;
    for (int i = 0; i < N; i++) {
      int x = scanner.nextInt();
      if ( x > xMax ) {
        xMax = x;
      }
    }
    for (int i = 0; i < M; i++) {
      int y = scanner.nextInt();
      if ( yMin > y) {
        yMin = y;
      }
    }

    for (int Z = X + 1; Z <= Y; Z++) {
      if (xMax < Z && Z <= yMin) {
        result = "No War";
        break;
      }
    }
    System.out.println(result);
  }
}


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

int main() {
  int N,K;
  cin >> N >> K;
  string str;
  cin >> str; 
  int count = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    	if (str.at(i) == 'L') A.at(i)=0;
        if (str.at(i) == 'R') A.at(i)=1;
  	}
  for(int i = 1; i < N; i++) {
    if (A.at(i) != A.at(i-1)==1 ) count++;
    /*
    if(i==0){
      if(A.at(i)==0 || A.at(1)==1 ) count++; 
    }
    else if(i!=N-1){
      if(A.at(i) ==0 && A.at(i-1)==1 ) count++;
      if(A.at(i) ==1 && A.at(i-1)==0 ) count++;
    }
    else{
      if(A.at(N-1) ==0 && A.at(N-2)==1 ) count++;
      if(A.at(N-1) ==1) count++;
    }
    */
  }
  int hanten = max( count - 2*K, 0 );
  int answer;
  answer = N -1 - hanten;  
  cout<< answer << endl; 
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 2000

ll N,K;
ll nCm[NUM][NUM];

int main(){

	scanf("%lld %lld",&N,&K);

	//コンビネーションを求める
	nCm[0][0] = 1;
	for(ll n = 1; n <= N+K-1; n++) {
		for (int m = 0; m <= N; m++) {
			if(m > 0){
				nCm[n][m] = nCm[n-1][m]+nCm[n-1][m-1];
			}else{ //m == 0
				nCm[n][m] = 1;
			}
			nCm[n][m] %= MOD;
		}
	}

	printf("%lld\n",nCm[N+K-1][N]);

	return 0;
}



Measured memory_bytes: 26676
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(i, a, n) for (int i = a; i < n; i++)
#define f1(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvpii vector<vpii>
#define vbl vector<bool>
#define upb upper_bound
#define lwb lower_bound
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define umap unordered_map
#define uset unordered_set
#define gcd __gcd
const ll MOD = 1e9 + 7;
#define INF INT_MAX
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ld l; cin >> l;
    ld ans = (l * l * l * 1.0)/27;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int min(int a, int b){return (a>b)? b:a;}

int eaten[101]; //1-based 

int main(void){
    // Your code here!
    int N,D,X;
    scanf("%d %d %d",&N,&D,&X);
    
    int A;
    for(int i = 0; i < N; i++){
        scanf("%d",&A);
    
        for(int k = 0; k*A+1 <= D; k++){
            eaten[k*A+1] += 1;
        }
    }
    
    int cnt = 0;
    for(int i = 1; i <= D; i++){
        cnt += eaten[i];
    }
    
    printf("%d\n",X+cnt);

}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int n;
	cin >> n;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	rep(i, n) {
		int k;
		cin >> k;
		if (k == 1) cnt1++;
		else if (k == 2) cnt2++;
		else cnt3++;
	}

	double dp[305][305][305];
	rep(c3,n+1)rep(c2,n+1)rep(c1,n+1) {
		double sumi = (double)c3 + (double)c2 + (double)c1;
		if (sumi == 0) continue;
		dp[c1][c2][c3] = (double)n / sumi;
		if (c3 > 0) dp[c1][c2][c3] += dp[c1][c2 + 1][c3 - 1] * (double)c3 / sumi;
		if (c2 > 0) dp[c1][c2][c3] += dp[c1 + 1][c2 - 1][c3] * (double)c2 / sumi;
		if (c1 > 0) dp[c1][c2][c3] += dp[c1 - 1][c2][c3] * (double)c1 / sumi;
	}

	cout << fixed << setprecision(12) << dp[cnt1][cnt2][cnt3] << endl;
}

Measured memory_bytes: 220928
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int a,b;
	cin>>a>>b;
	vector<string>v;
	for (int i=0;i<a;i++){
		string d;
		cin>>d;
		v.pb(d);
	}
	sort(all(v));
	for (int i=0;i<a;i++)  cout<<v[i];
	re 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
//#define int long long

const int N = 3000;
int n;
double p[N];
double dp[N][N];

int32_t main() {

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

    dp[0][0] = 1.0;
    
    for(int i = 0; i < n; ++i) {
        for(int heads = 0; heads < n; ++heads) {
            dp[i+1][heads+1] += dp[i][heads]*p[i];
            dp[i+1][heads] += dp[i][heads]*(1.0-p[i]);
        }
    }

    double ans = 0.0;
    for(int heads = n/2+1; heads <= n; ++heads) {
        ans += dp[n][heads];
    }

    cout << setprecision(15) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 70528
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;

int main(void){
  int n,i,x;
  cin>>n;
  int tmp,res,flag;

  res=0;
  flag=-1;
  cin>>tmp;

  for(i=1;i<n;i++){
    cin>>x;
    if(flag==-1){
      if(x>tmp) flag=1;
      else if(x<tmp) flag=0;
    }
    else if(flag==0){
      if(x>tmp){
        res++;
        flag=-1;
      }
    }
    else if(flag==1){
      if(x<tmp){
        res++;
        flag=-1;
      }
    }
    tmp=x;
  }

  cout<<res+1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int A, B;
  
  cin >> A >> B;
  
  if(A>=13){
    cout << B << endl;
  }
  else if(A>=6 && A<=12){
    cout << B/2 << endl;
  }
  
  else{
    cout << 0 << endl;
  }
  
  return 0;
}

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

using namespace std;
int n;
long long int dp[105][100005];
long long int knap(int i,int mw,long long int *v,int *w)
{
    if(i>=n || mw<=0)
        return 0;
    if(dp[i][mw])
        return dp[i][mw];
    else if(w[i]>mw)
    {
        return dp[i][mw]=knap(i+1,mw,v,w);
    }
    else
    {
        //mw=mw-w[i];
        return dp[i][mw]=max(v[i]+knap(i+1,mw-w[i],v,w),knap(i+1,mw,v,w));
    }
}

int main()
{
    int mw;
    cin>>n>>mw;
    long long int v[n];
    int w[n];
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    memset(dp,0,sizeof(dp));
    cout<<knap(0,mw,v,w)<<"\n";
    return 0;
}


Measured memory_bytes: 82304