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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,a,b;
		ll ans;
		cin>>n>>a>>b;
		ans=(a*(n/(a+b))) +min(a,(n%(a+b))) ;
		
		cout<<ans<<endl;
	}
	
	
return 0;
}


Measured memory_bytes: 256
s=gets.chomp

def ck(s)
  if s.size.even?
    return s[0,s.size/2] == s[s.size/2,s.size/2].reverse
  else
    return s[0,s.size/2] == s[s.size/2+1,s.size/2].reverse
  end

end

if ck(s) && ck(s[0,(s.size-1)/2]) && ck(s[((s.size+3)/2-1)..-1])
  puts "Yes"
else
  puts "No"
end

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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 




int main(int argc, char** argv) {
    fast_io
   
	
	
	int s;
	cin >> s;
	
	cout << s/3600 << ":" << (s%3600)/60 << ":" << s%60 << endl;
	

    return 0;
}























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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll snuke=0, ans=1e15;
    rep(i,n-1){
        snuke+=a[i];
        ans = min(ans, (abs(sum-2*snuke)));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
import numpy as np
H, W, K = [int(x) for x in input().split(" ")]
C = np.array([
  [True if x == "#" else False for x in input()]
  for _ in range(H)
], dtype=bool)

count = 0
for i in range(2**(H + W)):
    indicator = [i & 2**j != 0 for j in range(H + W)]
    Cc = C.copy()
    Cc[indicator[:H], :] = False
    Cc[:, indicator[H:]] = False
    if np.sum(Cc) == K:
        count += 1
print(count)

Measured memory_bytes: 27104
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 5e5 + 14;
const int inf = (int)1e9;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int q;
int n;
vector<rect> v;
int disty[N];
int ysz;
int t[N * 4];
int tag[N * 4];

void compress()
{
	vector<int> ycords;

	for (auto &pp : v)
	{
		ycords.push_back(pp.x.y);
		ycords.push_back(pp.y.y);
	}

	sort(all(ycords));
	ycords.resize(unique(all(ycords)) - ycords.begin());
	ysz = ycords.size();

	map<int, int> mp;

	for (int i = 0; i < ycords.size(); ++i)
	{
		mp[ycords[i]] = i;
		disty[i] = ycords[i] - ycords[0];
	}

	for (auto &pp : v)
	{
		pp.x.y = mp[pp.x.y];
		pp.y.y = mp[pp.y.y];
	}
}

void add(int tl, int tr, int v, int l, int r, int dlt)
{
	if (tl > r || tr < l)
		return;

	if (r < l)
		return;

	if (tl >= l && tr <= r)
	{
		tag[v] += dlt;

		if (tag[v])
			t[v] = disty[tr + 1] - disty[tl];
		else if (tl != tr)
			t[v] = t[v * 2] + t[v * 2 + 1];
		else if (tl == tr)
			t[v] = 0;

		return;
	}

	int mid = (tl + tr) / 2;

	add(tl, mid, v * 2, l, r, dlt);
	add(mid + 1, tr, v * 2 + 1, l, r, dlt);
	t[v] = (tag[v] ? (disty[tr + 1] - disty[tl]) : (t[v * 2] + t[v * 2 + 1]));
}

int get()
{
	return tag[1] ? (disty[ysz - 1] - disty[0]) : (t[2] + t[3]);
}

int solve()
{
	vector<pii> odr;

	for (int i = 0; i < n; ++i)
	{
		odr.emplace_back(i, 0);
		odr.emplace_back(i, 1);
	}

	sort(all(odr), [](pii p1, pii p2) {
	
		int x1 = 0;
		int x2 = 0;

		if (!p1.y)
			x1 = v[p1.x].x.x;
		else
			x1 = v[p1.x].y.x;

		if (!p2.y)
			x2 = v[p2.x].x.x;
		else
			x2 = v[p2.x].y.x;

		if (x1 == x2)
			return p1.y < p2.y;

		return x1 < x2;
	});

	int px = -1;
	ll ans = 0;

	for (auto &pr : odr)
	{
		int curx = 0;
		int up = v[pr.x].y.y;
		int down = v[pr.x].x.y;

		if (!pr.y)
			curx = v[pr.x].x.x;
		else
			curx = v[pr.x].y.x;

		ans += (ll)get() * (ll)(curx - px);

		px = curx;

		if (!pr.y)
			add(0, ysz - 2, 1, down, up - 1, 1);
		else
			add(0, ysz - 2, 1, down, up - 1, -1);
	}

	return ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	//cin >> q;
	q = 1;

	while (q--)
	{
		cin >> n;

		v.resize(n);

		for (int i = 0; i < n; ++i)
			cin >> v[i].x.x >> v[i].x.y >> v[i].y.x >> v[i].y.y;

		fill(t, t + n * 4 + 10, 0);
		fill(tag, tag + n * 4 + 10, 0);
		ysz = 0;
		fill(disty, disty + n + 10, 0);

		compress();

		cout << solve() << endl;
	}
}



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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a*b)%2==0)
			System.out.println("Even");
		else
			System.out.println("Odd");
		
	}

}


