akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int d;
    cin >> d;
    int n = 26;
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(n));
    for(int i = 0; i < d; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    vector<int> last(n, 0);
    for(int i = 0; i < d; i++)
    {
        cin >> t[i];
        t[i]--;
    }
    int ans = 0;
    for(int i = 0; i < d; i++)
    {
        int con = t[i];
        ans += s[i][con];
        for(int j = 0; j < 26; j++)
        {
            if(j == con) continue;
            ans -= c[j] * (i+1 - last[j]);
        }
        last[con] = i+1;
        cout << ans << endl;
    }
}




Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
    }
    sort(ALL(p));
    ll ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
    
    return 0;
}

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

public class Main {
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{
			String strN = insBR.readLine();
			int n = Integer.parseInt(strN);
			int[] intA = new int[n];
			String[] strA = insBR.readLine().split(" ");
			for(int i = 0;i < n ;i++){
				try{
					intA[i] = Integer.parseInt(strA[i]);
				}catch(NumberFormatException e){
					e.printStackTrace();;
				}
			}
			for(int i = intA.length -1; 0 <= i; i--){
				if(i != 0){
					System.out.print(intA[i] + " ");
				}else{
					System.out.println(intA[i]);
				}

			}
		}catch(IOException e){
			System.out.println("入力が無効です。");
		}catch(NumberFormatException e){
			System.out.println("数値を入力してください。");
		}
	}

}



Measured memory_bytes: 24200
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,sum=0;
    cin>>a>>b;
    int c[b];
    for(int i=0;i<b;i++){
        cin>>c[i];
    }
    for(int i=0;i<b;i++){
        sum=sum+c[i];
    }
    int d=a-sum;
    if(d>0){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 3932
N = int(input()) 
S = input()[::-1]

# 下の桁を固定した時上の桁のとりうる値を調べる
# 10のループが2つ回るので計算量は O(10^6)

ret = 0
# 1の位を固定して残りの桁の可能性を調べる
place1 = [True for i in range(10)]
for i, s in enumerate(S):
  if i > N - 3:
    break
  if place1[int(s)]:
    place1[int(s)] = False
    
    # 10の位を固定して残りの桁の可能性を調べる
    place2 = [True for j in range(10)]
    for j, t in enumerate(S[i+1:], i+1):
      if j > N - 2:
        break
      if place2[int(t)]:
        place2[int(t)] = False
      
        # 100の位は残ったユニークな数字の数
        ret += len(set(S[j+1:]))
        
print(ret)

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

ll cnt[2][1010][1010];
ll sumW[1010][1010];
ll sumB[1010][1010];
// sumW[x][y]は、[0,x)*[0,y)内の白点の個数、sumBも同様
ll preW_x[1010][1010]; ll preW_y[1010][1010];
ll preB_x[1010][1010]; ll preB_y[1010][1010];
// preW_x は i = x-1, 0 <= j < yにおける白点の個数　他も同様

int main(){ 
  
  int N,K; cin >> N >> K;
 
  for(int i = 0; i < N; i++){
    ll x,y; char c; cin >> x >> y >> c;
    int judge = 0;
    if( c == 'B'){ judge = 1;} //1で黒、0で白
    ll m = x/K; ll n = y/K;
    
    if( (m+n)%2 == 1){ //色が反転
      if(judge == 1){ judge = 0;}
      else{ judge = 1;}
    }
    
    cnt[judge][x%K][y%K]++;
  }
  
  //先に累積和で格子点(i,j)以下の白点の個数をsumW[i][j]と求めておく sumBも同様
  
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
     
      if(x-1>=0){ 
        preW_x[x][y+1] = preW_x[x][y]+cnt[0][x-1][y];
        preB_x[x][y+1] = preB_x[x][y]+cnt[1][x-1][y];
      }
      if(y-1>=0){
        preW_y[x+1][y] = preW_y[x][y]+cnt[0][x][y-1];
        preB_y[x+1][y] = preB_y[x][y]+cnt[1][x][y-1];
      }
      
    }
  }
      
  
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
      
      if(x+1 <= K){ 
       sumW[x+1][y] = sumW[x][y]+preW_x[x+1][y];
       sumB[x+1][y] = sumB[x][y]+preB_x[x+1][y];
      }
      if(y+1 <= K){
       sumW[x][y+1] = sumW[x][y]+preW_y[x][y+1];
       sumB[x][y+1] = sumB[x][y]+preB_y[x][y+1];
      }
      
    }
  }
  
  // ここまで問題なし
  
 
  ll ans = 0; 
  
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
      
      ll res1 = sumW[x][y]+(sumW[K][K]-sumW[x][K]-sumW[K][y]+sumW[x][y]);
      res1 += sumB[x][K]+sumB[K][y]-2*sumB[x][y];
      
      
      ll res2 = sumB[x][y]+(sumB[K][K]-sumB[x][K]-sumB[K][y]+sumB[x][y]);
      res2 += sumW[x][K]+sumW[K][y]-2*sumW[x][y];
      
      
      ans = max(ans, max(res1,res2)); 
      
    }
  }
  
  cout << ans << endl;
  
  return 0;
}
     

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

