akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

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

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

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

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

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

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

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin>>com;
    if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 26764
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long long int N;
 
    cin >> N;

	cout << 180 * (N-2) << endl;
	return 0;
}

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

using namespace std;

int main()
{
    string str;
    map<int,int> bm, am;
    int num, day;
    char ch;
     
    while (getline(cin, str) && str.size() > 0) {
        stringstream s1(str);
        s1 >> num >> ch >> day;
        ++bm[num];
    }
    while (getline(cin, str)) {
        stringstream s2(str);
        s2 >> num >> ch >> day;
        ++am[num];
    }
    for (auto &it: bm) {
        if (am[it.first]) {
            cout << it.first << " " << it.second + am[it.first] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define MAX 100000000

int n;
int minFunc(int v[102], int k){
	int i;
	for(i = 0;i < n;i++){
		if(v[i] > k)break;
	}
	return i;
}

int main(){
	int a[102], b[102];
	while(cin >> n, n){
		for(int i = 0;i < n;i++)cin >> a[i];
		sort(a, a+n);
		int r = 0, l = 0;
		for(int i = 1;i <= 2*n;i++){
			if(a[l] != i)b[r++] = i;
			else l++;
		}
		
		int p = 0, f = 1, x, y;
		while(r && l){
			p = 0;
			int rr = 1, ll = 1;
			while(rr || ll){
				if(f){
					x = minFunc(a, p);
					if(x != n) p = a[x], r--, a[x] = 0;
					else rr = 0;
					f = 0;
				}
				if(!r)break;
				if(x == n)p = 0;
				if(!f){
					x = minFunc(b, p);
					if(x != n) p = b[x], l--, b[x] = 0;
					else ll = 0;
					f = 1;
				}
				if(!l || x == n)break;
			}
		}
		cout << l << endl << r << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

a = gets.chomp

if /[[:upper:]]/.match(a)
  puts "A"
else
  puts "a"
end

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

for i in range(N):
    a,b,c = map(int,input().split())
    L = [a,b,c]

    m = L.pop(L.index(max(L)))
    d = L[0] ** 2 + L[1] ** 2

    if m ** 2 ==d:  
        print("YES")
    else:
        print("NO")



Measured memory_bytes: 5596
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	cin >> A >> B;
	if(A <= B) cout << A;
	else cout << A-1;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    ll a[n];
    rep(i,n){
        cin>>a[i];
        a[i]=a[i]-i-1;
    }
    //ここから先はaからbを引いて、絶対値をとる→和が最小になるように
    //bはaの中央値
    sort(a,a+n);

    ll b=(n%2!=0?a[n/2]:(a[(n-1)/2]+a[(n+1)/2])/2);
    ll ans=0;
    rep(i,n){
        ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool valid(int x, int y, string& s){
    for(int i = x; i + 1 <= y; ++i){
        if(s[i] == '#' and s[i+1] == '#')
            return false;
    }
    return true;
}
int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    --A; --B; --C; --D;
    string s; cin >> s;
    if(not valid(A,C,s) or not valid(B,D,s))
        return puts("No") * 0;
    if(C < D){
        //reachble...
        puts("Yes");
    } else {
        //s[A] = '#';
        //C >= D
        bool flag = false;
        for(int i = B; i <= D; ++i){
            if(i - 1 >= 0 and i + 1 < N){
                if(s[i - 1] =='.' and s[i] == '.' and s[i + 1] == '.'){
                    flag = true;
                }
            }
        }
        ( flag ? puts("Yes") : puts("No"));
    }
    
}



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

#define ll long long

const ll MXN = 1e5 + 10;
const ll MXM = 100 + 10;

ll n, k;
ll A[MXN];
bool dp[MXN];

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> A[i];

    dp[0] = 0;
    for(int i = 1; i <= k; i ++){
        for(int j = 1; j <= n; j ++){
            if(A[j] <= i){
                dp[i] = dp[i] | (!dp[i - A[j]]);
            }
        }
    }

    cout << (dp[k] ? "First" : "Second");

    return 0;
}
//! N.N


Measured memory_bytes: 384
import sys;input=sys.stdin.readline
from collections import deque
M=lambda:map(int,input().split())
n,q=M()
s=[[]for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].append(b-1)
  s[b-1].append(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
v=[1]+[0]*(n-1)
d=deque([(0,0)])
while d:
  b,c=d.popleft()
  c+=p[b]
  p[b]=c
  for i in s[b]:
    if v[i]:continue
    v[i]=1
    d.append((i,c))
print(*p)

Measured memory_bytes: 59236
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int N = 22;
int n, v[N][N];
long long dp[N][(1 << N)];
long long calc(int idx, unsigned int mask) {
	if (idx >= n)
		return 1;
	long long &ret = dp[idx][mask];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int i = 0; i < n; ++i)
		if (v[idx][i] == 1 && !((mask >> i) & 1))
			ret = (ret + calc(idx + 1, mask | (1 << i))) % MOD;
	return ret;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cin >> v[i][j];
	memset(dp, -1, sizeof(dp));
	cout << calc(0, 0) << endl;
	return 0;
}

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

using namespace std;

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

  if(1 <= a && a <= 9 && 1 <= b && b <= 9) cout << a * b << endl;
  else cout << -1 << endl;                                                                

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var c [3][3]int

func f(a0, b0, a1, b1 int) int {
	return c[a0-1][b0-1] - c[a1-1][b1-1]
}

func main() {
	sc.Split(bufio.ScanWords)
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			c[i][j] = getInt()
		}
	}

	ans := "Yes"

	if f(1, 1, 2, 1) != f(1, 2, 2, 2) {
		ans = "No"
	}
	if f(1, 1, 2, 1) != f(1, 3, 2, 3) {
		ans = "No"
	}
	if f(2, 1, 3, 1) != f(2, 2, 3, 2) {
		ans = "No"
	}
	if f(2, 1, 3, 1) != f(2, 3, 3, 3) {
		ans = "No"
	}

	if f(1, 1, 1, 2) != f(2, 1, 2, 2) {
		ans = "No"
	}
	if f(1, 1, 1, 2) != f(3, 1, 3, 2) {
		ans = "No"
	}
	if f(1, 2, 1, 3) != f(2, 2, 2, 3) {
		ans = "No"
	}
	if f(1, 2, 1, 3) != f(3, 2, 3, 3) {
		ans = "No"
	}
	out(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
  int N,i,j;
  char a,z,S[10000];
  a='A';
  z='Z';
  scanf("%d",&N);
  scanf("%s",&S);
  for(i=0;i<strlen(S);i++)
  {
    for(j=0;j<N;j++)
    {
    if(S[i]==z)
    {
      S[i]=a;
    }
    else
    {
    S[i]=S[i]+1;
    }
    }
  }
  printf("%s",S);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

    static <T extends Comparable<? super T>> boolean nextPermutation(T[] sequence) {
        int first = getFirst(sequence);
        if (first == -1) return false;
        int toSwap = sequence.length - 1;
        while (sequence[first].compareTo(sequence[toSwap]) >= 0) --toSwap;
        swap(sequence, first++, toSwap);
        toSwap = sequence.length - 1;
        while (first < toSwap) swap(sequence, first++, toSwap--);
        return true;
    }

    static <T extends Comparable<? super T>> int getFirst(T[] sequence) {
        for (int i = sequence.length - 2; i >= 0; --i)
            if (sequence[i].compareTo(sequence[i + 1]) < 0) return i;
        return -1;
    }

    static <T extends Comparable<? super T>> void swap(T[] sequence, int i, int j) {
        T tmp = sequence[i];
        sequence[i] = sequence[j];
        sequence[j] = tmp;
    }

    static class Coordinate {
        int x, y;

        public Coordinate(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Coordinate> points = new ArrayList<>();
        for (int i = 0; i < n;++ i) {
            points.add(new Coordinate(sc.nextInt(), sc.nextInt()));
        }

        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; ++i) arr[i] = i;

        double sum = 0;
        int cnt = 0;
        do {
            for (int i = 0; i < n - 1; ++i) {
                sum += Math.sqrt(Math.pow(points.get(arr[i]).x - points.get(arr[i+1]).x, 2) +
                        Math.pow(points.get(arr[i]).y - points.get(arr[i+1]).y, 2));
            }
            ++cnt;
        } while(nextPermutation(arr));

        System.out.println(sum / cnt);
    }
}

Measured memory_bytes: 23640
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
ll LCM(ll x, ll y);

int main() {
	ll N, K, A, key, ans, l, r, p;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A == 1) {
			key = i;
		}
	}

	if (K >= N) {
		ans = 1;
	}
	else {
		ans = 0;
		l = key;
		p = K - 1;
		r = N - key - 1 - ((l + p - 1) / p * p - l);
		ans += (l + p - 1) / p;
		ans += (r + p - 1) / p;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 10001;

vector<int> par(N);

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

void merge(int a, int b){
    par[find(a)] = find(b);
}


int main(){
    
    int n, q;
    cin >> n >> q;
    
    for(int i = 0; i < n; i++)
        par[i] = i;
    
    for(int i = 0; i < q; i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            merge(x, y);
        }
        else{
            if(find(x) == find(y))
                cout << 1 <<endl;
            else
                cout << 0 <<endl;
        }
    }
    
}

Measured memory_bytes: 3336
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
  long long int n, x;
  cin >> n >> x;
  long long int a[n+1];
  long long int check;
  for(long long int i = 0; i < n; i++)
    cin >> a[i];
    a[n]=-100000;
  long long int count = 0;
  for(long long int i = 0; i < n-1; i++){
    if(a[i]+a[i+1]>x){
        check=a[i]+a[i+1]-x;
        count+=check;
        a[i+1]-=check;
        if(a[i+1]<0)
            a[i+1]=0;
    }
  }
    cout << count << endl;
    return 0;
}

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

int v[101]={0};
int w[101];


int m[101][10001]={0};

int knap(int i,int W,int N){
  
  if(i==N){
    return 0;
  }
  if(m[i][W]!=0){
    return m[i][W];
  }
  if(W-w[i]>=0){
    m[i][W]=max(knap(i+1,W-w[i],N)+v[i],knap(i+1,W,N));
    return m[i][W];
  }else if (W-w[i]<0){
    m[i][W]=knap(i+1,W,N);
    return m[i][W];
  }
}

int main(){
  int N,W;
  cin >>  N >> W;
  for(int i=0;i<N;i++){
    cin >> v[i] >> w[i];
  }
  cout << knap(0,W,N) << endl;
  return 0;
}

Measured memory_bytes: 6828
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(b, n*a) << endl;


	return 0;



}