Measured memory_bytes: 23764
import math
cos60=math.cos(math.radians(60))
sin60=math.sin(math.radians(60))

def koch(d,p1_x,p2_x,p1_y,p2_y):
    if d==0:
        return 

    s_x=(2*p1_x+1*p2_x)/3
    s_y=(2*p1_y+1*p2_y)/3
    t_x=(1*p1_x+2*p2_x)/3
    t_y=(1*p1_y+2*p2_y)/3
    u_x=(t_x-s_x)*cos60-(t_y-s_y)*sin60+s_x
    u_y=(t_x-s_x)*sin60+(t_y-s_y)*cos60+s_y
    
    koch(d-1,p1_x,s_x,p1_y,s_y)
    print(s_x,s_y)
    koch(d-1,s_x,u_x,s_y,u_y)
    print(u_x,u_y)
    koch(d-1,u_x,t_x,u_y,t_y)
    print(t_x,t_y)
    koch(d-1,t_x,p2_x,t_y,p2_y)
    
d=int(input())
p1_y=0
p1_x=0
p2_x=100
p2_y=0
print(float(p1_x),float(p1_y))
koch(d,p1_x,p2_x,p1_y,p2_y)
print(float(p2_x),float(p2_y))


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 5e14;
const double eps = 1e-10;
const double PI = acos(-1);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

string s;
ll dp[100010][5];

void add(ll &a, ll b) {
	if (a + b < MOD)a += b;
	else {
		a += b;
		a %= MOD;
	}
	return;
}

int main() {
	cin >> s;
	dp[0][0] = 1;
	for (int i = 0;i < s.size();i++) {
		for (int j = 0; j < 4; j++) {
			if (s[i] != '?') add(dp[i + 1][j], dp[i][j]);
			else add(dp[i + 1][j], dp[i][j] * 3 % MOD);
		}
		if (s[i] == 'A' || s[i] == '?') add(dp[i + 1][1], dp[i][0]);
		if (s[i] == 'B' || s[i] == '?') add(dp[i + 1][2], dp[i][1]);
		if (s[i] == 'C' || s[i] == '?') add(dp[i + 1][3], dp[i][2]);
	}
	cout << dp[s.size()][3] << endl;
	return 0;
}

Measured memory_bytes: 4352
def cmb(n,r,mod):
    if r<0 or r>n:return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod


mod=10**9+7
n=10000
g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,n+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

n=int(input())

ans=0
for i in range(1,n):
    if 3*i>n:break
    ans +=cmb(n-3*i+i-1,i-1,mod)
    ans %=mod
print(ans)

