akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int ta[10010],to[60010],nt[60010];
int id[10010],rid[10010],cmp[100010],r=0,f[10010]={0};
void sdfs(int e,int s,int k){
  int i;
  f[s]++;
  for(i=ta[s];i+1;i=nt[i]){
    if(i<e&&k<0&&f[to[i]]==0||i>=e&&k>=0&&f[to[i]]==1)sdfs(e,to[i],k);
  }
  k<0?(id[rid[s]=r++]=s):(cmp[s]=k);
}
void scc(int v,int e,int *a,int *b){
  int i,k;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+e;
  }
  for(i=k=0;i<v;i++){
    if(f[i]==0)sdfs(e,i,-1);
  }
  for(i=r;i;i--){
    if(f[id[i-1]]==1)sdfs(e,id[i-1],id[i-1]);
  }
}
int main(){
  int v,e,a[100010],b[100010],s,t,i;
  scanf("%d %d",&v,&e);
  for(i=0;i<e;i++)scanf("%d %d",&a[i],&b[i]);
  scc(v,e,a,b);
  scanf("%d",&v);
  while(v--){
    scanf("%d %d",&s,&t);
    printf("%d\n",cmp[s]-cmp[t]?0:1);
  }
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll N = nextLong();
  ll K = nextLong();
  ll ans = min(N % K, K - N % K);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=110;
struct{
	int x,y,h;
}mes[maxn];

int main(){
	int n;
	scanf("%d",&n);
	int a;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&mes[i].x,&mes[i].y,&mes[i].h);
		if(mes[i].h>0) a=i;
	}
	
	int H,ans;
	bool flag;
	for(int cx=0;cx<=100;cx++){
		for(int cy=0;cy<=100;cy++){
			flag=true;
			H=abs(mes[a].x-cx)+abs(mes[a].y-cy)+mes[a].h;
			for(int i=0;i<n;i++){
				ans=max((H-abs(mes[i].x-cx)-abs(mes[i].y-cy)),0);
				if(ans!=mes[i].h){
					flag=false;
					break;
				}
			}
			if(flag){
				printf("%d %d %d\n",cx,cy,H);
				return 0;
			}
		}
		
	}
	
	
	return 0;
}

Measured memory_bytes: 256
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    int n;
    cin>>n;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j <= n; j++) {
    		int val =__gcd(i,j);
    		if(val == 1) {
    			ans += n;
    			continue;
    		}
    		for(int k = 1; k <= n; k++) {
    			ans += __gcd(val, k);
    		}
    	}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string, int> mp;
string s[1000]; 
int main() {
	int n;
	cin>>n; 
	cin>>s[1]; mp[s[1]]=1;	
	for(int i=2;i<=n;i++) {
		cin>>s[i];
		if(mp[s[i]]==1 || s[i][0]!=s[i-1][s[i-1].length()-1]) {
			puts("No"); return 0;
		}
		mp[s[i]]=1;
	}
	puts("Yes");
}

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

