akhauriyash/Code-Regression huggingface dataset:
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e5+10;

long long A[maxm],Top1,N,X,ans1;
long long B[maxm],Top2,ans2;

long long Gcd(long long x,long long y){
	return y==0?x:Gcd(y,x%y);
}

int main(){
	register int i,now;
	scanf("%lld%lld",&N,&X);
	for(i=1;i<=N;i++){
		scanf("%lld",&now);
		if(now<X){
			A[++Top1]=X-now;
		}else{
			B[++Top2]=now-X;
		}
	}
	for(i=1;i<=Top1;i++){
		ans1=Gcd(ans1,A[i]);
	}
	for(i=1;i<=Top2;i++){
		ans2=Gcd(ans2,B[i]);
	}
	printf("%lld",Gcd(ans1,ans2));
	return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
par = [i for i in range(n)]
rank = [1] * n
size = [1] * n


ab = []
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab.append([a,b])
'''
ab = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
'''
def find(x):
  if par[x] == x:
    return x
  else:
    return find(par[x])

def same(x, y):
  return find(x) == find(y)

def union(x, y):
  x = find(x)
  y = find(y)
  if x != y:
    if rank[x] < rank[y]:
      par[x] = y
      size[y] += size[x]
    else:
      par[y] = x
      size[x] += size[y]
      if rank[x] == rank[y]:
        rank[x] += 1


ans = [0 for i in range(m)]
# print (par,size,rank)
for i in range(m-1, -1, -1):
  x = find(ab[i][0])
  y = find(ab[i][1])
  if x != y:
    ans[i] = size[x] * size[y]
    union(x,y)
  # print(par,size,rank)
'''
print (ans)
print (par)
print (size)
print (rank)
'''
s = 0
for i in ans:
  s += i
  print (s)


Measured memory_bytes: 27992
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int K = sc.nextInt();
      N = (N+1)/2;
      if(N >= K){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }
}

