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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    a.at(i)--;
  }

  vector<int> b(N);
  for(int i = 0; i < N; i++){
    cin >> b.at(i);
  }

  vector<int> c(N-1);
  for(int i = 0; i < N-1; i++){
    cin >> c.at(i);
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    ans += b.at(a.at(i));
    if(i > 0 && a.at(i) == a.at(i-1)+1 ){
    ans += c.at(a.at(i-1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_left(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)

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

     public static void main(String []args){
        int arr[]=new int[5];
        Scanner sc=new Scanner(System.in);
       for(int i=0;i<5;i++)
          arr[i]=sc.nextInt();
    for(int i=0;i<5;i++)
    if(arr[i]==0)
       System.out.print(i+1);
         
     }
}

Measured memory_bytes: 35616
// ロジック見直して, 再提出.
// 解き直し.
// https://img.atcoder.jp/agc015/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAX = 61;

int main(){
    
    // 1. 入力情報.
    LL A, B;
    scanf("%lld %lld", &A, &B);
    if(A > B) swap(A, B);
    
    // 2. A = B の 場合.
    if(A == B){
        puts("1");
        return 0;
    }
    
    // 3. 二進数用意(61乗未満).
    vector<LL> vPow2(MAX);
    vPow2[0] = 1LL;
    repx(i, 1, MAX) vPow2[i] = vPow2[i - 1] << 1;
    // rep(i, MAX) printf("%lld\n", vPow2[i]);
    
    // 4. 二進数変換(61桁).
    string binA, binB;
    rep(i, MAX){
        if(1 & (A >> i)) binA = "1" + binA;
        else             binA = "0" + binA;
        if(1 & (B >> i)) binB = "1" + binB;
        else             binB = "0" + binB;
    }
    // printf("A=%s\n", binA.c_str());
    // printf("B=%s\n", binB.c_str());
    
    // 5. 操作 BITWISE OR を取って出来る整数をカウント.
    // 5-1. 二進数 A, B が, 最初に異なる桁.
    int r = -1;
    rep(i, MAX){
        if(binA[i] != binB[i]){
            r = MAX - i;
            break;
        }
    }
    assert(r != -1);
    // printf("r=%d\n", r);
    
    // 5-2. r桁より大きい部分(A, B の 共通部分)を計算し, A を 更新.
    LL extra = 0;
    rep(i, MAX - r) if(binA[i] == '1') extra += vPow2[MAX - 1 - i];
    A -= extra;
    
    // 6. 各パターンを集計.
    // 6-1. A ～ 2 の (r - 1)乗未満 の 整数 を カウント(パターン①).
    LL ans = vPow2[r - 1] - A;
    
    // 6-2. 最上位が 1 の 整数のみ使う場合(パターン②).
    // 12.txt, 24.txt で, WA版 だったため, k = -1 から k = 0 に ロジック変更.
    int k = 0;
    repx(i, MAX - r + 1, MAX){
        if(binB[i] == '1'){
            k = MAX - i;
            break;
        }
    }
    // printf("k=%d\n", k);
    // 15.txt, 16.txt, 18.txt, 53.txt で WA版だったため, maxP2 = -1 から maxP2 = 0 に 変更.
    // -> B が 1000 の ような形で, k = -1 となったパターンについて考慮が必要とのこと.
    LL minP2 = vPow2[r - 1], maxP2 = vPow2[r - 1] + vPow2[k];
    
    // 6-3. 最上位が 0, 1 の 整数を使う場合(パターン③).
    LL minP3 = vPow2[r - 1] + A;
    LL maxP3 = vPow2[r];
    
    // 6-4. パターン②, ③ を 統合.
    if(maxP2 >= minP3) ans += maxP3 - minP2;
    else               ans += maxP2 - minP2, ans += maxP3 - minP3;
    
    // 7. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
const int twx=+100;
const int inf=0x7fffffff;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int qwe;
void init()
{
	n=read();
    f1(1,n,i)
    {
        int qwe=(double)1.08*i;
        if(qwe==n)
        {
            printf("%d\n",i);
            exit(0);
        }
    }
    puts(":(");
}
void work()
{
	
}
void print()
{
	
}
int main()
{
    init();
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func solution(h, a int) int {
	var i int = 1
	for h > a*i {
		i++
	}
	return i
}

func main() {
	var h, a int
	fmt.Scan(&h, &a)
	fmt.Println(solution(h, a))
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cstring>
#define prDouble cout << fixed << setprecision(10) << x
#define fast_io ios_base::sync_with_stdio(false)
#define ii pair<int,int>
#define ll long long int
using namespace std;
int main()
{
	fast_io;
	int n;
	cin >> n;
	ll nums[n];
	ll sum = 0;
	for(int i = 0;i < n;++i)
		cin >> nums[i],sum += nums[i];
	ll dp[n][n];
	memset(dp,0,sizeof(dp));
	for(int i = n - 1;i >= 0;--i)
	{
		for(int j = i;j < n;++j)
		{
			if(i == j)
				dp[i][j] = nums[i];
			else if(i + 1 == j)
				dp[i][j] = max(nums[i],nums[j]);
			else 
				dp[i][j] = max(nums[i]+min(dp[i+2][j],dp[i+1][j-1])
					,nums[j]+min(dp[i+1][j-1],dp[i][j-2]));
		}
	}
	cout <<(dp[0][n-1] - (sum - dp[0][n-1]))<< "\n";
	return 0;
}

Measured memory_bytes: 73908
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

/* subroutines */

void divnum(int n, vpii& nums) {
  nums.clear();
  for (int k = 1; k * k <= n; k++)
    if (n % k == 0)
      nums.push_back(pii(k, n / k));
}

/* main */

int main() {
  for (;;) {
    int a, b;
    cin >> a >> b;
    if (a == 0) break;

    vpii adivs, bdivs;
    divnum(a, adivs);
    divnum(b, bdivs);

    if (false) {
      for (vpii::iterator apit = adivs.begin(); apit != adivs.end(); apit++)
	printf("%d=%d*%d\n", a, apit->first, apit->second);
      for (vpii::iterator bpit = bdivs.begin(); bpit != bdivs.end(); bpit++)
	printf("%d=%d*%d\n", b, bpit->first, bpit->second);
    }
    
    int ns[4];
    int minsum = INF;
    
    for (vpii::iterator apit = adivs.begin(); apit != adivs.end(); apit++) {
      int a0 = apit->first;
      int a1 = apit->second;
      for (vpii::iterator bpit = bdivs.begin(); bpit != bdivs.end(); bpit++) {
	int b0 = bpit->first;
	int b1 = bpit->second;

	ns[0] = a0; ns[1] = a1; ns[2] = b0; ns[3] = b1;
	sort(ns, ns + 4);
	int d0 = ns[1] - ns[0], d1 = ns[2] - ns[1], d2 = ns[3] - ns[2];
	int sum = d0 * d0 + d1 * d1 + d2 * d2;
	if (minsum > sum) minsum = sum;
      }
    }

    cout << minsum << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*SS=SZB,*TT=SZB;
    inline char gc(){   if (SS==TT){  TT=(SS=SZB)+fread(SZB,1,GYN,stdin); if (SS==TT) return '\n';  }   return *SS++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=1000010,mod=1e9+7;
ll f[N],sum[N],n,ans;
ll get(ll x){return x*(x+1)/2;}
int main(){
	n=read();
	f[0]=1;
	For(i,0,n){
		Add(sum[i+1],sum[i]);
		Add(f[i],sum[i]);
		Add(sum[i+1],f[i]);
		Add(f[i+2],-f[i]);
	}
	ans=1;//全1
	Add(ans,f[n-1]*(n-1));
	For(i,0,n-2)Add(ans,f[i]*(n-1)%mod*(n-1));//后面都是2,3,。。。。
	For(i,0,n-2)Add(ans,f[i]*(n-1));//2,11111
	Add(ans,mod);
	writeln(ans);
}
/*
1 1 1 1...
1 1 2 2...
1 1 3 3...
1 2 2 2...
1 2 3 3...
1 3 1 1...
1 3 2 2...
1 3 3
*/

Measured memory_bytes: 16640
#include <iostream>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
typedef long double ld;
typedef pair<int, int> P;
int main(void){
    int x1, y1, x2, y2, n, xl, xu, yl, yu;
    vector<P> v;
    cin>>x1>>y1>>x2>>y2>>n;
    xl=min(x1, x2);
    xu=max(x1, x2);
    yl=min(y1, y2);
    yu=max(y1, y2);
    for(int i=0;i<n;i++){
        int x, y;
        cin>>x>>y;
        if(x>=xl&&x<=xu&&y>=yl&&y<=yu){
            v.push_back(P(x, y));
        }
    }
    ld D=100, R=10;
    ld l=(ld)(xu-xl+yu-yl)*D;
    int s=v.size();
    if(x1==x2||y1==y2){
        if(s==1)l+=R*(M_PI-2);
    }else if(s>0){
        sort(v.begin(), v.end());
        int c=1;
        if((x1==xl&&y1==yu)||(x1==xu&&y1==yl))c=-1;
        int d[200000], m=0;
        fill(d, d+s, 1e9);
        for(int i=0;i<s;i++){
            int y=c*v[i].second;
            auto itr=upper_bound(d, d+s, y);
            (*itr) = y;
            m=max(m, (int)distance(d, itr));
        }
        if(m<min(xu-xl, yu-yl))l+=R*(M_PI/((ld)2)-2)*((ld)m+1);
        else l+=R*(M_PI/((ld)2)-2)*((ld)m)+R*(M_PI-2);
    }
    cout<<setprecision(20)<<l<<endl;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
void solve()
{
	ll n;
	rl(n);
	map<ll,ll> mp,mp2;
	VL arr(n);
	fr(i,0,n)
	{
		rl(arr[i]);
		mp[arr[i]]+=1;
	}
	ll ans=0;
	for(auto i: mp)
	{
		ll x=((i.S*(i.S-1))/2);
		mp2[i.F]=x;
		ans+=x;
	}
	fr(i,0,n)
	{
		ll x=mp2[arr[i]];
		ll tmp=ans;
		tmp-=x;
		ll y=mp[arr[i]];
		ll z=((y-1)*(y-2))/2;
		tmp+=z;
		cout<<tmp<<"\n";
	}
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 18944
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

#include <bits/stdc++.h>
using namespace std;
/* UnionFind：素集合系管理の構造体(union by rank)
    isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
    unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
*/
struct UnionFind {  // The range of node number is u 0 v n-1
    vector<int> rank, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        rank.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        rank[x] = 0;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    void unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (rank[x] > rank[y]) {
            parents[y] = x;
        } else {
            parents[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
    int findRoot(int x) {
        if (x != parents[x]) parents[x] = findRoot(parents[x]);
        return parents[x];
    }
};
// 辺の定義
struct Edge {
    long long u;
    long long v;
    long long cost;
};
bool comp_e(const Edge &e1, const Edge &e2) { return e1.cost < e2.cost; } // 辺を直接比較するための関数
/* Kruskal :クラスカル法で minimum spanning tree を求める構造体
    入力: 辺のvector, 頂点数V
    最小全域木の重みの総和: sum
    計算量: O(|E|log|V|)
*/
struct Kruskal {
    UnionFind uft;
    long long sum;  // 最小全域木の重みの総和
    vector<Edge> edges;
    int V;
    Kruskal(const vector<Edge> &edges_, int V_) : edges(edges_), V(V_) { init(); }
    void init() {
        sort(edges.begin(), edges.end(), comp_e); // 辺の重みでソート
        uft = UnionFind(V);
        sum = 0;
        for (auto e : edges) {
            if (!uft.isSame(e.u, e.v)) { // 閉路にならなければ加える
                uft.unite(e.u, e.v);
                sum += e.cost;
            }
        }
    }
};
int main() {
    int V,E;
    cin >> V >> E;
    vector<Edge>edges(E);
    rep(i,E) {
        int a,b,c;
        cin >> a >> b >> c;
        Edge e = {a,b,c};
        edges[i] = e;
    }
    Kruskal krs(edges,V);
    cout << krs.sum << endl;
}








Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int a,b; cin >> a >> b;
  if((a+b)%2 == 0) cout << (a+b)/2 << endl;
  else cout << (a+b)/2+1 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

T = int(input())
anss = []
for _ in range(T):
    N = int(input())
    Ls = defaultdict(list)
    Rs = defaultdict(list)
    ans = 0
    for i in range(N):
        K, L, R = map(int, input().split())
        if L > R:
            Ls[K].append(L-R)
            ans += R
        elif L < R:
            Rs[N-K].append(R-L)
            ans += L
        else:
            ans += L

    def f(Ls):
        PQL = []
        for j in range(1, N+1):
            for L in Ls[j]:
                heappush(PQL, L)
            while len(PQL) > j:
                heappop(PQL)
        return sum(PQL)

    ans += f(Ls)
    ans += f(Rs)

    anss.append(ans)

print('\n'.join(map(str, anss)))


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

ll n, l, a[MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> l;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int ind = 0;
	for (int i = 1; i < n; i++)
		if (a[i] + a[i + 1] >= l)
			ind = i;
	if (!ind)
		return cout << "Impossible" << endl, 0;
	cout << "Possible" << endl;
	for (int i = 1; i < ind; i++)
		cout << i << endl;
	for (int i = n - 1; i > ind; i--)
		cout << i << endl;
	cout << ind << endl;
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    struct edge { int to; int cost; };
    vector<vector<edge>> d(n+1);
    for(int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edge e;
        e.to = b; e.cost = c;
        d[a].push_back(e);
        e.to = a; e.cost = -c;
        d[b].push_back(e);
    }

    vector<int> ans(n+1);
    int INF = 1000000000;
    for(int i = 0; i <= n; i++)
    {
        ans[i] = INF;
    }

    ans[1] = 0;
    vector<bool> former(n+1);
    queue<int> que;
    for(int i = 1; i <= n; i++)
    {
        if(former[i]) continue;
        que.push(i);
        while(!que.empty())
        {
            int a = que.front();
            que.pop();
            if(former[a]) continue;
            for(int j = 0; j < d[a].size(); j++)
            {
                edge e = d[a][j];
                int to = e.to;
                int cost = e.cost;
                if(ans[to] == INF)
                {
                    ans[to] = ans[a] + cost;
                    que.push(to);
                }
                if(ans[to] != ans[a] + cost)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
            former[a] = true;
        }
      
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 9344
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = (int) (380 * 5 * 0.8);
		int b = (int) (550 * 4 * 0.85);
		int c = (int) (850 * 3 * 0.88);
		int[] g = { 200, 200, 200, 200, 300, 300, 300, 500, 500, 1000, 1000,
				1000, 1000, 1000, 1200, 1200, 1200, 1200, 1500, 1500, 1500 };
		int[] yen = { 380, 380, 380, 380, 550, 550, 550, 850, 850, a, a, a, a,
				a, b, b, b, b, c, c, c };

		Map<Integer, Integer> memo = new HashMap<Integer, Integer>();
		memo.put(0, 0);
		for (int i = 0; i < g.length; i++) {
			Map<Integer, Integer> memotmp = new HashMap<Integer, Integer>();
			memotmp.putAll(memo);
			for (Entry<Integer, Integer> entry : memo.entrySet()) {
				int k = entry.getKey() + g[i];
				int v = entry.getValue() + yen[i];
				if (k > 5000) {
					continue;
				}
				if (!memotmp.containsKey(k)) {
					memotmp.put(k, v);
				} else {
					int oldv = memotmp.get(k);
					if (oldv > v) {
						memotmp.put(k, v);
					}
				}

			}
			memo = memotmp;
		}
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			System.out.println(memo.get(n));
		}

	}
}

Measured memory_bytes: 17256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],k=0;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]!=i)
		{
			k++;
		}
	}
	if (k==0 || k==2)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

map<string, int> mp;

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

    ll ans;
    for (ll i = 0; i <= sqrt(n); i++) {
        if (i*i <= n)
            ans = i * i;
    }

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

Measured memory_bytes: 256
//include
//------------------------------------------
#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 <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N,K;
    cin >> N >> K;
    int L[N];
    REP(i,N) cin >> L[i];
    sort(L,L+N,greater<int>());
    int ans=0;
    for(int i=0;i<K;++i) ans+=L[i];
    cout << ans;
    }

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

using namespace std;


int main(){

string s;
cin >> s;
vector<char> v;

for (int i = 0; i < s.size(); i++){
    if(s[i] == '0'){
      v.push_back('0');
    }
    else if(s[i] == '1'){
      v.push_back('1');
    }
    else{
      if(v.size() != 0){
        v.erase(v.begin() + v.size() - 1 );
      }
    }
  }

for (int i = 0; i < v.size(); i++){
    cout << v[i];
  }

return 0;

}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

    int N;
    cin >> N;

    vi A(N), B(N);
    ll as = 0, bs = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        as += A[i];
        bs += B[i];
    }

    ll ans = min(as, bs);

    vector<array<int, 2>> vals(2 * N);
    for (int i = 0; i < N; i++) {
        vals[2 * i] = { i, 0 };
        vals[2 * i + 1] = { i, 1 };
    }
    sort(all(vals), [&](auto v1, auto v2) {
        int val1 = v1[1] ? B[v1[0]] : A[v1[0]];
        int val2 = v2[1] ? B[v2[0]] : A[v2[0]];
        return val1 < val2;
    });

    vi aloc(N), bloc(N);
    vll psum(2 * N);
    for (int i = 0; i < vals.size(); i++) {
        if (vals[i][1]) {
            bloc[vals[i][0]] = i;
            psum[i] = B[vals[i][0]];
        } else {
            aloc[vals[i][0]] = i;
            psum[i] = A[vals[i][0]];
        }
        if (i) psum[i] += psum[i-1];
    }

    for (int ut = 0; ut < N; ut++) {
        int pi = N - 2;
        while (true) {
            int elt = pi;
            if (aloc[ut] < pi) elt--;
            if (bloc[ut] < pi) elt--;
            if (elt < N - 2) {
                pi++;
            } else break;
        }

        ll cand = pi ? psum[pi - 1] : 0;
        if (aloc[ut] >= pi)
            cand += A[ut];
        if (bloc[ut] >= pi)
            cand += B[ut];
        ans = min(ans, cand);
    }

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



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int A, B;
	cin >> A >> B;
 
	int kotae = 0;
	for (int i = A; i <= B; i++) {
		string S = to_string(i);
		if (S[0] == S[4] && S[1] == S[3]) kotae++;
	}
	co(kotae);
 
	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

char toupper_char(char ch) {
    // (char)(ch - 32)
    return (char)toupper(ch);
}

int main() {
    string str;
    
    REP(i, 3) {
        cin >> str;
        cout << toupper_char(str[0]);
    }
    cout << "\n";
    
    return 0;
}


Measured memory_bytes: 256
def read_input():
    n, d = map(int, input().split())
    return n, d


def submit():
    n, d = read_input()

    rg = 2 * d + 1
    if n % rg:
        print(n // rg + 1)
    else:
        print(n // rg)

    return


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long f[10100],n,ans;
int main()
{
	scanf("%lld",&n);
	if(n % 2)
	{
		printf("0");
		return 0;
	}
	long long x = 2;
	for(int i = 1; ; i++)
	{
		x *= 5;
		if(x > 1e18)	break;
		f[++f[0]] =x;
	}
	for(int i = 1; i <= f[0]; i++)
		ans += n / f[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define int ll
signed main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    if(n == 1) {
        if(k == 0) cout << 1 << endl;    
        else cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for(int b = k+1; b <=n; b++) {
        int q = (n-b+1)/b;
        ans+=(q+1)*((b-1)-k+1);
        if(k == 0) ans--;
        if((q+1)*b+k>n) continue;
        ans += n - (q+1)*b - k + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long Gcd(long x,long y)
        {
            if (x < y) Gcd(y, x);
            while (y > 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long Lcm(long x,long y)
        {
            return x * y / Lcm(x, y);
        }

        public static bool IsLowercaseAlphabet(char target)
        {
            return new Regex("^[a-z]+$").IsMatch(target.ToString());
        }

        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var d = Reads();
            var m = Read();
            var t = Reads();
            var p = new Dictionary<long, long>();
            var q = new Dictionary<long, long>();
            for (int i = 0; i < n; i++)
            {
                if (p.ContainsKey(d[i])) p[d[i]]++;
                else p.Add(d[i], 1);
            }
            for (int i = 0; i < m; i++)
            {
                if (q.ContainsKey(t[i])) q[t[i]]++;
                else q.Add(t[i], 1);
            }
            var ans = true;
            foreach (var item in q)
            {
                var f = p.ContainsKey(item.Key) && p[item.Key]>= item.Value;
                if (!f) ans = false;
            }
            WriteLine(ans ? "YES" : "NO");
            

            
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 46412
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef pair<int, int> ii;

const int N = 300005;

int n, a[N], ans;
ii dp[N];

int main() {
//    freopen("cc.inp", "r", stdin);
//    freopen("cc.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < (1 << n); i++)
        cin >> a[i];
    dp[0] = {a[0], 0};
    for (int i = 1; i < (1 << n); i++) {
        //dp[i] = max(dp[i], dp[i - 1]);
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
            }
        }
        int id = dp[i].y;
        for (int j = 0; j < n; j++) {
            if (id & (1 << j)) {
                ans = max(ans, dp[i].x + dp[i ^ (1 << j)].x);
            }
        }
        ans = max(ans, dp[i].x + a[i]);
        dp[i] = max(dp[i], {a[i], i});
        cout << ans << '\n';
    }
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    string S;
    cin >> S;
    int n = S.size();

    string T;
    bool ok = false;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            T = S;
            T.erase(T.begin() + i, T.begin() + j);
            if (T == "keyence") {
                ok = true;
                break;
            }
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

ll pow(int n, int p)
{
    ll tmp = 1;
    for(int i = 0; i < p; i++){
        tmp *= n;
    }
    return tmp;
}

int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    ll x[n];
    ll sub = 0;
    for(int i = 1; i < n; i += 2){
        sub += a[i];
    }
    x[0] = sum - 2 * sub;
    for(int i = 1; i < n; i++){
        x[i] = 2 * a[i-1] - x[i-1];
    }
    for(int i = 0; i < n; i++){
        cout << x[i] << ' ';
    }
}

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

using ll = long long;

int main() {
	ll n, k, r, s, p;
	cin >> n >> k;
	cin >> r >> s >> p;
	string t;
	cin >> t;

	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		switch (t[i]) {
		case 'r':
			if ((i >= k) && (t[i - k] == 'r')) {
				t[i] = '_';
				break;
			}
			ans += p;
			break;
		case 's':
			if ((i >= k) && (t[i - k] == 's')) {
				t[i] = '_';
				break;
			}
			ans += r;
			break;
		case 'p':
			if ((i >= k) && (t[i - k] == 'p')) {
				t[i] = '_';
				break;
			}
			ans += s;
			break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

int main(void){
		char s;
			
		while(1){
				scanf("%c", &s);
				if(islower(s)){
						printf("%c",toupper(s));			
				}else if(isupper(s)){
						printf("%c",tolower(s));
				}else{
						printf("%c", s);
				}
				if( s == '\n') break;
		}
		return 0;
}

Measured memory_bytes: 1104
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main() 
{
	long int a,b,c,k;
	long int ans = 0;
	cin >> a >> b >> c >> k;
	
	for (long int i = 1; i <= k; i++)
	{
		if (a >= i) ans++;
		else if (a + b < i)ans--;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
const int di[]={-1,0,1,0};
const int dj[]={0,1,0,-1};
int main()
{
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int fi, fj;
    cin >> fi >> fj;
    --si; --sj; --fi; --fj;
    string s[h];
    REP(i,h) cin >> s[i];
    const int INF = 1e9;
    deque<pair<int,int>> q;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    dist[si][sj] = 0;
    q.emplace_front(si, sj);
    while(!q.empty()){
        int fir = q.front().first;
        int sec = q.front().second;
        int d = dist[fir][sec];
        q.pop_front();
        REP(i,4){
            int a = fir + di[i];
            int b = sec + dj[i];
            if (a < 0 || b < 0 || a >= h || b >= w) continue;
            if (s[a][b] == '#') continue;
            if (dist[a][b] <= d) continue;
            dist[a][b] = d;
            q.emplace_front(a,b);
        }
        for(int ei = -2; ei<= 2; ++ei){
            for(int ej = -2; ej<=2; ++ej){
                int a = fir + ei;
                int b = sec + ej;
                if (a < 0 || b < 0 || a >= h || b >= w) continue;
                if (s[a][b] == '#') continue;
                if (dist[a][b] <= d + 1) continue;
                dist[a][b] = d + 1;
                q.emplace_back(a,b);
            }
        }

    }
    if(dist[fi][fj] == INF) cout << -1 << endl;
    else cout << dist[fi][fj] << endl;
    return 0;
}

Measured memory_bytes: 8628
n = int(input())
lst = input().split(" ")
a = [int(item) for item in lst]
ans = 0
while sum(a) > 0:
    left = 0
    right = -1
    for i in range(len(a)):
        if not a[i] == 0:
            left = i
            break
    for i in range(left, len(a)):
        if a[i] == 0:
            right = i
            break
    if -1 == right:
        right = len(a)
    right = right - 1
    min_val = a[left]
    for i in range(left, right + 1):
        min_val = min(min_val, a[i])
    ans += min_val
    for i in range(left, right + 1):
        a[i] -= min_val
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
int n;
int A[30] = {};
bool help(int d,int t);
int main()
{
    int q;
	cin >> n;
	for(int i=0;i<n;i++) cin >> A[i];
	cin >>q;
	int m[200] = {};
	int b;
	for(int i=0; i<q ; i++) cin >> m[i];

	for(int i=0; i<q ; i++) cout << (help(0,m[i])? "yes":"no") << endl;	

	
	return 0;
}

bool help(int d,int t){
	if(t == 0) return true;
	if(d >=n or t<0) return false;
	return help(d+1,t) or help(d+1,t-A[d]);
}


Measured memory_bytes: 3104
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N=100000;
int n;
int a[N+1];
int Sum[N+1],Sum0[N+1];
signed main(){
	cin>>n;
	vector<int> nepos;
	for(int i=1;i<=n;i++){
		bool ne=false;
		if(i>1){
			char c;
			cin>>c;
			if(c=='-')ne=true,nepos.pb(i);
		}
		cin>>a[i];
		if(ne)a[i]=-a[i];
		Sum[i]=Sum[i-1]+a[i];
		Sum0[i]=Sum0[i-1]+abs(a[i]);
	}
//	for(int i=1;i<=n;i++)cout<<a[i]<<" ";puts("");
	nepos.pb(n+1);
	int ans=Sum[n];
	for(int i=1;i<=n;i++)if(a[i]<0){
		int fd=*lower_bound(nepos.begin(),nepos.end(),i+1);
//		printf("fd=%lld\n",fd);
		ans=max(ans,Sum[i]-(Sum[fd-1]-Sum[i])+(Sum0[n]-Sum0[fd-1]));
	}
	cout<<ans;
	return 0;
}
/*1
3
5 - 1 - 3
*/
/*2
5
1 - 2 + 3 - 4 + 5
*/
/*3
5
1 - 20 - 13 + 14 - 5
*/

Measured memory_bytes: 3444
from math import gcd
a, b = map(int, input().split())
x = gcd(a,b)
cnt = 1
for i in range(2, int(x ** 0.5) + 1):
        if x == 1:
            break
        if x % i == 0:
            cnt += 1
            while x % i == 0:
                x //= i
else:
    if x != 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 9268
#include <stdio.h>
  
  
int main() {
    int i,j,n,a,b,c;
	int M[100][100] = { 0 };
	
	scanf("%d" ,&n);
	
	for ( i = 0; i < n; i++){
		scanf("%d", &a);
		scanf("%d", &b);
		if( b != 0){
			for( j = 0; j < b; j++){
				scanf("%d", &c);
				M[a - 1][c - 1] = 1;
			}
		}
	}

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            printf("%d", M[i][j]);
            if (j != n - 1) {
                putchar(' ');
            }
        }
        putchar('\n');
    }
	
    return 0;
}


Measured memory_bytes: 2144
import java.util.Scanner;

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

        if(n == 1 && m == 1) {
            System.out.println(1);
        } else if(n == 1) {
            System.out.println(m-2);
        } else if(m == 1) {
            System.out.println(n-2);
        } else {
            System.out.println((n-2)*(m-2));
        }
    }
}


Measured memory_bytes: 35480
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数


//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}



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

	ll n, k;
	cin >> n >> k;
	n %= k;
	chmin(n, k - n);
	cout << n << endl;
}

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

int main(){
  int n,ans;
  cin >> n;
  ans=0;
  string str;
  for(int i=1;i<n+1;++i){
    str=to_string(i);
    if(str.length()%2==1){
      ans +=1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
res = 0
for i in range(N):
    while True:
        exist_odd = False
        for j in range(N):
            if A[j] % 2 != 0:
                exist_odd = True

        if exist_odd:
            break

        for k in range(N):
            A[k] /= 2

        res += 1

print(res)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,t;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r<=H && A[r] > A[largest]) largest = r;
  if(largest != i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1 ; i<=H ; i++) scanf("%d",&A[i]);
  for(i=H/2 ; i>=1 ; i--) maxHeapify(i);
  for(i=1 ; i<=H ; i++){
    printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

  return 0;
}

  



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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int a,b,t;cin>>a>>b>>t;
  int ans=0;
  for(int i=a;i<=t;i+=a){
    ans+=b;
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3632
using System;

public class Hello{
    public static void Main(){
        // Your code here!
        var N = int.Parse(Console.ReadLine());
        var money = 0;
        
        for(var i = 0; i < N; i += 1000)
        {
            money = i;
        }
        
        money += 1000;
        
        var change = money - N;
        
        System.Console.WriteLine(change);
    }
}

Measured memory_bytes: 27496
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.par.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_==true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 64632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<long> domx(n),domy(m);
    for(int i = 0; i < n; i++)
        cin>>domx[i];
    for(int i = 0; i < m; i++)
        cin>>domy[i];
    long max = *max_element(domx.begin(),domx.end());
    long min = *min_element(domy.begin(),domy.end());
    for(int i = x+1; i<=y; i++){
        if(i>max&&i<=min){
            cout<<"No War";
            return 0;
        }
    }
    cout<<"War";
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

	void run() {
		
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		
		//隙間の数
		//例えば123だったら1○2○3のように隙間が2つある
		//この隙間に＋を入れるか入れないかで判断する。
		
		//隙間の数は文字の数-1
		int n=str.length()-1;
		
		long ans=0;
		
		
		//隙間の数に対応したビットを全列挙する。
		for(int i=0;i<(1<<n);i++) {
			long sum=0;
			long a=str.charAt(0)-'0';
			
			for(int j=0;j<n;j++) {
				
				if((i>>j)%2==1) {
					
					sum+=a;
					a=0;
					
				}
				
				a=a*10+(str.charAt(j+1)-'0');
				
			}
			
			//ループを抜けた時に格納されている残りを足す。
			sum+=a;
			
			//一回ループが終わったら、結果を足しておく。
			ans+=sum;
			
		}
		
		System.out.println(ans);


	}




}





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

int N, M, A[1111], B[1111], V[1111];
 
int main()
{
    cin >> N >> M;
 
    for (int i = 1; i <= N; i++)
        cin >> A[i];
 
    for (int i = 1; i <= M; i++)
        cin >> B[i];
 
    for (int i = 1; i <= M; i++)
    {
        for (int j = 1; i <= N; j++)
        {
            if (A[j] <= B[i])
            {
                V[j]++;
 
                break;
            }
        }
    }
 
    cout << distance(V, max_element(V, V + N)) << endl;
 
    return 0;
}

Measured memory_bytes: 3108
#include<iostream>
#include<queue>
#include<utility>

int main() {
    int n, timePiece, val, totalTime;
    std::string name;
    std::queue<std::pair<std::string, int>> queueCtn;
    std::pair<std::string, int> tmp;

    totalTime = 0;

    std::cin >> n >> timePiece;

    for (int i = 0; i < n; i++) {
        std::cin >> name >> val;
        queueCtn.push(make_pair(name, val));
    }
    
    while (!queueCtn.empty()) {
        tmp = queueCtn.front();
        queueCtn.pop();

        if (std::get<1>(tmp) > timePiece) {
            totalTime += timePiece;
            tmp.second -= timePiece;
            queueCtn.push(tmp);
        } else {
            totalTime += std::get<1>(tmp);
            std::cout << std::get<0>(tmp) << " " << totalTime << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6336