bool x_dp[4001][50000];
bool y_dp[4001][50000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    int X, Y;
    cin >> s >> X >> Y;
    vector<int> cnt;
    int temp = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'F'){
            ++temp;
        }
        else{
            cnt.push_back(temp);
            temp = 0;
        }
    }
    cnt.push_back(temp);
    
    int n = cnt.size();
    
    const int dif = 25000;
    x_dp[0][cnt[0] + dif] = true;
    y_dp[0][dif] = true;
    
    int yn = n / 2;
    int xn = n - yn;
    
    // 原点を25000とする
    for(int i = 1; i < xn; ++i){
        int d = cnt[2 * i];
        for(int x = -8000; x <= 8000; ++x){
            x_dp[i][x+dif] = x_dp[i-1][x-d+dif] || x_dp[i-1][x+d+dif];
        }
    }
    for(int i = 0; i < yn; ++i){
        int d = cnt[2 * i + 1];
        for(int y = -8000; y <= 8000; ++y){
            y_dp[i+1][y+dif] = y_dp[i][y-d+dif] || y_dp[i][y+d+dif];
        }
    }
    
    if(x_dp[xn-1][X+dif] && y_dp[yn][Y+dif]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    dump(s, t);
    if (s.compare(t) == 0) {
      cout << "Yes" << endl;
      return 0;
    }
    char c = s[s.size() - 1];
    for (int j = s.size() - 1; 0 < j; j--) {
      s[j] = s[j - 1];
    }
    s[0] = c;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,int>in;
    vector<int>time;
    rep(i,n){
      int sum=0;
      int num;
      cin>>num;
      rep(i,4){
	int a,b;
	cin>>a>>b;
	sum+=a*60+b;
      }
      in[sum]=num;
      time.pb(sum);
    }
    sort(all(time));
    cout<<in[time[0]]<<endl<<in[time[1]]<<endl<<in[time[n-2]]<<endl;
  }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

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

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

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    sort(p.begin(), p.end());

    int sum = 0;
    for (int i = 0; i < N - 1; i++) sum += p[i];
    sum += p[N - 1] / 2;

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define int long long

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto c : s) {
        mp[c]++;
    }

    string ans = "Yes";
    for (auto p : mp) {
        if (p.second % 2 != 0) {
            ans = "No";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def resolve():
    cnt = 0
    n, m, c = map(int, input().split())
    b_list = list(map(int, input().split()))
    for i in range(n):
        a_list = list(map(int, input().split()))
        siki = 0
        for x in range(m):
            siki += (a_list[x] * b_list[x])
        if siki+c > 0:
                cnt += 1
    print(cnt)
resolve()

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 (b<a) { a=b; return 1; } return 0; }

int n,ans;

int main(){
    int N=1000000;
    int prime[N];
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
    while(cin>>n){
        ans=0;
        rep(i,n+1)ans+=prime[i];
        out(ans);
    }
}



Measured memory_bytes: 6936
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin >> s;
  int i,j,k,l,m,o,p,n = s.size(),z,dp[n+1][2][2][2][2] = {};dp[0][0][0][0][0] = 1;
  for(i=0;i<n;i++){
    z = s[i]-'0';
    for(j=0;j<2;j++){
      for(k=0;k<2;k++){
        for(m=0;m<2;m++){
          for(o=0;o<2;o++){
            for(p=3;p<=(j ? 7:min(7,z));p+=2) dp[i+1][j|(p<z)][k|(p==3)][m|(p==5)][o|(p==7)] += dp[i][j][k][m][o];
          }
        }
      }
    }
    dp[i+1][1][0][0][0]++;
  }
  cout << dp[n][0][1][1][1]+dp[n][1][1][1][1] << "\n";
}

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

S = {}
for _ in range(N):
    s = list(input())
    s.sort()
    s = tuple(s)
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

ans = 0
for value in S.values():
    ans += value*(value-1)//2

print(ans)





Measured memory_bytes: 23652
from itertools import product
N=int(input())
data=[]
for i in range(N):
    for j in range(int(input())):
        x,y=map(int,input().split())
        data.append((i,x-1,y))
#print(data)

ans=0
for i in product([1,0],repeat=N):
    #print(i)
    s=True
    for k in data:
        if i[k[0]]==1 and i[k[1]]!=k[2]:
            s=False
            break
    if s:
        ans=max(ans,sum(i))
print(ans)


Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt()+sc.nextInt();
    int b=sc.nextInt()+sc.nextInt();
    System.out.println(a>b?"Left":a<b?"Right":"Balanced");
  }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> nums;
    int now = 1;
    int cnt = 0;
    rep(i, n){
        if(s[i] - '0' == now) cnt++;
        else{
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    nums.push_back(cnt);
    if(now == 0) nums.push_back(0);
    
    if(2 * k + 1 >= nums.size()){
        cout << n << endl;
        return 0;
    }
    int memo = 0;
    rep(i, 2 * k + 1) memo += nums[i];
    int ans = memo;
    for(int i = 0; i < nums.size() - 2 * k - 1; i += 2){
        memo += nums[2 * k + 1 + i] + nums[2 * k + 2 + i];
        memo -= nums[i] + nums[i+1];
        ans = max(ans, memo);
    }
    cout << ans << endl;
    return 0;
}

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

object Helpers {
  def readIntLine = readLine.split(" ").map(_.toInt)
  def readInts(n: Int) = Array.fill(n)(readInt)

  def splitDigits(i: Int): Seq[Int] = i.toString.map(_.asDigit)

  def log[A](x: A): A = {println(x); x}

  implicit class IntImplicits(val i: Int) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Int): Int = scala.math.pow(i, exp).intValue
  }

  implicit class LongImplicits(val i: Long) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Long): Long = scala.math.pow(i, exp).longValue
  }
}

