akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	string s;
	int Q;
	cin >> s>>Q;
	deque<char> q;
	rep(i, s.size())q.push_back(s[i]);
	//cout << q.front() << endl;
	int sw(1);
	rep(i, Q) {
		int buf;
		cin >> buf;
		if (buf == 1)sw *= -1;
		if (buf == 2) {
			int f;
			char c;
			cin >> f >> c;
			if (f == 1) {
				if (sw == 1)q.push_front(c);
				else q.push_back(c);
			}
			else {
				if (sw == -1)q.push_front(c);
				else q.push_back(c);
			}
		}
	}
	int qs = q.size();
	rep(i, qs) {
		
		if (sw == 1) {
			cout << q.front(); q.pop_front();
		}
		else {
			cout << q.back(); q.pop_back();
		}
		//cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3968
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] nums = Console.ReadLine().Split(' ');
    int A = int.Parse(nums[0]);
    int B = int.Parse(nums[1]);
    
    if(B % A == 0) Console.WriteLine(A + B);
    else Console.WriteLine(B - A);
  }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
}

Measured memory_bytes: 51344
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m;
  cin>>n>>m;
  vector<vector<pair<int,int>>> hoge(n);
  for(int i=0; i<m; i++){
    int a,b;
    cin>>a>>b;
    hoge.at(a-1).push_back(make_pair(b-1,i+1));
    hoge.at(b-1).push_back(make_pair(a-1,i+1));
  }

  vector<int> ans(n);
  vector<int> dist(n,-1);
  queue<int> que;

  dist[0]=0;
  que.push(0);

  cout<<"Yes"<<endl;
  while(!que.empty()){
    int v=que.front();
    que.pop();

    for(int i=0; i<hoge.at(v).size(); i++){
      int nv=hoge.at(v).at(i).first;
      if(dist[nv]!=-1) continue;

      dist[nv]=dist[v]+1;
      ans.at(nv)=v;
      que.push(nv);
    }
  }

  for(int i=1; i<n; i++){
    cout<<ans.at(i)+1<<endl;
  }
}

Measured memory_bytes: 12668
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<bool> ac(n);
    vector<int64_t> wa(n);
    for (auto i : irange(0L, m)) {
        int64_t p;
        string s;
        cin >> p >> s;
        --p;

        if (s == "AC") {
            ac[p] = true;
        } else if (!ac[p]) {
            ++wa[p];
        }
    }

    int64_t num_ac = 0, num_wa = 0;
    for (auto i : irange(0L, n)) {
        if (ac[i]) {
            ++num_ac;
            num_wa += wa[i];
        }
    }

    cout << num_ac << " " << num_wa << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void fuk() { puts("-1"); exit(0); }

const int MAXN = 100055;

int A[MAXN];

ll S, E;
int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	if(2 < A[N]) fuk();

	S = E = 2;
	for(int i = N; i; i--) {
		ll K = A[i];
		S = (S+K-1)/K * K;
		E = (E/K)*K + K-1;
		if(S > E) fuk();
	}

	cout << S << " " << E << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
// #include <numeric>
// #include <set>
// #include <cmath>
// #include <string>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}


