akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans=inf;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	for (int i=0; i<n; i++) cin>>A[i];
	for (int i=0, j=k-1; j<n; i++, j++){
		if (A[i]<=0 && 0<=A[j]) ans=min(ans, min(A[j]-2*A[i], 2*A[j]-A[i]));
		if (0<=A[i] && 0<=A[j]) ans=min(ans, A[j]);
		if (0>=A[i] && 0>=A[j]) ans=min(ans, -A[i]);
	}
	cout<<ans<<'\n';
	
	return 0;
}
/*
          .---.                                                                     .---.              ...-'  |`. ..-'''-.       / .--. \        .-''-.
          |   |.--.                       .                     .                   |   |.--.          |      |  |\.-'''\ \     ' '    ' '     .' .-.  )
          |   ||__|                     .'|                   .'|                   |   ||__|          ....   |  |       | |    \ \    / /    / .'  / /
          |   |.--.                    <  |                  <  |                   |   |.--.            -|   |  |    __/ /      `.`'--.'    (_/   / /
    __    |   ||  |                     | |             __    | |             __    |   ||  |             |   |  |   |_  '.      / `'-. `.        / /
 .:--.'.  |   ||  |                 _   | | .'''-.   .:--.'.  | | .'''-.   .:--.'.  |   ||  |          ...'   `--'      `.  \   ' /    `. \      / /
/ |   \ | |   ||  |               .' |  | |/.'''. \ / |   \ | | |/.'''. \ / |   \ | |   ||  |          |         |`.      \ '. / /       \ '    . '
`" __ | | |   ||  |              .   | /|  /    | | `" __ | | |  /    | | `" __ | | |   ||  |          ` --------\ |       , || |         | |  / /    _.-')
 .'.''| | |   ||__|            .'.'| |//| |     | |  .'.''| | | |     | |  .'.''| | |   ||__|           `---------'        | || |         | |.' '  _.'.-''
/ /   | |_'---'              .'.'.-'  / | |     | | / /   | |_| |     | | / /   | |_'---'                                 / ,' \ \       / //  /.-'_.'
\ \._,\ '/                   .'   \_.'  | '.    | '.\ \._,\ '/| '.    | '.\ \._,\ '/                              -....--'  /   `.'-...-'.'/    _.'
 `--'  `"                               '---'   '---'`--'  `" '---'   '---'`--'  `"                               `.. __..-'       `-...-'( _.-'
*/