Measured memory_bytes: 256
N = int(input())
z = [tuple(map(int,input().split())) for i in range(N)]
z.sort()
y = [(z[i][1],i) for i in range(N)]
y.sort()
cost = [[] for i in range(N)]
for i in range(N-1):
    j = y[i][1]
    cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1]))))
    j_ = y[i-1][1]
    cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0]))))
    cost[i].append((i+1,min(abs(z[i+1][0]-z[i][0]),abs(z[i+1][1]-z[i][1]))))
    j_ = y[i+1][1]
    cost[j].append((j_,min(abs(y[i+1][0]-y[i][0]),abs(z[j_][1]-z[j][1]))))

i = N-1
j = y[i][1]
cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1]))))
j_ = y[i-1][1]
cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0]))))


import heapq

def prim(cost):
    V = len(cost)
    res = 0
    mincost = [float('inf')]*V
    used = [False]*V
    hq = []
    mincost[0] = 0
    heapq.heappush(hq,(0,0))
    while hq:
        weight,u = heapq.heappop(hq)
        if not used[u]:
            used[u] = True
            res += weight
            mincost[u] = weight
            for v, v_cost in cost[u]:
                if not used[v]:
                    heapq.heappush(hq,(v_cost,v))
    return res

print(prim(cost))

Measured memory_bytes: 93660
N,A = map(int,input().rstrip().split(" "))
X = list(map(int,input().rstrip().split(" ")))
DPq = [0 for _ in range(1300)]
DPp = [0 for _ in range(1300)]
DPp[0] = 1
DPm = [0 for _ in range(1300)]
DPm[0] = 1
just = 0
ans = 0
for i in X:
    if i > A:
        for i2 in range(1250,-1,-1):
            DPp[i2 + (i - A)] += DPp[i2]
    elif i < A:
        for i2 in range(1250,-1,-1):
            DPm[i2 + (A - i)] += DPm[i2]
    else:
        just += 1