int main(){

int N;
  cin >> N;
bool ans = false;  
  
  for(int i = 0; i <= N / 4;i++){
    for(int j = 0;j <= N / 7;j++){
      if(i * 4 + j * 7 == N){
        ans = true;
        break; 
  }
    }
  }
      
      if(ans) cout << "Yes" << endl;
      else cout << "No" << endl;

return 0;
      
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 
int a, b;
cin>>a>>b;
 
if ((a > 0 && b >= a )|| (a <= b && b < 0 && (b-a+1)%2 == 0)) cout << "Positive";
else if (a <= 0 && b >= 0) cout << "Zero";
else if (a <= b && b < 0 && (b-a+1)%2 != 0) cout << "Negative" ;
}

Measured memory_bytes: 3632
#include<map>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
vector<int> list[1000000];
int N, M, E;
int match[100000];
bool used[100000];
int x, y;

bool DFS(int V){
    used[V] = true;
    for(int i = 0; i < list[V].size(); i++){
        int u = list[V][i]; int w = match[u];
        if(w < 0 || !used[w] && DFS(w)){
            match[V] = u;
            match[u] = V;
            return true;
        }
    }
    return false;
}

int supermatching(){
    int r = 0;
    memset(match, -1, sizeof(match));
    for(int j = 0; j < N + M; j++){
        if(match[j] < 0){
            memset(used, 0, sizeof(used));
            if(DFS(j)) { r++; }
        }
    }
    return r;
}

int main(){
    int n; cin >> n;
    N = 2*n;
    M = 2*n;

    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);

    map<pair<int, int>, int> red;
    map<pair<int, int>, int> blue;    

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        red[{a[i], b[i]}] = i + 1;
    }

    for(int i = 0; i < n; i++){
        cin >> c[i] >> d[i];
        blue[{c[i], d[i]}] = i + 1;        
    }

    int E = 0;
    vector<int> x;
    vector<int> y;

    for(int i = 0; i < n; i++){
        for(int X = a[i] + 1; X <= 2*n; X++){
            for(int Y = b[i] + 1; Y <= 2*n; Y++){
                if(blue.find({X, Y}) != blue.end()){
                    E++;
                    x.push_back(red[{a[i], b[i]}] - 1);
                    y.push_back(blue[{X, Y}] - 1);
                }
            }
        }
    }
    //cout << E << endl;

    for(int i = 0; i < E; i++){
        y[i] += N;
        list[y[i]].push_back(x[i]);
        list[x[i]].push_back(y[i]);        
    }

    /*for(int i = 0; i < x.size(); i++){
        cout << x[i] << " ";
    }
    cout << endl;

    for(int i = 0; i < y.size(); i++){
        cout << y[i] << " ";
    }
    cout << endl;
    */
    
    cout << supermatching() << endl;
    return 0;
}

Measured memory_bytes: 24320
#include <stdio.h> // C++???????????????
#include <string.h> // c++???????????????
#include <math.h> // c++???????????????
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long int lli;
#define PI 3.1415926535897932
#define N 100
#define MAX(a,b) ((a>b)?(a):(b)) // ?????§????????????
#define MIN(a,b) ((a<b)?(a):(b)) // ????°?????????????
#define INRANGE(a,b,c) ((a<=b&&b<=c)?(1):(0)) // a<=b<=c??????????????????????????????


void swap(int &a, int &b) { // c??????*
	int w = a;
	a = b;
	b = w;
}

int getdigit(int num) { // ??´??°????????°?????????
	int i, j;
	if (num<0) num *= -1; // ?????°???????????¢
	if (num == 0)return 1;
	for (i = 10, j = 1;; i *= 10, j++) {
		if (INRANGE(i / 10, num, i - 1))return j;
	}
	return 0; // ????????¨??????
}

int getN(int num, int digit) {
	int i = 1, j;
	for (j = 1; j<digit; i *= 10, j++);
	return (num / i) % 10;
}

int zeller(int y, int m, int d) { // 0????????\????????§??????
	if (m<3) { y--; m += 12; }
	return (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + d) % 7;
}

int gcd(int a, int b) {	// ?????§??¬?´???°
	if (b == 0) return a;
	return gcd(b, a%b);
}

int lcm(int a, int b) {	// ????°???¬?????°
	return a*b / gcd(a, b);
}

int stoi(const string str) { // ?????????????????´??°
	int i = 0, j;
	int len = str.length();
	int w = 0;
	for (i = 1, j = 1; i <= len && INRANGE('0', str[len - i], '9'); i++, j *= 10) {
		w += (str[len - i] - '0')*j;
	}
	if (str[0] == '-')w *= -1;
	return w;
}

string itos(int a) { // ??´??°???????????????
	int i;
	string str = "";
	int keta;
	if (a<0) { str += '-'; a *= -1; } // ?????°??????????????????
	for (keta = 10; a / keta != 0; keta *= 10);
	for (i = keta / 10; i != 0; i /= 10) {
		str += ((a / i) % 10) + '0';
	}
	return str;
}

