akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

char abc[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int main() {
    ll n;
    cin >> n;
    n--;
    vector<char> ans;
    while(n >= 0){
        ans.push_back(abc[n%26]);
        n/=26;
        n--;
    }
    reverse(all(ans));
    rep(i, ans.size())cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int res = 0;
  for(int i=0; i<27; i++){
    for(int j=0; j<16; j++){
      int total = 4*i + 7*j;
      if(total == n)++res;
    }
  }
  if(res > 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// Problem Code: abc170_c

#include <iostream>
#include <cmath>
#include <unordered_set>
#include <limits>

using namespace std;

int forbidden_list(int X, int N, unordered_set<int>& p) {
	int ele, min_d = numeric_limits<int>::max();

	for (int i = 0; i <= 101; i++)
		if (!p.count(i) && abs(X - i) < min_d) {
			ele = i;
			min_d = abs(X - i);
		}

	return ele;
}

int main() {
	int X, N;
	cin >> X >> N;
	unordered_set<int> p(N);
	for (int i = 0; i < N; i++) {
		int val;
		cin >> val;
		p.insert(val);
	}
	cout << forbidden_list(X, N, p);
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n;
  scanf("%lld", &n);

  llong i = 1, res = 0;
  while(i * i <= n){
    res = i * i;
    i++;
  }

  printf("%lld\n", res);

  return 0;
}



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

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	long long sum = 0;
	long long mod = 1e9 + 7;
	for(long long i = k; i <= n + 1; i++){
		long long maxi, mini;
		mini = i * (i - 1)/2;
		maxi = n * i - mini;
		sum += maxi - mini + 1;

	}
	cout << sum % mod <<  '\n';
}


Measured memory_bytes: 3628
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = G;
		for (var i = 0; i < N; i++) A[i] -= i;
		Array.Sort(A);
		var b = A[N / 2];
		var s = 0L;
		foreach (var x in A) s += Abs(x - b);
		WriteLine(s);
	}
}


Measured memory_bytes: 28892
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR( i, k, n ) for ( int i = ( k ); i < ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 0, n )

#define MAX_N 100000

int main() {
	int n, q;
	int nums[ MAX_N ];
	scanf( "%d", &n );
	REP( i, n ) scanf( "%d", &nums[ i ] );
	scanf( "%d", &q );
	int ans = 0;
	REP( i, q ) {
		int num;
		scanf( "%d", &num );
		if( binary_search( nums, nums + n, num ) ) ++ans;  // 二分探索
	}
	printf( "%d\n", ans );
	return 0;
}

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

static const int MAX_N = 15;
static const int MAX_M = 15000000;

enum Tray { A, B, C, NUM };
enum Dir { LEFT = -1, RIGHT = 1 };

static int dir[]{LEFT, RIGHT};

struct Data {
  set<int, greater<int>> tray[NUM];
  Tray from, to;
  int count;
};

int N, M;

int bfs(Data d) {
  queue<Data> que;
  que.push(d);

  while (!que.empty()) {
    Data d = que.front(); que.pop();
    if (d.tray[A].size() == N || d.tray[C].size() == N)
      return d.count;
    if (d.count >= M)
      break;
    for (int t{A}; t <= C; ++t) {
      for (int i{}; i < 2; ++i) {
        int nt = t + dir[i];
        if (nt < A || nt > C)
          continue;
        if (t == d.to && nt == d.from)
          continue;
        auto it = d.tray[t].begin();
        if (it == d.tray[t].end())
          continue;
        int t_cup = *it;
        it = d.tray[nt].begin();
        int nt_cup{};
        if (it != d.tray[nt].end()) {
          nt_cup = *it;
        }
        if (t_cup < nt_cup)
          continue;
        Data nd = d;
        nd.tray[nt].insert(t_cup);
        nd.tray[t].erase(t_cup);
        nd.from = static_cast<Tray>(t);
        nd.to = static_cast<Tray>(nt);
        ++nd.count;
        que.push(nd);
      }
    }
  }

  return -1;
}

