akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <vector>

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

using namespace std;

const int N=100010;

int n,a,b;
vector<int> g[N];
vector<int> cur,path;
bool vis[N];

void dfs1(int u,int pa) {
    cur.pb(u);
    if (u==n) path=cur;
    for (int v:g[u]) {
        if (v!=pa) dfs1(v,u);
    }
    cur.pop_back();
}

int dfs(int u) {
    int ret=1;
    vis[u]=1;
    for (int v:g[u]) { 
        if (!vis[v]) ret+=dfs(v);
    }
    return ret;
}

int main() {
    scanf("%d",&n);
    for (int i=0;i<n-1;i++) {
        scanf("%d%d",&a,&b);
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs1(1,0);
    for (int i:path) {
        vis[i]=1;
    }
    int rf=0,rs=0;
    int sz=path.size();
    if (sz&1) rf++;
    for (int i=0;i<path.size();i++) {
        if (i*2<path.size()) {
            for (int j:g[path[i]]) {
                if (!vis[j]) rf+=dfs(j);
            }
        } else {
            for (int j:g[path[i]]) {
                if (!vis[j]) rs+=dfs(j);
            } 
        }
    }
    if (rf>rs) printf("Fennec\n");
    else printf("Snuke\n");
}

Measured memory_bytes: 14584
H,W=map(int,input().split())

def warshall_floyd(vl,d):
  #d[i][j]: iからjへの最短距離
  for vk in vl:
    for vi in vl:
      for vj in vl:
        if vk in d[vi] and vj in d[vk]:
          d[vi][vj]=min(d[vi][vj],d[vi][vk]+d[vk][vj])
  return d

cmat=[]
for i in range(10):
  cmat.append([int(c) for c in input().split()])
#print(cmat)

amat=[]
for i in range(H):
  amat.append([int(a) for a in input().split()])
#print(amat)

vlist=list(range(10))
dist={}
for vi in vlist:
  dist[vi]={vi:0}
  for vj in vlist:
    dist[vi][vj]=cmat[vi][vj]
#print(dist)

dist=warshall_floyd(vlist,dist)
#print(dist)
    
answer=0
for i in range(H):
  for j in range(W):
    if amat[i][j]==-1:
      continue
    answer+=dist[amat[i][j]][1]
    
print(answer)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, w;
ll p[100];
vector<pi> e[100];

void dfs (int v, int par, vector<ll>& dp) {
    rep(i,e[v].size()) {
        if (e[v][i].first == par) continue;
        vector<ll> tmp(w+1, -linf);
        for (int j = e[v][i].second; j <= w; j++) {
            tmp[j] = dp[j-e[v][i].second];
        }
        dfs(e[v][i].first, v, tmp);
        rep(j,w+1) dp[j] = max(dp[j], tmp[j]);
    }
    rep(i,w+1) dp[i] += p[v];
}

int main() {
    auto start = chrono::system_clock::now();
    cin >> n >> w;
    rep(i,n) cin >> p[i];
    rep(i,n-1) {
        int u, v, c;
        cin >> u >> v >> c;
        u--; v--;
        e[u].push_back(pi(v,c));
        e[v].push_back(pi(u,c));
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        auto end = chrono::system_clock::now();
        if (chrono::duration_cast<chrono::milliseconds>(end-start).count() > 1800) break;
        vector<ll> dp(w+1, -linf);
        dp[0] = 0;
        dfs(i, i, dp);
        ans = max(ans, *max_element(dp.begin(), dp.end()));
    }
    cout << ans << endl;
}



Measured memory_bytes: 61624
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll a[n+1];
    for (i=1;i<=n;i++)
        cin>>a[i];
    int ctr=1;
    ll ans[n+1];
    if (n&1)
    {
        for (i=n;i>=1;i-=2)
            ans[ctr++]=a[i];
        for (i=2;i<=n;i+=2)
            ans[ctr++]=a[i];
        for (i=1;i<=n;i++)
            cout<<ans[i]<<" ";
    }
    else
    {
        for (i=n;i>=1;i-=2)
            ans[ctr++]=a[i];
        for (i=1;i<=n;i+=2)
            ans[ctr++]=a[i];
        for (i=1;i<=n;i++)
            cout<<ans[i]<<" ";
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split("");
		String answer = "";

		for (int i = 0; i < line.length; i++) {
			switch (line[i]) {
			case "0":
			case "1":
				answer = answer + line[i];
				break;
			case "B":
				if (!(answer.equals(""))) {
					answer = answer.substring(0, answer.length() - 1);

				}
			}
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 21076
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n,a[100004],ans=0,t=0;
void make1(){
	int at=a[0],bt=a[n-1];
	for (int i=1;i<n-1;i++) if (a[i]<=0){
		cout<<bt<<" "<<a[i]<<"\n";
		bt-=a[i];
	}
	for (int i=1;i<n-1;i++) if (a[i]>0){
		cout<<at<<" "<<a[i]<<"\n";
		at-=a[i];
	}
	cout<<bt<<" "<<at<<"\n";
}
void make2(){
	cout<<a[0]<<" "<<a[1]<<"\n";
	int at=a[0]-a[1];
	for (int i=2;i<n-1;i++){
		cout<<at<<" "<<a[i]<<"\n";
		at-=a[i];
	}
	cout<<a[n-1]<<" "<<at<<"\n";
}
void make3(){
	cout<<a[n-1]<<" "<<a[n-2]<<"\n";
	int at=a[n-1]-a[n-2];
	for (int i=0;i<n-2;i++){
		cout<<at<<" "<<a[i]<<"\n";
		at-=a[i];
	}
}
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if (a[i]<0) ans-=a[i];
		else ans+=a[i],t++;
	}
	if (n==2){
		cout<<max(a[0]-a[1],a[1]-a[0])<<"\n";
		if (a[0]-a[1]>a[1]-a[0]) cout<<a[0]<<" "<<a[1];
		else cout<<a[1]<<" "<<a[0];
		return 0;
	}
	sort (a,a+n);
	if (t!=0 && t!=n){
		cout<<ans<<"\n";
		make1();
	}
	else if (t==0){
		ans+=a[0]+a[n-1];
		ans-=a[0]-a[n-1];
		cout<<ans<<"\n";make3();
	}else{
		ans-=a[0]+a[n-1];
		ans+=a[n-1]-a[0];
		cout<<ans<<"\n";
		make2();
	}
}

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

int main(){
    int n;
    cin >>n;
    int h[n];
    for(int i=0;i<n;i++)cin >>h[i];
    int a=h[0];
    for(int i=1;i<n;i++){
        if(h[i-1]<h[i]){
            a+=h[i]-h[i-1];
        }
    }
    cout << a << endl;
}

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

using namespace std;

int sum, cnt;

int main(){
string s;
cin >> s;
for(int i = 0; i < s.size(); i++){
if(s[i] == '1'){
    sum++;
}
if(s[i] == '0'){
    cnt++;
}
}
if(sum > cnt){
    return cout << sum+cnt-(sum-cnt), 0;
}
if(cnt > sum){
    return cout << sum + cnt - (cnt-sum), 0;
}
if (sum == cnt){
    return cout << sum + cnt, 0;
}
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
long long a[222222];
long long d[222222];
int pd;
int s[222222];
int main()
{
	int n=io::F(),k=io::F();
	for(register int i=1;i<=n;++i)a[i]=io::F()-k;
	for(register int i=1;i<=n;++i)d[i]=a[i]+=a[i-1];
	std::sort(d+1,d+n+2);
	pd=std::unique(d+1,d+n+2)-d-1;
	for(register int i=0;i<=n;++i)a[i]=std::lower_bound(d+1,d+pd+1,a[i])-d;
	long long ans=0;
	for(register int i=0;i<=n;++i)
	{
		for(register int j=a[i];j;j-=j&-j)ans+=s[j];
		for(register int j=a[i];j<=pd;j+=j&-j)s[j]++;
	}
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 4224
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define GRESORT(v) sort(v.begin(),v.end(),greater<int>())
#define REVERSE(v) reverse(v.begin(),v.end())
#define overlap(v) v.erase(unique(v.begin(),v.end()),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF 999999999
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

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

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

ll mod = (ll)1e9+7;
int n,m;
vector<int> d;

void solve(){
    cin >> n;
    rep(i,n){
        cin >> m;
        d.resize(m);
        int nobo = 0, ori = 0;
        rep(j,m) cin >> d[j];
        FOR(j,1,m){
            int val = d[j-1]-d[j];
            val < 0 ? maxs(nobo,-val) : maxs(ori,val);
        }

        cout << nobo << " " << ori << endl;
    }
}

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

    solve();

    return 0;
}

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 1e5 + 5;
int arr[MAX];

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int n, k;
		cin >> n >> k;
		for(int i = 1; i <= n; i++)
		{
			cin >> arr[i];
		}
		ll sum = 0;
		sort(arr + 1, arr + n + 1);
		for(int i = 1; i <= k; i++)
			sum += arr[i];
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    for(int i=0;i<N;i++){
        ll s, d;
        cin >> s >> d;
        int ans = 0;
        while(d-s>0){
            if(s%2!=0){
                ans++;
                s++;
            }
            if(d%2!=0){
                ans++;
                d--;
            }
            s /= 2;
            d /= 2;
        }
        cout << ans << endl;
    }
}

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

using namespace std;

int main(){
 int N,M;
 cin >> N;
 vector<long int> A(N + 1);
 vector<long int> B(N);

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

 for(int i = 0; i < N; i++){
   cin >> B[i];
 }
 long int c = 0;


 for(int i = 0; i < N; i++){
  if(A[i] <= B[i]){ c += A[i]; B[i] -= A[i]; }
  else if(A[i] > B[i]){ c += B[i]; A[i] -= B[i]; B[i] = 0; }

  if(A[i + 1] <= B[i]){ c += A[i + 1]; A[i + 1] = 0; }
  else if(A[i + 1] > B[i]){ c += B[i]; A[i + 1] -= B[i]; } 


 }

 cout << c << endl;


 return 0;
}





Measured memory_bytes: 1792
a=input()
flag=0
if a[0]=='A':
    i=1
    c=0
    while i<len(a):
        if i>=2 and i<=len(a)-2 and a[i]=='C' and c==0:
            i+=1
            c=1
        elif ord(a[i])>=97 and ord(a[i])<=122 and a[i]!='C':
            i+=1
        else:
            flag=1
            break
    if flag==0 and c!=0:
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		sc.close();
		
		while(n >= 500) {
			n -= 500;
		}
		
		if(n <= a) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22740
import scala.io.StdIn._

object Main extends App {
  val S = readLine().toArray.map(_.asDigit).map(_.toString)

  val limit = S.length - 3
  val doggy = for (n <- 0 to limit) yield {
    S(n) + S(n + 1) + S(n + 2)
  }

  val diff = for(e <- doggy) yield {
    Math.abs(753 - e.toInt)
  }

  println(diff.min)

}


Measured memory_bytes: 25536
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;




int main(){
    int h,w,a,b;cin >> h >> w >> a >> b;
    vector<vector<int>> ans(h,vector<int> (w,0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans[i][j] = (i<b) ^ (j<a);
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5120
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)
m = 10 ** 9 + 7
s = 0
ss = 0
(n - 2).downto(0) { |i|
  ss += arr[i + 1]
  s += arr[i] * ss
  s %= m
}
puts s


Measured memory_bytes: 35772
from collections import Counter
N=int(input())
A=list(map(int ,input().split()))
D=Counter(A)
#print(D.items())
L=[]
for num, v in D.items():
    if v>=4:
        L.append((num,4))
    elif v>=2:
        L.append((num, 2))

L=sorted(L, reverse=True)
if len(L)==0:
    print(0)
    exit()
elif len(L)==1 and L[0][1]==2:
    print(0)
    exit()
ans=1
for i,t in enumerate(L):
    num,v=t
    if i==0:
        if v==4:
            ans=num*num
            break
        else:
            ans*=num
    elif i==1:
        ans*=num
        break
print(ans)

Measured memory_bytes: 18600
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    la = [(item,i+1) for i,item in enumerate(a)]
    la.sort()
    for rep in la:
        print(f"{rep[1]} ",end="")
    return

if __name__=='__main__':
    n = I()
    a = list(IL())
    solve()

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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        if(500*a+100*b+50*c == X) ans += 1;
      }
    }
  }
  cout << ans;
  
}

