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

int main(){
  int n,  minus = 0, minV = 10000000;
  cin >> n;
  int a[n];
  long long sum = 0;
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] < 0){
      minus++;
    }
    sum += abs(a[i]);
    minV = min(minV, abs(a[i]));
  }

  if(minus % 2 == 0){
    cout << sum << endl;
  } else {
    cout << sum - 2*minV << endl;
  }


  return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    int[] numPatternCount = new int[19];
    int i, j, k, l;
    int size = 9;
    int sum;
    for (i = 0; i <= size; i++) {
      for (j = 0; j <= size; j++) {
        if (i+j > 18)
              break;
        for (k = 0; k <= size; k++) {
          if (i+j+k > 18)
              break;
          for (l = 0; l <= size; l++) {
            sum = i + j + k + l;
            if (sum > 18)
              break;
            numPatternCount[sum]++;
          }
        }
      }
    }
    while ((readStr = reader.readLine()) != null) {
      int n = Integer.parseInt(readStr);
      System.out.println(
              n > 36 ? 0
              : numPatternCount[n > 18 ? numPatternCount.length - (n - numPatternCount.length) - 2 : n]
      );
    }
  }

}

Measured memory_bytes: 16876
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int l, r ,d, ans=0;
    cin >> l >> r >> d;
    for(int i=l; i <= r ; i++){
        if(i%d == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int H, W;

vector<vector<char > > board;
vector<vector<int>> d;

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

int main() {
	cin >> H >> W;
	board.assign(H, vector<char>(W));
	d.assign(H, vector<int>(W, -1));
	queue<P>que;
	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < W; j++) {
			board[i][j] = s[j];
			if (s[j] == '#') {
				que.push(P(i, j));
				d[i][j] = 0;
			}
		}
	}

	while (que.size()) {
		P p = que.front(); que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx && nx < H && 0 <= ny && ny < W&&board[nx][ny] == '.') {
				if (d[nx][ny] == -1) {
					d[nx][ny] = d[p.first][p.second] + 1;
					que.push(P(nx, ny));
				}
				else if (d[nx][ny] > d[p.first][p.second] + 1) {
					d[nx][ny] = d[p.first][p.second] + 1;
					que.push(P(nx, ny));
				}
			}
		}
	}
	int score = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			score = max(score, d[i][j]);
		}
	}
	cout << score << endl;




	return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}
typedef complex<double> P;

double dot(P a,P b){
  return a.real() * b.real() + a.imag() * b.imag();
}

P project(P s1, P s2,P p){
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

P reflect(P s1, P s2, P p){
  return p + (project(s1,s2,p) - p) * 2.0;
}

int main(void){
  P s1,s2,p;
  string line;
  while(getline(cin,line)){
    replace(line.begin(),line.end(),',',' ');
    stringstream ss(line);
    ss >> s1.real() >> s1.imag()
       >> s2.real() >> s2.imag()
       >> p.real() >> p.imag();
    P q = reflect(s1,s2,p);
    printf("%.8f %.8f\n", q.real(), q.imag());
    
  }
}

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

const long long mod = 1e9 + 7;

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

  vector<vector<long long>> dp(100005, vector<long long>(13, 0));
  dp[0][0] = 1;
  for ( int i = 0; i < s.size(); i++ ) {
    int c = ( s[i] != '?' ) ? s[i]-'0' : -1;

    for ( int j = 0; j < 10; j++ ) {
      if ( c != -1 && c != j ) { continue; }
      for ( int k = 0; k < 13; k++ ) {
        dp[i+1][(k*10+j)%13] += dp[i][k];
      }
    }
    for ( int j = 0; j < 13; j++ ) { dp[i+1][j] %= mod; }
  }

  cout << dp[s.size()][5] << endl;
  return 0;
}


Measured memory_bytes: 16724
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 100010
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n;
int g[MAXN],nume;
int d[MAXN];
int ans;

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x){
	for(int i=g[x];~i;i=e[i].next) dfs(e[i].to);
	static vector<int> S;
	S.clear();
	for(int i=g[x];~i;i=e[i].next) S.push_back(d[e[i].to]);
	sort(S.begin(),S.end());
	int len=S.size();
	for(int i=0;i<len;i++)
		if(S[i]+len-i>d[x]) d[x]=S[i]+len-i;
}

int main(){
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int t;
		scanf("%d",&t);
		addEdge(t,i);
	}
	dfs(1);
	printf("%d\n",d[1]);
}


Measured memory_bytes: 7296
n, c = gets.chomp.split(' ').map(&:to_i)
d = Array.new(c)
c.times { |i| d[i] = gets.chomp.split(' ').map(&:to_i) }
colors = Array.new(3)
3.times { |i| colors[i] = Array.new(c, 0) }
n.times do |i|
  r = gets.chomp.split(' ').map(&:to_i)
  r.each_index do |j|
    colors[(i + j) % 3][r[j] - 1] += 1
  end
end
min = 250000001
(0...c).each do |i|
  (0...c).each do |j|
    (0...c).each do |k|
      next if i == j || j == k || i == k
      counts = 0
      colors.each_with_index do |row, idx1|
        row.each_with_index do |r, idx2|
          if idx1 == 0
            counts += d[idx2][i] * r
          elsif idx1 == 1
            counts += d[idx2][j] * r
          elsif idx1 == 2
            counts += d[idx2][k] * r
          end
        end
      end
      min = [counts, min].min
    end
  end