Measured memory_bytes: 640
function Main(input) {
  input = input.split("\n");
  const a = parseInt(input[0],10);
  const b = parseInt(input[1],10);
  const c = parseInt(input[2],10);
  const x = parseInt(input[3],10);
  let ans = 0;
  for (var a_i = 0; a_i < a + 1; a_i++) {
    for (var b_i = 0; b_i < b + 1; b_i++) {
      for (var c_i = 0; c_i < c + 1; c_i++) {
        if (x === (500*a_i + 100 * b_i + 50*c_i)) {
          ans++;
        }
      }
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32468
import sys
input = sys.stdin.readline

n,k=map(int, input().split()) 
a=list(map(int, input().split()))
mod=10**9+7
dp=[[0]*(k+1) for i in range(n+1)]

for i in range(n+1):
    dp[i][0]=1



for i in range(1,n+1):
    for j in range(1,k+1):
        if j-1-a[i-1]>=0:
            dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1-a[i-1]])%mod
        
        else:
            dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod

print(dp[-1][-1]%mod)
    
    

Measured memory_bytes: 119532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[] kosu=new int[100001];
		long[][] aa=new long[M][3];
		for(int i=0; i<=100000; i++) {
			kosu[i]=0;
		}
		for(int i=0; i<M; i++) {
			long a=sc.nextLong();
			long b=sc.nextLong();
			kosu[(int)a]++;
			aa[i][0]=a*10000000000L+b;
			aa[i][1]=i;
		}
		for(int i=1; i<=100000; i++) {
			kosu[i]=kosu[i-1]+kosu[i];
		}
		quick_sort(aa,0,M-1);
		for(int i=0; i<M; i++) {
			aa[i][2]=i+1;
		}
		long[][] ansss=new long[M+1][2];
		for(int i=0; i<M; i++) {
			ansss[(int)aa[i][1]][0]=aa[i][0];
			long ban=aa[i][0]/10000000000L;
			ansss[(int)aa[i][1]][1]=aa[i][2]-kosu[(int)ban-1];
		}
		String unti="";
		String buri="";
		for(int i=0; i<M; i++) {
			long aaaa=ansss[i][0]/10000000000L;
			unti=String.format("%06d", (int)(aaaa));
			buri=String.format("%06d", (int)(ansss[i][1]));
			System.out.println(unti+buri);
		}
	}
	static void quick_sort(long[][] d, int left, int right) {
		if (left>=right) {
			return;
		}
		long p = d[(left+right)/2][0];
		int l = left, r = right;
		long tmp,tmp1,tmp2;
		while(l<=r) {
			while(d[l][0] < p) { l++; }
			while(d[r][0] > p) { r--; }
			if (l<=r) {
				tmp = d[l][0]; d[l][0] = d[r][0]; d[r][0] = tmp;
				tmp1=d[l][1]; tmp2=d[r][1]; d[l][1]=tmp2; d[r][1]=tmp1;
				l++; r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}

	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 114152
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            break
        if x[j] == y[z[i][j]]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order:
            print('Yes')
            break
        if (z[i][3] == 0 or z[i][3] == 3) and sum(order) % 2:
            print('Yes')
            break
        if z[i][3] == 1 and not sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Measured memory_bytes: 7716
from sys import stdin
import numpy as np
from fractions import gcd


# noinspection PyShadowingBuiltinsInspection

def lcm(x, y):
    return (x * y) // gcd(x, y)

def main():
    N, M = [int(x) for x in input().split()]
    a = sorted(list({int(x) for x in input().split()}), reverse=True)
    x = a[0]
    p2 = 1
    while x % 2 == 0:
        p2 *= 2
        x //= 2
    flag = False
    y = 1 # a//2 の最小公倍数
    for i in range(len(a)):
        if a[i] % p2 != 0 or (a[i] // p2) % 2 == 0:
            flag = True
            break
        a[i] //= 2
        y = lcm(a[i], y)
    if flag:
        return 0
    z = M // y
    return z // 2 if z % 2 == 0 else z // 2 + 1
    # b = [a[0]]
    # for i in range(1, len(a)):
    #     flag = False
    #     for x in b:
    #         if x % a[i] == 0:
    #             flag = True
    #             break
    #     if not flag:
    #         b.append(a[i])
    # # print(b)
    # y = 1
    # for x in b:
    #     # print(b)
    #     y *= x
    # z = M // y
    # # print(y, z*y)
    # ret = z // 2 if z % 2 == 0 else z // 2 + 1
    # # print(ret)
    #
    # return ret


if __name__ == "__main__":
    print(main())

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  // priority_queue<int> a;
  // for (int i = 0; i < n; i++) {
  //   int j;
  //   cin >> j;
  //   a.push(j);
  // }

  // int bob = 0, alice = 0;
  // for (int i = 0; i < n; i++) {
  //   if (i % 2 == 0) {
  //     alice += a.top();
  //   } else {
  //     bob += a.top();
  //   }
  //   a.pop();
  // }

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());

  int alice = 0, bob = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      alice += a[i];
    } else {
      bob += a[i];
    }
  }

  cout << alice - bob << endl;

  return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
  ll ret=1;
  ll left=MOD-2;
  ll ks=a;
  while(left>0)
  {
    if(left%2==1)
    {
      ret=(ret*ks)%MOD;
    }
    ks=(ks*ks)%MOD;
    left/=2;
  }
  return ret;
}