Measured memory_bytes: 256
<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
if ($a === 'H') {
    if ($b === 'H') {
        echo 'H';
    } else {
        echo 'D';
    }
} elseif ($a === 'D') {
    if ($b === 'H') {
        echo 'D';
    } else {
        echo 'H';
    }
}


Measured memory_bytes: 16012
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a, _n=b; i<=_n; ++i)
using namespace std;

const int N = 1e5+5, open = -1e7, close = 1e7;
int n, m, ans[N], bit[N];
vector<pair<int, int> > qu;

void update(int i, int x)
{
    for(; i>0; i-=i&-i) bit[i] += x;
}
int get(int i)
{
    int res =0 ; for(; i<=m; i+=i&-i)
    res += bit[i]; return res;
}
int main()
{
    ios::sync_with_stdio(); cin.tie(0);
    ///freopen("a.inp","r",stdin);

    cin >> n >> m;
    FOR(i, 1, n) {
        int l, r; cin >> l >> r;
        FOR(j, 2, sqrt(m)) if (l <= r/j*j) ans[j] += 1;
        qu.pb(mp(l, open));
        qu.pb(mp(r, close+l));
    }
    FOR(j, sqrt(m)+1, m) for(int x=j; x<=m; x+=j) qu.pb(mp(x, j));

    sort(qu.begin(), qu.end());
    FOR(i, 0, qu.size()-1)
    if (qu[i].y == open) {
        update(qu[i].x, 1);
    } else
    if (qu[i].y > close) {
        update(qu[i].y-close, -1);
    } else {
        ans[qu[i].y] += get(qu[i].x-qu[i].y+1);
    }

    ans[1] = n;
    FOR(i, 1, m) cout << ans[i] << '\n';
}