end
puts min

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		int x;
		s=sc.nextLine();
		//System.out.println(s);
		x=s.length();
		//System.out.println(x);
		char ch[]=s.toCharArray();
		for(int i=x-1;i>=0;i--)
		{
			System.out.print(ch[i]);
		}
		System.out.print("\n");
			
		

	}

}

Measured memory_bytes: 17120
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>
#include<math.h>
#include<iomanip>

using namespace std;


int main(void)
{
    string s;
    cin>>s;
    
    string s1(s.size(),'a'),s2(s.size(),'a');
    
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            s1[i]='0';
            s2[i]='1';
        }
        else{
            s1[i]='1';
            s2[i]='0';
        }
    }
    int a1=0,a2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=s1[i]) a1++;
        if(s[i]!=s2[i]) a2++;
    }
    
    if(a1<a2){
        cout<<a1<<endl;
    }
    else{
        cout<<a2<<endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define va first.first
#define vb first.second
#define vc second.first
#define vd second.second
using namespace std;

using ll = unsigned long long;
const size_t mod = 1e9 + 7;
const size_t b[2] = {23, 29};

size_t Pow(size_t x, int n){
    if(n < 0) n = mod - 1 + n;
    size_t ret = 1, pv = x;
    for(;n;n>>=1){
        if(n & 1) ret = 1LL * ret * pv % mod;
        pv = 1LL * pv * pv % mod;
    }
    return ret;
}

int P[250005];
ll V[250005][2];
string S, T;
int n;
unordered_map<ll,int> m;

ll H(size_t b1, size_t b2){
    return ll(b1) << 32ll | b2;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    cin >> S;
    T = "*";
    T += S;
    for(int i = 1; i <= n; i++){
        switch(T[i]){
        case '+':
            P[i] = P[i-1];
            for(int k = 0; k < 2; k++) V[i][k] = (V[i-1][k] + Pow(b[k], P[i])) % mod;
            break;
        case '-':
            P[i] = P[i-1];
            for(int k = 0; k < 2; k++) V[i][k] = (V[i-1][k] + mod - Pow(b[k], P[i])) % mod;
            break;
        case '>':
            P[i] = P[i-1] + 1;
            for(int k = 0; k < 2; k++) V[i][k] = V[i-1][k];
            break;
        case '<':
            P[i] = P[i-1] - 1;
            for(int k = 0; k < 2; k++) V[i][k] = V[i-1][k];
            break;
        }
    }
    ll ans = 0;
    m[H(V[n][0],V[n][1])]++;
    for(int i = 1; i <= n; i++){
        ans += m[H(V[i][0],V[i][1])];
        size_t v0 = (Pow(b[0],P[i]) * V[n][0] + V[i][0])%mod;
        size_t v1 = (Pow(b[1],P[i]) * V[n][1] + V[i][1])%mod;
        ll key = H(v0,v1);
        //cout << "i : " << v0 << " " << v1 << '\n';
        m[H(v0,v1)]++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 25352
import math

n = int(input())

ans = [0 for _ in range(10001)]

for i in range(1,math.ceil(math.sqrt(n))):
    for j in range(1,math.ceil(math.sqrt(n))):
        for k in range(1,math.ceil(math.sqrt(n))):
            v = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if(v < 10001):
                ans[v] += 1

for i in range(n):
    print(ans[i+1])


Measured memory_bytes: 74548
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  vector<int> left = vector<int>(N, 0);
  vector<int> right = vector<int>(N, 0);
  for (int i = 0; i < N; i++)
  {
    if (i == 0)
    {
      if (S[0] == 'W')
      {
        left[0]++;
      }
      else
      {
        right[0]++;
      }
    }
    else
    {
      right[i] += right[i - 1];
      left[i] += left[i - 1];
      if (S[i] == 'W')
      {
        left[i]++;
      }
      else
      {
        right[i]++;
      }
    }
  }

  int res = 1e9;
  for (int i = 0; i < N; i++)
  {
    // i=reader
    int temp = 0;
    if (i == 0)
    {
      temp = right[N - 1];
    }
    else
    {
      temp = left[i] + (right[N - 1] - right[i - 1]) - 1;
    }
    res = min(res, temp);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3076
//import java.lang.Math;
import java.util.*;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;
 
 
class Main{
     
    public static void main(String[] arg){
         
     
 
     
        Scanner sc= new Scanner(System.in);
        List<Integer> list =new ArrayList<Integer>();
        int[] s=new int[3];
        for(int i=0;i<3;i++){
            s[i]=sc.nextInt();
            list.add(new Integer(s[i]));
        }
         
                int a=Collections.min(list);
               
        int b=Collections.max(list);
         
        System.out.println(a+" "+b);
         
}
        }


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

int main() {
  int64_t a, b, k;
  cin >> a >> b >> k;
  if(a > k) cout << a - k << ' ' << b << endl;
  else if(a + b > k) cout << 0 << ' ' << b + a - k << endl;
  else cout << 0 << ' ' << 0 << endl;
}


Measured memory_bytes: 256
X, K, D = map(int,input().split())

X = abs(X)
a=X%D
b=D-a

at=(X-a)//D
bt=at+1

if K<= at:
	print(X-K*D)
	exit()
if at %2==0:
	if K%2==0:
		print(a)
	else:
		print(b)
else:
	if K%2==0:
		print(b)
	else:
		print(a)

Measured memory_bytes: 61812
x, n = map(int, input().split())
ls = list(map(int, input().split()))

# 数列内の最大最小値幅のリストを新たに作る
base = list(range(-1, 100 + 2))
# 数列内に無い数値を抽出する
diff = list(set(base) - set(ls))

diff = sorted(diff)

ans = 1000
for i in diff:
    if abs(x - ans) > abs(x - i):
        ans = i

print(ans)

Measured memory_bytes: 9200
program  ec12;
var 
	n,m,i,j,ans,tot:longint;
	a:array[1..100001] of longint;
procedure qsrt(l,r:longint);
var 
	i,j,v,s:longint;
begin
	i:=l; j:=r; v:=a[(l+r) div 2];
	repeat
	while a[i]<v do inc(i);
	while a[j]>v do dec(j);
	if i<=j then 
	begin 
		s:=a[i];
		a[i]:=a[j];
		a[j]:=s;
		inc(i);
		dec(j);
	end;
	until i>=j;
	if l<j then qsrt(l,j);
	if i<r then qsrt(i,r);
end;
begin 
	readln(n);
	for i:=1 to n do
	readln(a[i]);
	qsrt(1,n);
	tot:=1;
	ans:=0;
	for i:=2 to n do 
	begin 
		if a[i]=a[i-1] then 
		inc(tot)
		else
		begin 
			if tot mod 2=1 then 
			inc(ans);
			tot:=1;
		end;
	end;
	if tot mod 2=1 then 
	inc(ans);
	writeln(ans);
end. 

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rep2(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
// int ans;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N;
    vector<int> p(N), q(N);
    rep(i, N) {
        cin >> p[i];
    }
    rep(i, N) {
        cin >> q[i];
    }

    vector<int> text(N);
    rep(i, N) {
        text[i] = i + 1;
    }

    int i = 0;
    do {
        if (text == p) P = i;
        if (text == q) Q = i;
        i++;
    } while (next_permutation(all(text)));
 
    cout << abs(P - Q) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

    int N, M, ans;
    cin >> N >> M;

    int max = M / N;

    for (int i = max; i > 0; i--) {
        if ((M % i) == 0) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
s = input()
t = input()
n = len(s)
changed_s = defaultdict(list)
changed_t = defaultdict(list)
flag = True
used = []
for i in range(n):
    if s[i] != t[i]:
        changed_s[s[i]].append(t[i])
        changed_t[t[i]].append(s[i])
    else:
        used.append(s[i])

#print(changed_s)
#print(changed_t)
#print(used)
for key, lis in changed_s.items():
    if len(set(lis)) == 1 and key in used:
        flag = False
    elif len(set(lis)) != 1:
        flag = False
for key, lis in changed_t.items():
    if len(set(lis)) == 1 and key in used:
        flag = False
    elif len(set(lis)) != 1:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 66108
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  int N;
	      	  cin >> N;
	      	  vector<int> d(N);
	      	  REP(i,N) cin >> d[i];
	      	  
	      	  sort(d.begin(),d.end());
	      	  d.erase(unique(d.begin(),d.end()),d.end());
	      	  
	      	  cout << (int)d.size() << endl;


	          return 0;
}


Measured memory_bytes: 256
// scanf, printfの実行時間テスト

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, K, Q, who;

    cin >> N >> K >> Q;

    vector<int> score(N, K);

    for (int i = 0; i < Q; i++)
    {
        scanf("%d", &who);
        score[who - 1]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (score[i] - Q < 1)
        {
            printf("%s", "No\n");
        }

        else
        {
            printf("%s", "Yes\n");
        }
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
int A[maxn];
int main(void)
{
	LL n; cin >> n;
	cout << n*(n + 1) / 2 - n << endl;
	return 0;
}

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

namespace ABC161D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());

            Queue<long> que = new Queue<long>();
            for (int i = 1; i < 10; i++)
            {
                que.Enqueue(i);
            }
            long ans = 0;
            for (int i = 0; i < K; i++)
            {
                long now = que.Dequeue();
                ans = now;

                long nd = now * 10;
                long fd = now % 10;
                if (fd - 1 >= 0) que.Enqueue(nd + fd - 1);
                que.Enqueue(nd + fd);
                if (fd + 1 <= 9) que.Enqueue(nd + fd + 1);
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 15072
// Aizu 1257: Sum of Consecutive prime Numbers
// 2017.9.22 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX  10000
#define SQRT 100     // sqrt(MAX)
char np[MAX+3], *pmax = np + MAX;    // prime = !np

#define N 1229
int prime[N+10];

int dp[2][MAX+3], ans[MAX+3];

void nptbl()
{
	int k;
	register char *p, *q;
	np[1] = 1, np[2] = 0;
	for (p = np + 4; p <= pmax; p += 2) *p = 1;
	for (k = 3, p = np + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
}

int main()
{
	int n, i, k1, k2;

	nptbl(); for (n = 1, i = 1; i <= MAX; i++) if (!np[i]) prime[n++] = i;
	for (k1 = 0, k2 = 1, i = 1; i <= N; i++, k1 = k2, k2 = !k1) {
		int a = prime[i];
		memset(dp[k2], 0, sizeof(dp[k2]));
		ans[a]++, dp[k2][a]++;
		for (n = 1; n + a <= 10000; n++) if (dp[k1][n])
			dp[k2][n+a] += dp[k1][n], ans[n+a]++;
	}

	while (scanf("%d", &n) && n) printf("%d\n", ans[n]);
	return 0;
}

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

int main() {
  int N, F, a,b,c,d,e,f,g,h,i;
  cin >> N;
  a = N / 100000000,
  b = N / 10000000 - 10 * a,
  c = N / 1000000 - 10 * b - 100 * a,
  d = N / 100000 - 10 * c - 100 * b - 1000 * a,
  e = N / 10000 - 10 * d - 100 * c - 1000 * b - 10000 * a,
  f = N / 1000 - 10 * e - 100 * d - 1000 * c - 10000 * b - 100000 * a,
  g = N / 100 - 10 * f - 100 * e - 1000 * d - 10000 * c - 100000 * b - 1000000 * a,
  h = N / 10 - 10 * g - 100 * f - 1000 * e - 10000 * d - 100000 * c - 1000000 * b - 10000000 * a,
  i = N % 10;
  F =a+b+c+d+e+f+g+h+i;
  if (N % F == 0) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long int pow2(int i){
  if(i > 0){
    return ((long long int)1<<i);
  }else{
    return 1;
  }
}
int main(void){
  for(;;){
    long long int N;
    cin >> N;
    if(N == 0){return 0;}
    long long int ptr = 0;
    // 以下， N 番目の短歌数を T[N] とする．

    // Step 1
    // 10...0(d桁) <= T[N] < 100...0 (d+1 桁) を満たす d を求める．
    // bd桁の短歌数は (81*(pow2(bd-1) - 1))個
    int d;  bool notfound = true;
    for(int bd = 2 ; notfound ; bd++){
      if(ptr < N && N <= ptr + (81*(pow2(bd-1) - 1))){
	notfound = false;
	d = bd;
      }else{
	ptr += 81*(pow2(bd-1) - 1);
      }
    }

    // Step 2
    // T[N] = k?...? を満たす k を求める．
    // すなわち，k0...0(d桁) <= T[N] < (k+1)0...0 (d 個) を満たす k を求める．
    // k0...0 〜 k9...9 までの短歌数は　9*(pow2(d-1)-1)
    int k; notfound = true;
    for(int bk = 1 ; notfound ; bk++){
      if((ptr <= N && N <= ptr+9*(pow2(d-1)-1)) || bk == 9){
	notfound = false;
	k = bk;
      }else{
	ptr += 9*(pow2(d-1)-1);
      }
    }

    // Step 3
    // T[N] = k...k?...? (k が最初に f 個連続する) を満たす f を求める
    // kk...k00...0     〜 kk...k(k-1)k...k までは k*pow2(d-f-1)     個
    // kk...kk0...0     〜 kk...kk9...9     までは 9*(pow2(d-f-1)-1) 個 (1個引いているのは全部kの場合)
    // kk...k(k+1)k...k 〜 kk...k9...9      までは (9-k)*pow2(d-f-1) 個
    // 要するに，
    //   N < ptr + k*pow2(d-f),  ptr + k*pow2(d-f) + 9*(pow2(d-f)-1) <= N
    // を満たす f を求めれば良い．
    int f; notfound = true;
    for(int bf = 1 ; notfound ; bf++){
      if(N <= ptr + k*pow2(d-bf-1) ||  ptr + k*pow2(d-bf-1) + 9*(pow2(d-bf-1)-1) < N || d-bf == 1){
	notfound = false;
	f = bf;
      }else{
	ptr += k*pow2(d-bf-1);
      }
    }

    // Step 4
    // T[N] = k...kj?...? を満たすjを求める．
    // 要するに，
    //    k...kj0...0(k が最初に f 個) <= T[N] < k...k(j+1)0...0 (k が最初に f 個)
    // を満たす j を求める．ただし， j != k に注意
    // k...kj?...? は pow2(d-f-1) 個
    int j; notfound = true;
    for(int bj = 0 ; notfound && bj <= 9 ; bj++){
      if(bj != k){
	if(ptr < N && N <= ptr + pow2(d-f-1)){
	  notfound = false;
	  j = bj;
	}else{
	  ptr += pow2(d-f-1);
	}
      }else if (bj != 9){
	ptr += 9*(pow2(d-f-1)-1);
      }
    }
    
    // Step 5
    // ここまでで，使う2つの数は決まった．
    // k...kj(kとjの列)
    // m = min(k,j), M = max(k,j) とする．
    // あとは，k...kjm...m から gap = N - ptr - 1 個進めた数を求めれば良い．
    // これを求めるのは，gap の 2 進表記の 0 を m，1 を M に取り替えたものを，k...kj0...0 に足したものである．
    // なお，gap の 2 進表記は，d-f-1 桁である．
    long long int gap = N - ptr - 1;
    int M = (k<j)?j:k;
    int m = (k<j)?k:j;

    // 答えの出力
    for(int i = 0 ; i < f ; i++){
      cout << k;
    }
    cout << j;
    for(int i = 0 ; i < d-f-1 ; i++){
      if((gap>>(d-f-i-2))%2 == 0){
	cout << m;
      }else{
	cout << M;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3108
import sys
import math
import numpy as np
sys.setrecursionlimit(10**7)

class Task:
    def __repr__(self):
        return str(self.__dict__)

    def time_toget_point(self, p):
        # p点とるのに必要な時間を返す
        if p >= self.max_minus:
            return math.ceil(self.b + (p - self.max_minus)/self.u)
        else:
            return math.ceil(p/self.l)

def solve():
    n, x = map(int, input().split())
    t_list = []
    total_behind = 0 # これだけ点を取らなければならない

    for i in range(n):
        t = Task()
        t.b, t.l, t.u = map(int, input().split())
        t.max_minus = t.b * t.l
        t.eff = ((x-t.b)*t.u) + (t.b*t.l) # 重み最高にした時の勉強効率
        t_list.append(t)
        total_behind += t.max_minus

    # 重み最高での勉強効率の降順に並び変え
    t_list = sorted(t_list, key=lambda t: t.eff, reverse=True)
    cumsum = list(np.cumsum([t.eff for t in t_list]))

    # 何要素目まで上から取ると必要点数を超えるか
    import bisect
    for max_i in range(len(t_list)):
        if cumsum[max_i] > total_behind:
            break

    # 部分点を取るtaskをi番目と決めたときの、必要勉強時間を求める。その最小値が答えになる
    min_time = -1
    for i, t in enumerate(t_list):
        if i <= max_i:
            # 上からとるものにiが含まれるケースでは、上から max_i 要素目までのうち i 以外を取り、iから最適な値をとる
            rest_p = total_behind - (cumsum[max_i] - t.eff)
        else:
            # 上からとるものにiが含まれないケースでは単に上から max_i-1 要素目までとり、iから最適な個数とる
            # rest_p が task i でとれる点数を超える場合があるが、解にはならないので気にしなくてよい
            if max_i == 0:
                rest_p = total_behind
            else:
                rest_p = total_behind - cumsum[max_i-1]

        # task i で rest_p とるのに必要な時間を求める
        time = x * (max_i) + t.time_toget_point(rest_p)

        if min_time == -1 or min_time > time:
            min_time = time
    print(min_time)

solve()

Measured memory_bytes: 61848
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

#define ll long long

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

    ll r = 0;
    vector<ll> ans(s.length(), 0);
    for (ll i = 0; i < s.length(); i++)
    {
        r++;
        if (s[i] == 'R' && s[i + 1] == 'L')
        {
            ll l = 0;
            for (ll j = i + 1; s[j] == 'L'; j++)
                l++;

            ll f = (r + l) / 2,
               b = (r + l) / 2;
            if (l % 2 == 1 && r % 2 == 0)
                b++;
            if (l % 2 == 0 && r % 2 == 1)
                f++;

            ans[i] = f;
            ans[i + 1] = b;
            for (ll j = 1; j < l; j++)
                ans[i + 1 + j] = 0;
            i += l;
            r = 0;
        }
    }

    for (ll i = 0; i < s.length(); i++)
        printf("%lld ", ans[i]);
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pp;
double PI=acos(-1);
int const N = 5e5 + 10,M=1e7+1, oo = 1e9;
const int mod = oo+7;
const ll  OO = 3e18;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=n;;i++){
        int u=i;
        vector<int > v;
        while(u){
            v.push_back(u%10);
            u/=10;
        }
        int s=v.size();
        sort(v.begin(),v.end());
        v.resize(unique(v.begin(),v.end())-v.begin());
        if((int)v.size()==1){
            for(int j=0;j<s;j++)cout<<v[0];
            return 0;
        }
    }
    return 0;
}

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

int main (){
    int N;
    int K;
    cin >> N;
    cin >> K;
    int i;
    int c = 0;
    int temp;
    for( i=0; i < N; i++){
        cin >> temp;
        if(temp < K){
            c++;
        }
    }
    cout << N - c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


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

  vector<int> a(N);

  rep(i,N) cin >> a[i];

  vector<bool> b(8,false);
  
  int c=0,ans=0;

  rep(i,N){
    int x=a[i],y=x/400;
    if(y>=8) c++;

    else b[y]=true;
  }

  bool color=true;//3199までの人が一人でもいるか

  rep(i,8){
    if(b[i]==true) ans++;
    color=color&&!b[i];
  }

  if(c>0&&color) cout << 1 << ' ' << c << endl;//3200以上の人しかいない場合、全員同じ色の1が最小、全員違う色にしたcが最大

  else cout << ans << ' ' << ans+c << endl;

  return 0;
}

Measured memory_bytes: 256
def maxnumseq( list )
	max = -100000 	

	while list.size > 0
		sum = 0
		list.each{ |n|
			sum += n
			
			if max < sum
				max = sum
			end
			if sum < 0
				break
			end
		}
		list.shift
	end
	return max
end

def main
	answers = Array.new
	while line = $stdin.gets
		n = line.chomp.to_i
		break if n == 0
		
		num_list = Array.new
		n.times{
			num = $stdin.gets.chomp.to_i
			num_list << num
		}
		answers << maxnumseq( num_list )
	end

	answers.each{ |a| puts a }
end

main


Measured memory_bytes: 6096
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
std::string s, t;
const int MAX_N = 3000;
int dp[MAX_N + 1][MAX_N + 1];
int m, n;
std::string ans = "";

std::string solve() {
    m = (int)(s.length());
    n = (int)(t.length());
    for (int i = 0; i <= m; i ++) {
        for (int j = 0; j <= n; j++) {
            if (i * j == 0) {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = dp[i - 1][j];
            if (dp[i][j] < dp[i][j - 1]) {
                dp[i][j] = dp[i][j - 1];
            }
            if (s[i - 1] != t[j - 1]) {
                continue;
            }
            if (dp[i - 1][j - 1] + 1 > dp[i][j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        }
    }
    while (m > 0 && n > 0) {
        if (s[m - 1] == t[n - 1]) {
            ans = s[m - 1] + ans;
            m--;
            n--;
        } else if (dp[m][n] == dp[m - 1][n]) {
            m--;
        } else {
            n--;
        }
    }
    return ans;
}

int main() {
    std::cin >> s;
    std::cin >> t;
    std::cout << solve() << "\n";
    return 0;
}

Measured memory_bytes: 35456
// AtCoder Grand Contest 007
// B - Construct Sequences

#include <cstdio>
#define MAX_N 200000
#define MAX_BIT_IDX MAX_N
using namespace std;


typedef long long int ll;

template <typename T>
class BIT {
public:
  T b[MAX_BIT_IDX + 1];
  int n;
  void init(int num);
  T sum(int i);
  void add(int i, T x);
};

template <typename T>
void BIT<T>::init(int num) {
  n = num;
  for (int i = 0; i <= n; i++) {
    b[i] = 0;
  }
  return;
}

template <typename T>
T BIT<T>::sum(int i) {
  T s = 0;

  for (; i > 0; i -= i & -i) {
    s += b[i];
  }
  return s;
}

template <typename T>
void BIT<T>::add(int i, T x) {
  for (; i <= n; i += i & -i) {
    b[i] += x;
  }
  return;
}

template <typename T>
class LinearBIT {
public:
  BIT<T> bit0, bit1;
  void init(int num);
  T sum(int i);
  void add(int l, int r, T x); // [l, r)
};

// [l, r)
template <typename T>
void LinearBIT<T>::init(int num) {
  bit0.init(num);
  bit1.init(num);
  return;
}

// [l, r)
template <typename T>
void LinearBIT<T>::add(int l, int r, T x) {
  bit0.add(l, -x * (l - 1));
  bit1.add(l, x);
  bit0.add(r, x * (r - 1));
  bit1.add(r, -x);
  return;
}

template <typename T>
T LinearBIT<T>::sum(int i) {
  return bit1.sum(i) * i + bit0.sum(i);
}


int N;
LinearBIT<ll> l_bit[2];
int p[MAX_N + 1];


int main() {

  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &p[i]);
  }
  l_bit[0].init(N);
  l_bit[1].init(N);

  for (int i = 1; i <= N; i++) {
    l_bit[0].add(i, i + 1, i);
    l_bit[1].add(i, i + 1, N + 1 - i);
  }

  for (int i = 1; i <= N; i++) {
    l_bit[0].add(p[i], N + 1, i - 1);
    l_bit[1].add(1, p[i] + 1, i - 1);
  }

  for (int j = 0; j < 2; j++) {
    for (int i = 1; i <= N; i++) {
      printf("%lld%c", l_bit[j].sum(i) - l_bit[j].sum(i - 1), i < N ? ' ' : '\n');
    }
  }

  return 0;

}




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

namespace TestProject20180923
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var rs = new Dictionary<char, char>();
            var rt = new Dictionary<char, char>();
            for (int i = 0; i < s.Length; i++)
            {
                if (rs.ContainsKey(s[i]))
                {
                    if (rs[s[i]] != t[i]) {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    rs.Add(s[i], t[i]);
                }
                if (rt.ContainsKey(t[i]))
                {
                    if (rt[t[i]] != s[i])
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    rt.Add(t[i], s[i]);
                }
                
            }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 14688
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;

#pragma endregion

struct edge {
	int from, to, cost;
};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/
signed main(void) {
	while (1) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<int> a(n);
		for (int i = n; i > 0; i--) {
			a[n - i] = i;
		}
		for (int i = 0; i < r; i++) {
			int pos, num;
			cin >> pos >> num;
			vector<int> s(num);
			for (int j = 0; j < num; j++) {
				s[j] = a[pos - 1 + j];
			}
			a.erase(a.begin() + pos - 1, a.begin() + pos - 1 + num);
			/*for (auto i = a.begin(); i != a.end();i++) {
				cout << *i;
			}
			cout << endl << "!!!" << endl;*/
			for (auto ite = a.begin(); ite != a.end(); ite++) {
				s.push_back(*ite);
			}
			a.resize(n);
			copy(s.begin(), s.end(), a.begin());
			/*for (auto i = a.begin(); i != a.end(); i++) {
				cout << *i;
			}
			cout << endl << "???" << endl;*/
		}
		cout << a[0] << endl;
	}
	return 0;
}


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

int main(){
	string s, t;
	cin >> s >> t;
	for (int i = 0;i<(int)s.length();i++){
		string s1;
		
		s1.append(s.begin()+i, s.end());
		s1.append(s.begin(),s.begin()+i);
		if (s1 == t) {cout << "Yes"; return 0;}

	}
	cout << "No";
 }


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

using namespace std;

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

  int n;
  cin >> n;
  n %= 10;
  if (n == 3) {
    cout << "bon";
  } else if (n <= 1 or n == 6 or n == 8) {
    cout << "pon";
  } else {
    cout << "hon";
  }

  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<cmath>
using namespace std;

typedef long long llong;
const int MAX = 100010;
int A[MAX];

int main(void)
{
	int n, x, k;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	x = A[n - 1];
	k = -1;
	for (int j = 0; j < n; j++) {
		if (A[j] <= x) {
			k++;
			swap(A[k], A[j]);
		}
	}
	//swap(A[k + 1], A[n - 1]);
	for (int i = 0; i < n; i++) {
		if (i)
			cout << " ";
		if (i == k)
			cout << '[' << A[i] << ']';
		else
			cout << A[i];
	}
	cout << endl;
	return 0;
}


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

int main() {
  int N; cin >> N;
  for(int i = 0; i < 10; i++) {
    if((N + 110) / 111 == i) {
      cout << i * 100 + i * 10 + i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long int a,b,c,i=1,count=0;
    scanf("%ld %ld %ld", &a,&b,&c);
    while(i<=3)
    {
        if(a!=b || b!=c || c!=a)
            count++;
        i++;
    }
    if(a==b || b==c || a==c)
        count--;
    if(a==b && b==c && a==c)
        count=1;
    printf("%ld", count);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 100005
#define MX 500005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int R,C;
vector <int> vec[MX];

int id(int x,int y)
{
	if(1<=x&&x<R&&1<=y&&y<C) return -1;
	if(x==0) return y;
	if(y==C) return C+x;
	if(x==R) return C+R+(C-y);
	if(y==0) return C+R+C+(R-x);
}
int main()
{
	int n;
	scanf("%d %d %d",&R,&C,&n);
	vector <P> edge;
	for(int i=0;i<n;i++)
	{
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		int s=id(a,b),t=id(c,d);
		if(s!=-1&&t!=-1)
		{
			edge.push_back(P(min(s,t),max(s,t)));
		}
	}
	vector <int> vx;
	for(int i=0;i<edge.size();i++)
	{
		P p=edge[i];
		vx.push_back(p.first);
		vx.push_back(p.second);
	}
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<edge.size();i++)
	{
		P p=edge[i];
		p.first=lower_bound(vx.begin(),vx.end(),p.first)-vx.begin();
		p.second=lower_bound(vx.begin(),vx.end(),p.second)-vx.begin();
		vec[p.first].push_back(p.second);
	}
	priority_queue <int,vector <int>,greater <int> > que;
	for(int i=0;i<vx.size();i++)
	{
		while(!que.empty()&&que.top()<i) que.pop();
		if(!que.empty())
		{
			int mn=que.top();
			for(int j=0;j<vec[i].size();j++)
			{
				int to=vec[i][j];
				if(mn<to)
				{
					puts("NO");
					return 0;
				}
			}
		}
		for(int j=0;j<vec[i].size();j++)
		{
			int to=vec[i][j];
			que.push(to);
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 17140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 1000000007;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}

int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll suml = 0;
    ll sumr = 0;
    ll l = 0;
    ll r = n;
    ll ans = 0;
    while(l<k){
        suml+= l;
        sumr+= r;
        l++;
        r--;
    }
    while(l<=n){
        ans+= ((sumr-suml+1)%mod);
        ans%= mod;
        suml+= l;
        sumr+= r;
        l++;
        r--;
    }
    cout<<(ans+1)%mod;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
ll mod= 1e9 + 7;



int main() {
  int a,b;
  cin >> a >>b;
  cout << max({a+b,a-b,a*b}) << endl; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

vector<long long int> factmod(200001);
vector<long long int> inversefactmod(200001);

void getfactmod()
{
	factmod[0] = 1;
	for(long long int i = 1; i < 200001; i++){
		factmod[i] = (factmod[i - 1] * i) % mod;
	}
	return;
}

void getinversefactmod()
{
	for(long long int i = 0; i < 200001; i++){
		// tmp[j] = factmod[i]^(2^j) % mod
		long long int tmp[31];
		tmp[0] = factmod[i];
		for(long long int j = 1; j < 31; j++){
			tmp[j] = (tmp[j - 1] * tmp[j - 1]) % mod;
		}
		long long int m = mod - 2;
		inversefactmod[i] = 1;
		for(long long int j = 30; j >= 0; j--){
			long long int pow2 = (long long int)pow(2, j);
			if(m >= pow2){
				inversefactmod[i] = (inversefactmod[i] * tmp[j]) % mod;
				m -= pow2;
			}
		}
	}
	return;
}

long long int getcomb(long long int n, long long int k)
{
	return factmod[n] * ((inversefactmod[k] * inversefactmod[n - k]) % mod) % mod;
}

int main()
{
	long long int h, w, a, b;
	cin >> h >> w >> a >> b;
	getfactmod();
	getinversefactmod();
	long long int ans = 0;
	for(long long int i = b; i < w; i++){
		ans += (getcomb(h - a + i - 1, i) * getcomb(w + a - i - 2, a - 1)) % mod;
		ans = ans % mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{

    long long ans = 0;
    char N[200010] = { '\0' };

    cin >> N;

    for (int i = 0; i < 200010; i++) {
        if (N[i] == '\0')break;
        ans += N[i] - 48;
    }

    if (ans % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 3788
#include <iostream>

using namespace std;

class Dice{
private:
  int tmp;
public:
  int d[6];

  void rollN(){
    tmp = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = tmp;
  }
 
  void rollE(){
    tmp = d[0];
    d[0] = d[3];
    d[3] = d[5];
    d[5] = d[2];
    d[2] = tmp;
  }

  void rollS(){
    tmp = d[0];
    d[0] = d[4];
    d[4] = d[5];
    d[5] = d[1];
    d[1] = tmp;
  }

  void rollW(){
    tmp = d[0];
    d[0] = d[2];
    d[2] = d[5];
    d[5] = d[3];
    d[3] = tmp;
  }
};

int main(){
  Dice dice;
  string str;

  for(int i = 0 ; i < 6 ; i++){
    cin >> dice.d[i];
  }
  cin.ignore();
  getline(cin,str);
  for(int i = 0 ; i < str.size() ; i++){
    switch(str[i]){
    case 'N':
      dice.rollN();
      break;
    case 'E':
      dice.rollE();
      break;
    case 'S':
      dice.rollS();
      break;
    case 'W':
      dice.rollW();
    break;
    }
  }
  cout << dice.d[0] << endl;

  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int n, A, B, C;
int l[10];

int dfs(int cur, int a, int b, int c) {
    if (cur == n) {
        if (min({a, b, c}) > 0) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        else return INF;
    }
    int ret0 = dfs(cur + 1, a, b, c);
    int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
    int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
    int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;

    return min({ret0, ret1, ret2, ret3});
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	string a,b;
	cin >> a >> b;
	int x,y;
	cin >>x  >> y;
	string t;
	cin >> t;
	if(t==a) --x;
	else --y;
	cout << x << " "<< y;
	return 0;
}

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

int main(void){

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

    sort(a.begin(), a.end());
    
    vector<pair<int, int>> cb(m);
    for(int i=0; i<m; i++) {
        cin >> cb[i].second >> cb[i].first;
    }
    
    sort(cb.begin(), cb.end(), greater<pair<int,int>>());
    
    int cb_index = 0;
    for(int i=0; i<n; i++) {
        if(a[i]<cb[cb_index].first) {
            a[i] = cb[cb_index].first;
            cb[cb_index].second--;
            if(cb[cb_index].second==0) cb_index++;
        }
        if(cb_index==m) break;
    }
    
    long long result =0;
    for(int i=0; i<n; i++) {
        result += a[i];
    }
    
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>

#define X first
#define Y second
using namespace std;

struct UnionFindTree{
	UnionFindTree():pos(pair<int, int>(-1, -1)), root(NULL){}
	pair<int, int> pos;
	UnionFindTree *root;
};

void dfs(int x, int y, int &count, vector<vector<UnionFindTree> > &pos){
	if(pos[pos[y][x].pos.Y][pos[y][x].pos.X].root==NULL){
		if(pos[y][x].root==NULL) pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = &pos[y][x];
		else pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = pos[y][x].root;
		dfs(pos[y][x].pos.X, pos[y][x].pos.Y, count, pos);
	}
	else if(pos[y][x].root == pos[pos[y][x].pos.Y][pos[y][x].pos.X].root){
		count++;
	}
	pos[y][x].root = pos[pos[y][x].pos.Y][pos[y][x].pos.X].root;
	return;
}

int main(){
	int n = 0;
	while(cin >> n && n != 0){
		vector<vector<UnionFindTree> > pos(n, vector<UnionFindTree>(n, UnionFindTree()));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> pos[i][j].pos.X >> pos[i][j].pos.Y;
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(pos[i][j].root != NULL) continue;
				dfs(j, i, count, pos);
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

using namespace std;

int get(int n) {
  int cnt = 0;
  while (n > 1) {
    cnt += n /= 2;
  }
  return cnt;
}

bool par(int n, int k) {
  return get(n) > get(k) + get(n - k);
}

int solve(vector<int> a) {
  for (int& x : a) {
    x &= 1;
  }
  int n = a.size();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!par(n - 1, i)) {
      ans ^= a[i];
    }
  }
  return ans;
}

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

  int n;
  cin >> n;
  vector<int> a(n);
  bool one = false;
  for (int& x : a) {
    char c;
    cin >> c;
    x = c - '1';
    one |= x == 1;
  }
  auto res = solve(a);
  if (res == 1) {
    cout << res;
  } else if (one) {
    cout << 0;
  } else {
    for (int &x : a) {
      x /= 2;
    }
    cout << solve(a) * 2;
  }

  return 0;
}

Measured memory_bytes: 8124