int main()
{
  string s;cin>>s;
  vector<ll> dp(s.size()+1,0);
  dp[0]=0;
  int i;
  ll bef1s=1;
  ll n3=1;
  ll ks=3;
  ll left=s.size()-1;
  while(left>0)
  {
    if(left%2==1)
    {
      n3=(n3*ks)%MOD;
    }
    left/=2;
    ks=(ks*ks)%MOD;
  }
  rep(i,s.size()-1)
  {
    if(i==0)
    {
      dp[i+1]=n3;
      bef1s=(bef1s*2)%MOD;
    }
    else if(s[i]=='0')
    {
      dp[i+1]=dp[i];
    }
    else
    {
      dp[i+1]=(dp[i]+bef1s*n3)%MOD;
      bef1s=(bef1s*2)%MOD;
    }
    n3=(n3*mod_inv(3))%MOD;
  }
  if(s[s.size()-1]=='0')
  {
    dp[s.size()]=(dp[s.size()-1]+bef1s)%MOD;
  }
  else
  {
    dp[s.size()]=(dp[s.size()-1]+bef1s*3)%MOD;
  }
  
  cout<<dp[s.size()]<<endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>

using namespace std;

int N;
string S[110000];

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

  int ac=0,wa=0,tle=0,re=0;

  for(int i=0;i<N;i++){
    if(S[i]=="AC") ac++;
    if(S[i]=="WA") wa++;
    if(S[i]=="TLE") tle++;
    if(S[i]=="RE") re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;

}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    char n[3];
    rep(i,3){
    cin>>n[i];
    }
    char ans=n[0]+1;
    if(n[0]==n[1]&&n[1]==n[2]){
     cout<<n[0]<<n[1]<<n[2]<<endl;
    }
    else if(n[0]>n[1]||(n[0]==n[1]&&n[0]>n[2])){
      cout<<n[0]<<n[0]<<n[0]<<endl;
    }
      else{
        cout<<ans<<ans<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;

  int main(){
    int n,m,x,y;cin>>n>>m>>x>>y;
    int s=-1e5,t=1e5;
    string p="War";
    for(int i=0;i<n;i++)
    {
      int a;cin>>a;
      s=max(s,a);
    }
    for(int i=0;i<m;i++)
    {
      int b;cin>>b;
      t=min(t,b);
    }
    for(int i=x+1;i<=y;i++)
    {
      if(s<i && i<=t)
        p="No War";
    }
    cout<<p;
  }
        
      

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	if (k == 1)
		cout << 0 << endl;
	else
		cout << n - k << endl;

	return 0;
}


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

int main(){
  string str;

  cin >> str;

  int x = 753;
  for(int i=0; i<str.size() - 2; ++i){
    int y = (str[i] - '0') * 100;
    y += (str[i+1] - '0') * 10;
    y += (str[i+2] - '0');
    x = (x > abs(753 - y) ? abs(753 - y) : x);
  }

  cout << x << endl;
}


Measured memory_bytes: 256
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define INT INT_MAX
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int N = 1e5 + 10;
int n;
int a[N], b[N], c[N];

// 1. Backtrack Solution = 2^N Time
int Backtrack(int i, int prev_choice = 0) {
    // Base Cases
    if(i == n) {
        if(prev_choice == 0) return max({a[i], b[i], c[i]});
        if(prev_choice == 1) return max(b[n], c[n]);
        if(prev_choice == 2) return max(a[n], c[n]);
        if(prev_choice == 3) return max(a[n], b[n]);
    }
    // Choice
    int h1 = INT_MIN, h2 = INT_MIN, h3 = INT_MIN;
    if(prev_choice != 1)
        h1 = a[i] + Backtrack(i+1, 1);
    if(prev_choice != 2)
        h2 = b[i] + Backtrack(i+1, 2);
    if(prev_choice != 3)
        h3 = c[i] + Backtrack(i+1, 3);

    return max({h1, h2, h3});
}

// 2. Top-Down Solution = Remove read-only arguments and redundant arguments
// and cache the results
// Time = (Range of possible values of the variable arguments) * (Time Compl of each function call)
// O(N*K) time
int dp[N][4];
int Top_Down(int i, int prev_choice=0) {
    // Base Cases
    if(i == n) {
        if(prev_choice == 0) return max({a[n], b[n], c[n]});
        if(prev_choice == 1) return max(b[n], c[n]);
        if(prev_choice == 2) return max(a[n], c[n]);
        if(prev_choice == 3) return max(a[n], b[n]);
    }
    if(dp[i][prev_choice] != -1)
        return dp[i][prev_choice];
    // Choice
    int h1 = INT_MIN, h2 = INT_MIN, h3 = INT_MIN;
    if(prev_choice != 1)
        h1 = a[i] + Top_Down(i+1, 1);
    if(prev_choice != 2)
        h2 = b[i] + Top_Down(i+1, 2);
    if(prev_choice != 3)
        h3 = c[i] + Top_Down(i+1, 3);

    return (dp[i][prev_choice] = max({h1, h2, h3}));
}

// // 3. Bottom-Up Solution
// int Bottom_Up() {
//     dp[n] = 0;
//     dp[n+1] = INT_MAX;
//     for(int i = n - 1; i >= 1; --i) {
//         int cost1 = dp[i+1] + abs(height[i+1] - height[i]);
//         int cost2 = dp[i+2] + abs(height[i+2] - height[i]);        
//         dp[i] = min(cost1, cost2);
//     }
//     return dp[1];
// }


int32_t main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; ++i) {cin >> a[i]; cin >> b[i]; cin >> c[i];}
    cout << Top_Down(1) << endl;
}

Measured memory_bytes: 12032
n = gets.chomp.to_i
x = gets.chomp.split.map(&:to_i)