Measured memory_bytes: 18664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define P 1000000007
ll modInverse(ll n, ll p);
ll binpow(ll x, ll y, ll p);
ll nCr(ll n, ll k)
{
    if (k < 0 || k > n)
        return 0;
    k = min(k, n - k);
    ll ans = 1;
    for (int i = 1; i <= k; ++i)
    {
        ans = (ans * modInverse(i, P))%P;
        ans *= (n + 1 - i);
        ans = ans %P;
        //ans =ans;
    }
    return ans;
}

ll modInverse(ll n, ll p)
{
    return binpow(n, p - 2, p);
}
ll binpow(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = binpow(2, n,P) - 1;
    ll ans1 = nCr(n,a) + nCr(n,b); 
    cout<<((ans-ans1)%P+P)%P;

        return (0);
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, K;
  scanf("%d %d", &N, &K);
  int ans = 1;
  for (int i = 0; i < N; ++i) {
    ans = min(2 * ans, ans + K);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;


int main(){
    int N, M, R; cin >> N >> M >> R;
    vector<int> r(R);
    rep(i,R) cin >> r[i];
    rep(i,R) r[i]--;

    vector<vector<ll>> cost(N, vector<ll>(N, INF));
    
    //rep(i,N) cost[i][i] = 0;
    rep(i,M){
        int a, b, c; cin >> a >> b >> c;
        a--;
        b--;
        // 無向グラフ
        cost[a][b] = c;
        cost[b][a] = c;
    }

    rep(k,N){
        rep(i,N){
            rep(j,N){
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
            }
        }
    }
    ll ans = INF;
    // next_permutationを使う場合は、昇順でソートしておく。
    sort(r.begin(), r.end());
    // 経路を全パターン試す。
    do{
        ll tmp = 0;
        rep(i,R-1){
            tmp += cost[r[i]][r[i+1]];
        }    
        ans = min(ans, tmp);

    }while(next_permutation(r.begin(), r.end()));
   
    cout << ans << endl;
} 

Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;


map<string, int>k;

void solve(long long N, std::vector<std::string> S){
    for (int i = 0; i < N; i++) {
        if(k[S[i]] > 0) {
            continue;
        }else {
            k.insert(make_pair(S[i], 1));
        }
    }
    map<std::string, int>::iterator iter = begin(k);
    int ans = 0;
    for(; iter != end(k); iter++) {
        ans++;
    }

    cout << ans << endl;

    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  
  if(x>=30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
import sys

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


def resolve():
    h1, m1, h2, m2, k = map(int, input().split())
    t = (h2 - h1) * 60 + (m2 - m1)
    print(max(0, t - k))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9176
#include<iostream>
#include<iomanip>
using namespace std;
#include<cmath>

double D(int *x,int *y,int n,int k){
    double d=0;
    if(k>4){
        for(int i=0;i<n;i++){
            if(d<abs(x[i]-y[i])){
                d=abs(x[i]-y[i]);
            }
        }
        return d;
    }
    else{
    for(int i=0;i<n;i++){
        d+=pow(abs(x[i]-y[i]),k);
    }
    return pow(d,1.0/k);}
}

int main(){
    int n;
    cin>>n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int j=0;j<n;j++){
        cin>>y[j];
    }
    cout<<fixed<<setprecision(8);
    cout<<D(x,y,n,1)<<endl;
    cout<<D(x,y,n,2)<<endl;
    cout<<D(x,y,n,3)<<endl;
    cout<<D(x,y,n,10000)<<endl;
    return 0;
}


Measured memory_bytes: 3448
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = ii()
    B = ii()
    print('GREATER' if A > B else 'LESS' if A < B else 'EQUAL')


if __name__ == '__main__':
    main()


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

int main() {
 int w,h,n;
  cin>>w>>h>>n;
  vector<int> x(n),y(n),a(n);
  int x1=0,y1=0,x2=w,y2=h;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>a[i];
    if(a[i]==1) x1=max(x1,x[i]);
    if(a[i]==2) x2=min(x2,x[i]);
    if(a[i]==3) y1=max(y1,y[i]);
    if(a[i]==4) y2=min(y2,y[i]);
  }
  if(x2<=x1||y2<=y1) {cout<<0<<endl; return 0;}
  else cout<<(x2-x1)*(y2-y1)<<endl;
}
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        long n = sc.nextLong();
        long k = sc.nextLong();

        double sum = 0;

        for (int i = 1; i <= n; i++) {
            long num = i;
            if (num < k) {
                int cnt = 0;
                do {
                    num *= 2;
                    cnt++;
                } while (num < k);
                sum += 1 / (double) n * Math.pow(0.5, cnt);
            } else {
                sum += 1 / (double) n;
            }
        }

        sc.close();

        System.out.println(sum);

    }
}

