akhauriyash/Code-Regression huggingface dataset:
A, B, C, D = map(int,input().split())

# A以上B以下の整数のうち、(CまたはDの倍数)でないものの個数を求める
# CまたはDの倍数の個数 = Cの倍数の個数+Dの倍数の個数-CとDの最小公倍数の倍数の個数
# 途中式でfloatが出てこないようにしないと大きな数の計算時に結果がズレるので注意

def ceil(x,y):
    if x%y == 0:
        return x//y
    else:
        return x//y+1

def n_multiple(x):
    return B//x - ceil(A,x) + 1

def lcd(x,y):
    while y>0:
        x,y = y, x%y
    return(x)

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

print(int((B-A+1) - (n_multiple(C)+n_multiple(D)-n_multiple(gcd(C,D)))))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	int a; cin >> a;
	int b;cin >> b;int g = 0;
	for (int i = 0; i < 10000000; i++) {
		if (a * i - i + 1 >= b)
			break;
		++g;
	}
		cout << g << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

n, a, b = map(int, input().split())

ans = 0

# for i in range(1, n+1):
#     s = str(i)
#     sum = 0
#     for j in s:
#         sum += int(j)
#     if a <= sum <= b:
#         ans += i

for i in range(1, n+1):
    sum = 0
    num = i
    while num > 0:
        sum += num%10 # 10で割ったあまりを取得することで最下位桁を取る
        num = num//10 # 10で割った商を取得することで一桁ずらす
    if a <= sum <=b:
        ans += i

print(ans)


Measured memory_bytes: 2940
#include <stdio.h>

char w[102];
int cnt[26];
int ans = 1;

int main(void)
{
	int i;

	scanf("%s", w);
	for (i = 0; w[i]; ++i)
	{
		cnt[w[i] - 'a']++;
	}
	for (i = 0; i < 26; ++i)
	{
		if (cnt[i] & 1) ans = 0;
	}
	printf(ans ? "Yes" : "No");

	return 0;
}

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

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

    // check palindrome whole string 
    string s_r; 
    s_r=s; 
    reverse(s_r.begin(),s_r.end()); 

    bool flag1=false; 
    if(s==s_r) 
      flag1=true; 

    // check palindrome first half string 
    string s_first_half; 
    string s_first_half_r; 
    
    for(int i=0;i<(n-1)/2;i++){ 
      s_first_half+=s.at(i); 
    } 
    s_first_half_r=s_first_half; 
    reverse(s_first_half_r.begin(),s_first_half_r.end()); 
    bool flag2=false; 
    if(s_first_half==s_first_half_r) 
      flag2=true; 

    // check palindrome second half string 
    string s_second_half; 
    string s_second_half_r; 
    
    for(int i=(n+3)/2-1;i<n;i++){ 
      s_second_half+=s.at(i); 
    } 
    s_second_half_r=s_second_half; 
    reverse(s_second_half_r.begin(),s_second_half_r.end()); 
    bool flag3=false; 
    if(s_second_half==s_second_half_r) 
      flag3=true; 

    // output result 
    if(flag3&&flag2&&flag1) 
      cout<<"Yes"<<endl; 
    else 
      cout<<"No"<<endl; 
    

    return 0; 
}

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3636
S = input()
N = len(S)
T = ""
flag = 0
ans = 0
for i in range(N-1):
  if flag == 1:
    flag = 0
    continue
  if S[i:i+2] == "BC":
    T += "D"
    flag = 1
  else:
    T += S[i]
M = len(T)
count = 0
for i in range(M):
  if T[i] == "A":
    count += 1
  elif T[i] == "D":
    ans += count
  else:
    count = 0
print(ans)

Measured memory_bytes: 3500
square = []
while True:
    data = [int(e) for e in input().split()]
    if data[0]==0 and data[1]==0:
        break
    square.append(data)
    