Measured memory_bytes: 67124
/*input
4 4
1 2
2 3
3 4
4 1
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

const int N = 1e5+1;

int t,n,m;
vector<int> adj[N];
int in[N];
vector<pii> ori;
vector<pii> edges;
int ans[N];
bool vis[N];
int pref[N];
vi qs;
set< pair<int,int> > one;

void dfs(int u,int p){
     vis[u] = 1;
     for(int v:adj[u]){
     	if(vis[v]){
     		continue;
     	}
     	dfs(v,u);
     	pref[u]+=pref[v];
     }
     if(pref[u]%2){
     	one.insert(mp(min(u,p),max(u,p)));
     }
}

void ini(){
	one.clear();
	qs.clear();
	edges.clear();
	REP(i,N){
		pref[i] = 0;
		in[i] = 0;
		vis[i] = 0;
		adj[i].clear();
		ans[i] = 0;
	}
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  t = 1;
  while(t--){
  	ini();
  	cin >> n >> m;
  	REP(i,m){
  		int a,b;cin >> a >> b;
  		ori.pb({a,b});
  		in[a]++;
        adj[a].pb(b);
        adj[b].pb(a);
        edges.pb(mp(min(a,b),max(a,b)));

  	}
  	REP(i,n){
  		if(in[i+1]%2)qs.pb(i+1);
  	}
  	if(qs.size()%2){
  		cout << -1 << endl;
  		continue;
  	}
  	for(int i = 0;i < qs.size();i+=2){
  		pref[qs[i+1]]++;
  		pref[qs[i]]++;
  	}
    dfs(1,1);
    REP(i,m){
       if(one.find(edges[i]) != one.end())swap(ori[i].f,ori[i].s);
       cout << ori[i].f << " " << ori[i].s << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 20704
import java.util.*;

public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        List<Character> list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) != 'B'){
                list.add(s.charAt(i));
            }else if(list.size() != 0){
                list.remove(list.size()-1);
            }
        }
        for(int i = 0; i < list.size(); i++){
            System.out.print(list.get(i));
        }
    }
}

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

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

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define INF 1e9
#define MOD 1e9+7

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------



int main() {
    CIN(N,K);
    int ans=0;
    while(N>0){
        N/=K;
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n;
  cin >> n;
  vec a(n);
  int m = 0;
  rep(i,n) {
    cin >> a[i];
    m = max(a[i], m);
  }
  vector<bool> d(m+1, false);
  vector<bool> e(m+1, false);

  rep(i,n) {
    if (d[a[i]]) {
      e[a[i]] = true;
    }
    d[a[i]] = true;
  }

  rep(i,m) {
    if (!d[i]) continue;

    for (int j = 2*i; j <= m; j += i) {
      d[j] = false;
    }
  }

  int c = 0;
  rep(i,m+1) {
    if (d[i] && !e[i]) c++;
  }

  cout << c << endl;
}


Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    uint64_t x;
    cin>>x;
    
    vector<uint64_t> num(150);
    rep(i,0,num.size()) num.at(i)=pow(i,5);

    uint64_t a,b;
    rep(i,0,num.size()){
        a=num.at(i);
        rep(j,0,num.size()){
            b=num.at(j);
            if(a-b==x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
            if(a+b==x){
                cout<<i<<" "<<-j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4056
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int ll;
char s[100005];
int main()
{	
	scanf("%s",&s);
	int len=strlen(s),shitou=0,bu=0;
	int ans=0;
	for(int i=0;i<len;++i){//bu<=shitou
		if(s[i]=='g'){
			if(bu<shitou){ans++;bu++;}
			else shitou++;
		}
		else {
			if(bu<shitou)bu++;
			else {shitou++;ans-=1;}
		}
	//	printf("i=%d shitou=%d bu=%d\n",i+1,shitou,bu);
	}
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int nmin = scan.nextInt();
        int nmax = scan.nextInt();
        int scores[];
        int maxdif;
        int result = 0;
        while (!(n == 0 && nmin == 0 && nmax == 0)) {
            maxdif = 0;
            scores = new int[n];
            for (int i = 0; i < n; i++) {
                scores[i] = scan.nextInt();
            }
            for (int i = nmin - 1; i < nmax; i++) {
                if (scores[i] - scores[i + 1] >= maxdif) {
                    maxdif = scores[i] - scores[i + 1];
                    result = i+1;
                }
            }
            System.out.println(result);
            n = scan.nextInt();
            nmin = scan.nextInt();
            nmax = scan.nextInt();
        }
    }
}

Measured memory_bytes: 56376
import sys

N = int(input())
a_list = list(map(int, input().split()))

dp = [[0] * 2 for _ in range(N + 1)]
dp[0][0] = 0
dp[0][1] = -sys.maxsize

for i in range(N):
    dp[i + 1][0] = max(dp[i][0] + a_list[i], dp[i][1] - a_list[i])
    dp[i + 1][1] = max(dp[i][0] - a_list[i], dp[i][1] + a_list[i])
print(dp[N][0])


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

int main() {
  int n, d;
  cin >> n >> d;
  int w = d * 2 + 1;
  int ans = n / w;
  if (n % w > 0) ans++;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> B(N-1);
  for (int i = 0; i < N-1; i++) {
    cin >> B[i];
  }
  
  int Asum = 0;
  for (int i = 1; i <= N; i++) {
    if (i == 1) {
      Asum += B[0];
    }
    else if (i == N) {
      Asum += B[N-2];
    }
    else {
      Asum += min(B[i-2], B[i-1]);
    }
  }
  cout << Asum << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def judge(leet):
    leet_len = len(leet)
    result = ""
    for num in range(leet_len):
        result = result + "x"
    
    return result
    

def main():
    leet = input()
    answear = judge(leet)
    print(answear)
    
if __name__ == "__main__":
    main()
    


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

int main(){
  int ans = 0, a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  ans += a[2] - a[1];
  a[0] += ans;
  ans += (a[2] - a[0]) / 2;
  if((a[2] - a[0]) % 2) ans += 2;
  cout << ans << endl;
}	

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"IMPOSSIBLE"<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e13+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
//abcabcabc...
int main(void){
	int i,t,n,ans=-1;cin>>n;
	int d[13]={0};
	for(i=0;i<n;i++){int x;cin>>x;d[x]++;}
	for(t=1;t<=11;t++){if(d[t]>=3){ans=0;}}
	if(d[0]>=1){ans=0;}
	if(d[12]>=2){ans=0;}
	if(ans==0){cout<<0<<endl;return 0;}
	for(int bi=0;bi<(1<<11);bi++){
		vector<int>hito;
		hito.pub(0);
		for(t=1;t<=11;t++){
			if(d[t]==2){hito.pub(t);hito.pub(-t);}
			if(d[t]==1){
				if((bi&(1<<(t-1)))==0){hito.pub(t);}
				else{hito.pub(-t);}
			}
		}
		if(d[12]>=1){hito.pub(12);}
		int gen=12;
		for(i=0;i<hito.size();i++){
			for(int j=i+1;j<hito.size();j++){
				mineq(gen,min(abs(hito[i]-hito[j]),24-abs(hito[i]-hito[j])));
			}
		}
		maxeq(ans,gen);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	string s;
	cin>>s;
	bool CF=true;
	int c=(int)s.find("C");
	if(c==-1)CF=false;
	else{
	int f=(int)s.find("F",c);
	if(f==-1)CF=false;
	}
	if(CF)cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 256
d=list(map(int,input().split()))
for o in list(input()):
 s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o]
 for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])

Measured memory_bytes: 5596
N = int(input())
s = [int(input()) for _ in range(N)]
li = []
x = 10**10
if(sum(s)%10!=0):
    print(sum(s))
else:
    for i in s:
        if(i%10!=0):
            x = min(x,i)
    x = x if x!=10**10 else sum(s)
    print(sum(s)-x)



Measured memory_bytes: 3060
#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;
}

vector<int> Z(string &S){
  ll N = S.size();
  vector<int> A(N);
  A[0] = S.size();
  int i = 1, j = 0;
  while (i < S.size()) {
    while (i+j < S.size() && S[j] == S[i+j]) ++j;
    A[i] = j;
    if (j == 0) { ++i; continue;}
    int k = 1;
    while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
    i += k; j -= k;
  }
  return A;
}

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

    int N;
    string S;
    cin >> N >> S;

    int ma = -1;
    REP(i, N){
      string T = S.substr(i, N-i);
      //dump(T)
      vector<int> A = Z(T);
      REP(i, A.size()){
        int tmp = min(i, A[i]);
        ma = max(ma, tmp);
      }
    }

	   cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll A,B,C;
	cin >> A >> B >> C;
	cout << A*B/2 << endl;
}

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

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }


int main(){
    ll N,M;
    cin >> N >> M;
    ll ans = 0;
    if(2 * N < M){
        ans = N + (M - 2 * N) / 4;
    }else{
        ans = M / 2;
    }

    cout << ans << endl;
}



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

long long cnt;
int l, A[1000000], n;
vector<int> G;

//間隔Gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
    for(int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;

        while(j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    //数列G = {1, 4, 13, 40, 121, 364, 1093, ...}を生成
    for(int h = 1; ; ) {
        if(h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }

    for(int i = G.size() - 1; i >= 0; i--) { //逆順にG[i] = gを指定
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    //より速い入力scanf関数を使用
    for(int i = 0; i < n; i++) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for(int i = G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for(int i = 0; i < n; i++) printf("%d\n", A[i]);

    return 0;
}


Measured memory_bytes: 7180
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

stocks = 0
money = 1000

A.each_cons(2) do |a, b|
  if b < a && stocks > 0
    # 売る
    money += a * stocks
    stocks = 0
  elsif b > a && stocks == 0
    # 買う
    buy = money / a
    stocks += money / a
    money -= buy * a
  end
  # p "stocks: #{stocks}, money: #{money}"
end

puts money + stocks * A.last


Measured memory_bytes: 14492
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){
    vector<pair<T,T>> out(input.size()-1);
    rep(i,input.size()-1){
        out[i].first =input[i  ];
        out[i].second=input[i+1];
    }
    return(out);
}
vector<char> String_to_vector_char(const string& input){
    vector<char> out(input.size());
    rep(i,input.size()){
        out[i]=input[i];
    }
    return out;
}

ll n,m;
vector<ll> a;
vector<ll> weight;
void input(){
    cin>>n>>m;
    a.resize(m,0);
    weight.resize(n+1,0);
    rep(i,m){
        cin>>a[i];
        weight[a[i]]=-1;
    }
}

void src(){
    if(n==1){cout<<1;return;}
    if(n==2 and m==0){cout<<2;return;}
    if(n==2 and m==1){cout<<1;return;}

    weight[0]++;
    rep(i,n-2){
        if( weight[i] > lim ){ weight[i] = weight[i] %lim;}
        if( weight[i]!=-1 ){
            weight[i+1] += (weight[i+1]!=-1 ? weight[i]:0 );
            weight[i+2] += (weight[i+2]!=-1 ? weight[i]:0 );
        }
    }
    if(weight[n-2]!=-1){
        weight[n-2] += (weight[n-1]!=-1 ? weight[n-2]:0 );
    }
    ll ans = (weight[n-1]!=-1? weight[n-1]:0ll) + (weight[n-2]!=-1? weight[n-2]:0ll);
    cout<<ans%lim;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

typedef pair<pll,pll> dpll;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    a[i]--;
  }
  ll ans=0;
  for(ll i=0;i<n;i++) ans+=i==a[a[i]];
  cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define F first
#define S second
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define MP make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define debug(x) cout << " > " << #x << ':' << x << endl;
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using vec = vector<T>;
template<typename T> using Prior = priority_queue<T>;
template<typename T> using prior = priority_queue<T, vec<T>, greater<T>>;

const int INF = 1e9;
const ll LLINF = (ll)4*1e18;
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
const int xx[8] = {0,1,0,-1,1,1,-1,-1};
const int yy[8] = {1,0,-1,0,1,-1,-1,1};

void pmod(ll &a, ll b) {a = (a+b)%MOD;}
void mmod(ll &a, ll b) {a = (a-b+MOD)%MOD;}
void tmod(ll &a, ll b) {a = (a*b)%MOD;}
ll POW(ll a, ll b) {ll res=1; do{if(b%2)tmod(res,a);tmod(a,a);}while(b>>=1); return res;}
template<typename T> void amax(T &a, T b) {if(a < b) a = b;}
template<typename T> void amin(T &a, T b) {if(a > b) a = b;}

#define N 500010
#define sqN 2000

struct query{
    int l, r, idx;
};

bool cmp1(query a, query b){
    return (a.l/sqN < b.l/sqN) || (a.l/sqN == b.l/sqN && a.r < b.r);
}

int cnt[N], tot;

void solve(){
    int n, m;
    
    cin >> n >> m;
    vec<int> v(n);
    for(auto &i:v) cin >> i;
    
    vec<query> q(m);
    rep(i, m) {
        cin >> q[i].l >> q[i].r;
        q[i].l--; q[i].r--;
        q[i].idx = i;
    }
    
    vec<int> ans(m);
    sort(ALL(q), cmp1);
    
    int l, r;
    l = r = 0;
    for(auto i:q){
        while(r <= i.r){
            if(cnt[v[r]] == 0) tot++;
            cnt[v[r++]]++;
        }
        while(r > i.r+1){
            cnt[v[--r]]--;
            if(cnt[v[r]] == 0) tot--;
        }
        while(l < i.l){
            if(cnt[v[l]] == 1) tot--;
            cnt[v[l++]]--;
        }
        while(l > i.l){
            cnt[v[--l]]++;
            if(cnt[v[l]] == 1) tot++;
        }
        ans[i.idx] = tot;
    }
    
    for(auto i:ans) cout << i << endl;
}

int main(){
//    kiyohime
    int T = 1;
    
//    cin >> T;
    while(T--){
        solve();
    }
}



Measured memory_bytes: 15460
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;
    s64 k;
    cin >> k;

    char ans = '1';
    rep (i, MIN(100, k))
    {
        if (s[i] != '1')
        {
            ans = s[i];
            break;
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t 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) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

ll n,w;
ll weight[100];
ll v[100];
ll dp[101][100005] = {0};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>w;
    rep(i,n) cin>>weight[i]>>v[i];

    rep(i,n)rep(sumw,w+1){
        if(sumw - weight[i]>=0){
            chmax(dp[i+1][sumw -weight[i]], dp[i][sumw]+v[i]);
        }
        chmax(dp[i+1][sumw],dp[i][sumw]);
    }

    cout<<*max_element(dp[n],dp[n]+w)<<endl;   
}

Measured memory_bytes: 81652
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int i,n,sum=0;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        if( (i%3!=0 || i%5!=0)&&(i%3!=0 && i%5!=0))
            sum=sum+i;
    }


cout<<sum<<endl;

}


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

int main(void) {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
}

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

int main(){
  int m, f, r;

  while(1){
    cin>>m>>f>>r;
    if(m==-1 && f==-1 && r==-1){
      break;
    }
    if(m==-1 || f==-1){
      cout<<"F"<<endl;
    }else{
      if(m+f>=80){
        cout<<"A"<<endl;
      }else if(m+f>=65){
        cout<<"B"<<endl;
      }else if(m+f>=50){
        cout<<"C"<<endl;
      }else if(m+f>=30){
        if(r>=50){
          cout<<"C"<<endl;
        }else{
          cout<<"D"<<endl;
        }
      }else{
        cout<<"F"<<endl;
      }
    }
  }

  return 0;
}

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

public class Main {

	public static void main(String[] args)throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String tmps = new String(in.readLine());
        int n = Integer.parseInt(tmps);
        String num = new String(in.readLine());
        String[] numarray = num.split("");
		boolean flg = true;
		if(n % 2 == 1){
			System.out.println("No");
		}else{
			for(int i = 0;i<n/2;i++){
				int tmp = n/2 + i;
				if(!numarray[i].equals(numarray[tmp])){
					flg = false;
				}
			}
			if(flg){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int fun(int x)
{
	if(x==1)
		return 1;
	return 2*fun(x/2)+1;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int h;
	cin>>h;
	cout<<fun(h)<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	int n,m ;
	cin >> n >> m;
	if(n==m){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
	printf("a > b\n");
}
	else if(a<b){
	printf("a < b\n");
}
	else{
	printf("a == b\n");
}
	return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vs(n);
  for (int i = 0; i < n; ++i)
    cin >> vs[i].first >> vs[i].second;
  vector<pair<int, int>> vc(m);
  for (int i = 0; i < m; ++i)
    cin >> vc[i].first >> vc[i].second;

  for (int i = 0; i < n; ++i) {
    int ans = 0;
    for (int j = 1; j < m; ++j) {
      int dist = abs(vs[i].first - vc[ans].first) + abs(vs[i].second - vc[ans].second);
      int new_dist = abs(vs[i].first - vc[j].first) + abs(vs[i].second - vc[j].second);
      if (new_dist < dist)
        ans = j;
    }
    cout << ans + 1 << endl;
  }

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 384
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))



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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int32_t main()
{
	run();
	int n, W;
	cin >> n >> W;
	vector<int> w(n + 1), v(n + 1);
	int sum = 0;
	rep(i, 1, n + 1)
	{
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	int dp[n + 1][sum + 1];
	memset(dp, -1, sizeof(dp));
	int ans = 0;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= sum; j++)
		{
			dp[i][j] = INT_MAX;
		}
	}
	for (int i = 0; i <= n; i++)
	{
		dp[i][0] = 0;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= sum; j++)
		{
			if (j >= v[i])
			{
				dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
			if (dp[i][j] <= W)
			{
				ans = max(ans, j);
			}
			else {
				dp[i][j] = min(dp[i][j], (int)INT_MAX);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79232
import Control.Applicative ((<$>))
import Data.Int (Int64)


computeMax :: Integral a => [a] -> [a] -> a
computeMax cs vs = sum $ filter (> 0) $ zipWith (-) cs vs


main :: IO ()
main = do
    _ <- getLine
    vs <- fmap read . words <$> getLine :: IO [Int64]
    cs <- fmap read . words <$> getLine :: IO [Int64]
    print $ computeMax vs cs

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

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

using namespace std;
using ll = long long;

struct T {
	char a;
	char b;
};

bool compFirst(struct T& a, struct T& b)
{
	return a.a < b.a;
}

bool compSecond(struct T& a, struct T& b)
{
	return a.b < b.b;
}

int main()
{
	string S, T;
	cin >> S >> T;
	vector<struct T> a;

	for (int i = 0; i < (int)S.size(); ++i) {
		struct T t = {
			.a = S[i],
			.b = T[i],
		};
		a.push_back(t);
	}

	sort(all(a), compFirst);
	for (int i = 0; i < (int)a.size()-1; ++i) {
		if (a[i].a != a[i+1].a)
			continue;
		if (a[i].b != a[i+1].b) {
			cout << "No" << endl;
			return 0;
		}
	}

	sort(all(a), compSecond);
	for (int i = 0; i < (int)a.size()-1; ++i) {
		if (a[i].b != a[i+1].b)
			continue;
		if (a[i].a != a[i+1].a) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



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

int main(){
    std::string S;
    std::cin >> S;
    
    std::vector< int > cnt(2019, 0);
    cnt[0] = 1;
    long long num = 0;
    int digit = 1;
    for(int i=S.size() - 1; i>=0; i--){
        num = ( num + (S[i] - '0') * digit ) % 2019;
        cnt[num]++;
        digit = (digit * 10) % 2019;
    }
    
    int ans = 0;
    for(int i=0; i<2019; i++){
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> froml(n), fromr(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int j;
    for(int i = 0; i < n; i++){
        j = n - 1 - i;
        froml[i] = __gcd(a[i], froml[i - 1]);
        fromr[j] = __gcd(a[j], fromr[j + 1]);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(i == 0){
            ans = max(ans, fromr[i + 1]);
        }
        else if(i == n - 1){
            ans = max(ans, froml[i - 1]);
        }
        else {
            ans = max(ans, __gcd(froml[i - 1], fromr[i + 1]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int m,n;

int main(){
	while(cin>>m>>n){
		int ans=0;
		for(int i=0;i<20;i++)for(int j=0;j<20;j++){
			for(int k=0;k<20;k++){
				double h=pow(2,i)*pow(3,j)*pow(5,k);
				if(h>=m&&h<=n)ans++;
				if(h>1e+6)break;
			}
			if(pow(2,i)*pow(3,j)>1e+6)break;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
n, m = map(int, input().split())
res = [0] * n
flag = [False] * n
for i in range(m):
    s, c = map(int, input().split())
    if flag[s - 1] == False:
        flag[s - 1] = True
        res[s - 1] = c
    elif res[s - 1] != c:
        print(-1)
        exit()

if n > 1 and flag[0] == False:
    res[0] = 1

if n > 1 and res[0] == 0:
    print(-1)
else:
    ans = str(int(''.join(map(str, res))))
    print(ans)


Measured memory_bytes: 38256
#include "cstring"
#include "math.h"
#include "iostream"

using namespace std;

int main()
{
	int a, b, d;
	int N;
	char str[200];
	char check[100];


	cin >> N;
	cin >> str;



	int c=0;
	int t;
	int t1, t2;
	int back=1;
	check[c++] = str[0];
	for (t = 1; t < N; t++) {
		back = 1;
		for (t1 = 0; t1 < c; t1++) {
			if (str[t] == check[t1])
				back = 0;
		}
		if (back == 1)
			check[c++] = str[t];
	}
	int i1, i2,c1;
	int s1, s2;
	int D=0;
	int Dmax=-1;
	for (t2 = 1; t2 < N; t2++) {
		D = 0;
		for (c1 = 0; c1 < c; c1++) {
			s1 = 0; s2 = 0;
			for (i1 = 0; i1 < t2; i1++) {
				if (str[i1] == check[c1])
					s1 = 1;
			}

			for (i2 = t2; i2 < N; i2++) {
				if (str[i2] == check[c1])
					s2 = 1;
			}
			if (s1 == s2) {
				D++;
			}
		}
		if (D > Dmax)
			Dmax = D;
	}

	cout << Dmax;

    return 0;
}



Measured memory_bytes: 256
function Main(input) {
  var tmp = input.trim().split('\n')
  var N = parseInt(tmp[0])

  var max = 1

  var votedHash = {}
  for (var i = 1; i <= N; i++) {
    if (votedHash[tmp[i]]) {
      votedHash[tmp[i]] += 1
      if (votedHash[tmp[i]] > max) {
        max = votedHash[tmp[i]]
      }
    } else {
      votedHash[tmp[i]] = 1
    }
  }

  var resultArr = []
  Object.keys(votedHash).forEach(elem => {
    if (votedHash[elem] === max) {
      resultArr.push(elem)
    }
  })

  var result = resultArr.sort().join('\n')

  console.log(result)
  return result
}

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

Measured memory_bytes: 95700
import sys
import math

n = int(sys.stdin.readline().rstrip())
nums = list(map(int, sys.stdin.readline().rstrip().split()))

g = nums[0]
for num in nums[1:]:
    g = math.gcd(g, num)

ans = set()
for i in range(1, int(math.sqrt(g)) + 1):
    if g % i == 0:
        ans.add(i)
        ans.add(g // i)

for n in sorted(ans):
    print(n)


Measured memory_bytes: 5668