Measured memory_bytes: 21076
function Main(input) {
	input = parseInt(input.trim());
  if(input < 1200){
     console.log("ABC");
  }else if(input >= 1200 && input <2800){
    console.log("ARC");
  }else{
    console.log("AGC");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));

    for(int i = 0; i < M; i++) {
        cin >> B[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    //cout << A[1][2] << endl; // 2

    int ans = 0;
    for(int i = 0; i < N; i++) {
        int sum = 0;
        for(int j = 0; j < M; j++) {
            //cout << A[i][j] << B[j] << endl;
            sum += A[i][j] * B[j];
        }
        if(sum + C > 0) {
            ans++;
        }
        
    }

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

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        List<int> A = new List<int>();

        int maxValue = 1;
        int secondMaxValue = 0;
        int currentValue;

        for(int i = 0; i < N; i++) {
            currentValue = int.Parse(Console.ReadLine());
            A.Add(currentValue);

            if(maxValue < currentValue) {
                secondMaxValue = maxValue;
                maxValue = currentValue;
            } else if(secondMaxValue < currentValue) {
                secondMaxValue = currentValue;
            }
        }

        int cntMaxValue = A.Count(m => m == maxValue);

        for(int i = 0; i < N; i++) {
        
            if(cntMaxValue > 1) {
                Console.WriteLine(maxValue);
                continue;
            }
            
            if (A[i] == maxValue) {
                Console.WriteLine(secondMaxValue);
            }
            else {
                Console.WriteLine(maxValue);
            }

        }
    }
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    string s;cin>>s;
    VI c(3);

    REP(i,3){
        c[s[i]-'a']++;
    }
    REP(i,3){
        if(c[i] != 1){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();
		String ans = "";
		int[] diff = new int[s.length()];
		int min = 0;

		for(int i=0; i<s.length()-2; i++) {
			int target= Integer.parseInt(s.substring(i,i+3));
				if(target > 753) {
					diff[i] = target-753;
				}else {
					diff[i] = 753-target;
				}
					if(min != 0) {
						if(min > diff[i]) {
							min = diff[i];
						}
					}else {
						min = diff[0];
					}
			}

		System.out.println(min);
	}
}


Measured memory_bytes: 23764
n,*A=map(int,open(0).read().split());n+=1;f=[1]*-~n;r=f[:];M=10**9+7
for a in A:r[a]+=1
i=r.index(3);d=A.index;L=d(i);L+=n-d(i,L+1);*X,=range(1,n+1)
for i in X:f[i]=e=f[i-1]*i%M;r[i]=pow(e,M-2,M)
for k in X:print((f[n]*r[k]*r[n-k]-(k<=L)*(f[L-1]*r[k-1]*r[L-k]))%M)


Measured memory_bytes: 20272
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
string s;int w;
cin>>s>>w;
for (int i=0;i<s.size();i+=w) pc(s[i]);
}

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n), bs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> as[i] >> bs[i];
	}
	vector<pair<int64_t, int>> cs(n);
	for (int i = 0; i < n; i++)
	{
		cs[i] = {as[i] + bs[i], i};
	}
	sort(cs.begin(), cs.end());
	reverse(cs.begin(), cs.end());
	int64_t x = 0, y = 0;
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			x += as[cs[i].second];
		}
		else
		{
			y += bs[cs[i].second];
		}
	}
	cout << x - y << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