for i in range(len(square)):
    for j in range(square[i][0]):
        for k in range(square[i][1]):
            if k==0 or k==square[i][1]-1 or j==0 or j==square[i][0]-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7012
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long k = sc.nextLong();

		long ans = n;
		long x = n;
		if (x > k) {
			x = k + (x % k);
		}
		HashSet<Long> map = new HashSet<Long>();
		while (true){

			long diff = Math.abs(x - k);
			if (map.contains(diff)){
				break;
			}
			map.add(diff);
			ans = Math.min(ans, diff);
			x = diff;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
n, k = gets.strip.split.map(&:to_i)
td = readlines.map {|line| line.strip.split.map(&:to_i) }.sort_by(&:last).reverse

already_max = {}
td = td.map do |t, d|
  unless already_max[t]
    already_max[t] = 1
    [1, d]
  else
    [0, d]
  end
end

all = td.sort.sort_by(&:last).reverse
#p all

selected = all.take(k)
unselected = all[k...n]

mobile = []
in_result = 0
selected.each do |t, d|
  if !t.zero?
    in_result+=1
  else
    mobile.push([t, d])
  end
end

current_score = selected.map(&:last).inject(:+)

result = current_score + in_result**2

if n==k
  p result
  exit
end

#p selected
unselected.each do |t, d|
  next if t.zero?

  swap_target = mobile.pop
  break if swap_target.nil?
  current_score -= swap_target.last
  current_score += d
  in_result+=1
  current_result = current_score + in_result**2

  if current_result > result
#    p [result, current_result, [current_score, in_result**2], t,d, swap_target]
    result = current_result 
  end
end

p result



Measured memory_bytes: 31184
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        double D = scanner.nextInt();
        int ret = 0;
        for(int i = 0; i < N; i++) {
            double x = scanner.nextLong();
            double y = scanner.nextLong();
            if(Math.sqrt(x*x + y*y) <= D){
                ret++;
            }
        }
        System.out.println(ret);


    }
}


Measured memory_bytes: 60988
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+100;
const LL inf=99999999999999;
int a[maxn];
int n,k;

int main()
{
    //freopen("1.txt","r",stdin);
    while (scanf("%d%d",&n,&k)!=EOF)
    {
        for (int i=0;i<n;i++) scanf("%d",&a[i]);
        LL ans=inf;
        for (int i=0;i<n-k+1;i++)
        {
            if (a[i]<0 && a[i+k-1]>0) ans=min(ans,min(abs(a[i])*2LL+abs(a[i+k-1]),abs(a[i])+abs(a[i+k-1])*2LL));
            else if (a[i]>=0) ans=min(ans,1LL*a[i+k-1]);
            else if (a[i+k-1]<=0) ans=min(ans,abs(a[i])*1LL);
        }
        printf("%lld",ans);
    }
    return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    double n;
    cin>>n;
    cout<<(int)pow((int)sqrt(n),2)<<endl;
    return 0;
}

Measured memory_bytes: 256
inf = float('inf')

N = int(input())
a = tuple(map(int, input().split()))

c_sum = [0]
t = 0
for aa in a:
    t += aa
    c_sum.append(t)

ans = inf
p, q = 0, 2  # c_sum上のindex
for cut in range(2, N - 2 + 1):
    # [0, cut)と[cut, N)に分ける
    # 各区間を二分割する
    # 分割位置は、要素の合計の差が最小になるように取る

    # c_sum上のカーソルpを動かす
    # 右区間に一つ以上の要素が含まれるように、pはcut-1まで取る
    # c_sum[p]: 二分割した左区間の和
    # c_sum[cut] - c_sum[p]: 二分割した右区間の和
    while p < cut - 1:
        if abs(c_sum[cut] - c_sum[p] * 2) >= abs(c_sum[cut] - c_sum[p + 1] * 2):
            p += 1
        else:
            break

    # c_sum上のカーソルqを動かす
    # 右区間に一つ以上の要素が含まれるように、qはN-1まで取る
    # c_sum[q]: 二分割した左区間の和
    # c_sum[N] - c_sum[q]: 二分割した右区間の和
    while q < N - 1:
        if abs(c_sum[N] - c_sum[q] - (c_sum[q] - c_sum[cut])) >= abs(
                c_sum[N] - c_sum[q + 1] - (c_sum[q + 1] - c_sum[cut])):
            q += 1
        else:
            break

    cands = [c_sum[cut] - c_sum[p], c_sum[p], c_sum[N] - c_sum[q], c_sum[q] - c_sum[cut]]
    # print(cands)
    ans = min(ans, max(cands) - min(cands))
print(ans)


Measured memory_bytes: 25928
#include <bits/stdc++.h>
using namespace std;
int main () {
  long A, B;
  cin >> A >> B;
  if(A % B == 0){
    cout << -1 << endl;
    return 0;
  }
  long count = 1;
  while(1){
    if((count * A) % B != 0){
      cout << count * A << endl;
      return 0;
    }
    count++;
  }
  return 0;
}


Measured memory_bytes: 256
import time
from random import randint
d = int(input())
c = list(map(int,input().split()))
starttime = time.time()
timelimit = 1.8
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for i in range(d):
    s = sl[i]
    sp = sum(pen)
    temp = -(10**9)
    for j in range(26):
        if s[j]-(sp-pen[j]) > temp:
            temp = s[j]-(sp-pen[j])
            tempans = j+1
    ans += [tempans]
    sat += s[tempans-1]-sp+pen[tempans-1]
    for j in range(26):
        pen[j] += c[j]
        pen[tempans-1] = 0