int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<int> counts(9, 0);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a < 400) {
            counts[0] += 1;
        } else if (a < 800) {
            counts[1] += 1;
        } else if (a < 1200) {
            counts[2] += 1;
        } else if (a < 1600) {
            counts[3] += 1;
        } else if (a < 2000) {
            counts[4] += 1;
        } else if (a < 2400) {
            counts[5] += 1;
        } else if (a < 2800) {
            counts[6] += 1;
        } else if (a < 3200) {
            counts[7] += 1;
        } else {
            counts[8] += 1;
        }
    }

    int c = 0;
    for (int i = 0; i < 8; i++) {
        if (counts[i] > 0) {
            c += 1;
        }
    }

    int n_min = max(c, 1);
    int n_max = c + counts[8];

    cout << n_min << " " << n_max << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int answer = 0;
		for(int i = 3;i <=n;i+=2) {
			if(isYakusuEight(i)) {
				answer++;
			}
		}
		System.out.println(answer);

	}

	private static boolean isYakusuEight(int number) {
		int yakusu = 0;
		for(int i =1; i <=number;i++) {
			if(number % i ==0) {
				yakusu++;
			}
		}

		if(yakusu ==8) {
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 22740
<?php

$case = 1;
while (true) {
    fscanf(STDIN, '%d', $W);
    if ($W === 0) {
        break;
    }
    fscanf(STDIN, '%d', $N);
    $v = array();
    $w = array();
    for ($i = 0; $i < $N; $i++) {
        fscanf(STDIN, '%d,%d', $v[], $w[]);
    }
    $dp = array_fill(0, $N + 1, array_fill(0, $W + 1, 0));
    for ($i = 1; $i <= $N; $i++) {
        for ($j = 1; $j <= $W; $j++) {
            $dp[$i][$j] = $dp[$i - 1][$j];
            if ($j - $w[$i - 1] >= 0) {
                $dp[$i][$j] = max(array($dp[$i][$j], $dp[$i - 1][$j - $w[$i - 1]] + $v[$i - 1]));
            }
        }
    }

    $sumV = 0;
    $sumW = 0;
    for ($i = 0; $i <= $W; $i++) {
        if ($dp[$N][$i] > $sumV) {
            $sumV = $dp[$N][$i];
            $sumW = $i;
        }
    }
    echo sprintf('Case %d:', $case++) . PHP_EOL;
    echo $sumV . PHP_EOL;
    echo $sumW . PHP_EOL;
}

Measured memory_bytes: 143440
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
#include <bits/stdc++.h>
using namespace std;
//fold
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
//using ll = long long;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(ONLINE_JUDGE)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define push_back pb
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
int main(){
    speed;
	ll x,y,sum=0;
	cin>>x>>y;
	ll ar[y];
	for(ll i=0;i<y;i++){
		cin>>ar[i];
		sum+=ar[i];
	}
	if(sum>=x)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	














































return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/




Measured memory_bytes: 1024
S = input()

ans = 0
count_l = 0
count_u = 0

if S[0] == '<':
    count_u += 1
elif S[0] == '>':
    count_l += 1


for i in range(1, len(S)):
    if S[i] == '<' and S[i] != S[i-1]:
        if count_u < count_l:
            count_u -= 1
        else:
            count_l -= 1
        ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2
        count_u = 1
        count_l = 0
    elif S[i] == '<':
        count_u += 1
    elif S[i] == '>':
        count_l += 1

if count_u < count_l:
    count_u -= 1
else:
    count_l -= 1

ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2

print(int(ans))


Measured memory_bytes: 42824
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> dp(h + 1, vector<int>(w, 0)); dp[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int l = 0; l < 1 << (w - 1); l++) {
                bool ok = true;
                for (int m = 0; m < w - 2; m++) {
                    if (((l >> m) & 1) && ((l >> (m + 1)) & 1)) {
                        ok = false;
                    }
                }
                if (ok) {
                    if (j >= 1 && ((l >> (j - 1)) & 1)) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= MOD;
                    }
                    else if (j <= w - 2 && ((l >> j) & 1)) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= MOD;
                    }
                    else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= MOD;
                    }
                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
    return 0;
}


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

int main()
{
  int64_t n,m;
  cin >> n >> m;
  
  int64_t h[n+1];
  for(int i = 1; i <= n; i++){
    cin >> h[i];
  }
  
  int64_t a[m+1],b[m+1];
  for(int i = 1; i <= m; i++){
    cin >> a[i] >> b[i];
  }
  
  int peek[n+1];
  for(int i = 1; i <= n; i++){
    peek[i] = 1;
  }
  
  for(int i = 1; i <= m; i++){
    if(h[a[i]] > h[b[i]]){
      peek[a[i]] *= 1;
      peek[b[i]] = 0;
    }else if(h[a[i]] == h[b[i]]){
      peek[a[i]] = 0;
      peek[b[i]] = 0;
    }else{
      peek[a[i]] = 0;
      peek[b[i]] *= 1;
    }
  }
  
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(peek[i] == 1){
      ans++;
    }
  }//for
  
  cout << ans << endl;  
  
}