bool check_killable(long hit, int N, int A, int B, int* mons) {
  int remaining_atk = hit;
  for (int i = 0; i < N; ++i) {
    long remaining_life = (mons[i] - B * hit);
    if (remaining_life > 0) {
      long atks = remaining_life / (A - B);
      if (remaining_life % (A - B) != 0) {
        atks++;
      }
      remaining_atk -= atks;
    }
    if (remaining_atk < 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int N = 0;
  int A = 0;
  int B = 0;
  int mons[100001] = {};
  scanf("%d %d %d", &N, &A, &B);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &(mons[i]));
  }

  long lower = 0;
  long upper = 1000000001;

  while (upper - lower > 1) {
    long mid = (lower + upper) / 2;
    if (check_killable(mid, N, A, B, mons)) {
      upper = mid;
    } else {
      lower = mid;
    }
  }

  printf("%ld\n", upper);
  return 0;
}

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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

int N, A, B;
signed main() {
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}

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

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

    int first = std::atoi(s.substr(0, 2).c_str());
    int second = std::atoi(s.substr(2, 2).c_str());

    bool mayYYMM = false;
    bool mayMMYY = false;

    if (1 <= first && first <= 12) {
        mayMMYY = true;
    }
    if (1 <= second && second <= 12) {
        mayYYMM = true;
    }

    if (mayMMYY && !mayYYMM) {
        std::cout << "MMYY" << std::endl;
    } else if (!mayMMYY && mayYYMM) {
        std::cout << "YYMM" << std::endl;
    } else if (mayMMYY && mayYYMM) {
        std::cout << "AMBIGUOUS" << std::endl;
    } else {
        std::cout << "NA" << std::endl;
    }
}