fin = ans
ans = []
pen = [0]*26
while time.time() - starttime <= timelimit:
    ans = fin
    d1 = randint(0,d-1)
    d2 = randint(d1,min(d-1,d1+15))
    if randint(0,1):
        ans[d1],ans[d2] = ans[d2],ans[d1]
        # print(1)
    else:
        ans[d1] = randint(1,26)
        # print(0)
    pen = [0]*26
    sattemp = 0
    for i in range(d):
        # print(i,fin,fin[i])
        s = sl[i]
        sp = sum(pen)
        tempans = ans[i]
        sattemp += s[tempans-1]-sp+pen[tempans-1]
        for j in range(26):
            pen[j] += c[j]
            pen[tempans-1] = 0
        # print(sattemp)
    if sattemp > sat:
        fin = ans
        sat = sattemp
        # print(sat)
for i in fin:
    print(i)
# print(sat)



Measured memory_bytes: 91676
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

deque<pair<pii, int> > pos;
bool vis[805][805];
int Bvis[805][805];
int N, M, K;
char kotak[805][805];
int x1[4]={0, 1, 0, -1};
int y2[4]={1, 0, -1, 0};
vector<pii> tmp;
bool bfs()
{
    while(!pos.empty()) pos.pop_front();
    for(int z=0;z<tmp.size();z++)
    {
        pos.push_back(pair<pii, int> (tmp[z], K));
        vis[tmp[z].fi][tmp[z].se]=1;
    }
    tmp.clear();
    while(!pos.empty())
    {
        int nowx=pos.front().fi.se, nowy=pos.front().fi.fi, nowcost=pos.front().se;
        pos.pop_front();
        if(nowx==1 || nowy==1 || nowx==M || nowy==N) return 1;
        if(nowcost==0)
        {
            tmp.push_back(pii(nowy, nowx));
            continue;
        }
        bool done=0;
        for(int z=0;z<4;z++)
        {
            int newy=nowy+y2[z], newx=nowx+x1[z];
            if(newy<1 || newx<1 || newy>N || newx>M) continue;
            if(kotak[newy][newx]=='#') continue;
            if(vis[newy][newx]) continue;
            vis[newy][newx]=1;
            pos.push_back(pair<pii, int> (pii(newy, newx), nowcost-1));
            done=1;
        }
        if(!done)
        {
            tmp.push_back(pii(nowy, nowx));
        }
    }
    return 0;
}

void createpath()
{
    while(!pos.empty()) pos.pop_front();
    for(int z=0;z<tmp.size();z++)
    {
        pos.push_back(pair<pii, int> (tmp[z], K));
        Bvis[tmp[z].fi][tmp[z].se]=1;
    }
    queue<pii> STMP;
    while(!pos.empty())
    {
        int nowx=pos.front().fi.se, nowy=pos.front().fi.fi, nowcost=pos.front().se;
        pos.pop_front();
        STMP.push(pii(nowy, nowx));
        if(nowcost==0) continue;
        for(int z=0;z<4;z++)
        {
            int newy=nowy+y2[z], newx=nowx+x1[z], nc=nowcost-(kotak[newy][newx]=='#');
            if(newy<1 || newx<1 || newy>N || newx>M) continue;
            if(Bvis[newy][newx]>=nc) continue;
            Bvis[newy][newx]=nc;
            if(nc==nowcost)
            {
                pos.push_front(pair<pii, int> (pii(newy, newx), nc));
            }
            else
            {
                pos.push_back(pair<pii, int> (pii(newy, newx), nc));
            }
        }
    }
    while(!STMP.empty())
    {
        kotak[STMP.front().fi][STMP.front().se]='.';
        STMP.pop();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>N>>M>>K;
    memset(Bvis, -1, sizeof(Bvis));
    for(int a=1;a<=N;a++)
    {
        for(int b=1;b<=M;b++)
        {
            cin>>kotak[a][b];
            if(kotak[a][b]=='S')
            {
                tmp.push_back(pii(a, b));
            }
        }
    }
    int cnt=1;
    while(!bfs())
    {
        createpath();
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	LL ans = 0;
	inc(bit, 1 << (s.size() - 1)) {
		LL v = 0;
		inc(i, s.size()) {
			v = v * 10 + (s[i] - '0');
			if(bit & (1 << i)) { ans += v; v = 0; }
		}
		ans += v; v = 0;
	}
	
	cout << ans << endl;
	
	return 0;
}


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


double cal(double hour,double minu,double a,double b)
{
  

  double temph=(double)(30*hour+minu*0.5);
  double tempm=(double)(6*minu);

  if(temph>tempm)
    {
       double temp=temph-tempm>180?360-(temph-tempm):temph-tempm;
        //cout<<temp<<endl;
        temp = (temp*3.141592653589793238)/(180);
        //cout<<temp<<endl;
       double total=((a*a)+(b*b)-(2*a*b*cos(temp)));
       //cout<<total<<endl;
       return sqrt(total);
    }
  else
    {
      double temp=tempm-temph>180?360-(tempm-temph):tempm-temph;
      //cout<<temp<<endl;
       temp = (temp*3.141592653589793238)/(180);
      double total=((a*a)+(b*b)-(2*a*b*cos(temp)));
      //cout<<total<<endl;
       return sqrt(total); 
    }
}



int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

    
    double a,b,c,d;
    cin>>a>>b>>c>>d;

    double temp=cal(c,d,a,b);
    cout<<setprecision(10)<<temp<<endl;



  return 0;

}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
#define all(a) a.begin(),a.end()

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    reverse(all(d));
    REP(i, 10) d.push_back(-1);
    vector<int> ans(5, -1);
    ans[0] = 0;
    REP(i, 10000){
        bool f = false;
        REP(j, n){
            REP(k, 5){
                if(ans[k] == -1){
                    f = true;
                    break;
                }
                if(ans[k] != d[j+k]) break;
            }
            if(f) break;
        }
        if(!f){
            cout << i << endl;
            return 0;
        }
        else{
            ans[0]++;
            REP(j, 4){
                if(ans[j] >= 10){
                    ans[j+1] = max(1, ans[j+1]+1);
                    ans[j] = 0;
                }
            }
        }
    }
}