ans = 10 ** 15
1.upto(100) do |i|
  tmp = 0
  x.each do |xx|
    tmp += (i-xx) ** 2
  end
  ans = [ans, tmp].min
end
p ans


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

struct L {
  int a, b, c;
  L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
vector<L> lh, lv;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mpx, mpy;
  mpx[0] = 0, mpy[0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    mpx[a] = 0, mpx[b] = 0, mpy[c] = 0;
    lh.emplace_back(a, b, c);
  }
  rep(i, m) {
    int a, b, c;
    cin >> c >> a >> b;
    mpy[a] = 0, mpy[b] = 0, mpx[c] = 0;
    lv.emplace_back(a, b, c);
  }
  vector<int> xs, ys;
  for (auto &it : mpx) {
    it.second = xs.size();
    xs.push_back(it.first);
  }
  for (auto &it : mpy) {
    it.second = ys.size();
    ys.push_back(it.first);
  }

  int h = ys.size() * 2;
  int w = xs.size() * 2;
  vector<vector<int>> d(h, vector<int>(w));
  for (auto l : lh) {
    for (int i = mpx[l.a] * 2; i <= mpx[l.b] * 2; i++)
      d[mpy[l.c] * 2][i] = -1;
  }
  for (auto l : lv) {
    for (int i = mpy[l.a] * 2; i <= mpy[l.b] * 2; i++)
      d[i][mpx[l.c] * 2] = -1;
  }
  queue<pair<int, int>> to_visit;
  int x = mpx[0] * 2, y = mpy[0] * 2;
  d[y][x] = 1;
  to_visit.push(make_pair(x, y));
  ll sum = 0;
  if (x % 2 == 1 && y % 2 == 1) {
    sum += (ll)(xs[(x + 1) / 2] - xs[(x - 1) / 2]) * (ll)(ys[(y + 1) / 2] - ys[(y - 1) / 2]);
  }
  bool inf = false;
  while (!to_visit.empty()) {
    x = to_visit.front().first;
    y = to_visit.front().second;
    if (x <= 0 || w - 1 <= x || y <= 0 || h - 1 <= y) {
      //cout << "INF" << endl;
      inf = true;
      break;
    }
    to_visit.pop();
    rep(i, 4) {
      int xx = x + dx[i], yy = y + dy[i];
      if (d[yy][xx] == -1 || d[yy][xx] == 1) continue;
      d[yy][xx] = 1;
      if (xx % 2 == 1 && yy % 2 == 1) {
        sum += (ll)(xs[(xx + 1) / 2] - xs[(xx - 1) / 2]) * (ll)(ys[(yy + 1) / 2] - ys[(yy - 1) / 2]);
      }
      to_visit.push(make_pair(xx, yy));
    }
  }
  if (inf)
    cout << "INF" << endl;
  else
    cout << sum << endl;
  return 0;
}

Measured memory_bytes: 144368
/*

        /////////     /////        ////      ////
        //           //   //      //   //  // //
        //////      //    //     //     //   //
            //     // /// //    //          //
      ////////    //      //   //          //
*/

#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,s,n) for(int i=s;i<n;i++)
#define pb(x) push_back(x);
#define Mod 1000000007

void solve(int n,int h[])
{
    ll dp[n+1]={INT_MAX};
    //dp[0]=h[0];
    dp[0]=0;//abs(h[1]-h[0]);
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    }
    //fo(i,0,n)
    //    cout<<dp[i]<<" ";
    cout<<dp[n-1];
}