for i in range(1250):
    ans += DPp[i] * DPm[i]
ans *= 2 ** just
ans -=1
print(ans)

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

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

    int ans=0;
    for(int i=0;i<S.length();i++){
        if(S[i]=='+') ans++;
        if(S[i]=='-') ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
gets()
arr = gets().chomp().split(' ').map!(&:to_i)

arr.each_with_index do |v, i|
  arr[i] = v - i - 1
end

arr.sort!()

thr = arr[0]
i = 0

while i < arr.size() / 2 do
  i += 1
  thr = arr[i] if thr != arr[i]
end

sum = 0

arr.each do |v|
  sum += (v - thr).abs
end

puts sum


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


std::string s, t;
int dp[3005][3005];
int main()
{
	std::cin >> s >> t;

	for (size_t i = 0, end1 = s.size(); i < end1; ++i)
		for (size_t j = 0, end2 = t.size(); j < end2; ++j) {
			if (s[i] == t[j])
				dp[i + 1][j + 1] = std::max(dp[i + 1][j + 1], dp[i][j] + 1);
			dp[i + 1][j + 1] = std::max(dp[i + 1][j + 1], dp[i + 1][j]);
			dp[i + 1][j + 1] = std::max(dp[i + 1][j + 1], dp[i][j + 1]);
		}

	int i = static_cast<int>(s.size());
	int j = static_cast<int>(t.size());
	std::string ans;
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j])
			--i;
		else if (dp[i][j] == dp[i][j - 1])
			--j;
		else {
			ans = s[i - 1] + ans;
			--i, --j;
		}
	}

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