int main(void) {
	char str[N];
	char next[N];
	int i, j;
	int a, b;
	while (scanf("%s", str) != EOF) {
		for (j = 10; j > 1; j--) {
			for (i = 0; i < j-1; i++) {
				a = getN(str[i] - '0' + str[i+1] - '0', 1);
				next[i] = a + '0';
			}
			next[i] = '\0';
			strcpy(str, next);
		}
		printf("%c\n", str[0]);
	}
	return 0;
}

Measured memory_bytes: 1144
# classを使うのをやめてlistで実施する
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def dfs(v):
    visited[v] = True
    for i in range(len(AL[v][CHILDREN])):
        u = AL[v][CHILDREN][i]
        if visited[u]:
            AL[v][CHILDREN][i] = None
            continue
        AL[v][SIZE] += dfs(u)
    return AL[v][SIZE]

def anaaki(v):
    ret = powp - 1
    for ch in AL[v][CHILDREN]:
        if ch is None: continue
        ret -= pow(2, AL[ch][SIZE], p) - 1
        ret %= p
    ret -= pow(2, n - AL[v][SIZE], p) - 1
    ret %= p
    return ret

n = int(input())
SIZE = 0
CHILDREN = 1
AL = [[1, []] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
powp = pow(2, n - 1, p)

for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    AL[a][CHILDREN].append(b)
    AL[b][CHILDREN].append(a)

dfs(0)
numer = 0
for i in range(n):
    numer += anaaki(i)
    numer %= p

denom = powp * 2 % p
print(numer * pow(denom, p - 2, p) % p)

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

int main() {
  string s;
  cin >> s;
  
  for(int i = 0; i < 19; i++){
    if(s.at(i) == ','){
      cout << " ";
    }
    else{
      cout << s.at(i);
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector <int> v[200005];
int n,i,c0,cost[200005],q,j,x,t,y,d[800005],dp[200005],b[200005];
int query(int k,int t,int w,int x,int y)
{
	if ((t>y) || (x>w))
	  return 2000000000;
	if ((x<=t) && (w<=y))
	  return d[k];
	int mid=(t+w)/2;
	return min(query(k*2,t,mid,x,y),query(k*2+1,mid+1,w,x,y));
}
void xiugai(int k,int t,int w,int x,int y)
{
	if ((t>x) || (w<x))
	  return;
	if (t==w)
	{
		d[k]=y;
		return;
    }
    int mid=(t+w)/2;
    xiugai(k*2,t,mid,x,y);
    xiugai(k*2+1,mid+1,w,x,y);
    d[k]=min(d[k*2],d[k*2+1]);
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	  {
	  	scanf("%d",&b[i]);
	  	if (b[i]==0)
	  	  c0++;
	  	if (b[i]==0)
	  	  cost[i]=-1;
	  	else
	  	  cost[i]=1;
	  }
	scanf("%d",&q);
	for (i=1;i<=q;i++)
	{
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
	}
	memset(d,127,sizeof(d));
	memset(dp,127,sizeof(dp));
	dp[0]=0;
	for (i=1;i<=n;i++)
    {
    	for (j=0;j<v[i].size();j++)
    	{
    		x=v[i][j];
    		t=min(dp[i-1],query(1,1,n,max(i-1,1),x));
    		if (t<dp[x])
    		{
    			dp[x]=t;
    		    xiugai(1,1,n,x,t);
			}
		}
	dp[i]=min(dp[i],dp[i-1]+cost[i]);
	}
    printf("%d",dp[n]+c0);
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

struct vectim{double v,t;};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  int te=0;
  vector<int>t(n),v(n);
  rep(i,n){cin>>t[i];t[i]*=2;}
  rep(i,n){cin>>v[i];v[i]*=2;}
  rep(i,n)te+=t[i];
  vector<int>vmax(te+1);
  int tt=1;
  rep(i,n)
  {
    repi(j,tt,tt+t[i])vmax[j]=v[i];
    tt+=t[i];
  }
  //for(auto a:vmax)cout<<a<<endl;
  vector<vector<double>>dp(40009,vector<double>(400,-1e9));
  dp[0][0]=0;
  rep(i,te)
  {
    repi(j,0,vmax[i+1]+1)
    {
      double tres=-1e9;
      if(j>0)chmax(tres,dp[i][j-1]+j-0.5);
      chmax(tres,dp[i][j]+j);
      if(j+1<=vmax[i+1])chmax(tres,dp[i][j+1]+j+0.5);


      dp[i+1][j]=tres;
      //cout<<i+1<<" "<<j<<" "<<tres<<endl;
    }
  }
  cout<<setprecision(15)<<dp[te][0]/4<<endl;


  return 0;

}


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

int main() {
  int count=0;
  string S;
  cin >> S;
  if (S.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i=0; i<S.size()-1; i++) {
    if (S.at(i) == S.at(i+1)) {
      count++;
      if (S.at(i) == '0') S.at(i+1) = '1';
      else S.at(i+1) = '0';
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int h, w, k;
	std::cin >> h >> w >> k;
	std::vector<std::vector<char> > map(h, std::vector<char> (w));
	std::vector<std::vector<char> > mapcpy(h, std::vector<char> (w));
	int ans = 0;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			std::cin >> map[i][j];
		}
	}
	for (int bith = 0; bith < (1 << h); ++bith)
	{	
		for (int bitw = 0; bitw < (1 << w); ++bitw)
		{
			mapcpy = map;
			for (int i = 0; i < h; i++)
			{
				if (bith & (1 << i))
				{
					for (int x = 0; x < w; x++)
					{
						mapcpy[i][x] = 'r';
					}
				}
			}
			for (int j = 0; j < w; j++)
			{
				if (bitw & (1 << j))
				{
					for (int y = 0; y < h; y++)
					{
						mapcpy[y][j] = 'r';
					}
				}
			}
			int count = 0;
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					if (mapcpy[i][j] == '#')
						++count;
				}
			}
			if (count == k)
				++ans;
		}
	}
	std::cout << ans << '\n';
	return (0);
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            int result = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    result++;
                }
            }


            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27324
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vp a;

int main(){
	cin>>n;
	a=vp(n);
	for(auto &p:a) cin>>p.first>>p.second;
	sort(a.rbegin(),a.rend());
	stack<pll> st;
	for(int i=0;i<n;i++){
		ll x=a[i].first,t=1;
		while(!st.empty()&&x+a[i].second>st.top().first){
			(t*=st.top().second)%=mod;
			st.pop();
		}
		(t+=1)%=mod;
		st.push({x,t});
	}
	ll t=1;
	while(!st.empty()){
		(t*=st.top().second)%=mod;
		st.pop();
	}
	cout<<t<<endl;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main()
{
	int a, b, c, d ;
	(void)fscanf(stdin, "%d %d %d %d", &a, &b, &c, &d);

	a += b;
	c += d;
	if (a == c)
		printf("Balanced\n");
	if (a < c)
		printf("Right\n");
	if (a > c)
		printf("Left\n");

	return 0;
}


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

int main(){
  string n;cin>>n;
  
  int ans=0;
  for(int i=0;i<n.length();i++){
    ans+=n[i]-'0';
    ans%=9;
  }
  if(ans%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=210;
int main()
{
    fast();
    ll n,sum=0;
    cin>>n;

    vector<ll>arr(n);
    for(ll i=0;i<n;i++)
        cin>>arr[i];

    sort(arr.rbegin(),arr.rend());
    for(ll i=0;i<n;i++)
    {
        if(i%2==0)
            sum+=arr[i];
        else
            sum-=arr[i];
    }
    cout<<sum;
}


Measured memory_bytes: 256
import collections
n,m=list(map(int,input().split()))

arr=[]
for _ in range(n):
  k,*a=list(map(int,input().split()))
  arr.extend(a)

c = collections.Counter(arr)

cnt=0
for c_ in c.most_common():
  if n == c_[1]:
    cnt+=1
print(cnt)

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i = a; i < b; i++)
#define FORD(i,a,b) for(ll i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%lld", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%lld", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define sf3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define all(c) (c).begin(),(c).end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
const ll INF = 2e18;

bool prime[1000009];
unordered_map<ll,ll> largest_factor;
void SieveOfEratosthenes(ll n)
{
    memset(prime,true, sizeof(prime));
    prime[1]=false;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p){
                prime[i] = false;
                largest_factor[i]=p;
            }

        }
    }
}


ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}