Measured memory_bytes: 6328
import java.util.Scanner;
import java.util.Arrays;

class Main {

  public static void main(String args[]){

    Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
  
        int l = sc.nextInt();

        String tinge[] = new String[n];

     for(int i = 0; i < n; i++){
 
        tinge[i] = sc.next();

      }
          
    Arrays.sort(tinge);
   
        for(String t: tinge){
             System.out.print(t);
        }

        
  }

}

Measured memory_bytes: 10192
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
for i in range(0,N):
    A = list(map(int, input().split()))
    sum = 0
    for i in range(0,M):
        sum += A[i] * B[i]
    if sum + C > 0:
        num += 1
print(num)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll dp[2001][2001][2], n, m;
bool a[2001], b[2001];
unordered_map<bool, int>v;
ll solve(ll i, ll j, bool s) {
	ll sum = 0;
	if (i < n&&a[i] == s) {
		if (dp[i + 1][j][v[!s]] != -1)
			sum = 1 + dp[i + 1][j][v[!s]];
		else
			sum = 1 + (dp[i + 1][j][v[!s]] = solve(i + 1, j, !s));
	}
	if (j < m&&b[j] == s) {
		if (dp[i][j + 1][v[!s]] != -1)
			sum = max(sum, 1 + dp[i][j + 1][v[!s]]);
		else
			sum = max(sum, 1 + (dp[1][j + 1][v[!s]] = solve(i, j + 1, !s)));
	}
	if (sum == 1) {
		if (!s) sum = 0;
	}
	return sum;
}
int main() {
	string u, w;
	v.insert(map<bool, int>::value_type(true, 0));
	v.insert(map<bool, int>::value_type(false, 1));
	while (cin >> n >> m) {
		cin >> u >> w;
		ll sum = 0;
		for (ll i = 0; i < n; i++) {
			if (u[i] == 'I') {
				a[i] = true;
			}
			else a[i] = false;
		}
		for (ll i = 0; i <= n; i++) {
			for (ll j = 0; j <= m; j++) {
				dp[i][j][0] = -1;
				dp[i][j][1] = -1;
			}
		}
		for (ll i = 0; i < m; i++) {
			if (w[i] == 'I') {
				b[i] = true;
			}
			else b[i] = false;
		}
		for (ll i = 0; i < n; i++) {
			for (ll j = 0; j < m; j++) {
				if (a[i]||b[j]) {
					if (dp[i][j][0] != -1) {
						sum = max(sum, dp[i][j][0]);
					}
					else
						sum = max(sum, (dp[i][j][0] = solve(i, j, true)));
				}
			}
		}
		cout << sum << endl;
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  char c = 'a';
  string s;
  cin >> s;
  int ans = 1145141919;
  rep(i, 0, 26) {
    int mx = 0, g = 0;
    rep(j, 0, s.length()) {
      if(s[j] != c) g++;
      else g = 0;
      mx = max(mx, g);
    }
    ans = min(ans, mx);
    c++;
  }
  cout << ans << endl;
}


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

namespace ABC155C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] S = new string[N];
            for(int i = 0; i < N; i++)
            {
                S[i] = Console.ReadLine();
            }
            Array.Sort(S);
            List<int> hyousuu = new List<int>();
            int h = 1;
            for (int i = 1; i < N; i++)
            {
                if (S[i] == S[i - 1])
                {
                    h += 1;
                }
                else
                {
                    hyousuu.Add(h);
                    h = 1;
                }
            }
            hyousuu.Add(h);
            int M = hyousuu.Count();
            int max = hyousuu.Max();
            int[] sum = new int[M+1];
            int s = 0;
            sum[0] = 0;
            for(int i = 1; i <= M; i++)
            {
                s += hyousuu[i-1];
                sum[i] = s;
            }
            for(int i = 0; i < M; i++)
            {
                if (hyousuu[i] == max)
                {
                    Console.WriteLine(S[sum[i]]);
                }
            }
        }
    }
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

long long dp[5][3100][3100];
long long sc[3100][3100];