object Main extends App {
  import Helpers._

  val x: Long = readLong

  var y: Double = 100

  def rec(t: Long, a: Int, n: Double): Int = {
    if (n >= t) a
    else rec(t, a + 1, scala.math.floor(n * 1.01))
  }

  println(rec(x, 0, y))
}



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

int main()
{
    int q, cmd, v;
    vector<int> vec;

    cin >> q;

    for (int i = 0; i != q; ++i)
    {
        cin >> cmd;

        switch (cmd)
        {
            case 0:
            {
                cin >> v;
                vec.push_back(v);
                break;
            }
            case 1:
            {
                cin >> v;
                cout << vec[v] << endl;
                break;
            }
            case 2:
            {
                vec.pop_back();
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3824
def main():
    t = []
    for _ in range(5):
        t.append(int(input()))

    max_wait = 0
    sum_wait = 0
    for d in t:
        wait = (10 - d % 10) % 10
        if max_wait < wait:
            max_wait = wait
        sum_wait += d + wait
    print(sum_wait - max_wait)


main()


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

using namespace std;

int main(){

	int a,b,n;
  	while(cin>>a>>b>>n){
		int d=a;
		d -= (d/b)*b;
		int sum=0;
		d*=10;
		for(int i = 0; i < n; i++){
			if(d==0)
				break;
			else if(d<b)
				d*=10;
			else{
				sum+=d/b;
				d=d%b;
				d*=10;
			}
		}
		cout<<sum<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
tenants = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]

n = int(input())

for _ in range(n):
    b,f,r,v = map(int,input().split())
    tenants[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print('',*tenants[i][j])
    if i!=3:
        print('####################')


Measured memory_bytes: 5628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  string a,b,c; cin>>a>>b>>c;
  int ans = 0;
  rep(i,n){
    if(a[i]==b[i]&&b[i]==c[i]) continue;
    if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]) ans+=2;
    else ans++;
  }
  cout << ans << endl;
  return 0;
}


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

void chmin(int &a, int b){
    if(a > b)a = b;
}

int main(){
    int D, G;
    cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    for(int i = 0; i < D; i++)cin >> p[i] >> c[i];
    int ans = 1e9;
    
    for(int s = 0; s < (1 << D); s++){
        int solve = 0, score = 0;
        int M = -1;
        
        for(int i = 0; i < D; i++){
            if(s & (1 << i)){
                solve += p[i];
                score += 100 * (i + 1) * p[i] + c[i];
            }else{
                M = i;
            }
        }
        
        int less = G - score;
        if(less > 0){
            int one = 100 * (M + 1);
            if(less - (one * p[M]) > 0)continue;
            solve += less / one;
            if(less % one != 0)solve++;
        }
        
        chmin(ans, solve);
    }
    
    cout << ans << endl;
    return 0;
}

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

const int INF=1e7;
const int M=105;
int a[M],b[M];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",&b[i]);
	int ans=0;
	b[0]=b[n]=INF;
	for(int i=1;i<=n;i++)
		ans+=min(b[i-1],b[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
ans = 'Yes'

for i in range(N):   
    if S[i] == 'R' and (i+1)%2 == 0:
        ans = 'No'
        break
    elif S[i] == 'L' and (i+1)%2 == 1:
        ans ='No'
        break

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  char w[101];
  cin >> w;
  int n=strlen(w);
  map<char,int> m;
  REP(i,n) {
    char x=w[i];
    m[x]++;
  }
  bool flg=true;
  for(const auto& [i,j]:m) {
    if(j%2!=0) flg=false;
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3608
M, D = map(int, input().split())
res = 0

for m in range(1, M + 1):
    for d in range(1, D + 1):
        d1 = d // 10
        d2 = d % 10
        if m == d1 * d2 and d1 >= 2 and d2 >= 2:
            res += 1
print(res)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,k,l,p,q,u,dp[115][4][4],mod=1e9+7,ans;
string st1,st2;
int main()
{
	cin>>n>>st1>>st2;
	st1=" "+st1;
	st2=" "+st2;
	dp[0][0][0]=1;
	for (i=1;i<st1.length();i++)
	{
		if (st1[i]!=st2[i])
		{
			if (st1[i-1]==st1[i]&&st2[i-1]==st2[i])
			{
				for (j=1;j<=3;j++)
				{
					for (k=1;k<=3;k++)
					{
						dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k])%mod;
					}
				}
			}
			else			 
			{
				for (j=1;j<=3;j++)
				{
					for (k=1;k<=3;k++)
					{
						for (l=0;l<=3;l++)
						{
							for (p=0;p<=3;p++)
							{
								if (j!=l&&k!=p&&j!=k)
								{
									dp[i][j][k]=(dp[i][j][k]+dp[i-1][l][p])%mod;
								}
							}
						}
					}
				}
			}
		}
		else
		{
			for (j=1;j<=3;j++)
			{
				k=j;
				for (l=0;l<=3;l++)
				{
					for (p=0;p<=3;p++)
					{
						if (j!=l&&k!=p)
						{
							dp[i][j][k]=(dp[i][j][k]+dp[i-1][l][p])%mod;
						}
					}
				}
			}
		}
	}
	/*for (i=1;i<st1.length();i++)
	{
		for (j=0;j<=3;j++)
		{
			for (k=0;k<=3;k++)
			{
				cerr<<dp[i][j][k]<<' ';
			}
			cerr<<" ||| ";
		}
		cerr<<endl;
	}*/
	for (i=1;i<=3;i++)
	{
		for (j=1;j<=3;j++)
		{
			ans=(ans+dp[st1.length()-1][i][j])%mod;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int c = 0;
	if (n % k != 0)
		c++;
	cout << c << endl;
}

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

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}
int diff(int a, int b) {
	return std::max(a, b);
}
int e() {
	return 0;
}
static void D_task()
{
	int N, K;
	get(N, K);

	std::vector<int> ai(N);
	int maxValue = 0;
	for (int i = 0; i < N; i++) {
		get(ai[i]);
		maxValue = std::max(ai[i], maxValue);
	}

	atcoder::segtree<int, diff, e> seg(maxValue + 2);
	std::vector<int> dp(N, 1);
	int max = 1;
	int maxval = ai[N - 1];

	for (int i = N - 1; i >= 0; i--) {
		
		int val = seg.prod(std::max(ai[i] - K, 0), std::min(ai[i] + K + 1, maxValue + 1)) + 1;
		seg.set(ai[i], val);
	}
	printf("%d\n", seg.all_prod());
}


Measured memory_bytes: 9764
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
cnt = Counter(S)
M = max(list(cnt.values()))
ans = []

for k, v in cnt.items():
    if v==M:
        ans.append(k)

ans.sort()

for ans_i in ans:
    print(ans_i)

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

using D=double;

int main()
{
   int N; cin>>N;
   vector<D> p(N);
   for(int i=0;i<N;i++) cin>>p[i];

   vector<vector<D>> dp(N+1,vector<D>(N+1));
   dp[0][0]=1.0;
   for(int i=0;i<N;i++) for(int j=0;j<=i;j++){
      dp[i+1][j+1]+=dp[i][j]*p[i];
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
   }
   D ans=0.0;
   for(int j=(N+1)/2;j<=N;j++) ans+=dp[N][j];
   cout<<fixed<<setprecision(10)<<ans<<endl;
   return 0;
}


Measured memory_bytes: 70784
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

typedef complex<int> P;

bool er;

void is_error(P& p){
	er |= !(abs(p.real()) <= 10000 && abs(p.imag()) <= 10000);
}

P expr(const char *& s);
 
P val(const char *& s){
    if(*s == '('){
        s++;
        P ret = expr(s);
        s++;
        return ret;
    }
	if(*s == 'i'){
		s++;
		return P(0,1);
	}
    int v = 0;
    while(*s >= '0' && *s <= '9'){
        v *= 10;
        v += *s - '0';
        s++;
		P p(v,0);
		is_error(p);
    }
	return P(v,0);
}
 
P pri(const char *& s){
	if(*s == '-'){
		s++;
		return -1 * pri(s);
	}
    P l = val(s);
    while(true){
        char ope = *s;
        if(ope != '*' && ope != '/')
            return l;
        s++;
        P r = val(s);

        if(ope == '*')
            l *= r;
        else
            l /= r;
		is_error(l);
    }
}
 
P expr(const char *& s){
    P l = pri(s);
    while(true){
        char ope = *s;
        if(ope != '+' && ope != '-')
            return l;
        s++;
        P r = pri(s);
        if(ope == '+')
            l+=r;
        else
            l-=r;

		is_error(l);
    }
}

int main(){
 
	string s;
    while(cin>>s){
		const char *p = s.c_str();
		er = false;
		P ans = expr(p);
		if(er){
			puts("overflow");
		}else{
			if(ans.imag() == 0)
				printf("%d\n",ans.real());
			else if(ans.real() == 0){
				printf("%di\n",ans.imag());
			} else {
				printf("%d%+di\n",ans.real(),ans.imag());
			}
		}

	}
    return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

#define MAX 10001

int main() {
  int n;
  long int a,b;
  long int x,pre;
  int i;
  long int cost = 0;

  scanf("%d%ld%ld", &n, &a, &b);
  scanf("%ld", &x);
  pre = x;

  for(i = 0; i < n; i++){
    long int dx;
    scanf("%ld", &x);
    dx = x - pre;

    if(dx*a >= b){ //テレポートの方が便利なら
      cost += b;
    } else{
      cost += dx *a;
    }

    pre = x;
  }

  // for(i = 1; i < n; i++){
  //   dx = x[i] - x[i-1];
  //   // printf("%d ", dx);
  //
  //   if(dx*a >= b){ //テレポートの方が便利なら
  //     cost += b;
  //   } else{
  //     cost += dx *a;
  //   }
  // }

  printf("%ld", cost);

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int x[3000];
	int y[3000];
	int i=0;
	for ( i = 0; i <= 3000; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
		if (x[i]>y[i])
		{
			int tmp = x[i];
			x[i] = y[i];
			y[i] = tmp;
		}
		if (x[i] == 0 && y[i] == 0){
			break;
		}
	}
	for (i = 0; i <= 3000; i++)
	{
		if (x[i] == 0 && y[i] == 0){
			break;
		}
		printf("%d %d\n", x[i], y[i]);
	}
	return 0;
}

Measured memory_bytes: 2780
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

static const int MAX_N = 100010;
long long int h[MAX_N];
long long int cost[MAX_N];//そこまでの最小costをメモる

void dp(long long int n){
  if(n == 0){
    cost[n] = 0;
  }
  else if(n == 1){
    cost[n] = abs(h[0] - h[1]);
  }
  else{
    long long int temp_cost1, temp_cost2;
    temp_cost1 = cost[n - 1] + abs(h[n - 1] - h[n]);
    temp_cost2 = cost[n - 2] + abs(h[n - 2] - h[n]);
    cost[n] = min(temp_cost1, temp_cost2);
  }
}

int main(void){
  long long int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  for(int i = 0; i < N; i++){
    dp(i);
  }
  cout << cost[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn gcd(a: i64, b: i64) -> i64 {
    match b {
        0 => a,
        _ => gcd(b, a% b)
    }
}

fn lcm(a: i64, b: i64) -> i64 {
    let gcd = gcd(a, b);
    (a / gcd) * b
}

fn main() {
    let n: usize = read();
    let t: Vec<i64> = readn(n);

    let mut ans = 1i64;
    for ti in t {
        ans = lcm(ans, ti);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = gets.to_i
A = gets.split.map &:to_i
minuses, pluses = A.partition{|a| a < 0 }
minuses.sort!.reverse!
pluses.sort!

ans = []
if pluses.empty?
  a, b = minuses.shift(2)
  c = a - b
  ans << [a, b]
  pluses.unshift c
elsif minuses.empty?
  a, b = pluses.shift(2)
  c = a - b
  ans << [a, b]
  minuses.unshift c
end

while minuses.size >= 1 && pluses.size >= 1
  a = minuses.shift
  b = pluses.shift
  if pluses.empty?
    c = b - a
    ans << [b, a]
    pluses.unshift c
  else
    c = a - b
    ans << [a, b]
    minuses.unshift c
  end
end

p pluses[0] || -minuses[0]
puts ans.map{|a| a*' ' }


Measured memory_bytes: 34032
N = int(input())
A, B, C = [input() for i in range(3)]
ans = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        pass
    elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        ans += 1
    else:
        ans += 2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int G[n][n + 1];
    memset(G, 0, sizeof(G));
    for (int i = 0; i < m; i++) { 
        int a, b; cin >> a >> b;
        a--, b--;
        G[a][b] = 1;
        G[b][a] = 1;
    }
    int perm[n + 1];
    for (int i = 0; i < n; i++) perm[i] = i;

    int ans = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            if (!G[perm[i]][perm[i+1]]) break;
            if (i == n - 2) ans++;
        } 
    } while (next_permutation(perm, perm + n) && perm[0] == 0);
    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;

vector<pair<ll, int> > v;
ll arr[5];

int main(){
	ll q, h, s, d, n;
	scanf("%lld%lld%lld%lld%lld", arr + 0, arr + 1, arr + 2, arr + 3, &n);
	v.pb(mp(arr[0] * 8, 0));
	v.pb(mp(arr[1] * 4, 1));
	v.pb(mp(arr[2] * 2, 2));
	v.pb(mp(arr[3] * 1, 3));

	sort(v.begin(), v.end());

	ll ans = 0;
	for(int i = 0; i < 4; i++){
		if(v[i].se == 0){
			ll cur = n * 8 / 2;
			ans += cur * arr[0];
			n = 0;
		}
		if(v[i].se == 1){
			ll cur = n * 4 / 2;
			ans += cur * arr[1];
			n = 0;
		}
		if(v[i].se == 2){
			ll cur = n * 2 / 2;
			ans += cur * arr[2];
			n = 0;
		}
		if(v[i].se == 3){
			ll cur = n / 2;
			ans += cur * arr[3];
			n %= 2LL;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int f[100005],o[100005];
int32_t main() {
	int a,b,m,i;
	cin>>a>>b>>m;
	int mn1=mod,mn2=mod;
	for(i=1;i<=a;i++)
	{	cin>>f[i];
		mn1=min(mn1,f[i]);
	}
	for(i=1;i<=b;i++)
	{	cin>>o[i];
		mn2=min(mn2,o[i]);
	}
	int ans=mn1+mn2;
	for(i=0;i<m;i++)
	{
		int x,y,c;
		cin>>x>>y>>c;
		ans=min(ans,f[x]+o[y]-c);
	}
	cout<<ans<<"\n";
	
}

Measured memory_bytes: 1792
#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
using namespace std;

int main() {
	int H, A;
	cin >> H >> A;

	if (H % A == 0) {
		cout << H / A << endl;
	}

	else {
		cout << H / A + 1 << endl;
	}
}


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

namespace AtTest.EducationalDP
{
    class J
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[] cnt = new int[3];
            for (int i = 0; i < n; i++) cnt[array[i] - 1]++;
            double[,,] dp = new double[400, 400, 400];
            //各皿の枚数のときの期待値

            DFS(ref dp, cnt[0], cnt[1], cnt[2], n);
            Console.WriteLine(dp[cnt[0], cnt[1], cnt[2]]);
        }

        static void DFS(ref double[,,] dp, int i, int j, int k, int n)
        {
            if (i == 0 && j == 0 && k == 0) return;
            if (dp[i, j, k] != 0) return;

            double val = 0;
            int ijk = i + j + k;
            if (i > 0)
            {
                DFS(ref dp, i - 1, j, k, n);
                val += dp[i - 1, j, k]*i/ijk;
            }
            if (j > 0)
            {
                DFS(ref dp, i + 1, j - 1, k, n);
                val += dp[i + 1, j - 1, k] * j / ijk;
            }
            if (k > 0)
            {
                DFS(ref dp, i, j + 1, k - 1, n);
                val += dp[i, j + 1, k - 1] * k / ijk;
            }
            val += 1.0 * n / ijk;
            dp[i, j, k] = val;
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 388064
#include<stdio.h>
int main(void)
{
  int m,n,l,t;
   
  while(scanf("%d %d",&m,&n)!=EOF)
    {
      l=1;
      if(m<n)
    {
      t=m;
      m=n;
      n=t;
}
      while(l!=0)
    {
      l=m%n;
      m=n;
      n=l;
    }
      printf("%d\n",m);
    }
  return 0;
}

Measured memory_bytes: 596
#include <cassert>
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int h, w, d; cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a = (i+j) % (2*d) / d * 2 + ((i-j) % (2*d) + 2*d) % (2*d) / d;
            cout << "RYGB"[a];
        }
        cout << endl;
    }
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
	do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
	return x * f;
}

const int MAXN = 200001;

int n,k,c,l[MAXN],r[MAXN];
char s[MAXN];

int main() {
	n = read(), k = read(), c = read();
	for(int i = 1;i <= n;i++) std::scanf("%c",s + i);
	int t = 0;
	l[0] = -MAXN * 2; 
	for(int i = 1;i <= n;i++) {
		if(i - l[t] > c && s[i] == 'o') l[++t] = i;
	}
	if(t > k) return 0;
	int tot = t;
	r[t + 1] = MAXN * 2;
	for(int i = n;i >= 1;i--) {
		if(r[t + 1] - i > c && s[i] == 'o') r[t--] = i;
	}
	for(int i = 1;i <= tot;i++) {
		if(l[i] == r[i]) std::printf("%d\n",l[i]);
	}
    return 0;
}

Measured memory_bytes: 3200
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//文字列分割
vector<int> split(string str, char del) {
	vector<int> re;
	string sub;
	for (char c : str) {
		if (c == del) {
			re.push_back(stoi(sub));
			sub.clear();
		}
		else {
			sub += c;
		}
	}
	re.push_back(stoi(sub));
	return re;
}

int main() {
	string s;
	while (true) {
		getline(cin, s);
		if (s == "0")break;

		VI a = split(s, ' ');
		int sum = 0, cnt1 = 0;
		for (auto n : a) {
			if (2 <= n && n <= 9)sum += n;
			else if (10 <= n && n <= 13)sum += 10;
			else if (n == 1 || n == 11)cnt1++;
		}
		int ans = -1;
		rep(i, cnt1 + 1) {
			int x = sum + 1 * i + 11 * (cnt1 - i);
			x = x > 21 ? 0 : x;
			ans = max(ans, x);
		}
		Cout(ans);
	}
}


Measured memory_bytes: 2988
#include<iostream>
using namespace std;
 
int main(){
  int holidays_length, housework_num, work_length;
  int i;

  cin >> holidays_length >> housework_num;
  
  for(i=0; i<housework_num; i++){
    cin >> work_length;
    holidays_length -= work_length;
  }

  if(holidays_length < 0){
    cout << -1 << endl;
  }
  else{
    cout << holidays_length << endl;
  }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define L 'L'
#define R 'R'
#define U 'U'
#define D 'D'

int main() {
  string s;
  cin >> s;
  string ans = "Yes";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == (i % 2 == 0 ? L : R)) {
      ans = "No";
      i = s.size();
    }
  }
  cout << ans << '\n';
  return 0;}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a==b)
	{
		cout<<"Draw";
	}
	else if (a==1)
	{
		cout<<"Alice";
	}
	else if (b==1)
	{
		cout<<"Bob";
	}
	else if (a>b)
	{
		cout<<"Alice";
	}
	else
	{
		cout<<"Bob";
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
// atcoder/abc143/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> v(n);
    cin >> v;
    sort(v.begin(), v.end());
    lli cnt = 0;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = i + 1; j + 1 < v.size(); ++j) {
        int x = lower_bound(v.begin() + j + 1, v.end(), v[i] + v[j]) - (v.begin() + j + 1);
        cnt += x;
        // cout << v[i] << ' ' << v[j] << ' ' << x << endl;
      }
    }
    cout << cnt << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
       string s1;
       cin>>s1;
       int n=s1.length();
       int l=(n-1)/2;
       int h=(n+3)/2;
       int z=n-h+1;
       vector<char> v1,v2,v3;
       for(int i=0;i<n;i++) v1.push_back(s1[i]);
       reverse(v1.begin(),v1.end());
       //for(auto it:v1) cout<<it;
       int flag1=0;
       for(int i=0;i<n;i++){
              if(v1[i]!=s1[i]){
                     flag1=1;
                     break;
              }
       }
       for(int i=0;i<l;i++) v2.push_back(s1[i]);
       reverse(v2.begin(),v2.end());
      // for(auto it:v2) cout<<it;
       int flag2=0;
       for(int i=0;i<l;i++){
              if(v2[i]!=s1[i]){
                     flag2=1;
                     break;
              }
       }
       for(int i=0;i<z;i++) v3.push_back(s1[i+h-1]);
       reverse(v3.begin(),v3.end());
       //for(auto it:v3) cout<<it;
       int flag3=0;
       for(int i=0;i<z;i++){
              if(v3[i]!=s1[i+h-1]){
                     flag3=1;
                     break;
              }
       }
       if(flag1==0&&flag2==0&&flag3==0) cout<<"Yes";
       else cout<<"No";
       
       
}

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

int main(){
    int T,i,j;

    int n,mn=107,cnt=0;
    cin>>n;
    int a[n+1];

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

    cnt=mn;
    for(i=1;i<=n;i++)
        a[i]-=mn;

    int x;
    for(i=1;i<=n;i++){
        if(a[i]!=0){
            x=a[i];
            cnt+=x;
            int l=i;
            while(a[l+1]!=0 && l<n) l++;

            j=i+1;
            while(j<=l){
                if(a[j]<x){
                    x=a[j];
                    a[j]=0;
                }
                else{
                    a[j]-=x;
                }
                j++;
            }

        }
    }
    printf("%d\n",cnt);





return 0;
}


Measured memory_bytes: 3780
#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 <math.h>
using namespace std;
#define int long long



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

    vector<int> a(32);
    a.at(0) = 1;
    a.at(1) = 1;
    a.at(2) = 1;
    a.at(3) = 2;
    a.at(4) = 1;
    a.at(5) = 2;
    a.at(6) = 1;
    a.at(7) = 5;
    a.at(8) = 2;
    a.at(9) = 2;
    a.at(10) =1 ;
    a.at(11) =5 ;
    a.at(12) =1 ;
    a.at(13) = 2;
    a.at(14) = 1;
    a.at(15) = 14;
    a.at(16) = 1;
    a.at(17) = 5;
    a.at(18) = 1;
    a.at(19) = 5;
    a.at(20) = 2;
    a.at(21) = 2;
    a.at(22) = 1;
    a.at(23) = 15;
    a.at(24) = 2;
    a.at(25) = 2;
    a.at(26) = 5;
    a.at(27) = 4;
    a.at(28) = 1;
    a.at(29) = 4;
    a.at(30) = 1;
    a.at(31) = 51;

    int k; cin >> k;

    cout << a.at(k-1) << endl;
}







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

int main(){
    int N,Ai,j;
    cin>>N;
    int A[N];

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


    for (int k=0;k<N-1;k++){
        cout<<A[k]<<" ";
        }
    cout<<A[N-1]<<endl; 

    for(int i=1;i<N;i++){
        

        j=i-1;
        Ai=A[i];

        while(j>=0 && A[j]>Ai){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=Ai;

        for (int k=0;k<N-1;k++){
            cout<<A[k]<<" ";
        }
        cout<<A[N-1]<<endl;

    }
    
    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
    mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n),f(n+1){
        //constructor 
        f[0] = f[1] = -1;
        for(ll i=2; i<=n;i++){
            if(f[i])continue;
            primes.push_back(i);
            f[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x){return f[x]==x;}
    vector<int> factorList(int x){
        vector<int> res;
        while(x!=1){
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x){
        vector<int> fl = factorList(x);
        if(fl.size()==0) return {};
        vector<P> res(1,P(fl[0],0));
        for(int p : fl){
            if(res.back().first==p){
                res.back().second++;
            }else{
                res.emplace_back(p,1);
                //新要素を末尾に追加
            }
        }
        return res;
    }
};

int main(){
    Sieve sieve(1e6);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    rep(i,n){
        auto f = sieve.factor(a[i]);
        for(auto p : f){
            mp[p.first] = max(mp[p.first], p.second);
        }
    }
    mint lcm = 1;
    for(auto p : mp){
        rep(i,p.second){
            lcm *= p.first;
        }
    }
    mint ans;
    rep(i,n){
        mint b = lcm/a[i];
        ans += b;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 4984
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

class Solution {
private:
    
public:
    int64 solve(vector<int64>& arr, int n) {
        vector<vector<int64>> dp(n + 1, vector<int64>(4, INT64_MIN / 2));
        dp[0][0] = 0;
        int k = n % 2 + 1;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j <= k; ++j) {
                chmax(dp[i + 1][j + 1], dp[i][j]);
                int64 cur = dp[i][j];
                if((i + j) % 2 == 0) cur += arr[i];
                chmax(dp[i + 1][j], cur);
            }
        }
        return dp[n][k];
    }
};

int main() {
    
    int n;
    cin >> n;
    vector<int64> arr(n);
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    Solution sol;
    auto ret = sol.solve(arr, n);
    cout << ret << endl;
}

Measured memory_bytes: 18840