Measured memory_bytes: 256
///Bismillahir Rahmair Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n,dg=1;
    cin>>n;
    int lft=1,rgt=26,tmp=26;
    while(1)
    {
       if(lft<=n && n<=rgt)break;
       dg++;
       lft=rgt+1;
       tmp=tmp*26;
       rgt=rgt+tmp;
    }
    string ses="";
    n=n-(lft-1);
    //cout<<dg<<" "<<n<<endl;
    for(int i=1;i<=dg;i++)
    {
       int baki=dg-i;
       int baki_can=1;
       for(int j=1;j<=baki;j++)baki_can=baki_can*26;
       for(char ch='a';ch<='z';ch++)
       {
           if(baki_can>=n)
           {
               ses+=ch;
               break;
           }
           else
           {
               n=n-baki_can;
           }
       }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 3600
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* main */
void Main(void)
{
    while (true)
    {
        int w, h;
        cin >> h >> w;
        if (w == 0 && h == 0)
        {
            break;
        }
        else
        {
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                        cout << "#";
                    else
                        cout << ".";
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



Measured memory_bytes: 3208
// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(0);  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x);
#define rep(i,a,n) for(int ( i ) = ( a ) ;( i ) <( n );( i )++)
 
 
int main()
{
    fast_io
    
    LL n,a,b;
    cin >> n >> a >> b ;
    cout << min(b,n*a) << endl;

    
    
    return 0;
}


 

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 10000000;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main(){
  ll N,M;
  cin >> N >> M;
  vector<vector<int>> v(N,vector<int>());
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    v.at(a).push_back(b);
    v.at(b).push_back(a);
  }
  queue<int> q;
  q.push(0);
  vector<int> dist(N,INF);
  dist.at(0) = 0;
  vector<int> pre(N,-1);
  while(!q.empty()){
    int k = q.front();
    q.pop();
    for(int l:v.at(k)){
      if(dist.at(l) != INF){
        continue;
      }
      dist.at(l) = dist.at(k) + 1;
      pre.at(l) = k;
      q.push(l);
    }
  }
  cout << "Yes" << endl;
  rep(i,N){
    if(i == 0)continue;
    cout << pre.at(i) + 1 << endl;
  }
  return 0;
}

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

using namespace std;

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

    int n, k, m;
    while (cin >> n >> k >> m, n | k | m)
    {
        std::vector<int> v;
        for (int i = 1; i <= n; i++)
            v.push_back(i);
        int pos = m - 1;
        while (v.size() > 1)
        {
            v.erase(v.begin() + pos);
            pos = (pos + k - 1) % v.size();
        }
        cout << v[0] << endl;
    }
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
//#define debug 1

int main() {
	int n;
	cin>>n;
	int a,b,num[3]={0,0,0};
	cin>>a>>b;
	int p;
	for(int i=0;i<n;i++) {
		cin>>p;
		if(p<=a) num[0]++;
		else if(p>a && p<=b) num[1]++;
		else num[2]++;
	}
	cout<<min(min(num[0],num[1]),num[2])<<endl;
#ifdef debug
	cout<<"Don't forget ndefine debug!"<<endl;
#endif
	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  if(n%k==0){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
def solve():
    N = int(input()) + 1
    A = list(map(int, input().split()))

    if N == 1:
        if A[0] == 1:
            return 1
        else:
            return -1

    # max node
    MN = [0 for _ in range(N)]
    MN[0] = 1
    for i in range(1, N):
        MN[i] = (MN[i-1] - A[i-1]) * 2
        if MN[i] <= 0:
            return -1

    if A[N-1] > MN[N-1]:
        return -1

    results = [0 for _ in range(N)]
    results[N-1] = A[N-1]
    if results[N-1] <= 0:
        return -1
    for i in range(N-2, -1, -1):
        results[i] += min(results[i+1] + A[i], MN[i])
        if results[i] <= 0:
            return -1

    return sum(results)

    # print(MI)
    # print(results)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 706892
#pragma GCC optimize("Ofast")
#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 <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll X,K,D;
  cin >> X >> K >> D;
  ll ans = INF;
  // cntかcnt+1が答え
  ll cnt = abs(X)/D;
  if(cnt >= K){
    chmin(ans,abs(X) - abs(K*D));
  }else{
    if((K-cnt)%2 == 0){
      chmin(ans,abs(X) - abs(cnt*D));
    }else{
      chmin(ans,abs(cnt*D+D)-abs(X));
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>

int prime(int);
int main()

{
    int N,i;
    int A[10001];
    scanf( "%d", &N );
    
    
    for( i=0; i<=N-1; i++ ) {
        scanf( "%d", &A[i] );
    }
    
    int all=0;
    for(i=0; i<=N-1; i++){
        all += prime(A[i]);
    }
    printf("%d\n", all);
    
    return 0;
}

    
int prime(int x)
{
   
    if(x==2 || x==3) return 1;
    if(x==1) return 0;
    if(x%2==0) return 0;
    int i;
    for (i=3; i<=sqrt((double)x); i+=2){
        if (x%i==0) return 0;
    }
    return 1;
    
}

Measured memory_bytes: 628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, m;
    cin >> n >> m;
    int num[m];
    rep(i, m) num[i] = 0;
    rep(i, n){
        int k;
        cin >> k;
        int a[k];
        rep(i, k) {
            cin >> a[i];
            a[i]--;
            num[a[i]]++;
        }
    }
    int ans = 0;
    rep(i, m){
        if (num[i] == n){
            ans++;
        }
    }
    // rep(i, m) cout << num[m] << " ";
    // cout << endl;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
px=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  px[p-1]+=x
ans=[0]*n
def dsf(index,u):
  ans[index]=ans[u]+px[index]
  for i in l[index]:
    if i==u:continue
    dsf(i,index)
dsf(0,-1)
print(*ans)

Measured memory_bytes: 236924
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int ans=0;
  string s;
  cin >> s;
  for(int a=1; a<s.size(); a++) {
    if(s.at(a-1)+s.at(a)-'0'-'0'!=1) {
      if(s.at(a)=='0') s.at(a)++;
      else s.at(a)--;
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<char,int>mp;
    string s;cin>>s;
    REP(i,s.size()) mp[s[i]]++;
    for(auto a:mp){
        if(a.second % 2 !=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 105
#define oo 1e18

using namespace std;
int n;
long long W, F[N][100005], v[N], w[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>W;
    for(int i=1; i<=n; i++) cin>>w[i]>>v[i];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=100000; j++)
        {
            F[i][j]=oo;
        }
    }
    F[0][0]=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<=100000; j++)
        {
            F[i][j]=F[i-1][j];
            if(j-v[i]<0) continue;
            F[i][j]=min(F[i][j], F[i-1][j-v[i]] + w[i]);
        }
    }
    for(int i=100000; i>=0; i--)
    {
        if(F[n][i]<=W)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 82528
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,a,b,j,t;
  while(cin>>a>>b)
  {
    if((a+b)%2==1)printf("IMPOSSIBLE\n");
    else cout<<(a+b)/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def larger(x, y):
	if x > y: return x
	return y

N = int(input())
A = list(map(int, input().split()))
dp1 = [A[0], -A[1]-A[0]] #change
dp2 = [A[0], A[1]+A[0]] #notchange
for i in range(2, N):
	newdp1 = larger(dp1[i-1]+2*A[i-1], dp2[i-1]-2*A[i-1]) - A[i]
	newdp2 = larger(dp1[i-1], dp2[i-1]) + A[i]
	dp1.append(newdp1)
	dp2.append(newdp2)
print(larger(dp1[N-1], dp2[N-1]))

Measured memory_bytes: 72864
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        e: usize,
        f: usize,

    }
    let mut x_l = vec![];
    let mut y_l = vec![];
    let cons = e as f64 / 100f64;
    let mut ans = (0usize, 0usize, 0f64);
    for i in 0..f {
        for j in 0..f {
            let x = 100 * (a * i + b * j);
            if x <= f {
                x_l.push(x);
            }
            let y = (c * i + d * j);
            if y <= f {
                y_l.push(y);
            }
        }
    }
    x_l.sort();
    x_l.dedup();
    y_l.sort();
    y_l.dedup();
    for x in x_l.iter() {
        for y in y_l.iter() {
            let cons_acc = *y as f64 / *x as f64;
            if x + y <= f && cons_acc <= cons {
                if ans.2 <= cons_acc {
                    ans = (*x, *y, cons_acc);
                }
            }
        }
    }
    println!("{} {}", ans.0 + ans.1, ans.1);
}


Measured memory_bytes: 8444