Measured memory_bytes: 35584
#include <stdio.h>
#define EPSIRON (1.0e-10)
#define ABS(X) ((X)<0.0 ? -(X):(X))

int main(void){
    int n;
    double x1, x2, x3, x4, dx1, dx2;
    double y1, y2, y3, y4, dy1, dy2;
    double cp; // cross product
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
        scanf("%lf %lf %lf %lf", &x3, &y3, &x4, &y4);
        dx1 = x2 - x1;
        dy1 = y2 - y1;
        dx2 = x4 - x3;
        dy2 = y4 - y3;
        cp = dx1 * dy2 - dy1 * dx2;
        printf("%s\n", ABS(cp) < EPSIRON ? "YES" : "NO");
    }
    
    return 0;
}

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

int main(void){
  int n;
  double a, tmp = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    tmp += 1/a;
  }
  printf("%lf\n", 1/tmp);
  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 long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    string S[N];
    REP(i,N){
        string a;
        cin >> a;
        vector<char> X(10);
        REP(j,10) X[j] = a[j];
        sort(X.begin(),X.end());
        REP(j,10) a[j] = X[j];
        S[i] = a;
    }
    map<string, int> M;
    ll ans = 0;
    REP(i,N){
        if(M.count(S[i])){
            M.at(S[i])++;
            ans += M.at(S[i]);
        }
        else M[S[i]] = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11904
N=int(input())
MOD,D=10**9+7,{}
primes=list(map(int,"2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997".split()))
for i in primes:D[i]=1
for i in range(2,N+1):
    number=i
    while number!=1:
        for prime in primes:
            if number%prime==0:
                D[prime]=D[prime]+1
                number=number//prime
L,ans=list(D.values()),1
for j in L:ans*=j
print(ans%MOD)

Measured memory_bytes: 3064
#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 IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const ll INF = 1e14;

ll dp[3001][3001];
int A[3001];
ll solve(int s, int t) {
  if (s == t)
    return 0;
  if (dp[s][t] != INF)
    return dp[s][t];
  return dp[s][t] = max((ll)A[t-1] - solve(s, t-1), (ll)A[s] - solve(s+1, t));
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  IN(N);

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

  REP(i, N)
    cin >> A[i];
  OUT(solve(0, N));

  return 0;
}


Measured memory_bytes: 70912
import sys
import numpy as np
i4 = np.int32
i8 = np.int64


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.types import Array, int64
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('solve', (Array(int64, 2, 'C'), int64))
    def solve(ab, N):
        parents = np.arange(N)
        depth = np.zeros(N, i8)

        def uf_find(x):
            while True:
                if parents[x] == x:
                    return x
                else:
                    x = parents[x]

        def uf_union(x, y):
            x = uf_find(x)
            y = uf_find(y)
            if x == y:
                return

            if depth[x] == depth[y]:
                depth[x] += 1
                parents[y] = x
            elif depth[x] > depth[y]:
                parents[y] = x
            else:
                parents[x] = y

        for i in range(ab.shape[0]):
            uf_union(ab[i, 0], ab[i, 1])
        num = np.zeros(N, i8)
        for i in range(N):
            p = uf_find(i)
            num[p] += 1
        return np.amax(num)

    cc.compile()
    exit(0)
else:
    from my_module import solve


def main(in_file):
    stdin = open(in_file)
    N, M = [int(x) for x in stdin.readline().split()]
    ab = (np.fromstring(stdin.read(), i8, sep=' ') - 1).reshape(-1, 2)
    ans = solve(ab, N)
    print(ans)


if __name__ == '__main__':
    main(0)

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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	int N, con = 0;
	cin>>N;
	for(int i = 1; i <= N; i++){
		string num = to_string(i);
		if(num.size()%2) con++;
	}
	
	cout<<con<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n],b[n],s1=0,s2=0;
  rep(i,n) R a[i];
  rep(i,n) R b[i];
  rep(i,n) {
    s1+=a[i];
    s2+=b[i];
  }
  if(s1<s2) {
    pr(-1);
    return;
  }
  ll s=0;
  rep(i,n) a[i]-=b[i];
  sort(a,a+n);
  int r=n-1,ans=0;
  rep(i,n) {
    if(a[i]<0) ans++;
    while(a[i]<0) {
      ll x=min(s,abs(a[i]));
      s-=x;
      a[i]+=x;
      if(a[i]<0&&!s) {
        s+=a[r];
        r--;
        ans++;
      }
    }
  }
  pr(ans);
}

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


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