Measured memory_bytes: 3172
"""
K = int(input())

def gcd(a, b): # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a # int
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            d = gcd(gcd(i,j),k)
            if i==j==k:
                ans += d
            elif i==j or j== k or k==i:
                ans += 3*d
            else:
                ans += 6*d
print(ans)
"""
N = int(input())
S = input()
R = []
G = []
B = []
import bisect
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)
ans = 0
for rr in R:
    for gg in G:
        
        r = min(rr,gg)
        g = max(rr,gg)
        if 2*r-g>=0:
            id = bisect.bisect_left(B,2*r-g)
            if id < len(B) and 2*r-g == B[id]:
                ans -=1
        
        if 2*g-r < N:
            id = bisect.bisect_left(B,2*g-r)
            if id < len(B) and 2*g-r == B[id]:
                ans -=1
        
        if (g+r)%2==0:
            id = bisect.bisect_left(B,(g+r)//2)
            if id < len(B) and (g+r)//2 == B[id]:
                ans -= 1
        ans += len(B)
        
print(ans)
        


Measured memory_bytes: 80480
#include <iostream>

using namespace std;

int main(void) {
    int isec, h, m, osec;
    
    cin >> isec;
    h = isec / 60 / 60;
    m = (isec / 60) - (h * 60);
    osec = isec - (h * 60 * 60) - (m * 60);
    cout << h << ":" << m << ":" << osec << "\n";
    
    return 0;
}

Measured memory_bytes: 1168
def resolve():
	bin = [0]*10**5
	n, k = map(int, input().split())
	for _ in range(n):
		a, b = map(int, input().split())
		bin[a-1] += b
	s = 0
	for i in range(len(bin)):
		s += bin[i]
		if s >= k:
			print(i+1)
			return
resolve()

Measured memory_bytes: 46960
#include <stdio.h>
int main(void){
	int H,W;
	int i,j;
	for(;;){
		scanf("%d %d",&H,&W);
		if((H == 0)&&(W == 0))break;
		for ( i = 0; i < H; i++ ){
			for ( j = 0; j < W; j++ ){
				if(((i+j) % 2 == 1)){
					printf(".");
				} else {
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
#pragma warning(disable: 4996)
int n, a[100009], b[100009], c[100009], bit[100009]; vector<tuple<double, double, double>>F, G;

void add(int p, int x) {
	while (p <= 100008) { bit[p] += x; p += (p&-p); }
}
void zero() {
	for (int i = 0; i < 100009; i++)bit[i] = 0;
}
int sum(int p) {
	int s = 0;
	while (p >= 1) { s += bit[p]; p -= (p&-p); }
	return s;
}
int search(double p) {
	vector<pair<double, int>>T; vector<double>E;
	for (int i = 0; i < F.size(); i++) {
		double V = (get<2>(F[i]) - get<0>(F[i])*p) / get<1>(F[i]);
		double W = get<0>(F[i]) / get<1>(F[i]);
		E.push_back(W);
	}
	sort(E.begin(), E.end());
	for (int i = 0; i < F.size(); i++) {
		double V = (get<2>(F[i]) - get<0>(F[i])*p) / get<1>(F[i]);
		double W = get<0>(F[i]) / get<1>(F[i]);
		int pos1 = lower_bound(E.begin(), E.end(), W) - E.begin();
		T.push_back(make_pair(V, pos1 + 1));
	}
	sort(T.begin(), T.end());
	int ret = 0;
	for (int i = 0; i < T.size(); i++) {
		ret += sum(T[i].second);
		add(T[i].second, 1);
	}
	return ret;
}
double solve() {
	double L = -1e9, R = 1e9, M;
	for (int i = 0; i < 90; i++) {
		M = (L + R) / 2; zero();
		int F = search(M);
		if (F <= (n*(n - 1) / 2) / 2)R = M; else L = M;
	}
	return M;
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i] >> b[i] >> c[i];
	for (int i = 1; i <= n; i++)F.push_back(make_tuple(a[i], b[i], c[i]));
	long double I = solve();
	for (int i = 1; i <= n; i++)G.push_back(make_tuple(b[i], -a[i], c[i]));
	F = G;
	long double J = solve();
	printf("%.15Lf %.15Lf\n", I, J);
	return 0;
}

Measured memory_bytes: 5168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

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


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num;
	while (cin >> pay)

	{
		num = 0;
		if (!pay) break;

		pay = 1000 - pay;
		if (pay / 500 == 1){
			pay -= 500;
			num++;
		}
		for (;;){
			if (pay / 100 >= 1){
				pay -= 100;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 50 >= 1){
				pay -= 50;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 10 >= 1){
				pay -= 10;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 5){
				pay -= 5;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 1){
				pay -= 1;
				num++;
			}
			else break;
		}
		cout << num << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
    int sweat[1000][4],n,sum[4]={0},eiyou[4],count=0;
    while(1){
        cin>>n;
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<4;j++){
                cin>>sweat[i][j];
            }
        }
        for(int i=0;i<4;i++){
            cin>>eiyou[i];
        }
        for(int i=0;i<n;i++){
            if(sweat[i][1]<=eiyou[0] && sweat[i][2]<=eiyou[1] && sweat[i][3]<=eiyou[2] && sweat[i][1]*4+sweat[i][2]*9+sweat[i][3]*4<=eiyou[3]){
                cout<<sweat[i][0]<<endl;count++;
            }
        }
        if(count==0){
            cout<<"NA"<<endl;
        }
        count=0;
    }
    return 0;
}

Measured memory_bytes: 3120
import sys

n, u, v = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    graph[a].append(b)
    graph[b].append(a)

def dfs(v):
    dist = [-1] * (n+1)
    dist[v] = 0
    stack = [v]
    while stack:
        now = stack.pop()
        dw = dist[now] + 1
        for ne in graph[now]:
            if dist[ne] >= 0:
                continue
            dist[ne] = dw
            stack.append(ne)
    return dist

Takahashi = dfs(u)
Aoki = dfs(v)

ans = 0
for t, a in zip(Takahashi[1:], Aoki[1:]):
    if t < a:
        ans = max(ans, a - 1)

print(ans)

Measured memory_bytes: 30004
# encoding: utf-8

import sys
from collections import deque

input_ = sys.stdin.readlines()


def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time])


message_queue()

Measured memory_bytes: 23548
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    int n,d,x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans=x;
    for(int i=0;i<n;i++){
        int day=1;
        while(day<=d){
            ans++;
            day+=a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,r,temp,sum=0;
	cin>>n;
	temp=n;
	while(n>0)
	{
		r=n%10;
		sum=sum+r;
		n=n/10;
	}
	if(temp%sum==0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>

int main(void){
    int n;
    scanf("%d\n",&n);
    int x;
    int count=0;
    int i;
    while(n--){
        scanf("%d\n",&x);
        if(x==2)count++;
        else if(x%2!=0){
            for(i=3;i<=sqrt(x);i=i+2){
                if(x%i==0)break;
            }
            if(i>sqrt(x))count++;
        }
    }
    
    printf("%d\n",count);
    
    return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int n;
	int ans = 0;
	cin >> n;

	while (n) {
		if (n % 10 == 2) {
			ans++;
		}
		n /= 10;
	}
	cout << ans << endl;

	return 0;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int r[9] = {};

    for (int i = 0; i < n; i++)
    {
        r[min(a[i] / 400, 8LL)]++;
    }

    int cnt = 0;
    for (int i = 0; i < 8; i++)
    {
        if (r[i] > 0)
            cnt++;
    }

    int mx = 0;
    int mn = 0;
    if (cnt == 0)
    {
        mn = 1;
        mx = min(r[8], 8LL);
    }
    else
    {
        mn = cnt;
        mx = min(cnt + r[8], INF);
    }

    cout << mn << " " << mx << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<string> s(n);
	rep(i, n) cin >>s[i];
	
	VI ssk(26, 99999);
	rep(i, n){
		VI w(26);
		rep(j, sz(s[i])) w[s[i][j]-'a']++;
		rep(j, 26) ssk[j] = min(ssk[j], w[j]);
	}
	rep(i, 26) cout << string(ssk[i], 'a'+i);
	cout <<"\n";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
        int a,b,ab;
        int i;

        for(i = 0; i < 7; i++){
                scanf("%d",&a);
                scanf("%d",&b);
                
                ab = b - a;
                ab = abs(ab);

                printf("%d\n",ab);
                 
        }

        return 0;
}

Measured memory_bytes: 600
#include <array>
#include <cstdio>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };

int pack(array<array<int, 3>, 3> const & d) {
    int acc = 0;
    repeat (y, 3) {
        repeat (x, 3) {
            acc = acc * 10 + d[y][x];
        }
    }
    return acc;
}
tuple<array<array<int, 3>, 3>, int, int> unpack(int acc) {
    array<array<int, 3>, 3> d;
    int zy = -1, zx = -1;
    repeat_reverse (y, 3) {
        repeat_reverse (x, 3) {
            d[y][x] = acc % 10;
            acc /= 10;
            if (d[y][x] == 0) {
                zy = y;
                zx = x;
            }
        }
    }
    return make_tuple(d, zy, zx);
}

int main() {
    while (true) {
        // input
        int ch, cv; scanf("%d%d", &ch, &cv);
        if (ch == 0 and cv == 0) break;
        array<array<int, 3>, 3> start, goal;
        repeat (y, 3) repeat (x, 3) scanf("%d", &start[y][x]);
        repeat (y, 3) repeat (x, 3) scanf("%d", &goal[y][x]);
        // solve
        unordered_map<int, int> used;
        priority_queue<pair<int, int> > que;
        used[pack(start)] = 0;
        que.emplace(0, pack(start));
        int pack_goal = pack(goal);
        while (not que.empty()) {
            int c, s; tie(c, s) = que.top(); que.pop();
            c *= -1;
            if (used[s] < c) continue;
            if (s == pack_goal) break;
            array<array<int, 3>, 3> d; int y, x; tie(d, y, x) = unpack(s);
            repeat (i, 4) {
                int nx = x + dx[i];
                int cy = 0;
                if (nx == -1) {
                    nx = 2;
                    cy = -1;
                }
                if (nx == 3) {
                    nx = 0;
                    cy = 1;
                }
                int ny = (y + dy[i] + cy + 3) % 3;
                swap(d[y][x], d[ny][nx]);
                int ns = pack(d);
                swap(d[y][x], d[ny][nx]);
                int nc = c + (i < 2 ? cv : ch);
                if (not used.count(ns) or nc < used[ns]) {
                    used[ns] = nc;
                    que.emplace(- nc, ns);
                }
            }
        }
        // output
        printf("%d\n", used[pack_goal]);
    }
    return 0;
}

Measured memory_bytes: 20680
/*input
4
1 1 1 1

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) cout << #container << " "; for (auto it : container) cout << it << " "; cout << endl;

template < typename T> int sz(T x) {return x.size();}
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

bool isPrime (ll n) {
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;

    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int v;
  vector <int> vec;
  int s = 0;
  for (int i = 0; i < n; i++) {
    cin >> v;
    vec.pb(v);
    s += v;
  }
  int cur = 0, ans = 100000000;
  for (int i = 0; i < n; i++) {
    cur += vec[i];
    s -= vec[i];
    // cout << cur << " " << s << endl;
    ans = min(ans, abs(s - cur));
  }
  cout << ans << endl;



  return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> Dss(N);
	
	for(int i = 0;i<N;i++){
		cin >> Dss.at(i);
	}
	
	sort(Dss.begin(),Dss.end());
	
	int MXD = 0;
	int cnt = 0;
	
	for(int j = 0;j<N;j++){
		int c = Dss.at(j);
		
		if(c > MXD){
			MXD = c;
			cnt++;
		}
	}
	
	cout << cnt << endl;
}

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

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    
    vector<int> t(N);
    for(int i = 0; i < N; i++) cin >> t[i];

    long lost = 0;
    for(int i = 1; i < N; i++) {
        if(t[i] > t[i-1] + T) lost += t[i] - (t[i-1] + T);
    }

    long ans = t[N-1] + T - lost;
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		a.at(i) -= i + 1;
	}
	long long l = -1e18;
	long long r = 1e18;
	ll ans = 1e18;
	while (r - 1 > l) {
		long long mid = (r + l) / 2;
		bool f = true;
		ll res = 0;
		for (int i = 0; i < n; i++)res += abs(a.at(i) - mid);
		ll resl1 = 0;
		for (int i = 0; i < n; i++)resl1 += abs(a.at(i) - (mid-1));
		ll resr1 = 0;
		for (int i = 0; i < n; i++)resr1 += abs(a.at(i) - (mid+1));
		if (resl1 == res || res == resr1) {
			cout << res << endl;
			//cout << mid << " "<<resl1<<" " <<res<<" "<<resr1 << endl;
			return 0;
		}
		else if (resl1 < res && res < resr1)r = mid;
		else if (resl1 > res && res > resr1)l = mid;
		else if (resl1 > res && res < resr1) {
			cout << res << endl;
			//cout << mid << " " << resl1 << " " << res << " " << resr1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
#define vii vector <pair <int, int> >
using namespace std;

const ll MAXN = 111;

bool used[MAXN];
ll n;
vector < pair <ll, ll> > ans;

void solve() {

    cin >> n;

    if(n % 2 != 0) {

        for(int i = 1; i <= n / 2; ++i) {

            ll k = n - 1;

            ll l = i;
            ll r = k - i + 1;

            ans.pb(mper(l, n));
            ans.pb(mper(r, n));

        }

        n--;


    }


        for(int i = 1; i <= n / 2; ++i) {

            ll l = i;
            ll r = n - i + 1;
            used[r] = 1;

            for(int j = l + 1; j <= n; ++j) {

                if(!used[j]) {

                    ans.pb(mper(j, l));
                    ans.pb(mper(j, r));

                }

            }

        }

    cout << ans.sz() << '\n';

    sort(all(ans));

    for(auto to : ans) {

        cout << to.fe << ' ' << to.se << '\n';

    }

}

int main(){

mal
//freopen("ladder.in", "r", stdin);
//freopen("ladder.out", "w", stdout);

ll tt = 1;


while(tt--) {

    solve();

}

return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
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 main(void){

  int N;    cin >> N;
  vector<int> A(N);
  for(int i = 0 ; i < N ; i++)
    cin >> A[i];

  
  int lcm_num = 1;
  for(int i = 0 ; i < N ; i++){
    //最小公倍数を求める
    lcm_num = lcm(lcm_num , A[i]);
  }

  int down = 0;
  for(int i = 0 ; i < N ; i++)
    down += lcm_num / A[i];
  

  cout << lcm_num / (float)down << endl;

  return 0;
}

Measured memory_bytes: 256
//“Failure is unimportant. It takes courage to make a fool of yourself.”

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define b(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 1000
#define PI 3.14159265359
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;

signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ll n;
    cin>>n;
    map<string,ll> m;
    f(i,0,n){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<sz(m);
    return 0;
}


Measured memory_bytes: 19280
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, k; cin >> n >> k;
	cout << min(n % k, k - n % k) << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int score=0;
		int a=0,b=0,c=0;
		for(int out=0;out<3;)
		{
			string s;cin>>s;
			if(s=="HIT")
			{
				score+=c;
				c=b;
				b=a;
				a=1;
			}
			else if(s=="HOMERUN")
			{
				score+=a+b+c+1;
				a=b=c=0;
			}
			else
			{
				out++;
			}
		}
		cout<<score<<endl;
		
	}
}

Measured memory_bytes: 1212
program main
	integer N, i, j, ans
	integer, allocatable :: A(:, :), S(:, :)
	read(*, *) N
	allocate(A(1:2, 1:N))
	allocate(S(1:2, 0:N))
	read(*, *) A(1, 1:N)
	read(*, *) A(2, 1:N)
	S(1:2, 0) = 0
	do i = 1, N
		do j = 1, 2
			S(j, i) = S(j, i-1) + A(j, i)
		end do
	end do
	ans = 0
	do i = 1, N
		ans = max(S(1, i) + (S(2, N) - S(2, i-1)), ans)
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,A,B;

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

    cout<<min(N*A,B)<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())

count = defaultdict(int)
for x in map(str, range(1, N+1)):
    head = x[0]
    tail = x[-1]
    count[(head, tail)] += 1
    
ans = 0
items = list(count.items())
for (head, tail), c in items:
    ans += c * count[(tail, head)]
    
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[100],b;
	a[5] = 0;
	a[7] = 0;
	for(int i=1;i<=3;i++){
		scanf("%d",&b);
		a[b]++;
	}
	if(a[5] == 2 && a[7] == 1){
		printf("YES");
	}
	else{
		printf("NO");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M; cin >> N >> M;
  ll path[M][3];
  rep(i, M) {
    cin >> path[i][0] >> path[i][1] >> path[i][2];
    path[i][0]--; path[i][1]--;
  } 

  ll s_max[N], s_prev[N];
  ll s_1, s_2;
  rep(i, N) s_max[i] = -1 * pow(2,40); s_max[0] = 0;
  rep(i, M) {
    rep(i, N) s_prev[i] = s_max[i];
    for (auto x: path) s_max[x[1]] = max(s_max[x[1]], s_prev[x[0]]+x[2]); 
  }
  s_1 = s_max[N-1];
  rep(i, M) {
    rep(i, N) s_prev[i] = s_max[i];
    for (auto x: path) s_max[x[1]] = max(s_max[x[1]], s_prev[x[0]]+x[2]); 
  }
  s_2 = s_max[N-1];

  if (s_1>=s_2) cout << s_1 << endl;
  else cout << "inf" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  sort(ALL(a));
  int ans = abs(*a.begin() - *a.rbegin());
  cout << ans << endl;
  return 0;
}

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

long long MOD = 1e9+7;

long long fac(long long n) {
  return n - 1 ? n * fac(n - 1) % MOD : 1;
}

int main() {
  long long N, M;
  cin >> N >> M;
  cout << ((abs(N - M) > 1) ? 0 : (N == M) ? fac(N) * fac(M) % MOD * 2 % MOD : fac(N) * fac(M) % MOD) << "\n";
}

Measured memory_bytes: 1792
using System;
class Program
{
    static void Main(string[] args)
    {
		string[] str = Console.ReadLine().Split(' ');
		int n = int.Parse(str[0]);
		string output = "";
		float cakesNum = 0;
		int donutsNum = 0;

		output = "No";
		for (int i = 0; n - 7 * i >= 0;i++){
			cakesNum = (n - 7 * i )/ 4f;
			//Console.WriteLine(cakesNum);
			if (cakesNum == (int)cakesNum)
			{
				output = "Yes";
				break;
			}            
		}        

        //出力        
		Console.WriteLine(output);

    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;


int sum[2][2001][2001];


int getScore(int i, int x, int y, int k) {
    if (x < 0 || y < 0 || x - k + 1 >= 2 * k || y - k + 1 >= 2 * k)
        return 0;

    int x1 = min(x - k, 2 * k - 1);
    int y1 = min(y, 2 * k - 1);

    int x2 = min(x, 2 * k - 1);
    int y2 = min(y - k, 2 * k - 1);

    int x3 = min(x - k, 2 * k - 1);
    int y3 = min(y - k, 2 * k - 1);

    x = min(x, 2 * k - 1);
    y = min(y, 2 * k - 1);

    int score = sum[i][x][y];

    if (x1 >= 0 && y1 >= 0)
        score -= sum[i][x1][y1];

    if (x2 >= 0 && y2 >= 0)
        score -= sum[i][x2][y2];

    if (x3 >= 0 && y3 >= 0)
        score += sum[i][x3][y3];

    return score;
}


int main() {
    int n, k;
    cin >> n >> k;

    REP(i, n) {
        int xi, yi;
        string ci;
        cin >> xi >> yi >> ci;
        sum[0][(xi + (ci[0] == 'B' ? k : 0)) % (2 * k)][yi % (2 * k)]++;
    }

    REP(p, 2) REP(q, 2 * k) REP(r, 2 * k)
        sum[p][q][r] += (q > 0 ? sum[p][q - 1][r] : 0) + (r > 0 ? sum[p][q][r - 1] : 0) - (q > 0 && r > 0 ? sum[p][q - 1][r - 1] : 0);

    int best = 0;

    REP(p, 2 * k) REP(q, 2 * k) {
        int current = 0;

        int index = 0;
        REP(i, 5) REP(j, 5) {
            current += getScore(index, p - 2 * k + k * i, q - 2 * k + k * j, k);
            index ^= 1;
        }

        best = max(best,current);
    }
    
    cout << best << endl;
    
    return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
cin >> str;
int i;
int m,b;
while(str!="-"){
cin >> m;
for(i=0;i<m;i++){
cin >> b;
str=str.substr(b,str.size()-b)+str.substr(0,b);
}
cout << str << endl;
cin >> str;
}
return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> S;
    if(S == "Y"){
    cout << "Four" << endl;
      break;
    }
  } //for
  if (S != "Y"){
    cout << "Three" <<endl;
  }
} //main


Measured memory_bytes: 256