Measured memory_bytes: 22612
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut count: Vec<usize> = vec![0; n];
    let a = (0..n).map(|_| sc.read::<usize>() - 1).collect::<Vec<_>>();
    for &a in a.iter() {
        count[a] += 1;
    }

    let mut total = 0;
    for &c in count.iter() {
        if c > 0 {
            total += c * (c - 1) / 2;
        }
    }
    for i in 0..n {
        let count = count[a[i]];
        if count >= 2 {
            let before = count * (count - 1) / 2;
            let after = (count - 1) * (count - 2) / 2;
            sc.write(total - before + after);
        } else {
            sc.write(total);
        }
        sc.write("\n");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 5;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main () {
    std_quick_io();
    int n, r;
    cin >> n >> r;
    if(n >= 10)
    cout <<r;
    else {
        cout << r + 100 *( 10 - n);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
    long long ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int i0=1;i0<=n;i0++)
        {
            for(int i1=1;i1<=n;i1++)
            {
                ans+=__gcd(__gcd(i,i0),i1);
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3816
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
#include <functional>

using namespace std;

//FILE * in = freopen("A", "r", stdin);

int n, m;

void process() {
	int data[100];
	memset(data, 0, sizeof(data));

	int cnt = m, cur = 0;;
	while(true) {
		if(cnt > 0) {
			--cnt;
			data[cur]++;

			if(cnt == 0 && data[cur] == m) {
				printf("%d\n", cur);
				break;
			}
		}
		else {
			cnt = data[cur];
			data[cur] = 0;
		}
		cur = (cur + 1) % n;
	}
}

int main() {
	while(true){
		scanf("%d%d", &n, &m);
		if(n == 0) break;
		process();
	}
	return 0;
}

Measured memory_bytes: 1012
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static long ans = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<List<int[]>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            List<int[]> list2 = new ArrayList<>();
            for (int j = 0; j < a; j++) {
                int[] aa = new int[2];
                int x = Integer.parseInt(sc.next()) - 1;
                int y = Integer.parseInt(sc.next());
                aa[0] = x;
                aa[1] = y;
                list2.add(aa);
            }
            list.add(list2);
        }
        int ans = 0;
        f:
        for (int i = 0; i < (1 << n); i++) {
            for (int j = 0; j < list.size(); j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                List<int[]> tmpAry = list.get(j);
                for (int k = 0; k < tmpAry.size(); k++) {
                    int[] tmp = tmpAry.get(k);
                    int num = tmp[0];
                    int bit = tmp[1];
                    int ii = i >> num & 1;
                    if (ii != bit) {
                        continue f;
                    }
                }
            }
            ans = Math.max(ans, Integer.bitCount(i));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

void swap(int *a, int *b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int lenearSearch(int *arry, int len)
{
	int i = 0;
	int pos = 0;
	int min = arry[0];

	for (; i <= len; i++)
	{
		if (arry[i] < min)
		{
			min = arry[i];
			pos = i;
		}
	}

	return pos;
}

bool selectionSort(int *arry, int len)
{
	int i = 0;
	int pos = 0;
	int swapCnt = 0;
	
	for (i = 0; i <= len; i++)
	{
		pos = lenearSearch(&arry[i], len - i);
		if (pos > 0)
		{
			swap(&arry[i], &arry[pos + i]);
			swapCnt++;
		}
		
		if (swapCnt > 1)
			return false;
	}

	return true;
}

int main()
{
	int n = 0;
	int i = 0;
	int *arry = NULL;
	bool result;

	if(scanf("%d", &n) != 0);

	arry = malloc(sizeof(int) * n);

	for (; i < n; i++)
		scanf("%d", &arry[i]);

	result = selectionSort(arry, n - 1);
	if (result == true)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

Measured memory_bytes: 128
import itertools
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

next=set()
for a,b in AB:
  if a==1:
    next.add(b)
for a,b in AB:
  if a in next and b==n:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Measured memory_bytes: 54920
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lolo;
    lolo k=LLONG_MAX;
     
    void dj(lolo n,lolo ss,vector<lolo>&d,vector<vector<pair<lolo,lolo>>>&adj)
    {
        
        bool v[n+1]={false};
        d[ss]=0;
        set<pair<lolo,lolo>>s;
        s.insert({0,ss});
        while(s.size()!=0)
        {
            int op=s.begin()->second;
            s.erase(s.begin());
            for(int g=0;g<adj[op].size();++g)
            {
               int u=adj[op][g].first;
               int w=adj[op][g].second;
               if(d[u]>d[op]+w)
               {
                   
                   if(s.find({d[u],u})!=s.end())
                   s.erase({d[u],u});
                   d[u]=d[op]+w;
                   s.insert({d[u],u});
                }
            }
        }
    }
     
     
     
    int main() {
        lolo n,m,i,j=-1,l=0,w;
        lolo x,y;
        cin>>n>>x>>y;
        vector<vector<pair<lolo,lolo>>>pp(n+1);
    	i=1;j=2;
    	m=n-1;
        while(m--)
        {
            w=1;
            pp[i].push_back(make_pair(j,w));
            pp[j].push_back(make_pair(i,w));
            i++;j++;
        }
        w=1;
        pp[x].push_back(make_pair(y,w));
        pp[y].push_back(make_pair(x,w));
        lolo ans[n+1]={0};
        for(i=1;i<=n;i++)
        {
    	    vector<lolo>d(n+1,k);
            
            dj(n,i,d,pp);
            for(j=1;j<=n;j++)
            if(d[j]!=k)
            ans[d[j]]++;
        }
        for(i=1;i<n;i++)
        cout<<ans[i]/2<<"\n";
        return 0;
    }

Measured memory_bytes: 384
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m,g;
string s,t;
int main()
{
    scanf("%d%d",&n,&m);
    int g=__gcd(n,m);
    cin>>s; cin>>t;
    bool f=true;
    for(int i=0;i<g;i++)
    {
        if(s[i*(n/g)]!=t[i*(m/g)])
        {
            f=false;
            break;
        }
    }
    if(!f) puts("-1"); else printf("%lld\n",1LL*n*m/g);
    return 0;
}



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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n;cin>>n;
    int cnt=0;
    vector<int>p(n);
    rep(i,n){
        cin>>p[i];
    }

    rep(i,n-2){
        vector<int>pp={p[i],p[i+1],p[i+2]};
        sort(pp.begin(),pp.end());
        if(pp[1]==p[i+1]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 5001
#define int ll
#define INF (ll)1e10

int N,K,P[maxn],C[maxn];
bool vis[maxn];


int qry(int x,int k){
	int res = 0, ans = -INF;
	FOR(i,0,k-1){
		x = P[x];
		res += C[x];
		ans = max(ans,res);
	}
	return ans;
}
int32_t main(){
	fast;
	
	cin>>N>>K;
	
	FOR(i,1,N) cin>>P[i];
	FOR(i,1,N) cin>>C[i];
	
	
	if (K <= 3 * N){
		int ans = -INF;
		FOR(i,1,N) ans = max(ans,qry(i,K));
		cout<<ans;
		return 0;
	}
	

	int ans = -INF;
	
	FOR(i,1,N){
		int res = 0;
		
		int x = i;
		mem(vis,0);
		
		int d1 = 0;
		while (!vis[x]){
			vis[x] = 1;
			x = P[x];
			res += C[x];
			d1++;
			ans = max(ans,res);
		}
		
		int dist = 0, amt = 0;
		
		int y = x;
		do{
			dist++; amt += C[y];
			y = P[y];
		}while (y != x);
		
		
		int a = K;
		a -= d1;

		int num = a / dist;
		
		ans = max(ans,res);
		ans = max(ans,res + qry(x,a - dist * num) + num * amt);
		if (num > 0) ans = max(ans,res + qry(x, a - dist * (num - 1)) + (num - 1) * amt);
	}
	cout<<ans;
	
}



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

int main(){
	int n;
	cin >> n;
	vector<long long int> lucas(n+10);
	lucas[0] = 2;
	lucas[1] = 1;
	for(int i = 2; i <= n; i++){
		lucas[i] = lucas[i-1] + lucas[i-2];
	}
	cout << lucas[n] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int M = 1e9 + 7;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x;
  cin >> x;
  for (int i = 0; i <= 64; ++i)
  {
    for (int j = 0; j <= 64; ++j)
    {
      if (i * i * i * i * i + j * j * j * j * j == x)
      {
        cout << i << " -" << j;
        exit(0);
      }
    }
  }
  for (int i = 120; i >= 0; --i)
  {
    for (int j = i; j >= 0; j--)
    {
      if (((i * i * i * i * i) - (j * j * j * j * j)) == x)
      {
        cout << i << " " << j;
        exit(0);
      }
    }
  }


}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
using namespace std;
#define pb push_back
#define N 100010

int n,m,ans;
int to[N],d[N];
vector<int> e[N];
vector<int> q;

int main()
{
	
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		e[x].pb(y);
		to[y]++;
	}
	
	for(int i=0;i<n;i++)
		if(!to[i]) q.pb(i);
	while(!q.empty())
	{
		int x=q.back();
		q.pop_back();
		ans=max(ans,d[x]);
		for(int i=0;i<e[x].size();i++)
		{
			int y=e[x][i];
			d[y]=max(d[y],d[x]+1);
			to[y]--;
			if(!to[y]) q.pb(y);
		}
	}
	cout<<ans<<'\n';
	
	return 0;
} 

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
import itertools

str = input()
a = int(str[0])
b = int(str[1])
c = int(str[2])
d = int(str[3])

pr = itertools.product([a], [b, -1 * b], [c, -1 * c], [d, -1 * d])

for li in pr:
    if sum(li) == 7:
        print('%d%+d%+d%+d=7' % li)
        break


Measured memory_bytes: 3060
T=(input()).split(' ')
A=T[0]
C=T[1]
result=0

for i in range(0,(int(C)-int(A)+1)):
    s1=(str(int(A)+i))[0:2]
    s2=((str(int(A)+i))[3:5])[::-1]
    
    if s1==s2:
        result=result+1
print(result)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ul unsigned long long
#define si short int
#define P pair<si,si>
using namespace std;
const int N=2000;
int n,m,x,y,fa[N],ans;
vector<int>e[N];
struct bit{
	ul a[32];
	inline void filp(int x){a[x>>6]^=(ul)1<<(x&63);}
	inline void operator|=(const bit &b){fo(i,0,31)a[i]|=b.a[i];}
	inline void operator&=(const bit &b){fo(i,0,31)a[i]&=b.a[i];}
}e2[N][N],ex[N],nex[N],b;
P d[2000*1000];
void ins(int x,int y){
	d[ans++]=P(x,y);
	ex[x].filp(y);ex[y].filp(x);
	nex[x].filp(y);nex[y].filp(x);
}
void dfs(int x,int st){
	b.filp(x);
	int is=0;
	for(int i:e[x])if(i!=fa[x]){
		is=1;fa[i]=x;dfs(i,st);
		e2[st][x]|=e2[st][i];
	}
	if(!is)e2[st][x]=b;
	b.filp(x);
}
void _and(bit &b,bit &x,bit &y,bit &z){
	fo(i,0,31)b.a[i]=x.a[i]&y.a[i]&z.a[i];
}
int main(){
	cin>>n>>m;
	fo(i,2,n)cin>>x>>y,--x,--y,e[x].push_back(y),e[y].push_back(x);
	fo(i,0,n-1)fo(j,0,n-1)nex[i].filp(j);
	fo(i,1,m)cin>>x>>y,--x,--y,ins(x,y);
	fo(i,0,n-1)
		for(int j:e[i])
			fa[j]=i,dfs(j,i);
	fo(i,0,n-1)fo(j,i+1,n-1)
		e2[i][j]|=e2[j][i],e2[i][j].filp(i),e2[i][j].filp(j);
	for(int j=0;j<ans;++j){
		int x=d[j].first,y=d[j].second;
		if(x>y)swap(x,y);
		_and(b,e2[x][y],ex[x],nex[y]);
		fo(i,0,31)if(b.a[i]){
			ul s=b.a[i];
			for(int j;s;s-=(ul)1<<j)
				j=__builtin_ctzll(s),ins(y,i<<6^j);
		}
		_and(b,e2[x][y],nex[x],ex[y]);
		fo(i,0,31)if(b.a[i]){
			ul s=b.a[i];
			for(int j;s;s-=(ul)1<<j)
				j=__builtin_ctzll(s),ins(x,i<<6^j);
		}
	}
	cout<<ans;
}

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

namespace ABC088B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] an = new int[n];
            for (int i = 0; i < n; i++)
            {
                an[i] = int.Parse(str[i]);
            }

            var orderan = from m in an orderby m descending select m;

            int sumofalice = 0;
            int sumofbob = 0;
            int j = 0;

            foreach (var item in orderan)
            {
                if (j%2 == 0)
                {
                    sumofalice += item;
                }
                else
                {
                    sumofbob += item;
                }
                ++j;
            }

            Console.WriteLine("{0}", sumofalice - sumofbob);
            Console.Read();

        }
    }
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 20;

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    set<int> s;

    rep(i,(1<<n)){
        bitset<MAX_N> b(i);

        int sum = 0;
        rep(j,n){
            if(b.test(j)) sum += a[j];
        }
        s.insert(sum);
    }

    int m; cin >> m;
    rep(_,m){
        int mi; cin >> mi;

        if(s.count(mi)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3132
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename F, typename... R>void input(F& f, R&... r) { cin >> f; input(r...); }
template<typename F, typename... R>void input(vector<F>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    int N, X; input(N, X);
    vector<int> L(N); input(L);
    int D = 0;
    int ans = 0, t = 0;
    while (D <= X && t < N) {
        D += L[t];
        ans++;
        t++;
    }
    if (t == N && D <= X) ans++;
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int a,b;
    

    scanf("%d %d", &a,&b);

   int c = a*b;
if(1<=a,b &&  a,b <= 10000){
    if(c % 2 == 0){
        printf("Even\n");
    }else{
        printf("Odd");
    }

    
}
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)

const int MOD = 1e9 + 7, D = 26;
int ct[D];

signed main() {
#ifdef HOME
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string s;
	int n;
	cin >> n >> s;

	for (char c : s) {
		ct[c - 'a']++;
	}

	ll ans = 1;
	for (int i = 0; i < D; i++) {
		ans = ans * (ct[i] + 1) % MOD;
	}

	ans = (ans - 1 + MOD) % MOD;

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

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

int main(){

	string S;
	cin >> S;
	int win = 15 - S.size();
	for(int i = 0; i < S.size(); i ++){
		if(S[i] == 'o')win ++;
	}
	if(win >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;

//"Hiroakimm0415"
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	long long n,x;
	cin >> n >> x;

	long long ans = x+n-x;

	long long width = n-(n-x);
	long long height = n-x;

	while(true)
	{
		if(width >= height)
		{
			ans+=(width/height)*height*2;
			if(width%height==0)
			{
				ans-=height;
				break;
			}
			width=width%height;
		}
		else if(width < height)
		{
			ans+=((height/width)*width*2);
			if(height%width==0)
			{
				ans-=width;
				break;
			}
			height=height%width;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
    int h, w, k;
    int c[6][6];
    char s[10];
    int count;
    int ans = 0;

  scanf("%d%d%d", &h,&w,&k);

  for (int i = 0; i < h; i++)
  {
      scanf("%s", s);
      for (int j = 0; j < w; j++)
      {
          if(s[j] == '#') c[i][j] = 1;
          else            c[i][j] = 0;
      }
      
  }
  for (int i = 0; i < (1<<h); i++)
  {
      for (int j = 0; j < (1<<w); j++)
      {
          count = 0;
          for (int l = 0; l < h; l++)
          {
              for (int m = 0; m < w; m++)
              {
                  if(c[l][m] == 1 && (((1<<l) & i) == (1<<l)) && (((1<<m) & j) == (1<<m))) count++;
              }
          }
          if(count == k) ans ++;
      }
  }
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 1736
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a):
  checkarr = ["o" if a[i] != i+1 else "x" for i in range(n)]
  res = 0
  for i in range(n):
    if checkarr[i] == "x":
      res += 1
      checkarr[i] = "o"
      if i != n-1:
        checkarr[i+1] = "o"
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 20652
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cout<<elem;}cerr<<endl;}

const int mod=998244353;

/*二項係数(mod付き)*/
struct Combination{
	const int max=51e4;			//適宜変更する.
	//const int mod=1e9+7;
	vector<llong> fact,inv,finv;//階乗,逆元,逆元の階乗.
	
	Combination():fact(max),inv(max),finv(max){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<max;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){//nが大きい場合に使用.
		llong res=1LL;
		REP(i,k) res=res*(n-i)%mod;
		res=res*finv[k]%mod;
		return res;
	}
};

template<class Type_k,class Type_p>
Type_p mod_pow(long long n,Type_k k,Type_p p){//n^k(mod p).
	if(k==0) return 1;
	long long res=mod_pow(n*n%p,k/2,p);
	if(k&1) res=res*n%p;
	return res;
}

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	
	llong ans=0;
	Combination ob;
	for(int i=0;i<=k;++i){//隣り合う組がi組.
		ans=(ans+(llong)m*mod_pow(m-1,n-i-1,mod)%mod*ob.nCk(n-1,i)%mod)%mod;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 15052
s = gets.chomp.chars
s.pop

ans = s.length

while ans > 0
  if ans % 2 == 1
    s.pop
    ans -= 1
    next
  end

  l = s[0..(ans / 2) - 1]
  r = s[(ans / 2)..ans - 1]
  break if l == r

  s.pop
  ans -= 1
end

puts ans


Measured memory_bytes: 1788
import java.util.Scanner;
 
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int max = 100000001;
		boolean [] sosuu = new boolean [max];
 		
		sosuulist(sosuu, max);
 		
 		syuturyoku(sosuu);
	}
 
	private static void sosuulist(boolean [] sosuu, int max) {
		for (int i = 1; i <= max - 1; i++) {
			sosuu[i] = true;
		}
		sosuu[0] = false;
		sosuu[1] = false;
 
		for (int i = 2; i <= Math.sqrt(max); i++) {
			if (sosuu[i] == true) {
				for (int j = i + i; j <= max - 1; j += i) {
					sosuu[j] = false;
				}
			}
		}
	}
	
	private static void syuturyoku(boolean [] sosuu) {
		int [] n = new int [10000];
		int count = 0;
		
		Scanner cin = new Scanner (System.in);
		int x = cin.nextInt();
 
		for (int i = 0; i < x; i++) {
			n[i] = cin.nextInt();
			if (sosuu[n[i]] == true) count++;
		}
 
		System.out.println(count);
	}
}

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

int main(){
	int ar[4][4], selisih[4];
	bool ans=true;
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin >> ar[i][j];
		}
	}
	for(int i=1; i<=3; i++){
		for(int j=1; j<3; j++){
			if(i == 1){
				selisih[j] = ar[i][j] - ar[i][j+1];
			}
			else {
				if(ar[i][j]-ar[i][j+1] != selisih[j]){
					ans = false;
					break;
				}
			}
		}
	}
	for(int j=1; j<=3; j++){
		for(int i=1; i<3; i++){
			if(j == 1)
				selisih[i] = ar[i][j] - ar[i+1][j];
			else {
				if(ar[i][j] - ar[i+1][j] != selisih[i]){
					ans = false;
					break;
				}
			}
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
l = []
r = []
for i in range(n):
    if i % 2 == 0:
        r.append(a[i])
    else:
        l.append(a[i])

if n % 2 == 0:
    print(*(l[::-1] + r))
else:
    print(*(r[::-1] + l))

Measured memory_bytes: 26180
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

ans = sum(A)
for i in range(N):
    temp = B[i] - A[i]
    if temp >= 0:
        A[i] = 0
        A[i+1] = max(A[i+1]-temp,0)
    else:
        A[i] -= B[i]
        
ans -= sum(A)
print(ans)

Measured memory_bytes: 19648
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int h, w;
    char maze[2010][2010];
    static int length[2010][2010], width[2010][2010];

    int ans = 0;
    int l;

    cin >> h >> w;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> maze[i][j];
        }
    }

    for (int i = 0; i < h; i++)
    {
        int count = 0;
        for (int j = 0; j < w; j++)
        {
            if (maze[i][j] == '#')
            {
                if (count > 0)
                {
                    length[i][j - 1] = count;
                    count = 0;
                }
            }
            else if (j + 1 == w)
            {
                count++;
                length[i][j] = count;
            }
            else
            {
                count++;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        l = 0;
        for (int j = w - 1; j >= 0; j--)
        {
            if (length[i][j] > 0)
            {
                l = length[i][j];
            }

            if (maze[i][j] == '.')
            {
                length[i][j] = l;
            }
            else
            {
                l = 0;
            }
        }
    }

    for (int j = 0; j < w; j++)
    {
        int count = 0;
        for (int i = 0; i < h; i++)
        {
            if (maze[i][j] == '#')
            {
                if (count > 0)
                {
                    width[i - 1][j] = count;
                    count = 0;
                }
            }
            else if (i + 1 == h)
            {
                count++;
                width[i][j] = count;
            }
            else
            {
                count++;
            }
        }
    }

    for (int j = 0; j < w; j++)
    {
        l = 0;

        for (int i = h - 1; i >= 0; i--)
        {
            if (width[i][j] > 0)
            {
                l = width[i][j];
            }

            if (maze[i][j] == '.')
            {
                width[i][j] = l;
            }
            else
            {
                l = 0;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            ans = max(ans, length[i][j] + width[i][j] - 1);
        }
    }

    cout << ans << endl;
}

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

int main(){
  ll a,v;
  cin >> a >> v;
  ll b,w;
  cin >> b >> w;
  ll t;
  cin >> t;
  ll diff = abs(a-b);
  ll spdiff = v-w;
  //cout << diff << " " << spdiff << endl;
  if( diff <= spdiff*t ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
f[168],z[]={24,23,25,12,36,11,13,35,37,22,26,48},x,s;main(y){for(;s?++f[y*12+x+z[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:0;);for(x=y=0,s=23;++s<144;s%12<10?y=fmax(y,f[s]),f[s]&&++x:0);x=!printf("%d\n%d\n",100-x,y);}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

import sys
import os


N, M = map(int, input().split())
if N < M:
    print('No')
    quit()

A = []
for i in range(N):
    lst = list(input().strip())
    A.append(lst)

B = []
for i in range(M):
    lst = list(input().strip())
    B.append(lst)

#print(A)
#print(B)

# search
for offset_i in range(N-M+1):
    for offset_j in range(N-M+1):
        # check match
        all_match = True
        for i in range(M):
            for j in range(M):
                if A[i+offset_i][j+offset_j] != B[i][j]:
                    all_match = False
        if all_match:
            print('Yes')
            quit()
print('No')


Measured memory_bytes: 3064
//B
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		
		String S = in.next();
		String T = in.next();
		int count = 0;
		
		for(int i = 0; i < S.length(); i++) {
			char s = S.charAt(i);
			char t = T.charAt(i);
			
			if(s != t) {
				count++;
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 41096
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

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

using namespace std;
int main(){
  string s,ret;
  int w,pos;
  cin >> s;
  cin >> w;
  pos = 0;
  ret = "";
  while(pos <= s.length()-1){
	ret += s[pos];
	pos += w;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main(void)
{
	int y;
	scanf("%d",&y);
	for(int z = 0;z < y;z++)
	{
		char suji1[100000],suji2[100000];
		char ans[100000] = {0};

		for(int i = 0;i<82;i++)
		{
			suji1[i] = '0';
			suji2[i] ='0';
		}

		int overflow = 0;

		scanf("%s",suji1);
		scanf("%s",suji2);
		int suji1s = strlen(suji1);
		int suji2s = strlen(suji2);

		int anss;
		if(suji1s>suji2s)  anss = suji1s;
		else anss = suji2s;

		suji1[suji1s] = '0';
		suji2[suji2s] = '0';

		reverse(suji1,suji1+suji1s);
		reverse(suji2,suji2+suji2s);

		for(int i = 0;i < 81;i++)
		{
			ans[i] = suji1[i]+suji2[i] - '0';
			if(ans[i] >= ':')
			{
				ans[i]  = ans[i] - 10;
				suji2[i+1] = suji2[i+1]+1;
			}
		}
		if(ans[anss]> '0')
		{
			anss++;
		}
		
		if(anss > 80) overflow = 1;
		reverse(ans,ans+anss);
		ans[anss] = 0;
		if(overflow >= 1)
		{
			printf("overflow");
		}
		else
		{
			printf("%s",ans);
		}
		printf("\n");
		
	}
	return 0;
}

Measured memory_bytes: 1140
N = int(input())
l = list(map(int,input().split()))



def count_even(a):
    if a % 2 == 1:
        return 0
    else:
        if a == 2:
            return 1
        return 1 + count_even(a/2)


cnt = 0

for a in l:
    cnt += count_even(a)


print(cnt)


Measured memory_bytes: 4148
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
using namespace std;


//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}

const ll mod = 1e9 + 7;
const ll N = 2e6 + 7;
const ll inf = 1e9 + 5;




ll n, r = 0, g = 0, b = 0, ans = 1;
string s;

int main()
{
    MohamedMotaz;
    cin >> n >> s;
    f(i,0,n ){
       if (s[i] == 'R') r++;
       if (s[i] == 'G') g++;
       if (s[i] == 'B') b++;
    }
    //cout << r <<  " " << g << " " << b << endl;
    ans = r * g * b;
    f(i,0,s.size()){
        f(j , 1, n){
            if (i + j + j < n)
                if (s[i]!=s[i+j]&&s[i+j]!=s[i+j+j]&&s[i]!=s[i+j+j]) ans--;

        }
    }
    cout << ans;
}





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

int main() {
  string str = "abcdefghijklnmopqrstuvwxyz";
  string C;
  cin >> C;
  for (int i = 0; i < str.size(); i++) {
    if (C.at(0) == str.at(i)) {
      cout << str.at(i + 1) << endl;
    }
  }
}

Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
--
local N = read.n()
local A = read.N(N)
local x = array(1,0)
local flipsum = 0
local sign = 1
for i=1,N do
    flipsum = flipsum + sign * A[i]
    sign = -1 * sign
end
x[1] = flipsum // 2
for i=2,N do
    x[i] = A[i-1] - x[i-1]
end
local x2 = {}
for i=1,N do
    x2[i] = 2 * x[i]
end
print(table.concat(x2, " "))

Measured memory_bytes: 17792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  string target = "keyence";
  int index = 0;
  if (s == target) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < s.length(); i++) {
    for (int j = i; j < s.length(); j++) {
      string part = "";
      for (int k = 0; k < s.length(); k++) {
        if (i <= k && k <= j) continue;
        part += s[k];
      }
      if (part == target) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    unsigned long long  a, b, xa,k;
    cin >> a >> b >> k;
    xa = a;
    if (a >= k) {
       cout<< a - k << " " << b;
    }
    else if(b >= k-a) {
        cout << 0 << " " << b-(k-a);
    }
    else {
        cout << 0 << " " << 0;
    }
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        r: u32,
        d: u32,
        x: u32,
    }
    let mut x_init = x;

    for i in 0..10 {
        x_init = x_init * r - d;
        println!("{}", x_init);
    }
}


Measured memory_bytes: 2140
from collections import Counter

def solve_baka(s: str):
    ans = 0
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            if int(s[i:j]) % 2019 == 0:
                print(i, j)
                ans += 1

    return ans


def main():
    s = input()
    sr = s[::-1]
    tn = [0]

    m = 1
    for i in range(len(s)):
        tn.append((tn[i]+int(sr[i])*m) % 2019)
        m = m * 10 % 2019

    ans = 0
    for _, v in Counter(tn).items():
        if v > 1:
            ans += v * (v - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16784
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long N = sc.nextLong();
    long ans = 0;
    if(N%2 == 0){
      N /= 2;
      while(N>0){
        ans += N/5;
        N /= 5;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    string s; cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int i,j,a,b,c[20],d[50001],min=2000000000;
int main(void)
{
	
	scanf("%d %d",&a,&b);
	for(i=0;i<b;i++){
		scanf("%d",&c[i]);
	}
	for(j=0;j<=a;j++){
		d[j]=min;
	}
	d[0]=0;
	for(i=0;i<b;i++){
		for(j=0;j<=a;j++){
			if(d[j]!=min && j+c[i]<=a){
				if(d[j]+1<d[j+c[i]]){
					d[j+c[i]]=d[j]+1;
				}
			}
		}
	}
	printf("%d\n",d[a]);
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
/*
Binary Search
2019. 4/30
*/

int A[1000000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;

    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid]) return 1;
        if (key > A[mid]) left = mid + 1;
        else if (key < A[mid]) right = mid;
    }
    return 0;
}

int main(){
    int i, q, k, sum = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; i++){
        scanf("%d", &k);
        if (binarySearch(k)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}



Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long N,T,A,t,a;
	cin>>N;
	t=a=1;
	for(long long n=0;n<N;n++){
		cin>>T>>A;
		long long k=max((t+T-1)/T,(a+A-1)/A);
		t=k*T;
		a=k*A;
//		cout<<t<<" "<<a<<endl; 
	} 
	cout<<t+a<<endl;
	return 0;
} 

Measured memory_bytes: 256
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};
 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                   > pq;*/
  /*   #define MAXN 1000001
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        // marking smallest prime factor for every
        // number to be itself.
        spf[i] = i;

    // separately marking spf for every even
    // number as 2
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        // checking if i is prime
        if (spf[i] == i)
        {
            // marking SPF for all numbers divisible by i
            for (int j=i*i; j<MAXN; j+=i)

                // marking spf[j] if it is not
                // previously marked
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<ll> getFactorization(ll x)
{
    vector<ll> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
*/
// take multiset of all edges
// meanwhile for all cc keep record of all edges in multiset too which can be used to digest
// one line or two lines
//
bool check(ll l,vector<ll> v,ll k)
{  //cout<<l<<endl;
    for(auto x:v)
    {
        ll cuts=(x+l-1)/l-1;
        if(k>=cuts)k-=cuts;
        else {return false;}
    }
    return true;
}
int main()
{  ll x;cin>>x;
   if(x>=30)cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int N = 17;
int seat[N+1];
int ans[100];

void sim(){
	int t = 0;
	rep(i, 100){
		int num = i%5==1?5:2;
		if(t < 5*i){
			rep(j, N) seat[j] -= min(seat[j], 5*i-t);
			t = 5*i;
		}
		bool ok = false;
		while(1){
			int cnt = 0;
			rep(j, num) cnt += !!seat[j];
			rep(j, N+1-num){
				if(cnt == 0){
					FOR(k, j, j+num) seat[k] = 17*(i%2)+3*(i%3)+19;
					ans[i] = t-5*i;
					ok = true;
					break;
				}
				if(seat[j+num]) ++cnt;
				if(seat[j]) --cnt;
			}
			if(ok) break;
			int mint = 1<<29;
			rep(j, N) if(seat[j]) mint = min(mint, seat[j]);
			rep(j, N) if(seat[j]) seat[j] -= mint;
			t += mint;
		}
		//printf("\ntime:%d\nseat:", t);
		//rep(j, N) printf("%3d", seat[j]);
	}
}

int main(){
	sim();
	int n;
	while(cin >> n) cout << ans[n] << endl;

	return 0;
}

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

int main() {
	vector<vector<int>> data(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> data.at(i).at(j);
		}
	}

	int n;
	cin >> n;

	for (int k = 0; k < n; k++) {
		int b;
		cin >> b;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (b == data.at(i).at(j)) {
					data.at(i).at(j) = 0;
				}
			}
		}
	}

	bool ans = false;
	for (int i = 0; i < 3; i++) {
		if (data.at(i).at(0) == 0 && 
			data.at(i).at(1) == 0 && 
			data.at(i).at(2) == 0) {
			ans = true;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (data.at(0).at(i) == 0 &&
			data.at(1).at(i) == 0 &&
			data.at(2).at(i) == 0) {
			ans = true;
		}
	}
	if (data.at(0).at(0) == 0 &&
		data.at(1).at(1) == 0 &&
		data.at(2).at(2) == 0) {
		ans = true;
	}
	if (data.at(0).at(2) == 0 &&
		data.at(1).at(1) == 0 &&
		data.at(2).at(0) == 0) {
		ans = true;
	}

	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256