int main()
{
    Fast
    int n;
    cin>>n;
    int h[n];
    fo(i,0,n)
        cin>>h[i];
    solve(n,h);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

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

	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<ll> sum(n + 1);
	sum[0] = 0;
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		sum[i + 1] = a[i] + sum[i];
	}
	for (int i = 0; i <= n; i++) {
		int now = sum[i] % m;
		mp[now]++;
	}
	ll ans = 0;
	for (auto p : mp) {
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define maxs 200202
#define mme(i,j) memset(i,j,sizeof(i))
#define LL long long
#define mod 1000000007
using namespace std;
LL fa[maxs];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
       mme(fa,0);
       for(int i=2;i<=n;i++){
            int k = i;
            for(int j=2;j<=k;j++){
                while( k%j==0){
                    fa[j]++;
                    k/=j;
                }
            }
            if(k) fa[k]++;
       }
            LL sum=1;

            for(int i=2;i<=n;i++)
            {
                if(fa[i])
                    sum = ( sum*(fa[i]+1) +mod)%mod;
            }

            printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	
	static int n;
	static String [] s;
	static int[] c;
	static ArrayList<Character> list=new ArrayList<>();
	static boolean[] used;
	static boolean[] begin;
	
	static int dfs(int now) {
		int count=0;
		if(now==list.size()) {
			int sum=0;
			int[] sumn=new int[n];
			for(int i=0; i<n-1; i++) {
				for(int j=0; j<s[i].length(); j++) {
					sumn[i]+=c[s[i].charAt(j)-'A'];
					sumn[i]*=10;
				}
				sumn[i]/=10;
			}
			for(int i=0; i<n-1; i++) {
				//System.out.println(s[i]+" "+sumn[i]);
				sum+=sumn[i];
			}
			int ans=0;
			for(int j=0; j<s[n-1].length(); j++) {
				ans+=c[s[n-1].charAt(j)-'A'];
				ans*=10;
			}
			//System.out.println(s[n-1]+" "+ans/10);
			if(sum==ans/10) return 1;
			else return 0;
		}
		for(int i=0; i<=9; i++) {
			if(i==0 && begin[list.get(now)-'A']) continue;
			if(used[i]) continue;
			used[i]=true;
			c[list.get(now)-'A']=i;
			count+=dfs(now+1);
			used[i]=false;
		}
		return count;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				n=sc.nextInt();
				if(n==0) break;
				s=new String[n];
				c=new int[27];
				used=new boolean[10];
				begin=new boolean[27];
				boolean[] t=new boolean[27];
				for(int i=0; i<n; i++) {
					s[i]=sc.next();
					if(s[i].length()>1) begin[s[i].charAt(0)-'A']=true;
					for(int j=0; j<s[i].length(); j++) {
						if(! t[s[i].charAt(j)-'A']) {
							t[s[i].charAt(j)-'A']=true;
							list.add(s[i].charAt(j));
						}
					}
				}
				System.out.println(dfs(0));
				list.clear();
			}
			

		}
	}
}


Measured memory_bytes: 112128
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
count=0

h,w=map(int,input().split())
ans=[[0]*w for i in range(h)]
n=int(input())
A=list(map(int,input().split()))
now=0
for i in range(h):
    for j in range(w):
        a=j
        if i%2==1:
            j=w-j-1
        if not A[now]:
            now+=1
        A[now]-=1
        ans[i][j]=now+1
        j=a
        # print(now)
for a in ans:
    print(*a)
# print(A)
            
        
        

Measured memory_bytes: 42608
#include <iostream>
#include <stdio.h>
#include <set>
#include<bits/stdc++.h>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
double dp[3000 ][3000];
int main(){
    int n;
    cin>>n;
    vector <double> v;
    v.push_back(0);
    for(int i = 0;i<n;i++){
        double z;
        cin>>z;
        v.push_back(z);
    }
    dp[1 ][1] = v[1];
    dp[1][0] = 1 - v[1];
    for(int i = 1;i<=n-1;i++){
        for(int j = 0;j<=i;j++){
            dp[i+1][j+1]+= dp[i][j]*v[i+1];
            dp[i+1][j]+= dp[i][j]*(1-v[i+1] );
        }
    }
    double answer = 0;
    for(int i = n/2+1;i<=n;i++){
        answer+= dp[n][i];
    }
    cout<<setprecision(12)<<answer;
}


Measured memory_bytes: 68992
a,b=['light fly', 'fly', 'bantam', 'feather', 'light', 'light welter','welter', 'light middle', 'middle', 'light heavy', 'heavy'],[48, 51, 54, 57, 60, 64, 69, 75, 81, 91]
while 1:
    try:
        c = float(input())
    except:break
    for i in range(10):
        if c <= b[i]:
            print(a[i])
            break
    else: print(a[10])


Measured memory_bytes: 5580
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int A[][] = new int[2][N];
		int sum = 0;
		for(int i=0;i<2;i++){
			for(int j=0;j<N;j++){
				A[i][j] = scan.nextInt();
				if(i==1) sum += A[i][j];
			}
		}
		sum += A[0][0];
		int S[] = new int[N];
		S[0] = sum;
		for(int i=1;i<N;i++){
			sum = sum - A[1][i-1] + A[0][i];
			S[i] = sum;
		}
		Arrays.sort(S);
		System.out.println(S[N-1]);
	}
}


Measured memory_bytes: 21844
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n) for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
/*ビットxにi番目のフラグが立っているかどうか
if(x & (1 << i))
↑ a << b == a*pow(b,2)
/*{0, 1, ..., n-1} の部分集合の全探索
for (int bit = 0; bit < (1 << n); ++bit)
*/