ll mod_power(ll a,ll b,ll m){
    ll res=1;
    a%=m;
    while(b){
        if(b&1){
            res=res*a%m;
        }
        a=a*a%m;
        b>>=1;
    }
    return res;
}


int main(){
    fast
    ll n;
    cin>>n;
    ll a[n];
    bool flag=true;
    FOR0(i,n)cin>>a[i];
    FOR0(i,n){
        if(a[i]%2==0 && (a[i]%3!=0 && a[i]%5!=0))flag=false;
    }
    if(flag){
        cout<<"APPROVED\n";
    }
    else cout<<"DENIED\n";
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ld N;
  cin >> N;
  Rep(i,1,3501){
    Rep(j,1,3501){
      ld A=i,B=j;
      ld W=1/(4/N-1/A-1/B);
      ll K=(ll)W;
      if(4*i*j*K==(ll)N*(i*K+i*j+j*K)){
        if(K>0){
          cout << i <<" " <<  j << " " << K << endl;
          return 0;
        }
      }
      K++;
      if(4*i*j*K==(ll)N*(i*K+i*j+j*K)){
        if(K>0){
        cout << i <<" " <<  j << " " << K << endl;
        return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> g(n);
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(n == 2)
    {
        if(a[0] == a[1]) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
    }
    bool ans = true;
    function<ll(int, int)> dfs = [&](int v, int pre)
    {
        if(g[v].size() == 1) return a[v];
        ll sum = 0;
        int ma = 0;
        for(int nx : g[v])
        {
            if(nx == pre) continue;
            int cur = dfs(nx, v);
            sum += cur;
            ma = max(ma, cur);
        }
        if(2 * a[v] < sum || ma > a[v] || a[v] > sum) ans = false;
        return 2 * a[v] - sum;
    };
    int res = -1;
    for(int i = 0; i < n; i++)
    {
        if(g[i].size() > 1)
        {
            res = dfs(i, -1);
            break;
        }
    }
    if(ans && res == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

typedef long long ll;

int m[111];
int l[111];
vector<int> v[100];
int t[101];
int d[(1<<17)];
int n;

int dp(int bit){
  int r = 0;

  if(d[bit] != -1) return d[bit];
  for(int i = 0; i < n; i++){
    if(!(t[i] & bit)){
      r = max(r,l[i]+dp(t[i] | bit));
    }
  }
  d[bit] = r;
  return r;

}

int main(){


  while(1){
    cin >> n;
    if(n == 0) break;


    memset(t,0,sizeof(t));
    memset(l,0,sizeof(l));
    memset(d,-1,sizeof(d));
    memset(m,0,sizeof(m));

    for(int i = 0; i < n; i++){
      cin >> m[i] >> l[i];
      for(int j = 0; j < m[i]; j++){
	int t1, t2;
	cin >> t1  >> t2;
	for(int s = t1-6; s < t2-6; s++){
	  t[i] = (t[i] | (1<<s));
	}
      }
      //   cout << bitset<16>(t[i]) << endl;
          }
    int ans = INT_MIN;
    ans = dp(0);
    cout << ans << endl;
  }

}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n], Cmp[n];
	map<int, pair<int, int> > mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a, a + n);
	mp[a[0]].first = a[0];
	mp[a[0]].second = 1;
	int Cnt = 1;
	for (int i = 1; i < n; i++) {
		mp[a[i]].first = a[i] + mp[a[i - 1]].first;
		Cnt++;
		mp[a[i]].second = Cnt;
	}
	int Ans = LINF, Sum = mp[a[n - 1]].first;
	for (auto e : mp) {
		// cout << e.first << " " << e.second.first << " " << e.second.second << endl;
		Ans = min(abs(e.second.first - (e.second.second * e.first)) + abs((Sum - e.second.first) - (n - e.second.second) * e.first), Ans);
	}
	cout << Ans << '\n';

	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>
#include <string.h>
#include <functional>
#include <vector>
#include <queue>
#include <algorithm>
#define int long long
#pragma warning(disable:4996)
using namespace std;
vector<pair<int, int>>length[200010];
int cost[200010];
priority_queue < pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>heap;
int bef[200010];
signed main()
{
	int V, E, S;
	scanf("%lld %lld", &V, &E);
	int i;
	for (i = 0; i < E; i++)
	{
		int x, y, z;
		scanf("%lld %lld", &x, &y);
		z = 1;
		length[x].push_back({ z, y });
		length[y].push_back({ z,x });
	}
	memset(cost, 63, sizeof(cost));
	cost[1] = 0;
	heap.push({ 0,1 });
	while (!heap.empty())
	{
		auto now = heap.top();
		heap.pop();
		if (cost[now.second] < now.first)
		{
			continue;
		}
		int j;
		for (j = 0; j < length[now.second].size(); j++)
		{
			if (length[now.second][j].first + now.first < cost[length[now.second][j].second])
			{
				heap.push({ length[now.second][j].first + now.first, length[now.second][j].second });
				cost[length[now.second][j].second] = length[now.second][j].first + now.first;
				bef[length[now.second][j].second] = now.second;
			}
		}
	}
	printf("Yes\n");
	for (i = 2; i <= V; i++)
	{
		printf("%lld\n", bef[i]);
	}
}

Measured memory_bytes: 22148
n, k = gets.chomp.split(" ").map(&:to_i)

i = n

div = n / k
n -= (div * k).abs
i -= div

loop do
  if i > 0 && (n - k).abs < n
    n = (n - k).abs
    i -= 1
  else
    break
  end
end

puts n


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 2e6 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

ll n, a[20][20];
ll dp[N], cost[N];
bool u[N];

ll rec(ll mask) {
	if(bit(mask) < 2) return 0;	

	if(u[mask]) return dp[mask];

	u[mask] = 1;
	dp[mask] = cost[mask];

	for(ll s = mask; s; s = (s - 1) & mask) {
		ll x = s;
		ll y = (mask ^ x);
		dp[mask] = max(dp[mask], rec(x) + cost[y]);
	}

	return dp[mask];
}

inline ll get(ll x) {
	vector<ll>cur;
	for(ll i = 0; i < n; i++)
		if(x & (1<<i)) cur.pb(i);    
	ll res = 0;
	for(ll i = 0; i < cur.sz; i++)
		for(ll j = i + 1; j < cur.sz; j++) {
			ll c = cur[i];
			ll b = cur[j];
			res += a[c][b];
		}
	return res;
} 
	
main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

    cin >> n;

    for(ll i = 0; i < n; i++)
    	for(ll j = 0; j < n; j++)
    		cin >> a[i][j];

	for(ll m = 0; m < (1<<n); m++)
		cost[m] = get(m);
	                     
	cout << rec((1<<n) - 1);
	   
    return 0;                                        
}

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

using namespace std;

const int INF = 1 << 30;

struct edge {
	int cost; //重み(距離)
	int to; //行先の頂点
};

void dijkstra(const int n, const vector<vector<edge>> &G, const int stpoint) {

	//優先キューは最短距離と頂点番号のペア、 距離を降順に並べる
	priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;

	vector<bool> seen(n,false); //訪問完了でtrue
	vector<int> cost(n,INF); //頂点nまでの距離

	cost[stpoint] = 0;
	pq.push(make_pair(0, 0));

	while (pq.empty() == false) {

		//ターゲット頂点設定（すでに決定したものの中のどれか）
		pair<int, int> target = pq.top();
		int tnum = target.second; //ターゲット頂点番号
		pq.pop();
		
		seen[tnum] = true;

		if (cost[tnum] < target.first) { continue; } //これの意味が分からない保留

		for (unsigned int j = 0; j < G[tnum].size(); j++) { //ターゲットから繋がる先を全部探す

			int v = G[tnum][j].to; //繋がる先の頂点をvにする

			if (seen[v] == true) { continue; } //もう見たとこ（仲間に入ってる）ならスキップ

			if (cost[v] > cost[tnum] + G[tnum][j].cost) {
				cost[v] = cost[tnum] + G[tnum][j].cost;
				pq.push(make_pair(cost[v], v));
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << cost[i] << endl;
	}

}

int main() {

	int n;
	cin >> n;

	int stpoint = 0; //この問題では0起点

	vector<vector<edge>> G(n);

	int in1, in2, in3, in4;
	for (int i = 0; i < n; i++) {
		cin >> in1 >> in2;
		for (int j = 0; j < in2; j++) {
			cin >> in3 >> in4;
			G[in1].push_back({ in4, in3 });
		}
	}

	dijkstra(n,G,stpoint);

	return 0;
}


Measured memory_bytes: 3172
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        a: usize,
        b: usize,
        n: usize
    }

    let x = if n >= b { n - (n % b) - 1 } else { n };
    let ans = (a as f64 * x as f64 / b as f64).floor() - a as f64 * (x as f64 / b as f64).floor();
    println!("{}", ans);
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	char a , b;
	cin >> a >> b;
	char ans;
	if(a == 'H'){
		ans = b;
	}else{
		ans = b == 'H' ? 'D' : 'H';
	}
	die(ans);

	return 0;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
at=list(map(int,input().split()))
bt=list(map(int,input().split()))
ans=min(at)+min(bt)
for i in range(m):
  x,y,c=map(int,input().split())
  ans=min(ans,at[x-1]+bt[y-1]-c)
print(ans)


Measured memory_bytes: 18736
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
ll powermod(ll x,ll y){
	ll res=1;
	while(y>0){
		if(y&1)
		res=(res*x)%mod;

		y/=2;
		x=(x*x)%mod;
	}
	return res;
}
ll go(string s,ll p,ll n){
    ll i,x;
    ll ans=0,z=0;
    for(i=0;i<n;i++){
        x=s[i]-'0';
        if(x%p==0) z++;
    }
    ans+=z;
    for(i=0;i<n;i++){
        x=s[i]-'0';
        if(x%p==0) z--;
        ans+=z;
    }
    return ans;
}
int main()
{
    boost;
    ll n,i,j,x,t,y,p;
	string s;
	cin>>n>>p>>s;
	if(p==2||p==5) {
		cout<<go(s,p,n);
		return 0;
	}
	vector<ll>v(p+5,0);
	ll cur=1,sum=0;
	for(i=n-1;i>=0;i--){
		x=s[i]-'0';
		x%=p;
		x=(x*cur)%p;
		x=(x+sum)%p;
		v[x]++;
		sum=x%p;
		cur=(cur*10)%p;
	}
	ll ans=v[0];
	cur=1;
	sum=0;
	for(i=n-1;i>=0;i--){
		x=s[i]-'0';
		x%=p;
		x=(x*cur)%p;
		x=(x+sum)%p;
		v[x]--;	
		v[x]=max(v[x],0LL);
		ans+=v[x];
		sum=x%p;
		cur=(cur*10)%p;
	}
	ans=min(ans,n*(n+1)/2);
	cout<<ans<<"\n";
}

Measured memory_bytes: 788
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 13;
    } else {
        return modpow(m, n - 1) * m % 13;
    }
}
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = pow(m, n / 2);
        return t * t;
    } else {
        return pow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
int main() {
    ll n;
    cin >> n;
    vector<P> ab(n);
    REP(i, n) {
        ll a, b;
        cin >> a >> b;
        ab[i].first = b;
        ab[i].second = a;
    }
    sort(ab.begin(), ab.end());
    ll time = 0;
    REP(i, n) {
        time += ab[i].second;
        if (time > ab[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6388
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto nr = readInts();
		auto n = nr[0];
		auto r = nr[1];
		if(n == 0 && r == 0) {
			return;
		}
		int[] cards = array(iota(n));
		reverse(cards);
		for(int i = 0; i < r; ++i) {
			auto pc = readInts();
			auto p = pc[0];
			auto c = pc[1];
			cards = cards[p-1..p-1+c] ~ cards[0..p-1] ~ cards[p-1+c..$];
		}
		writeln(cards[0]+1);
	}
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    double a,b,x;
    cin >> a >> b >> x;
    double rad;
    double s=x/a;
    if(2*x>=pow(a,2)*b){
        double h=(a*b-s)*2/a;
        rad=atan2(h,a);
    } else{
        double w=2*s/b;
        rad=atan2(b,w);
    }
    double PI=acos(-1);
    double deg=rad/(2*PI)*360;
    printf("%.10f\n",deg);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    long long int n, ans = 0;
	cin >> n;
   for (long long int i = 1; i <= n ; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
        
		}else{
      		ans += i;
    	}
   }  
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

class rational {
private:
  static ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
public:
  ll p, q;
  rational(ll _p, ll _q) {
    ll g = gcd(_p, _q);
    p = _p / g;
    q = _q / g;
  }
  bool operator==(const rational r) const { return p * r.q == q * r.p; }
  bool operator<(const rational r) const { return p * r.q < q * r.p; }
};

int main(void) {
  ll H, W;
  cin >> H >> W;
  vector<string> S(H + 1);
  REP(i, 0, H) {
    cin >> S[H - i - 1];
    S[H - i - 1] += '.';
  }
  S[H] = "";
  REP(i, 0, W + 1) S[H] += '.';

  vector<rational> vec;
  vec.push_back(rational(0, 1));
  vec.push_back(rational(1LL << 50, 1));
  REP(i, 0, H) REP(j, 0, W) {
    if(j != 0) vec.push_back(rational(i + 1, j));
    if(i != 0) vec.push_back(rational(i, j + 1));
    vec.push_back(rational(i + 1, j + 1));
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  vector<ll> imos(vec.size() + 1, 0);
  REP(i, 0, H) REP(j, 0, W) {
    if(S[i][j] != S[i + 1][j]) {
      ll s = lower_bound(vec.begin(), vec.end(), rational(i + 1, j + 1)) - vec.begin();
      ll e = lower_bound(vec.begin(), vec.end(), j != 0 ? rational(i + 1, j) : rational(1LL << 50, 1)) - vec.begin();
      imos[s + 1]++;
      imos[e + 1]--;
    }
    if(S[i][j] != S[i][j + 1]) {
      ll s = lower_bound(vec.begin(), vec.end(), i != 0 ? rational(i, j + 1) : rational(0, 1)) - vec.begin();
      ll e = lower_bound(vec.begin(), vec.end(), rational(i + 1, j + 1)) - vec.begin();
      imos[s + 1]++;
      imos[e + 1]--;
    }
  }
  REP(i, 0, imos.size() - 1) imos[i + 1] += imos[i];

  ll ans = 0;
  REP(i, 0, imos.size() - 1) ans = max(ans, imos[i]);
  cout << (ans + 1) / 2 + 1 << endl;
}



Measured memory_bytes: 36588
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll a,b;
    cin >> a >> b;
    if(b%a==0) cout << a+b << endl;
    else cout << b-a << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
	static ArrayList<Integer> primes = new ArrayList<Integer>();
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      long n = Long.parseLong(st.nextToken());
      sieve((int)Math.sqrt(n));
      int[] triangle = new int[] {1, 3, 6, 10, 15, 21, 28, 36, 45};
      int ans = 0;
      for(int p: primes) {
    	  int pow = 0;
    	  while(n%p == 0) {
    		  n /= p;
    		  pow++;
    	  }
    	  int i = 0;
    	  for(; i < 10; i++)
    		  if(triangle[i] > pow)
    			  break;
    	  ans += i;
    	  if(n == 1)
    		  break;
      }
      if(n != 1)
    	  ans++;
      out.println(ans);
      out.close();
   }
   static void sieve(int n) {
	   boolean[] dp = new boolean[n+1];
	   for(int i = 2; i < n; i++)
		   dp[i] = true;
	   for(int p = 2; p*p <= n; p++) {
		   for(int i = p*p; i <= n; i+= p) {
			   dp[i] = false;
		   }
	   }
	   for(int i = 2; i < n; i++)
		   if(dp[i])
			   primes.add(i);
   }
}

Measured memory_bytes: 36900
import sys

N = int(sys.stdin.readline())
V = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

ans = 0
for i in range(N):
    tmp = V[i] - C[i]
    if tmp > 0:
        ans += tmp
print(ans)

Measured memory_bytes: 3060
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strs = str.split(" ");
		double a = Integer.parseInt(strs[0]);
		double b = Integer.parseInt(strs[1]);
		//計算
		int d = (int) (a / b);
		int r = (int) (a % b);
		double f = a / b;
		String f2 = String.format("%.5f", f);
		System.out.println(d + " " + r + " " + f2);
		br.close();
	}
}

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

int main() {
string s;
int k=0;
cin >> s;
s+='$';
vector<int> v;
for(int i =0;i<=(int)s.size();i++) {
if(s[i]=='R') k++;
else v.push_back(k), k=0;
}
sort(v.begin(),v.end());
cout << v[v.size()-1] << '\n';
return 0;
}


Measured memory_bytes: 3592
n = int(input())
cnt_a = 0
cnt_b = 0
for i in range(n):
	list = input().split()
	list_sorted=sorted(list)
	if list[0]==list[1]:
		cnt_a +=1
		cnt_b +=1
	elif list[0] == list_sorted[1]:
		cnt_a +=3
	elif list[0] == list_sorted[0]:
		cnt_b +=3
print("{} {}".format(cnt_a,cnt_b))


Measured memory_bytes: 5596
#include <stdio.h>
#define N 100001

unsigned int a[N], b[N], c;


int main()
{		
	unsigned int K, i, x;
	
	scanf("%u", &K);
	if(K <= 9){
		printf("%u\n", K);
		return 0;
	}
	for(c = 1; c <= 9; c++){
		a[c] = b[c] = c;
	}
	for(i = 1; ; i++){
		x = b[i];
		if(x > 0){
			b[c] = x - 1;
			a[c] = 10 * a[i] + b[c];
			if(c == K){
				printf("%u\n", a[c]);
				return 0;
			}
			c++;
		}
		b[c] = x;
		a[c] = 10 * a[i] + b[c];
		if(c == K){
			printf("%u\n", a[c]);
			return 0;
		}
		c++;
		if(x < 9){
			b[c] = x + 1;
			a[c] = 10 * a[i] + b[c];
			if(c == K){
				printf("%u\n", a[c]);
				return 0;
			}
			c++;
		}
	}
	
			
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=3500,mo=1e9+7;
int m,n;
int f[N][N];
int DP(int n,int m)
{
	memset(f,0,sizeof(f));
	fo(i,0,n)f[0][i]=1;
	fo(i,1,m)fo(j,0,n)
	{
		if(j<n)((f[i][j]+=f[i-1][j+1])>=mo?f[i][j]-=mo:0),((f[i][j]+=f[i-1][j])>=mo?f[i][j]-=mo:0);
		if(j)((f[i][j]+=f[i-1][j])>=mo?f[i][j]-=mo:0),((f[i][j]+=f[i-1][j-1])>=mo?f[i][j]-=mo:0);
	}
	int ans=0;
	fo(i,0,n)((ans+=f[m][i])>=mo?ans-=mo:0);
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	printf("%d\n",(DP(n,m)-DP(n-1,m)+mo)%mo);
	return 0;
} 

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

typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n, a, b, ans = 1, MOD = 1e9 + 7;
    cin >> n >> a >> b;
    ll p = n, q = 2;
    while (p > 0) {
        if (p & 1) ans = (ans * q) % MOD;
        p /= 2;
        q = (q * q) % MOD;
    }
    //cout << ans << endl;
    ans = (ans + MOD - 1) % MOD;
    ll c = 1;
    rep(i, a) {
        c = (c * (n - i)) % MOD;
    }
    rep(i, a) {
        c = (c * mod_pow(i + 1, MOD - 2, MOD)) % MOD;
    }
    ans = (ans - c + MOD) % MOD;
     c = 1;
    rep(i, b) {
        c = (c * (n - i)) % MOD;
    }
    rep(i, b) {
        c = (c * mod_pow(i + 1, MOD - 2, MOD)) % MOD;
    }
    ans = (ans - c + MOD) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
A = sorted(list(map(int, input().split())), reverse = True)
l = 0
ln = []
for a in A:
    if l == a:
        ln.append(a)
        l = 0
    else:
        l = a
    if len(ln) == 2:
        break
if len(ln) == 2:
    print(ln[0]*ln[1])
else:
    print(0)

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pb emplace_back
#define pii pair<int, int>
#define mp make_pair

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a * b <= 0)
    {
        cout << "Zero";
        return 0;
    }
    if (a > 0 && b > 0)
    {
        cout << "Positive";
        return 0;
    }
    int cnt = abs(a - b) + 1;
    if (cnt % 2)
        cout << "Negative";
    else
        cout << "Positive";
}


Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()
lst = []
bef = s[0]
if bef == "0":
    lst.append(0)
cnt = 0
for ss in s:
    if bef == ss:
        cnt += 1
    else:
        lst.append(cnt)
        cnt = 1
        bef = ss
lst.append(cnt)
if s[-1] == "0":
    lst.append(0)

l = len(lst)
if l <= k * 2 + 1:
    print(n)
    exit()
tmp = sum(lst[:2 * k + 1])
ans = tmp
d = 2 * k + 1
for i in range(2 * k + 1, l, 2):
    tmp -= lst[i - d] + lst[i - d + 1]
    tmp += lst[i] + lst[i + 1]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 74480
n, q = map(int, input().split())
s = input()
a_lst = [0]*(n+1)
for i in range(n-1):
    if s[i:i+2] == 'AC':
        a_lst[i+1] = a_lst[i] + 1
    else:
        a_lst[i+1] = a_lst[i]
for i in range(q):
    l, r = map(int, input().split())
    print(a_lst[r-1] - a_lst[l-1])

Measured memory_bytes: 6060
N = int(input())
ans = [0, 0]
for _ in range(N):
    t, h = input().split()
    if t < h:
        ans[1] += 3
    elif t > h:
        ans[0] += 3
    else:
        ans[0] += 1
        ans[1] += 1
print(*ans)


Measured memory_bytes: 5600