void solve(long long R, long long C, long long K, std::vector<long long> r_,
           std::vector<long long> c_, std::vector<long long> v) {
    memset(dp, 0, sizeof(dp));
    memset(sc, 0, sizeof(sc));
    rep(i, K) sc[r_[i]-1][c_[i]-1] = v[i];

    dp[0][0][0] = 0;
    dp[1][0][0] = max(0LL, sc[0][0]);
    rep(r, R) rep(c, C) rep(k, 4) {
        dp[k][r][c + 1] = max(dp[k][r][c + 1], dp[k][r][c]);
        dp[k + 1][r][c + 1] = max(dp[k + 1][r][c + 1], dp[k][r][c] + sc[r][c + 1]);
        dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[k][r][c]);
        dp[1][r + 1][c] = max(dp[1][r + 1][c], dp[k][r][c] + sc[r + 1][c]);
    }
    long long ans = 0;
    rep(k, 4) { ans = max(ans, dp[k][R - 1][C - 1]); }
    cout << ans << endl;
}

int main() {
    long long R;
    scanf("%lld", &R);
    long long C;
    scanf("%lld", &C);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> r(K);
    std::vector<long long> c(K);
    std::vector<long long> v(K);
    for (int i = 0; i < K; i++) {
        scanf("%lld", &r[i]);
        scanf("%lld", &c[i]);
        scanf("%lld", &v[i]);
    }
    solve(R, C, K, std::move(r), std::move(c), std::move(v));
    return 0;
}


Measured memory_bytes: 458416
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 1e5;

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