using namespace std;
#define REP(i, n) for(int i=0; i < (int)(n); ++i)
#define REPR(i, n) for(int i=n; i>= 0; --i)
#define FOR(i, m, n) for(int i=m; i<(n); ++i)

#define ll long long

int main(){
    int N;
    cin >> N;
    vector<ll> T(N), A(N);
    REP(i, N){
        cin >> T[i] >> A[i];
    }

    ll tc = T[0], ac=A[0];

    REP(i,N){
        ll bai1 = tc/T[i], bai2 = ac/A[i];
        if(tc%T[i]) bai1++;
        if(ac%A[i]) bai2++;
        tc = T[i] * max(bai1, bai2);
        ac = A[i] * max(bai1, bai2);
    }
    cout << tc+ac << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

LL mod_mul (LL x, LL y, LL p) {
		LL s = 0 ;
		while (y > 0) {
				if (y & 1) {
						s += x ;
						s %= p ;
				}
				x <<= 1 ;
				x %= p ;
				y >>= 1 ;
		} return s ;
}


LL mod_exp (LL x, LL y, LL p) {
		LL s = 1 ;
		while (y > 0) {
				if (y & 1) s = mod_mul (s, x, p) ;
				x = mod_mul (x, x, p) ;
				y >>= 1 ;
		} return s ;
}

int main()
{
	int n ;
	scanf ("%d", &n) ;
	
	if (n < 2)
	{
		cout << 0 << endl ;
		return 0 ;
	}
	
	LL both09 = 2, only0 = 17, nether09 = 64 ;
	for (int i=3; i<=n; i++)
	{
		both09 = (both09 * 10 + 2 * only0) % MOD ;
		only0 = (only0 * 9 + nether09) % MOD ;
		nether09 = (nether09 * 8) % MOD ;
	}
	
	cout << both09 << endl ;

	return 0 ;
}

Measured memory_bytes: 3256
from collections import defaultdict
s = input()
n = len(s)
dp = defaultdict(int)
dp[0] = 1
ls = [1<<(ord(s[0])-97)]
for i in range(1,n):
  ls.append(ls[-1]^(1<<(ord(s[i])-97)))
if ls[-1] == 0:
  print(1)
  exit()
for i in range(n):
  for b in range(26):
    bit = 1<<b
    if dp[ls[i]^bit] == 0:
      continue
    if dp[ls[i]] == 0:
      dp[ls[i]] = dp[ls[i]^bit]+1
    else:
      dp[ls[i]] = min(dp[ls[i]^bit]+1,dp[ls[i]])
print(dp[ls[n-1]]-1)

Measured memory_bytes: 354960
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	int n; cin >> n;
	rep1(i, 9) {
		rep1(j, 9) {
			if (i*j == n) {
				cout << "Yes" << endl; return;
			}
		}
	}
	cout << "No" << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN], B[MAXN], ind[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i]>>B[i], ind[i]=i;
	sort(ind+1, ind+n+1, [](int i, int j){
		return A[i]+B[i]>A[j]+B[j];
	});
	for (int i=1; i<=n; i+=2) ans+=A[ind[i]];
	for (int i=2; i<=n; i+=2) ans-=B[ind[i]];
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