int main(){
  string s;  cin >> s;
  if(s == "Sunny"){
    cout << "Cloudy";
  }else if(s == "Cloudy"){
    cout << "Rainy";
  }else if(s == "Rainy"){
    cout << "Sunny";
  }
  
}

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


int main(){
  int x=0;
  int n;
 char s[4];
  scanf("%d",&n);
    if(n%2==0){
      printf("%d",n);
    }else{
      printf("%d",2*n);
    }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();

		if(x>=30) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35756
//
// Created by Yoshiki Shino on 2018/07/01.
//

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    string S, T;
    cin >> S >> T;

    string result = "No";

    for (int i = 0; i < S.length(); ++i) {
        for (int j = 0; j < S.length(); ++j) {
            if (S[(i + j) % S.length()] == T[j]) {
                if (j == S.length() - 1) result = "Yes";
                continue;
            } else {
                break;
            }
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
// use proconio::input;
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

fn main() {
    let n = read_vec::<i64>();
    let a = read_vec::<i64>();

    println!("{} {} {}", a.iter().min().unwrap(), a.iter().max().unwrap(), a.iter().sum::<i64>());
}



Measured memory_bytes: 5040
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmp = -1
sum = 0
for i in range(n):
    sum += b[i]
    if a[i] == tmp + 1:
        sum += c[tmp-1]
    tmp = a[i]
print(sum)

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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  
  int64_t X = ( N / (A + B) ) * A;
  int64_t Y = N - ( N / (A + B) ) * (A + B);
  
  if(Y >= A){
    cout << X + A << endl;
  }
  
  else{
    cout << X + Y << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

#define LENGTH_N 20
#define LENGTH_Q 200

int solveQ(int*, int, int, int);

int main() {
  int i, nl, ql, arrayN[LENGTH_N], q;

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

  scanf("%d", &ql);
  for(i=0 ; i < ql ; i++) {
    scanf("%d", &q);

    if(solveQ(arrayN, nl, 0, q)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

int solveQ(int* array, int nl, int num, int key) {
  int res;

  if(key == 0) {
    return 1;
  } else if(num >= nl) {
    return 0;
  }
  
  res = solveQ(array, nl, num+1, key) || solveQ(array, nl, num+1, key-array[num]);
  return res;
}



Measured memory_bytes: 2688
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Measured memory_bytes: 68832
S = str(input())
odd = ''
even = ''
for s in range(0,len(S),2):
  odd += S[s]
for s in range(1,len(S),2):
  even += S[s]

if 'L' not in odd and 'R' not in even:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <stdio.h>

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

int main()
{
  int x = 1, y = 1, z = 1, a1, a2, a3, m1, m2, m3;
  int cx,cy,cz;
  long long p;

  while(1){
    cx = 0;
    cy = 0;
    cz = 0;
    scanf("%d %d %d %d %d %d", &a1, &m1, &a2, &m2, &a3, &m3);

    if(a1 == 0 && a2 == 0 && a3 == 0 && m1 == 0 && m2 == 0 && m3 == 0){
      break;
    }

    while(1){
      x = (x * a1) % m1;
      cx++;
      if(x == 1){
        break;
      }
    }

    while(1){
      y = (y * a2) % m2;
      cy++;
      if(y == 1){
        break;
      }
    }

    while(1){
      z = (z * a3) % m3;
      cz++;
      if(z == 1){
        break;
      }
    }

    p = cx * cy / gcd(cx, cy);
    p = p * cz / gcd(p,cz);

    printf("%lld\n",p);
  }
  return 0;
}

Measured memory_bytes: 600
// AtCoder ABC132: C - Divide the Problems
// 2019.9.3 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int d[100005];

int cmp(const void *u, const void *v) { return *(int *)u - *(int *)v; }

int main()
{
	int i, N, ans;

	N = in(); for (i = 0; i < N; i++) d[i] = in();
	qsort(d, N, sizeof(int), cmp);
	ans = d[N/2] - d[N/2-1];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for((i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for((i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
using namespace std;
int main(){
    int a;
    char s[11];
    cin >> a;
    cin >> s;
    if(a>=3200)cout << s << endl;
    else cout<<"red"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll A, B, C, D; cin >> A >> B >> C >> D;
    ll ans = 0;
    REP(i, 100) {
        if (A<=i&&i<B && C<=i&&i<D) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll *fact, *fact_inv;

ll Mod(ll x) {
    if (x < 0)
        return (MOD - x % MOD);
    else
        return x % MOD;
}

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = Mod(res * a);
        a = Mod(a * a);
        b >>= 1;
    }
    return res;
}

ll inverse(ll x) { return power(x, MOD - 2); }

ll Comb(int N, int k) {
    if (k < 0 || N < k) {
        return 0;
    }
    return Mod(fact[N] * Mod(fact_inv[N - k] * fact_inv[k]));
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    fact = (ll *)malloc(sizeof(ll) * (N * M + 10));
    fact_inv = (ll *)malloc(sizeof(ll) * (N * M + 10));
    fact[0] = 1;
    fact_inv[0] = 1;
    for (int i = 1; i < N * M + 10; i++) {
        fact[i] = Mod(i * fact[i - 1]);
        fact_inv[i] = inverse(fact[i]);
    }

    ll comb = Comb(N * M - 2, K - 2);
    for (int d = 1; d < N; d++) {
        ans = Mod(ans + Mod(d * Mod((N - d) * Mod(M * Mod(M * comb)))));
    }
    for (int d = 1; d < M; d++) {
        ans = Mod(ans + Mod(d * Mod((M - d) * Mod(N * Mod(N * comb)))));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n, m, q[100];
    while (cin >> n >> m, n) {
        fill(q, q+100, 0);
        int a;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<m; ++j) {
                cin >> a;
                q[j] += a;
            }
        }
        vector<pair<int,int> > v;
        for (int i=0; i<m; ++i) {
            v.push_back(make_pair(-q[i], i+1));
        }
        sort(v.begin(), v.end());
        for (int i=0; i<m; ++i) {
            cout << (i == 0 ? "" : " ") << v[i].second;
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin>>x;
	int n = (x-400)/200;
	cout<<(8-n);
}


Measured memory_bytes: 3616
#include<iostream>

using namespace std;

int main(void){
	bool bFirst = true;
	while( true ){
		int a, b;
		bool bFound = false;

		cin >> a >> b;
		if( a==0 && b==0 ) break;
		
		if( bFirst ){
			bFirst = false;
		}else cout << endl;

		for(int i = a; i <= b; i++){
			if( i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)){
				bFound = true;
				cout << i << '\n';
			}
		}
		if( !bFound ) cout << "NA\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 2e5;
char S[MAXN+10];
int dp[2][MAXN+10];
int n, k, x;
int main(){
	scanf("%d %d %d", &n, &k, &x);
	scanf("%s", S);
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++){
		if(S[i-1] == 'x') dp[0][i] = dp[0][i-1];
		else dp[0][i] = 1 + (i - x - 1 >= 0 ? dp[0][i-x -1] : 0);
	}
	dp[1][n+1] = 0;
	for(int i = n; i > 0; i--){
		if(S[i-1] == 'x') dp[1][i] = dp[1][i+1];
		else dp[1][i] = 1 + (i + x + 1 <= n + 1 ? dp[1][i+x+1] : 0);
	}
	//for(int i = 1; i <= n; i++) printf("%d ", dp[1][i]); printf("\n");
	for(int i = 0; i < n; i++){
		if(dp[0][i] + dp[1][i+2] < k) printf("%d\n", i+1);
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

ll calc(ll n) {
    if (n&1) {
        if (((n+1)/2)&1) return 1;
        else return 0;
    }
    else {
        if ((n/2)&1) return 1^n;
        else return n;
    }
}

int main() {
    ll a, b;
    cin >> a >> b;

    ll ans = calc(a-1)^calc(b);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one
}

int main() {

    int n = inp1;

    ll ans = 0;

    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        ans += i;
    }

    Cout(ans);

    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 0;
    rep(i,n) {
        int a = x[i];
        int b = abs(k-x[i]);
        ans += min(a*2, b*2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int y , m , d;
  	cin >> y >> m;
  	cout << (float)y/m;
    return 0;
}


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

vector<int> a(5);

int main() {
    ios::sync_with_stdio(false);
    for (int i = 0; i < 5; i++)
        cin >> a[i];
    vector<int> p = {0,1,2,3,4};
    int fans = 987654321;
    do {
        int ans = 0;
        for (int i = 0; i < 5; i++) {

            while (ans % 10 != 0)
                ans++;

            ans += a[p[i]];
        }
        fans = min(fans, ans);

    }while (next_permutation(p.begin(), p.end()));

    cout << fans << endl;


    return 0;
}


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

class P
{
    static void Main()
    {
        List<int> intpow = new List<int>{ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824 };
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        for (int i = 0; i < a.Length; i++)
        {
            for (int j= intpow.Count - 1; j >= 0; j--)
            {
                if(a[i] % intpow[j] == 0)
                {
                    res += j;
                    break;
                }
            }
        }
        Console.WriteLine(res);
    }
    
}

Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll n;cin>>n;
  ll hoge,huga=1,ans=0;
  for(ll i=0;i<n;i++){
    cin>>hoge;
    if(hoge==huga){
      huga++;
      ans++;
    }
  }
  if(ans==0){
    ans=-1;
  }else{
    ans=n-ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define N 100 
#define BLACK 1
#define GRAY  2
#define WHITE 3
  
int G[N][N],d[N],f[N],color[N];
int n,time;
 
 void visit(int r){
  int v;
  
  color[r]=GRAY;
  time++;
  d[r]=time;
  
  for(v=0;v<=n;v++){
    if(G[r][v] && color[v]==WHITE){
      visit(v);
    }
  }
  color[r]=BLACK;
  f[r]=++time;
 }
 
void dfs(int n){
  int u;
   
  for(u=0;u<n;u++){
    if(color[u]==WHITE){
      visit(u);
    }
  }
}
 
int main(void){
   
  int  i,j,k,m;
  
  scanf("%d",&n);
   
  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      G[i][j]=0;
    }
    color[i] = WHITE;
  }
   
  for(i=0;i<n;i++){
    scanf("%d%d",&j,&k);
     
    for(j=0;j<k;j++){
      scanf("%d",&m);
      G[i][m-1]=1;
    }
  }
   
  dfs(n);
  
  for(i=0;i<n;i++)
    printf("%d %d %d\n",i+1,d[i],f[i]);
   
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
const int maxn=100000000;

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0); cin.tie(0);
  int n; cin>>n;
  int num[n];
  for (int i=0; i<n; i++) {
    cin>>num[i];
  }
  if (n==2) {
    for (int i=1; i<=maxn; i++) {
      if (num[0]%i==0 && num[1]%i==0) {
	cout<<i<<endl;
      }
    }
  }
  else {
    for (int i=1; i<=maxn; i++) {
      if (num[0]%i==0 && num[1]%i==0 && num[2]%i==0) {
	cout<<i<<endl;
      }
    }
  }
  return 0;
}



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

#define int long long
#define fi first
#define se second
#define INF (1 << 31 - 1)

int n, a, b, c, q, k, x, y, d[100005];
vector<pair<int, int> > g[100005];
bool used[100005];

void bfs(int s) {
    queue<int> que;
    que.push(s);
    used[s] = true;
    d[s] = 0;

    while (!que.empty()) {
        int p = que.front();
        que.pop();
        int si = g[p].size();
        for (int i = 0; i < si; ++i) {
            if (!used[g[p][i].fi]) {
                que.push(g[p][i].fi);
                d[g[p][i].fi] = g[p][i].se + d[p];
                used[g[p][i].fi] = true;
            }
        }
    }    
}

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

    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b >> c;
        a--, b--;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    cin >> q >> k;
    k--;
    bfs(k);
    for (int i = 0; i < q; ++i) {
        cin >> x >> y;
        x--, y--;
        cout << d[x] + d[y] << endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    mp[s]++;
  }
  int a = 0;
  for (auto p : mp) a = max(p.second, a);
  for (auto p : mp){
    if (p.second != a) continue;
    else cout << p.first << endl;
  }
}


Measured memory_bytes: 25216
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, a, b = map(int, input().split())

amari = n%(a+b)
if (amari > a) :
    amari = a

b = int(n/(a+b))
b = b * a

print(b+amari)


Measured memory_bytes: 2940
def ABC(n)
    if n==1 or n==3 or n==5 or n==7 or n==8 or n==10 or n==12
        return("A")
    elsif n==4 or n==6 or n==9 or n==11
        return("B")
    elsif n==2
        return("C")
    end
end


x,y=gets().chomp().split().map(&:to_i)
if ABC(x)==ABC(y)
    puts("Yes")
else
    puts("No")
end

Measured memory_bytes: 1788
from heapq import heappush, heappop
INF = 10 ** 10
h, w = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(10)]

cost_to_one = []
for i in range(10):
  costs = [INF] * 10
  que = []
  heappush(que, (0, i))
  costs[i] = 0
  while que:
    dist, node = heappop(que)
    for to, v in enumerate(edges[node]):
      if costs[to] > dist + v:
        costs[to] = dist + v
        heappush(que, (dist + v, to))
  cost_to_one.append(costs[1])

cost_to_one.append(0)
ans = 0
for _ in range(h):
  lst = list(map(int, input().split()))
  for i in lst:
    ans += cost_to_one[i]

print(ans)

Measured memory_bytes: 3064