int main()
{
	int n,x;
	cin >> n >> x;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] = abs(x - a[i]);
	}

	int ans = a[0];
	for(int i = 1; i < n; i++){
		ans = gcd(ans,a[i]);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 640
#include <iostream> 
using namespace std; 
int main() {
  long  n; 
  cin >> n; 
  long long total = 0; 
  for (int i = 1; i<= n; i++) {
    if ((i%3 != 0)&&(i%5 != 0) )
      total += i; 
  }
  cout << total; 
}

Measured memory_bytes: 3620
def resolve():
    K = int(input())
    N = 7
    c = 1
    for i in range(10**6):
        if N % K == 0:
            print(c)
            break
        else:
            N = N * 10 + 7
            N %= K
            c += 1
    else:
        print(-1)
resolve()

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define SZ(X) X.size()
#define pii pair<int,int>
#define ALL(X) X.begin(),X.end()

using namespace std;

LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
const int N = 2e5 + 11;
int h, n;
int a[N], b[N], f[N];
int main() {
	ios::sync_with_stdio(false);
	cin >> h >> n;
	for (int i = 1; i <= n; i++)cin >> a[i] >> b[i];
	for (int i = 1; i < N; i++)f[i] = 1e9;
	for (int i = 1; i <= n; i++) {
		for (int j = a[i]; j <= 20000; j++) {
			f[j] = min(f[j], f[j - a[i]] + b[i]);
		}
	}
	int ans = 1e9;
	for (int i = h; i <= 20000; i++) {
		ans = min(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


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

	for (int i = 0; i < n; i++)
	{
		int c = 0;
		for (int j = 0; j < n; j++)
			c += d[i][j];
		cout << c << endl;
	}
}



Measured memory_bytes: 3608
#include <stdio.h>
#define PMAX 100

struct state{
	int place;
	int num;
	struct state *next;
};

struct state *insert(struct state *head, struct state *p){
	if(head == NULL){
		return p;
	}
	if(p->num > head->num || p->num == head->num && p->place < head->place){
		p->next = head;
		head = p;
	}else{
		head->next = insert(head->next, p);
	}

	return head;
}

void print_list(struct state *head, int depth, int m){
	if(head == NULL){return;}
	printf("%d", head->place + 1);
	putchar(depth == m ? '\n' : ' ');
	print_list(head->next, depth+1, m);
}

int main(void){
	int n, m;
	int i, j;
	int tmp;
	int place[PMAX] = {0};
	struct state *head, *p;
	struct state memory[PMAX];
	while(1){
		scanf("%d%d", &n, &m);
		if(n == 0 && m == 0){break;}

		/* input */
		for(i = 0; i < n; i++){
			for(j = 0; j < m; j++){
				scanf("%d",&tmp);
				place[j] += tmp;
			}
		}

		/* sort */
		head = NULL;
		for(i = 0; i < m; i++){
			p = &memory[i];
			p -> num = place[i];
			p -> place = i;
			p -> next = NULL;
			head = insert(head, p);
		}

		/* output */
		print_list(head,1,m);

		/* clear */
		for(i = 0; i < m; i++){
			place[i] = 0;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    if (N >= 1000) {
        cout << "ABD" << endl;
    } else {
        cout << "ABC" << endl;
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<int> a[n];
  int h;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> h;
      a[i].push_back(h);
    }
  }
  int ans = 0;
  for (int k = 0; k < n; k++) {
    int s = 0;
    for (int i = 0; i < m; i++) {
      s += b[i] * a[k][i];
    }
    s += c;
    if (s > 0) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

int N, M, Q, ans;
vector<int> a, b, c, d;

void dfs(vector<int> &A) {
  if (int(A.size()) == N + 1) {
    int res = 0;
    for (int i = 0; i < Q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        res += d[i];
      }
    }
    ans = max(ans, res);
    return;
  }
  int tail = A.back();
  for (int add_elem = tail; add_elem <= M; add_elem++) {
    A.push_back(add_elem);
    dfs(A);
    A.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  a = b = c = d = vector<int>(Q);

  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector<int> v(1, 1);
  dfs(v);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
import numpy as np

from bisect import bisect_left

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

cum_A = np.cumsum(A)
cum_B = np.cumsum(B)

# print(cum_A, cum_B)

ans = 0
# idx_b = M

# for idx_a in range(N + 1):


for idx_a in range(N + 1):
    if A[idx_a] > K:
        break

    b = K - cum_A[idx_a]
    idx_b = min(bisect_left(cum_B, b), M)
    if cum_A[idx_a] + cum_B[idx_b] > K:
        idx_b -= 1
    if idx_b < 0:
        break
    ans = max(ans, idx_a + idx_b)
    # print(b, idx_a, idx_b, ans)

print(ans)


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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=jp

int CoinChangingProblem(int n,int m,vector<int> c) {
  vector<int> dp(n+1,INT_MAX);
  dp[0] = 0;
  for(int i=0;i<m;++i) {
    for(int j=0;j+c[i]<=n;++j) if( dp[j] != INT_MAX ) {
      dp[j+c[i]] = min(dp[j+c[i]],dp[j]+1);
    }
  }
  return dp[n];
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> c(m);
  for(int i=0;i<m;++i) cin >> c[i];
  cout << CoinChangingProblem(n,m,c) << endl;
  return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    unsigned long long int n;
    unsigned long long int a;
    unsigned long long int b;
    unsigned long long int c;
    unsigned long long int mod;
    int result;

    result = scanf("%llu", &n);
    result = scanf("%llu", &a);
    result = scanf("%llu", &b);
    c = (n / (a + b)) * a;
    mod = n % (a + b);
    if (mod < a)
      c = c + mod;
    else
      c = c + a;
    printf("%llu", c);
    return (0);
}


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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll n;
    cin >> n;

    if (n%2 == 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll t = 1;
    n /= 2;

    while (t <= n){
        t *= 5;
        ans += n/t;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
 
      if(N%2==0){
    System.out.println(N);
      }else{
	System.out.println(N*2);
      }
      }
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;

namespace AizuOnLine
{
    class Program
    {

        static void Main(string[] args)
        {
            //???????????????
            int n = Convert.ToInt32(Console.ReadLine());
            var hash = new HashSet<string>();

            for (int i = 0; i < n; i++)
            {
                string card = Console.ReadLine();
                hash.Add(card);
            }

            foreach (string symbol in new string[] { "S", "H", "C", "D" })
            {
                for (int num = 1; num <= 13; num++)
                {
                    string card = symbol + " " + num.ToString();

                    if (!hash.Contains(card))
                    {
                        Console.WriteLine(card);
                    }
                }
            }

        }
    }
}

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

int n, m, ans;
bool G[10][10];
bool used[10];

int dfs(int num, bool used[]){
    
    // 全てused
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(used[i]) cnt++;
    }
    if(cnt == n){
        return 1;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){

        // num - iパスがない or もう通った -> continue
        if(!(G[num][i]) or used[i]){
            continue;
        }

        // 通るで
        used[i] = true;
        ans += dfs(i, used);
        
        // 通ったで
        used[i] = false;
    }
    return ans;
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b] = true;
        G[b][a] = true;
    }

    used[0] = true;

    cout << dfs(0, used) << endl;

    return 0;
}

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

using namespace std;

bitset<4000000>D;


int main(){
    int N, A, S = 0;
    D[0] = 1;
    cin >> N;
    for(int i=0; i<N; i++) {
        scanf("%d", &A);
        D |= D << A;
        S += A;
    }

    for(int i=(S+1)/2;;i++) {
        if(D[i]) {
            printf("%d\n", i);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
n = int(input())
li_a = list(map(int, input().split()))

if 0 in li_a:
    print(0)
    exit(0)
w = li_a[0]
for a in li_a[1:]:
    w = w * a
    if w > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(w)
    exit(0)


Measured memory_bytes: 21636
#include <stdio.h>
int main(){
  int a, b;

  scanf("%d", &a );
  scanf("%d", &b );
  int tmp = a + b;
  
  if ( tmp < a - b){
    tmp = a - b;
  }
  if ( tmp < a * b ){
      tmp = a * b;
  }
  printf( "%d\n", tmp ); 
 
  return 0;
}

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

int main(){
int a[15][200]{};
a[0][0]=1;
for(int b=0;b<=9;b++){
	for(int c=100;c>=b;c--){
		for(int d=10;d!=0;d--){
			a[d][c]+=a[d-1][c-b];
		}
	}
}
int x,y;
while(cin>>x>>y,x|y){
	printf("%d\n",a[x][y]);
}
}

Measured memory_bytes: 3108
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")
 
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on
 
int main() {
    fastio();

    string S, T;
    cin >> S >> T;
    
    int match = 0;
    for (int i = 0 ; i < S.length() - T.length() + 1 ; i++) {
        int now = 0;
        for (int j = 0 ; j < T.length() ; j++) {
            if (T[j] == S[i + j])
                now++;
        }

        match = max(now, match);
    }

    cout << T.length() - match << endl;
    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;

    vector<int> sub(N, 0);
    for (int i = 1; i < N;++i)
    {
        int A;
        cin >> A;
        ++sub[A - 1];
    }

    for(auto p:sub)
        cout << p << endl;
}

Measured memory_bytes: 4056
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){	
	ll l,r;
	cin>>l>>r;
	ll ans=2020;
	ll MOD=2019;

	if(r-l>=2019)ans=0;
	else if(r%MOD<=l%MOD)ans=0;
 else {
		for(ll i=l;i<r;++i){
			for(ll j=l+1;j<=r;++j){
				ans=min((i%MOD*j%MOD)%MOD,ans);
				ans%=MOD;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
def sum_of_dig(n):
    s = str(n)
    l = len(s)
    return sum(int(s[i]) for i in range(l))

N = int(input())
ans = sum_of_dig(N//2)+sum_of_dig(N-N//2)
for A in range(1, N//2):
    tmp = sum_of_dig(A)+sum_of_dig(N-A)
    if ans > tmp:
        ans = tmp
else:
    print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>

bool sort_pair( std::pair< int, int > origin, std::pair< int, int > another )
{
    return origin.first < another.first;
}

int main()
{
    int a,b;
    std::cin>> a;
    std::cin>> b;

    std::vector< long int > value( a, 0 );
    std::vector< std::pair< int, int > > tree( a - 1 );

    int d,e,f,g;

    for( int i = 0; i < a - 1; i++ )
    {
        std::cin>> d;
        std::cin>> e;
        tree[i].first = d;
        tree[i].second = e;
    }

    for( int i = 0; i < b; i++ )
    {
        std::cin>> f;
        std::cin>> g;
        value[ f - 1 ] += g;
    }


    std::sort( tree.begin(), tree.end(), sort_pair );

    for( int i = 0; i < a - 1; i++ )
    {
        value[ tree[i].second - 1 ] += value[ tree[i].first - 1 ];
    }


    
    for( int i = 0; i < a; i++ )
    {
        std::cout<< value[i] <<" ";
    }
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string> v(3);
  rep(i,3) cin>>v[i];
  string ans;
  rep(i,3) ans+=(v[i])[i];
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define repn(i,n) for(int i=1; i<=n; i++)
int main(){
int N; cin>>N;
vector<int> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int c[5] = {}; // 74, 24, 14, 4, 2
for(auto& p : prime){
int k = N/p; int cnt = 0;
while(k!=0){
cnt+=k;
k = k / p;
}
if(cnt>=74) c[0]++;
else if(cnt>=24) c[1]++;
else if(cnt>=14) c[2]++;
else if(cnt>=4) c[3]++;
else if(cnt>=2) c[4]++;
}
repn(i, 4) c[i]+=c[i-1];
int ans = c[0] + c[1]*(c[4]-1) + c[2]*(c[3]-1) + c[3]*(c[3]-1)*(c[4]-2)/2;
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,c;
  cin>>n>>m>>c;
  vector<int> B(m);
  for(int i=0;i<m;i++)cin>> B[i];
  vector<vector<int>> A(n,vector<int> (m));
 for(int i=0;i<n;i++){
 for(int j=0;j<m;j++){
 cin>>A[i][j];
 
 }
 }
  int count=0;
  int sum=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(j !=m-1){sum += (A[i][j] * B[j]);}
        else{
          sum += (A[i][j] * B[j]);
          if(sum + c > 0){
        count++;
        sum=0;}
             else{sum=0;}
           
            
       }
      
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,m,arr[100000],a,b;
     cin>>t>>m;
     for(int i=1;i<=t;i++) arr[i]=0;
     while(m--)
     {
         cin>>a>>b;
         arr[a]++,arr[b]++;
     }
     for(int i=1;i<=t;i++)
        cout<<arr[i]<<endl;
}



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

const int Size=8;
char coma[2]={'o','x'};

bool isRange(int i){
  return 0<=i && i< Size;
}
bool isRange(int i,int j){
  return isRange(i) && isRange(j);
}

int inc(int &i){return ++i;};
int decr(int &i){return --i;};
int dx[8]={1,1,1,-1,-1,-1,0,0};
int dy[8]={1,0,-1,1,0,-1,1,-1};

int check(int i,int j,vector<string> &s,int turn){
  if(s[i][j]!='.') return -1;
  int res=0;
  for(int dir=0;dir<8;dir++){
    for(int k=1;k<Size;k++){
      int tox=i+dx[dir]*k;
      int toy=j+dy[dir]*k;
      if(!isRange(tox,toy)){
	break;
      }
      if(s[tox][toy]==coma[turn]){
	res+=k-1;
	break;
      }
      else if(s[tox][toy]=='.'){
	break;
      }
    }

  }
  return res;
}

void game(vector<string> &s,int turn){
  int start_h=turn*(Size-1);
  int start_w=turn*(Size-1);
  auto op=decr;
  if(turn==0){
    op=inc;
  }
  int max_put=0;
  pair<int,int> res;
  for(int i=start_h;isRange(i);op(i)){
    for(int j=start_w;isRange(j);op(j)){
      int cnt=check(i,j,s,turn);
      if(cnt>max_put){
	max_put=cnt;
	res=make_pair(i,j);
      }
    }
  }
  if(max_put==0) return;
  s[res.first][res.second]=coma[turn];
  for(int i=0;i<8;i++){
    for(int j=1;j<Size;j++){
      int tox=res.first+dx[i]*j;
      int toy=res.second+dy[i]*j;
      if(!isRange(tox,toy)) break;
      if(s[tox][toy]==coma[turn]){
	for(;j>=1;j--){
	  int x=res.first+dx[i]*j;
	  int y=res.second+dy[i]*j;
	  s[x][y]=coma[turn];
	}
	break;
      }
      else if(s[tox][toy]=='.'){
	break;
      }
    }
  }
  return;
}

int main(){
  vector<string> s(Size);
  for(int i=0;i<Size;i++){
    cin>>s[i];
  }

  for(int i=0;i<Size*Size;i++){
    game(s,i%2);
  }
  for(int i=0;i<Size;i++){
    cout<<s[i]<<endl;
  }
  return 0;
}

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

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            long N = IO.ReadLineToLong();
            var A = new List<List<long>>();

            A.Add(IO.ReadLineToLongList());
            A.Add(IO.ReadLineToLongList());

            long max = 0;
            for(int J = 0; J < N; J++)
            {
                long sum = 0;
                for(int j = 0; j <= J; j++)
                {
                    sum += A[0][j];
                }
                for(int j = J; j < N; j++)
                {
                    sum += A[1][j];
                }
                max = Math.Max(max, sum);
            }



            //ここまで

            Console.WriteLine(max);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static public long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(long n,long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
struct UnionFind{
  vector<int> p;
  int g;
  void init(int n){
    p = vector<int>(n, -1);
    g = n;
  }
  int find(int a){
    return p[a] < 0 ? a : p[a] = find(p[a]);
  }
  bool merge(int a, int b){
    a = find(a);
    b = find(b);
    if(a == b) return 0;
    g--;
    if(p[a] > p[b]) swap(a, b);
    p[a] += p[b];
    p[b] = a;
    return 1;
  }
} uf;
int n, m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  uf.init(n);
  FOR(i, 0, m){
    int x, y, z;
    cin >> x >> y >> z;
    uf.merge(--x, --y);
  }
  cout << uf.g << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,N,M,a,b,anssize=inf;
  cin>>N>>M;
  mat v(N);
  vec ans;
  rep(i,M){
    cin>>a>>b;
    a--;b--;
    v[a].pb(b);
  }
  rep(i,N){
    vec res,dist(N,inf),turn(N,-1);
    queue<ll> que;
    for(auto j:v[i]){
      que.push(j);
      turn[j]=i;
      dist[j]=1;
    }
    while(!que.empty()){
      auto x=que.front();que.pop();
      if(x==i)break;
      for(auto j:v[x]){
        if(dist[j]!=inf)continue;
        dist[j]=dist[x]+1;
        turn[j]=x;
        que.push(j);
      }
    }
    if(dist[i]>=anssize)continue;
    res.pb(i);
    ll now=turn[i];
    while(now!=i){
      res.pb(now);
      now=turn[now];
    }
    ans=res;anssize=dist[i];
  }
  if(anssize>N){
    cout<<-1<<endl;
  }else{
    cout<<anssize<<endl;
    for(auto i:ans)cout<<i+1<<endl;
  }
  return 0;
}

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

int digitSum(int x) {
    int sum = 0;
    while(x > 0) {
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int main()
{
  int N;
  cin>>N;
  
  if (N%digitSum(N) == 0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int X, A, B;
    cin >> X >> A >> B;
    if (A >= B) {
        cout << "delicious" << endl;
    } else if (B - A <= X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n; cin >> n;
  vector<ll> hoge(n);
  rep_i(i, n){
    cin >> hoge[i];
  }
  d_sort_vll(hoge);

  ll m1 = 0;
  ll m2 = 0;
  int i = 0;
  while (i < n){
    if(m1 == 0){
      if(hoge[i] == hoge[i+1]){
        m1 = hoge[i];
        i += 2;
      }else{
        i += 1;
      }
      continue;
    }
    if(m2 == 0){
      if(hoge[i] == hoge[i+1]){
        m2 = hoge[i];
        i += 2;
      }else{
        i += 1;
      }
      continue;
    }
    if(m1 != 0 && m2 != 0){
      break;
    }
  }
  ll ans = m1*m2;
  cout << ans << endl;
}

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

int main(){
    // あとで消す
    //std::ifstream in("cin5.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N ;
    int count=0;
    int minv = 2147483647;
    int tmpv;

    for(size_t i=0;i<N;i++){
        cin >> tmpv;
        if(minv>tmpv){
            count+=1;
            minv = tmpv;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256