ans = 0
for i in range(n):
    x = b[i]
    x -= min(x, a[i])
    # print("Kill", b[i] - x, i)
    ans += b[i] - x
    if x > 0:
        y = min(x, a[i+1])
        # print("Kill", y, i + 1)
        ans += y
        x -= y
        a[i+1] -= y
print(ans)


Measured memory_bytes: 19116
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;
ll dp[110][10];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w,k; cin >> h >> w >> k;
	k--;
	dp[0][0]=1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int p=0;p<(1<<(w-1));p++){
				bool ok=true;
				for(int l=0;l<w-2;l++){
					if((p&(1<<l))&&(p&(1<<(l+1))))ok=false;
				}
				if(!ok)continue;
				int nj=j;
				if(p&(1<<j))nj=j+1;
				else if(j>0&&(p&(1<<(j-1))))nj=j-1;
				(dp[i+1][nj]+=dp[i][j])%=mod;
			}
		}
	}
	cout << dp[h][k] << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  float T, A;
  cin >> T >> A;

  vector<int> H(N);
  rep(i, N) cin >> H[i];

  int ans = 0;
  float difMin = 1e9;
  for(int i = 0; i < N; i++){
    float temp = T - H[i] * 0.006;
    float dif = temp-A;
    if(dif < 0) dif = -dif;
    if(difMin > dif){
      ans = i;
      difMin = dif;
    }
  }

  cout << ans + 1 << endl;


  return 0;
}


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