int main() {
  while (true) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    Data d{};
    for (int t{A}; t <= C; ++t) {
      int num;
      cin >> num;
      for (int i{}; i < num; ++i) {
        int cup;
        cin >> cup;
        d.tray[t].insert(cup);
      }
    }
    cout << bfs(d) << endl;
  }
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int>a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    vector<int>dp(100,0);
    vector<pair<int,int>>kdp(100);
    dp[0]=1000;
    kdp[0]={0,0};
    for (int i = 0; i < n; i++)
    {
        chmax(dp[i+1],dp[i]);
        chmax(kdp[i+1],pair<int,int>(dp[i]/a[i],dp[i]%a[i]));
        chmax(kdp[i+1],kdp[i]);
        chmax(dp[i+1], kdp[i].second + kdp[i].first*a[i]);
        
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

void solve()
{
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    rep(i, h)
    {
        rep(j, 2) cout << c[i] << endl;
    }
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3640
def main():
    n, m, k = map(int, input().split())
    answer = False
    for i in range(n + 1):
        if answer:
            break
        for j in range(m + 1):
            if i * j + (n - i) * (m - j) == k:
                answer = True
                break
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
import qualified Control.Arrow               as Arrow
import qualified Control.Monad               as Monad
import qualified Data.Bits                   as Bits
import qualified Data.List                   as List
import qualified Data.ByteString.Char8       as BSC8
import qualified Data.Vector.Unboxed         as VU

getI :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString)
getI = fmap (Arrow.second BSC8.tail) . BSC8.readInt

getAN :: Int -> IO (VU.Vector Int)
getAN n = VU.unfoldrN n getI <$> BSC8.getLine

main :: IO ()
main = do
  n  <- readLn :: IO Int
  xs <- getAN n
  let ys = VU.map (Bits.xor (VU.foldl1' Bits.xor xs)) xs
  putStrLn $ unwords $ map show $ VU.toList ys

Measured memory_bytes: 11576
/**
  @date Time-stamp: <2019-05-14 21:41:58 tagashira>
  @file a.cpp
  @title A - Double Helix
  @brief https://atcoder.jp/contests/abc122/tasks/abc122_a
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  char s;
  cin >> s;

  if (s == 'A') {
    cout << 'T' << "\n";
  } else   if (s == 'T') {
    cout << 'A' << "\n";
  } else   if (s == 'C') {
    cout << 'G' << "\n";
  } else   if (s == 'G') {
    cout << 'C' << "\n";
  }

  return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MAX_COMB = 3e5 + 3;
const LL mod = 998244353;
LL fct[MAX_COMB+1];
LL invfct[MAX_COMB+1];

void build(){
	fct[0] = fct[1] = 1;
	repp(i,2,MAX_COMB+1){
		fct[i] = fct[i-1] * i % mod;
	}
	LL x = fct[MAX_COMB];
	invfct[MAX_COMB] = 1;
	for(int i = mod - 2 ; i > 0 ; i >>= 1){
		if(i % 2 == 1) (invfct[MAX_COMB] *= x) %= mod;
		(x *= x) %= mod;
	}
	repm(i,MAX_COMB,0){
		invfct[i-1] = invfct[i] * i % mod;
	}
}

LL comb(int x, int y){
	if(x < 0 || y < 0 || x < y) return 0;
	return fct[x] * invfct[y] % mod * invfct[x-y] % mod;
}

int main(){
	build();
	LL N,A,B,K; cin >> N >> A >> B >> K;
	LL ans = 0;
	repp(i,0,N+1) if(K >= A*i && (K-A*i)%B == 0){
		(ans += comb(N,i)*comb(N,(K-A*i)/B)) %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int N;
  int H;
  int x;  
  cin>>N>>H;
  int a[100010],b[100010];
  for(int i=0;i<N;i++)
     cin>>a[i]>>b[i];
  sort(a,a+N);
  x=a[N-1]; 
  sort(b,b+N); 
  int ans=0;
  for(int j=N;j>=0;j--)
  {
     if(x<b[j] and H>0)
     { H=H-b[j];
       ans++;}
  }
  if(H>0)
  ans+=(H+x-1)/x;
  //cout<<H<<(H+x-1)/x;
  cout<<ans<<endl;
  system ("pause");
  return 0;
}

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

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

class ModCase{ // modの元での場合の数
public:
  vector<ll> fact, finv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n % 2 == 0) return mod_pow((a * a) % mod, n/2);
    return (a * mod_pow(a, n-1) % mod);
  }

  ModCase(ll N):fact(N+1), finv(N+1){ // O(N)で初期化
    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = (i * fact[i-1]) % mod;
    finv[N] = mod_pow(fact[N],mod-2);
    ROF(i, N, 0) finv[i] = finv[i+1] * (i+1) % mod;
  }

  ll C(ll n, ll r){ // nCr
    if(r < 0 or n < r) return 0;
    return fact[n] * finv[r] % mod * finv[n-r] % mod;
  }

  ll P(ll n, ll r){ // nPr
    if(r < 0 or n < r) return 0;
    return fact[n] * finv[n-r] % mod;
  }

  ll H(ll n, ll r){ // nHr
    return C(n+r-1,r);
  }
};

signed main(){
  int n, k; cin >> n >> k;
  ModCase mc(n+k);
  vvi dp(n-k+2,vi(k+1)); // dp[i][j] i箇所にj個置く組み合わせ
  rep(i,n-k+2) dp[i][0] = 1;
  rep(i,n-k+1) rep(j,k){
    dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % mod;
  }
  FOR(i,1,k+1){
    //dump(mc.C(n-k+1,i));
    //dump(dp[i][k-i]);
    if(i > n-k+1) cout << 0 << endl;
    else cout << (mc.C(n-k+1,i) * dp[i][k-i]) % mod << endl;
  }
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)    cin>>a[i];
    int curr_max=a[0];
    ll ans=0;
    for(int i=1;i<n;i++){
        if(curr_max>=a[i]){
            ans+=curr_max-a[i];
        }else{
            curr_max=a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4384
#include<iostream>

int main(){
  int n, m,sum_t = 0, temp;
  std::cin >> n;
  int t[n];
  for(int i = 0; i < n; i++){
    std::cin >> t[i];
    sum_t += t[i];
  }
  std::cin >> m;
  int p[m], x[m];
  for(int i = 0; i < m; i++)
    std::cin >> p[i] >> x[i];
  for(int i = 0; i < m; i++){
    temp = p[i] - 1;
    std::cout << sum_t - t[temp] + x[i] << std::endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"a"# => r#"b"#,
r#"y"# => r#"z"#,

}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        c: bytes,
    }

    ((c[0] + 1) as char).to_string()
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,d[52]={},dr[52]={},i,j,k,sm1=24,sm2=24,sm3=24,smax=0;
	cin>>n;
	FOR(i,1,n+1){
		cin>>d[i];
	}
	n++;
	sort(d,d+n);
	FOR(i,0,n)dr[i]=24-d[i];
	d[n]=24;
	int f=0,s1,s2,s3=24;
	FOR(i,1,n){
		//cout<<d[i]<<" "<<dr[i]<<endl;
		if(f==0){
			s1=d[i]-dr[i-1];
			s2=dr[i]-d[i-1];
			if(s1<-12)s1+=24;
			//if(s2>12||s2<-12)s2=d[i]-d[i-1];
		}else{
			s2=d[i]-dr[i-1];
			s1=dr[i]-d[i-1];
			if(s1>12)s1-=24;
			//if(s2>12||s2<-12)s2=d[i]-d[i-1];
		}
		if(i>=2){
			s3=d[i]-d[i-2];
		}
		if(s1<0)s1=-s1;
		if(s2<0)s2=-s2;
		if(sm1>s1)sm1=s1;
		if(sm2>s2)sm2=s2;
		if(sm1>s3)sm1=s3;
		//if(sm2>s3)sm2=s3;
		f=(f+1)%2;
	}
	//sm1=sm1%12;
	//sm2=sm2%12;
	smax=sm1;
	if(n==2)smax=d[1];
	FORQ(i,1,12){
		if(upper_bound(d, d+n, i)-lower_bound(d, d+n, i)>=3)smax=0;
	}
	cout<<smax<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;

int n,m;
int c = 0;
bool graph[10][10];
bool visited[10];

void dfs(int y, int x) {
    if (visited[y]) return;
    visited[y] = true;
    bool allv = true;
    for (int i = 0; i < n; ++i) if (!visited[i]) allv = false;
    if (allv) c++;
    for (int i = 0; i < n; ++i) if (graph[y][i]) dfs(i, y);
    visited[y] = false;
    return;
}

int main(int argc, char const *argv[]) {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) for (int j = 0; j < m; ++j) graph[i][j] == false;
    for (int i = 0; i < n; ++i) visited[i] = false;
    int a, b;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        graph[a-1][b-1] = graph[b-1][a-1] = true;
    }
    
    dfs(0, 0);
    cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, k;
	int flag = 0;
	cin >> k;
	cin >> a >> b;
	for (int i = a; i <= b; i++)
	{
		if (i % k == 0)
		{
			cout << "OK";
			flag = 1;
			break;
		}
	}
	if (flag == 0)
	{
		cout << "NG";
	}

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A + B == C + D)cout << "Balanced" << endl;
    else if (A + B > C + D)cout << "Left" << endl;
    else if (A + B < C + D)cout << "Right" << endl;
    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N; cin >> N;
	vector <int> a(N);
	for (auto &i : a) cin >> i;
	bool allpos = false;
	int small = *min_element(a.begin(),a.end()), big = *max_element(a.begin(),a.end());
	int smallid = min_element(a.begin(),a.end()) - a.begin();
	int bigid = max_element(a.begin(),a.end()) - a.begin();
//	cout << small << " " << smallid << "\n";
//	cout << big << " " << bigid << "\n";
	queue <pair<int,int>> moves;
	if (!(big < 0 || small >= 0)){
		if (abs(big) >= abs(small)){
			for (int i = 0; i < N; ++i){
				if (a[i] < 0){
					moves.push(make_pair(bigid, i));
					a[i] += big;
				}
			}
			allpos = true;
		}else{
			for (int i = 0; i < N; ++i){
				if (a[i] > 0){
					moves.push(make_pair(smallid, i));
					a[i] += small;
				}
			}
			allpos = false;
		}
	}else if(small >= 0){
		allpos = true;
	}
	if (allpos){
		for (int i = 1; i < N; ++i){
			if (a[i-1] > a[i]){
				moves.push(make_pair(i-1, i));
				a[i] += a[i-1];
			}
		}
	}else{
		for (int i = N-2; i >= 0; --i){
			if (a[i+1] < a[i]){
				moves.push(make_pair(i+1, i));
				a[i] += a[i+1];		
			}
		}
	}
	int m = moves.size();
	cout << m << "\n";
	for (int i = 0; i < m; ++i){
		cout << moves.front().first+1 << " " << moves.front().second +1 << "\n";
		moves.pop();
	}	
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

ll ans[200005]={0};
bool bfs(ll te,vector<ll> v[],bool visited[])
{
	queue<pair<ll,ll>> q;
	q.push({te,0});
	visited[te]=true;
	while(!q.empty())
	{
		ll i,k;
		tie(i,k)=q.front();
		q.pop();
		if(i>=te)ans[k]++;
		for(auto it:v[i])
		{
			if(!visited[it])
			{
				q.push({it,k+1});
				visited[it]=true;
			}
		}
	}
}

void solve()
{
	ll n,x,y;
	cin>>n>>x>>y;
	vector<ll> v[n+1];
	bool visited[200005]={false};
	for(ll i=0;i<n-1;i++)
	{
		v[i+1].push_back(i+2);
		v[i+2].push_back(i+1);
	}
	v[y].push_back(x);
	v[x].push_back(y);
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=n;j++) visited[j]=false;
		bfs(i,v,visited);
	}
	for(ll i=1;i<n;i++) cout<<ans[i]<<endl;
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 640
import qualified Data.Set as Set

inits :: Int -> [a] -> [[a]]
inits 0 _ = []
inits _ [] = []
inits k (x:xs) = map (x:) ([] : inits (k-1) xs)

tails :: [a] -> [[a]]
tails [] = []
tails xs = xs : tails (tail xs)

substrings :: Int -> String -> [String]
substrings k = concatMap (inits k) . tails

solve :: Int -> String -> String
solve k = (!! (k-1)) . Set.toList . Set.fromList . substrings k

main :: IO ()
main = do
  s <- getLine
  k <- read <$> getLine
  putStrLn $ solve k s


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

int main()
{
    int a, n;  cin >> n;
    double sum = 0.0;

    rep(i,n) {
        cin >> a;
        sum += 1.0 / a;
    }
    
    double ans = 1.0 / sum;

    cout << setprecision(16) << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll d[200][200];

void solve()
{
    int n, m, R;
    scanf("%d%d%d", &n, &m, &R);
    vector<int> r(R);
    int i, j;
    for (i = 0; i < R; i++) {
        scanf("%d", &r[i]); r[i]--;
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (i != j) d[i][j] = LINF2;
        }
    }

    for (i = 0; i < m; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c); a--; b--;
        d[a][b] = MIN(d[a][b], c);
        d[b][a] = MIN(d[b][a], c);
    }

    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    ll ans = LINF;
    vector<int> v(R);
    for (i = 0; i < R; i++) v[i] = i;
    do {
        ll ans0 = 0;
        for (i = 1; i < R; i++) {
            ans0 += d[r[v[i - 1]]][r[v[i]]];
        }
        ans = MIN(ans, ans0);
    } while( next_permutation(v.begin(), v.end()) );

    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 512
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=998244353
pp=pow(2,mod-2,mod)

n,s=map(int,input().split())
l=list(map(int,input().split()))

dp=[[0 for j in range(s+1)] for i in range(n+1)]
dp[0][0]=pow(2,n,mod)

for i in range(n):
    for j in range(s+1):
        if dp[i][j]>=1:
            if j+l[i]<=s:
                dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod)
                dp[i+1][j+l[i]]%=mod
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod
print(dp[-1][-1]%mod)


Measured memory_bytes: 148564
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

typedef struct edge{
    int v;              // エッジの　終点　だと思われる
    LL w;               // エッジの　重み　だと思われる
    edge() {}                                              // 構造体のコンストラクタ 
    edge(int v, LL w) : v(v), w(w) {};                     // これはv,wを同時にpush_back(emplace_back)するために必要
} Edge;

vector<LL> dijkstra(int n, vector<vector<Edge> >& G, int s) {   // N , G , start (ノードは0-index)
    vector<LL> d(n, LLONG_MAX/10); d[s] = 0;                    // LLONG_MAX はlong　long　の最大値を呼び出す 
    priority_queue<pair<LL, int> > que;                         // p_queue の作成　s　はやっぱりstart地点の番号
    que.push(make_pair(0LL, s));                                // queue に　（0、辺の始点）をpushしてる。                 
    while (!que.empty()) {                                      // queue が空っぽになるまでループ
        auto p = que.top(); que.pop();                          // queue から一個もってくる
        int u = p.second;                                       // もってきたpairから　二番目の情報、つまり対象となるノード番号を獲得
        LL  dist = -p.first;                                    // dist は最短距離の一時変数で、 -p.first と負の数にしているのは、p_queue の greater を省略するため。逆順ソートしたいから。
        if (dist > d[u]) continue;                              // dはそのノードまでの最短距離を表現していると考えられる。
        for (Edge e : G[u]) {                                   // 作ったグラフの　u番目　のもつpairを呼び出してる
            if (d[e.v] > d[u]+e.w) {                            // d[e.v]はEdgeの接続先のこれまでの最短距離。　右辺は接続元までの距離＋辺の重み
                d[e.v] = d[u] + e.w;                            // 最短距離の更新 
                que.push(make_pair(-d[e.v], e.v));              // 更新したノードの（最短距離と番号）をpush
            }                                                   // つまり、拡張for文でpushされた要素たちは、最短距離を更新できなくなると廃棄されて行ってemptyになるということ。
        }
    }
    return d;                                                   // 各ノードまでのstart地点からの最短距離が出る。
}

int main(){
    int N;cin >> N;
    vector<vector<Edge>> G(N);
    rep(i,N-1){
        int a,b;cin >> a >> b;
        a--;b--;
        G[a].push_back((Edge){b,1LL});
        G[b].push_back((Edge){a,1LL});
    }

    vector<LL> d1;
    vector<LL> d2;

    d1 = dijkstra(N,G,0);
    d2 = dijkstra(N,G,N-1);

    int cf = 0;int cs = 0;
    rep(i,N){
        if(d1[i] <= d2[i])cf++;
        else cs++;
    }
    if(cs >= cf)cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
}

Measured memory_bytes: 9748
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
    
//     ll n, k;
//     cin >> n >> k;
//     vi a(n);
//     rep(i, n) cin >> a[i];
//     set<int> st;
//     vi ans;
//     int now = 1;
//     while (1) {
//         now = a[now-1];
//         if (st.count(now)) {
//             ans.pb(now);
//             break;
//         } else {
//             st.insert(now);
//             ans.pb(now);
//         }
//     }
//     int s = 0;
//     rep(i, n) {
//         if (ans[i] == ans.back()) {
//             s = i;
//             break;
//         }
//     }
//     vi repeat;
//     for (int i = s; i < sz(ans) - 1; ++i) {
//         repeat.pb(ans[i]);
//     }
//     int len = sz(ans) - s - 1;
//     if (k <= s) {
//         cout << ans[k-1] << endl;
//     } else {
//         k -= s;
//         k %= len;
//         if (k == 0) cout << repeat.back() << endl;
//         else cout << repeat[k-1] << endl;
//     }
// }

// int main() {
//     int n; ll k;
//     cin >> n >> k;
//     vi a(n);
//     rep(i, n) cin >> a[i];

//     vi s;
//     vi ord(n+1, -1);
//     int c = 0, l = 0;
//     {
//         int v = 1;
//         while (ord[v] == -1) {
//             ord[v] = sz(s);
//             s.pb(v);
//             v = a[v-1];
//         }
//         c = sz(s) - ord[v];
//         l = ord[v];
//     }
//     if (k < l) {
//         cout << s[k] << endl;
//     } else {
//         k -= l;
//         k %= c;
//         cout << s[l+k] << endl;
//     }
// }

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
    int n; ll k;
    cin >> n >> k;
    rep(i, n) {
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i, D-1) rep(j, n) to[i+1][j] = to[i][to[i][j]];
    int v = 0;
    rep(i, D) {
        if (k>>i&1) {
            v = to[i][v];
            k -= 1LL<<i;
        }
    }
    cout << v+1 << endl;
}

Measured memory_bytes: 50528
n = int(input())
dp = [-1 for i in range(n+1)]
c = [1]
for i in [6,9]:
    c += [i**j for j in range(1,10) if i**j <=10**5]
# print(c)
for i in range(n+1):
    # print(i)
    if i == 0:
        dp[0] = 0
    else:
        cand = [dp[i-j]+1 for j in c if i-j>=0]
        # print('candidate',cand)
        dp[i] = min(cand)
print(dp[n])

Measured memory_bytes: 3864
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,q;
    cin >> k >> q;
    vll d(k);
    REP(i,k) cin >> d[i];
    vll n(q),x(q),m(q);
    REP(i,q){
        cin >> n[i] >> x[i] >> m[i];
    }
    REP(i,q){
        ll tx = x[i]%m[i];
        ll rem = (n[i]-1)%k;
        ll sum = 0;
        REP(j,k){
            ll td = d[j]%m[i];
            if(td==0){
                td = m[i];
            }
            if(j<rem){
                tx+=td;
            }
            sum+=td;
        }
        tx+=sum*((n[i]-1)/k);
        tx/=m[i];
        cout << n[i]-1-tx << endl;
    }

    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, M, Q;
    	int[][] range;
    	
    	int ans(int p, int q) {
    		int sum = 0;
    		for (int i = p; i <= q; ++i) {
    			sum += range[i][q] - range[i][p - 1];
    		}
    		return sum;
    	}
    	
        void solve(InputReader in, PrintWriter out) {
        	N = in.nextInt();
        	M = in.nextInt();
        	Q = in.nextInt();
        	
        	range = new int[N + 1][N + 1];
        	for (int i = 0; i <= N; ++i) Arrays.fill(range[i], 0);
        	
        	for (int i = 0; i < M; ++i) {
        		int l = in.nextInt();
        		int r = in.nextInt();
        		range[r][l]++;
        	}
        	
        	for (int i = 1; i <= N; ++i) {
        		for (int j = 1; j <= N; ++j) {
        			range[i][j] += range[i][j - 1];
        		}
        	}
        	
        	for (int i = 0; i < Q; ++i) {
        		int p = in.nextInt();
        		int q = in.nextInt();
        		out.println(ans(p, q));
        	}
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 61752
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){\
cout << it.fi << " " << it.se << endl;}


#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
//#define endl "\n"
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m ;
    cin>>n>>m;
    vec v(n+1);
    fo(i, n+1)
        v[i] = i;
    foo(i, 1, n+1)
        v[i] += v[i - 1];
    int ans = 0;
    foo(i,m,n+2){
       int min1=v[i-1];
       min1 %= mod;
       int max1 = (i==n+1)?v[n]:v[n] - v[n-i];
       max1%=mod;
    //    deb(min1);
    //    deb(max1);
       if(max1<0)
           max1 += mod;
       ans += (max1 - min1 + 1);
       ans %= mod;
       if(ans<0)
           ans += mod;
    }
    cout << ans;
        

}


Measured memory_bytes: 4768
class UnionFind :
    def __init__(self, size) :
        """
        Parameters
        ---
        size : int
            頂点数
        """
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        """
        親のインデックスの取得

        Parameters
        ---
        index : int
            取得する頂点のインデックス

        Returns
        ---
        rootIndex : int
            指定した頂点の根のインデックス
        """
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        """
        木の結合

        Parameters
        ---
        index1 : int
        index2 : int
            結合する頂点のインデックス
        """
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        """
        同じ木に属するかを判定する

        Parameters
        ---
        index1 : int
        index2 : int

        Returns
        ---
        boolean
        """
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        """
        指定した頂点の属する木の大きさを取得する
        """
        return self.size[self.root(index)]

    def getComponent(self) :
        """
        連結成分数を取得する
        """
        return self.component

N, M = map(int, input().split())

AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a - 1, b - 1))

ans = [N * (N - 1) // 2]
tree = UnionFind(N)

for a, b in AB[1:][:: -1]:
    if tree.isSameRoot(a, b):
        ans.append(ans[-1])
    else:
        dis = tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b)
        ans.append(ans[-1] - dis)
    tree.union(a, b)

print(*ans[:: -1], sep='\n')


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

int main() {
  string s;
  cin>>s;
  int n= s.size();

  // vector<vector<int>> task(n);
  // task[0].push_back(0);

  const int M = 2019;
  int ans = 0;

  int mod[M];
  for(int i=0; i<M; i++) mod[i]=0;
  // mod[0]=1;

  int copy[M];
  for(int i=0; i<M; i++) copy[i]=mod[i];

  for(int i=0; i<n; i++) {
    // cout<<endl;
    // for(int j=0; j<M; j++) cout<<copy[j]<<' ';

    for(int j=0; j<M; j++) mod[j]=0;
    mod[int(s[i])-48] += 1;

    for(int j=0; j<M; j++) {
      if(copy[j]!=0) {
        // cout<<"copy["<<j<<"]!=0;"<<endl;
        int next = (j*10+(int)s[i]-48)%M;
        mod[next] += copy[j];
        if(next==0) {
          ans += copy[j];
        }
      }
    }

    for(int j=0; j<M; j++) copy[j]=mod[j];
  }

  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 3736
#include <cstdio>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;

long long int gcd(long long int x, long long int y) {
	if (x < y){
      return gcd(y, x);
    }
	long long int r;
	while (r = x % y) {
		x = y;
		y = r;
	}
	return y;
}

int main(void){
  long long int n,i,j;
  cin >> n;
  long long int a[n];
  long long int minusCount=0;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]<0) minusCount++;
  }
  long long int minAbs=abs(a[0]);
  long long int total = minAbs;
  for(i=1;i<n;i++){
    if(abs(a[i])<minAbs) minAbs = abs(a[i]);
    total += abs(a[i]);
  }
  if(minusCount%2!=0){
    total -= minAbs*2;
  }
  cout << total << endl;
  return 0;
}




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

int main()
{
	int N;
	cin >> N;
	
	int abc[100010][3];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 3; j++){
			cin >> abc[i][j];
		}
	}
	
	int happy[100010][3];
	for(int i = 0; i < 3; i++){
		happy[0][i] = abc[0][i];
	}
	
	for(int i = 1; i < N; i++){
		happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0];
		happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1];
		happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2];
	}
	
	int ans;
	ans = max(max(happy[N - 1][0], happy[N - 1][1]), happy[N - 1][2]);
	
	cout << ans << endl;
}


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

int a[26];

int main() {

    char c;

    while ( std::cin >> c ) {

        if ( c >= 'A' && c <= 'Z' ) a[c-'A']++;
        if ( c >= 'a' && c <= 'z' ) a[c-'a']++;
    }

    for ( int i = 0; i < 26; i++ ) {

        std::cout << (char)(i + 'a') << " : " << a[i] << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3096
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n;
    vector<int> A(n+10);
    cin >> n;
    vector<ll> m(n+10,0);

    REP(i,n) {
        int a;
        cin >> a;
        m[a]++;
        A[i] = a;
    }


    ll ans = 0;
    for(int i = 1; i <=n; i++) {
        ll value = m[i];
        if(value != 0) {
            ll tmp = value * (value -1) / 2;
            ans += tmp;
        }
    }

    for(int i = 0; i < n; ++i) {
        ll anstmp = ans;
        int a = A[i];
        ll key = m[a];
        ll tmp1 = key * (key-1) / 2;
        if(tmp1>0) {
            anstmp -= tmp1;
        }
        ll tmp2 = (key-1) * (key-2) / 2;
        if(tmp2>0) {
            anstmp += tmp2;
        }
        cout << anstmp << endl;
    }


    return 0;
}


Measured memory_bytes: 20608
import qualified Data.Map as Map
import Data.List

(|>) :: a -> (a -> b) -> b
infixl 1 |>
x |> f = f x

($>) :: (Functor m) => m a -> (a -> b) -> m b
infixl 1 $>
x $> f = fmap f x

calc :: Int -> (Int, Int) -> Int
calc x (num, len)
    | len >= num = x + len - num
    | otherwise  = x + len

main = do
    getLine
    ax <- getLine $> words $> map read :: IO [Int]
    let hi = Map.empty :: Map.Map Int Int
    let xs = ax |> foldl' (\h k -> Map.insertWith (+) k 1 h) hi |> Map.toList
    xs |> foldl' calc 0 |> print



Measured memory_bytes: 52604
#まずnが奇数なら値は0
#nが偶数なら素因数5の個数
#素因数10の個数を求めたい
n=int(input())
if n%2==1:
  print(0)
else:
  ans=0
  num=5
  n=n//2
  while num<=n:
    ans+=n//num
    num=num*5
  print(ans)
  

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    if(n>k)cout << 0<<endl;
    else cout << 1<<endl;
    return 0;
}



Measured memory_bytes: 3164
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  vector<char> t;
  for(int i=0;i<N;i++){
    if(s[i] != 'x') t.push_back(s[i]);
  }
  int M = t.size();

  //作れるかチェック
  bool able = true;
  if(M % 2 == 1){
    int p = M / 2;
    for(int i = 1; i <= p; i++){
      if(t[p + i] != t[p - i]){
        able = false;
        break;
      }
    }
  }
  else{
    int p = M / 2;
    for(int i = 1; i <= p; i++){
      if(t[p - i] != t[p + i - 1]){
        able = false;
        break;
      }
    }
  }
  // チェック終わり

  if(able == false){
    cout << -1 << endl;
    return 0;
  }

  int cnt = 0;
  int l = 0;
  int r = N - 1;
  while(l < r){
    if(s[l] == 'x' && s[r] == 'x'){
      l++;
      r--;
    }
    else if(s[l] == 'x' && s[r] != 'x'){
      l++;
      cnt++;
    }
    else if(s[l] != 'x' && s[r] == 'x'){
      r--;
      cnt++;
    }
    else{
      l++;
      r--;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

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

    int k = sc.nextInt();
    int x = sc.nextInt();

    for(int i = k; i > 0; i--){
      System.out.print((x - i + 1) + " ");
    }

    for(int i = 1; i < k; i++){
      System.out.print((x + i) + " ");
    }
  }
}


Measured memory_bytes: 21972
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String strs = sc.next();
		int ans=0;
		for(int i=0;i<3;i++){
			if (strs.charAt(i)=='1'){
				ans=ans+1;
			}
		}
	System.out.println(ans);	
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    double a[100], avg = 0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        avg += a[i];
    }
        
    avg = avg/N;
    double d = 999;
    int ans = 0;
    for(int i=0;i<N;i++){
        if(abs(a[i] - avg) < d){
            d = abs(a[i] - avg);
            ans = i;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

        System.out.printf("%d %d\n", a*b, 2*(a+b));
        sc.close();
    }
}


Measured memory_bytes: 26104