int main(){
  int x1,y1,x2,y2;
  int x3,y3,x4,y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = ((x2 - x1) - (y2 - y1)) + x1;
  y3 = ((x2 - x1) + (y2 - y1)) + y1;
  x4 = x1 - (y2 - y1);
  y4 = (x2 - x1) + y1;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std;

const ll mod = 1e9+7;

int main() {
    double d , s, t;
    cin >> d >> s >> t;
    double sp = (d / (t)*1.0);
    if(sp <= s){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}






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

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


int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    // dp[i] = 石が i 個のときに太郎くんが勝つかどうか
    vector<bool> dp(K+1, false);
    FOR(i, 1, K+1){
        REP(j, N){
            if(i >= a[j]) dp[i] = (dp[i] or !dp[i-a[j]]);
        }
    }

    if(dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(){
  long long n;
  cin>>n;
  long long r;
  if(n <= 2){
    r = 1;
  }
  for(long long i = 0 ; i < n ; i ++){
    if(i * i > n){
      r = i -1;
      break;
    }
  }

  cout<<r*r<<endl;
}

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

typedef  long long ll;

int main()
{
    ll i,n,m,abarjog=0;

    cin>>n>>m;
    double a[n+2],sum=0,flag;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }

    flag=sum/(4*m);
    //cout<<flag;
    for(i=0;i<n;i++)
    {
        if(a[i]>=flag)
            abarjog++;
    }
    if(abarjog>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int bindim(long long a){
    int ans = 0;
    while(a%2==0){
        a/=2;
        ans++;
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    int ans = 0;
    long long a;
    for(int i = 0;i<n;i++){
        cin >> a;
        ans+=bindim(a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 long int x,y=100,count=1;
  
  cin>>x;
  while(count){
   
    y=y/100+y;
    if(y>=x){
      cout<<count;
      break;
    }
    count++;
  }
  return 0;
}
                                                                                           

Measured memory_bytes: 3568
#include <stdio.h>

int main()
{
  int x,y,c,i;

  scanf("%d%d",&x,&y);

  if(x >= y){
    while(x % y > 0){
      c = x % y;
      x = y;
      y = c;
    }
    printf("%d\n",y);
  }

  if(x < y){
    while(y % x > 0){
      c = y % x;
      y = x;
      x = c;
    }
    printf("%d\n",x);
  }

  return 0;

}

Measured memory_bytes: 592
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    set<int> st;
    REP(i,n){int a; cin >> a; st.insert(a);}
    out(st.size());

    return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b)>(c+d)){
    cout << "Left" << endl;
  }else if((a+b)<(c+d)){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long k, a, b; cin >> k >> a >> b;
    if(a-1 >= k || a+1 >= b){
        cout << k+1 << endl;
        return 0;
    }
    k -= a-1;
    long long ans = a;
    if(k%2 == 0){
        ans += (b-a)*k/2;
    }
    else{
        ans += (b-a)*(k-1)/2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
const int INF = 1001001001;

int main(){
  ll X,K,D;
  ll K1, K2;
  cin >> X >> K >> D;
  X = abs(X);
  ll straight = min(K,X/D);
  K -= straight;
  X -= straight*D;
  if(K%2){
    cout << D - X << endl;
  }else cout << X << endl;

}


Measured memory_bytes: 3536
def gcd(a,b):
    c = 0
    if a < b:
        a,b = b,a
    while b!=0:
        a,b = b,a%b
        c += 1
    return a,c
while True:
    n,m = map(int,raw_input().split())
    if (n,m) == (0,0):
        break
    print "{} {}".format(*gcd(n,m))

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(a, b, c);
    rep(i, 10) {
        c = c * a - b;
        std::cout << c << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <utility>

int main(int argc, char const *argv[])
{
    std::queue<std::pair<std::string, int> > q;
    int n;
    std::cin >> n;
    int quantum;
    std::cin >> quantum;

    std::string name;
    int time;
    for (int i = 0; i < n; i++) {
        std::cin >> name;
        std::cin >> time;
        q.push(std::pair<std::string, int>(name, time));
    }

    int total = 0;
    std::pair<std::string, int> process;
    while (!q.empty()) {
        process = q.front();
        q.pop();

        if (process.second <= quantum) {
            total += process.second;
            std::cout << process.first << " " << total << std::endl;
        } else {
            total += quantum;
            q.push(std::pair<std::string, int>(process.first, (process.second - quantum)));
        }
    }

    return 0;
}

Measured memory_bytes: 4404
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>

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

int n, m;
bool used[400001];
int cmp[400001];
vector<int> g[400001], gr[400001];
vector<int> vs;
string s;

void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
	vs.push_back(x);
}

void rdfs(int v, int k){
	used[v]=1;
	cmp[v]=k;
	for(auto y:gr[v]){
		if(!used[y]) rdfs(y, k);
	}
}

int scc(){
	fill(used, used+2*n, 0);
	vs.clear();
	for(int i=0; i<2*n; i++){
		if(!used[i]) dfs(i);
	}
	fill(used, used+2*n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}

int main()
{
	cin>>n>>m;
	cin>>s;
	for(int i=0; i<m; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		if(s[a]==s[b]){
			g[a].push_back(b+n);
			g[b].push_back(a+n);
			gr[a+n].push_back(b);
			gr[b+n].push_back(a);
		}else{
			g[a+n].push_back(b);
			g[b+n].push_back(a);
			gr[a].push_back(b+n);
			gr[b].push_back(a+n);
		}
	}
  int k=scc();
	if(k<2*n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 48120
def main():
    h, w = map(int, input().split())

    g = [list("#" * (w + 2))]
    for _ in range(h):
        g.append(["#"] + list(input()) + ["#"])
    g += [list("#" * (w + 2))]
    area = [[0] * (w + 2) for _ in range(h + 2)]

    for i in range(h + 2):
        cnt = 0
        for j in range(w + 2):
            if g[i][j] == "#":
                for k in range(j - cnt, j):
                    area[i][k] += cnt
                cnt = 0
            else:
                cnt += 1

    for i in range(w + 2):
        cnt = 0
        for j in range(h + 2):
            if g[j][i] == "#":
                for k in range(j - cnt, j):
                    area[k][i] += cnt
                cnt = 0
            else:
                cnt += 1

    res = 0
    for i in range(h + 2):
        for j in range(w + 2):
            res = max(res, area[i][j])
    print(res - 1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 268584
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<int,int> P;
int ceil(int a,int b){// a以上bの倍数の最小値//
     return (a+b-1)/b*b;
 }
int stoii(string s){//stoi関数の代用 文字列⇒int型//
    return atoi(s.c_str());
}

int R,C;
int sy,sx;
int gy,gx;
string c[51];
void solve(){
	queue<P> qp;
	qp.push({sy,sx});
}
int dp[1010][1010]={0};
int main(){
	int n,k;
	cin>>n;
	vector<int> v(n,0);
	rep(i,n)cin>>v[i];
	sort(v.begin(),v.end());
	cout<<abs(v[n-1]-v[0])<<endl;
	return 0;
}

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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

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

    double n = stod(a+b);
    n = sqrt(n);
    if((int)n==n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}

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

namespace Atcoderrr
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            List<Func<int, int,int>> funcList = new List<Func<int, int,int>>();
            funcList.Add(Plus);
            funcList.Add(Minus);
            int[] N = new int[4];
            for (int i = 0; i < 4; i++) N[i] = int.Parse(input[i].ToString());
            List<string> comb = MakeCombination();
            for (int i = 0; i < comb.Count; i++)
            {
                int sum = N[0];
                for (int j = 0; j < 3; j++) sum = (comb[i][j] == '0') ? Plus(sum,N[j+1]):Minus(sum,N[j+1]);
                if(sum == 7)
                {
                    Console.WriteLine(N[0] + s(comb[i][0]) + N[1] +  s(comb[i][1]) + N[2] + s(comb[i][2]) + N[3]+"=7");
                    return;
                }
            }
        }
        static string s(char c)
        {
            return (c == '0') ? "+" : "-";
        }
        static List<string> MakeCombination()
        {
            List<string> ret = new List<string>();
            for (int i = 0; i < 8; i++)
            {
                string str = (Convert.ToString(i, 2)).PadLeft(3,'0');
                ret.Add(str);
            }
            return ret;
        }
        static int Plus(int a , int b)
        {
            return a + b;
        }
        static int Minus(int a, int b)
        {
            return a - b;
        }
    }
}


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

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			long n = cin.Long();
			long k = cin.Long();
			long[] a = cin.ArrayLong((int)n);
			long[] pre = new long[n];
			long[] post = new long[n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (i == j) {
						continue;
					}

					if (j < i) {
						if (a[i] > a[j]) {
							pre[i]++;
						}
					} else {
						if (a[i] > a[j]) {
							post[i]++;
						}
					}
				}
			}

			long ans = 0;
			for (int i = 0; i < n; i++) {

				ans = (ans + (((k * (k + 1) / 2) % MOD) * post[i] % MOD)) % MOD;
				ans = (ans + (((k * (k - 1) / 2) % MOD) * pre[i] % MOD)) % MOD;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13240