akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long min = in.nextInt();
            long max = in.nextInt();

            if (n == 1 && min != max || min > max) {
                out.println(0);
            } else {
                out.println((n - 2) * (max - min) + 1);
            }
        }

    }
}



Measured memory_bytes: 21844
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
num_ls = [i for i in range(1, m+1)]

comb = combinations_with_replacement(num_ls, n)
ans = 0
for v in comb:
    cnt = 0
    for a, b, c, d in abcd:
        if v[b-1] - v[a-1] == c:
            cnt += d
    ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 9140
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        class Student
        {
            public int midterm = -1;
            public int final = -1;
            public int extra = -1;

            private bool hasMidtermResult { get { return midterm != -1; } }
            private bool hasFinalResult { get { return final != -1; } }
            private bool hasExtraResult { get { return extra != -1; } }

            private int getSum()
            {
                int sum = 0;
                if (hasMidtermResult)
                {
                    sum += midterm;
                }
                if (hasFinalResult)
                {
                    sum += final;
                }
                return sum;
            }
            private bool isFforced { get { return midterm == -1 || final == -1; } }
            private bool isAup { get { return getSum() >= 80; } }
            private bool isBup { get { return getSum() >= 65; } }
            private bool isCup
            {
                get
                {
                    if (getSum() >= 50) return true;
                    if (isDup && hasExtraResult && extra >= 50) return true;
                    return false;
                }
            }
            private bool isDup { get { return getSum() >= 30; } }

            public string grade
            {
                get
                {
                    if (isFforced == false)
                    {
                        if (isAup) return "A";
                        if (isBup) return "B";
                        if (isCup) return "C";
                        if (isDup) return "D";
                    }
                    return "F";
                }
            }
        }
        static void Main(string[] args)
        {
            for (; ; )
            {
                var inputLine = Console.In.ReadLine();
                var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
                if (inputs.Length != 3)
                {
                    return;
                }

                var integers = new List<int>();
                foreach (var s in inputs)
                {
                    integers.Add(int.Parse(s));
                }

                Student student = new Student { midterm = integers[0], final = integers[1], extra = integers[2] };
                if (student.midterm == -1 && student.final == -1 && student.extra == -1)
                {
                    break;
                }

                Console.WriteLine(student.grade);
            }
        }
    }
}



Measured memory_bytes: 17900
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.print(x*y);
        System.out.print(" ");
        System.out.print(2*x+2*y);
        System.out.println();
    }
}


Measured memory_bytes: 25884
input_lines = input().split()
a = int(input_lines[0])
input_lines = input().split()
b = int(input_lines[0])
input_lines = input().split()
c = int(input_lines[0])
input_lines = input().split()
d = int(input_lines[0])
input_lines = input().split()
e = int(input_lines[0])
input_lines = input().split()
k = int(input_lines[0])
if e - a <= k:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 3060
def inWall(x,y,x1,y1,r):
	return True if ((x-x1)**2+(y-y1)**2)**0.5 <= r + 1e-9 else False

def isHide(x,y,r,a,b,c):
	D = abs(a*x+b*y+c)/(a**2+b**2)**0.5
	return True if D <= r + 1e-9 else False

def isBetween(x,y,tx,ty,sx,sy):
	a,b,c = (x-tx)**2+(y-ty)**2,(x-sx)**2+(y-sy)**2,(sx-tx)**2+(sy-ty)**2
	if c > b and c > a: return True
	a,b,c = sorted([a,b,c])
	return True if c-a-b <= 0 else False

while 1:
	n = input()
	if n == 0: break
	wall = [map(int,raw_input().split()) for i in range(n)]
	for i in range(input()):
		tx,ty,sx,sy = map(int,raw_input().split())
		a,b,c = -(ty-sy),tx-sx,sx*ty-sy*tx
		for x,y,r in wall:
			t_in,s_in = inWall(x,y,tx,ty,r),inWall(x,y,sx,sy,r)
			if t_in != s_in:
				print "Safe"
				break
			if not t_in and isBetween(x,y,tx,ty,sx,sy) and isHide(x,y,r,a,b,c):
				print "Safe"
				break
		else:
			print "Danger"

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

using namespace std;

const int maxn = 2e5+10;

int a[maxn];

int main(void)
{
	multiset<int> st;

	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		st.insert(-a[i]);
	}

	for (int i = 1; i <= n; i++)
	{
		auto it = st.find(-a[i]);
		st.erase(it);
		printf("%d\n", -*(st.begin()));
		st.insert(-a[i]);
	}
}

Measured memory_bytes: 11776
#include <iostream>
#include <algorithm>

using namespace std;

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

    int fav, food_num;
    for (int i=0; i<N; i++) {
        cin >> food_num;
        for(int j=0; j<food_num; j++) { cin >> fav; food[fav-1]++; }
    }

    int result = 0;
    for (int i=0; i<M; i++) if (food[i] == N) result++;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int f,t;
char c;
deque<char>dq;
char ch[300010];
int main(){
	cin>>s;
	int q;
	cin>>q;
	int flag=0;
	for(int i=0;i<s.size();i++){
		dq.push_back(s[i]);
	}
	for(int i=0;i<q;i++){
		cin>>t;
		if(t==1){
			if(flag==0){
				flag=1;
			}else{
				flag=0;
			}
		}else{
			cin>>f>>c;
			if(f==1){
				if(flag==0){
					dq.push_front(c);
				}else{
					dq.push_back(c);
				}
			}else{
				if(flag==1){
					dq.push_front(c);
				}else{
					dq.push_back(c);
				}
			}
		}
			//cout<<s<<endl;
	}
	if(flag==0){
		for (deque<char>::iterator iter = dq.begin(); iter != dq.end(); iter++){
        	cout << *iter;
    	}
    }else{
    	for (deque<char>::reverse_iterator riter = dq.rbegin(); riter != dq.rend(); riter++){
        	cout << *riter;
    	}
	}
    
    
    
}


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

int main()  
{  
    int a,b,c;
    int s;
    cin>>a>>b>>c;
    s=a+b+c;
    if(s>=22)
        cout<<"bust"<<endl;
    else
        cout<<"win"<<endl;


    return 0;  
}  
  


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <cmath>
using namespace std;

int main() {
	long double sum = 0;
	int N; cin >> N;

	for (int i = 1; i <= N; i++) {
		string V1; long double V2; cin >> V2 >> V1;
		if (V1 == "JPY") sum += 1.0L*V2;
		else sum += 380000.0L * V2;
	}
	printf("%.12Lf\n", sum);
	return 0;
}

Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int x, y;
                                                 
void solve(){
	cin >> x >> y;

	if (y >= x)
		cout << "unsafe";
	else
		cout << "safe";
}   
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;

    //cin >> q;

    while (q--){
        solve();
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  string A;
  cin>>A;
  ll N=A.size();
  map<char,ll> m;
  for(int i=0;i<N;i++){
    if(m.count(A.at(i))==0){
      m[A.at(i)]=0;
    }
    m[A.at(i)]++;
  }
  ll ans=0;
  for(auto x:m){
    ans+=x.second*(N-x.second);
  }
  cout<<ans/2+1<<endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  unordered_set<long> foo, bar;
  rep (i, M) {
    long a, b;
    cin >> a >> b;
    if (a == 1) foo.insert(b);
    if (b == N) bar.insert(a);
  }
  for (auto it: foo) {
    if (bar.count(it)) {
      cout << "POSSIBLE" << endl;
      return;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 8520
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  n: usize,
  k: i64,
  q: i64,
  }

  let mut vec = vec![0; n];

  for _ in 0..q {
    input! {
      a: i64,
    }
    vec[(a - 1) as usize] += 1;
  }

  debug!(vec);

  for i in vec {
    if k - q + i <= 0 {
      println!("No")
    } else {
      println!("Yes")
    }
  }

}


Measured memory_bytes: 3248
inf = 10 ** 15
mod = 10 ** 9 + 7

d,g = map(int, input().split())
p = [list(map(int, input().split())) for i in range(d)]
p.reverse()
ans = inf
for i in range(2**d):
    count = 0
    total = 0
    for j in range(d):  # このループが一番のポイント
        if ((i >> j) & 1):  # 1だったら(オンだったら)
            count += p[j][0]
            total += p[j][0] * 100*(d-j) + p[j][1]
    if total >= g:
        ans = min(ans, count)
    else:
        for j in range(d):
            if not ((i >> j) & 1):
                num = p[j][0]
                score = 100*(d-j)
                if score*num >= g-total:
                    must = (g-total+score-1)//score
                    total+=score*must
                    count+=must
                    break
                else:
                    total+=score*num
                    count+=num
        ans = min(ans, count)
print(ans)

Measured memory_bytes: 40944
#include <cstdio>

int N,K,M,f[305][305][305];

int main()
{
    scanf("%d%d%d",&N,&K,&M),f[0][1][0]=1;
    for(int i=0;i<=N;i++)
        for(int j=1;j<=K;j++)
            for(int k=i;k>=0;k--)
                if(f[i][j][k])
                {
                    if(k)(f[i][j][k-1]+=f[i][j][k])%=M;
                    else(f[i][j+1][i]+=f[i][j][k])%=M;
                    f[i+1][j][k]=(f[i+1][j][k]+(k+1ll)*f[i][j][k])%M;
                }
    printf("%d\n",f[N][K+1][N]);
    return 0;
}


Measured memory_bytes: 110720
#include <stdio.h>
#define Q_MAX 100000
#define A_MAX 2147483647

int main() {
    int n, x, bit, i, q, a[Q_MAX][3];
    scanf("%d%d", &n, &q);
    a[0][0] = 0;
    a[0][1] = n-1;
    a[0][2] = A_MAX;
    i = 1;
    while (~scanf("%d", &bit)) {
        if (bit) {
            scanf("%d", &x);
            for (int j=i-1; j>=0; j--)
                if (x >= a[j][0] && x <= a[j][1]){
                    printf("%d\n", a[j][2]);
                    break;
                }
        } else {
            int *m = *(a+i);
            scanf("%d%d%d", m, m+1, m+2);
            i++;
        }
    }
}



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

int main() {
  long K;
  cin >> K;
  long count = 1;
  long X = 7;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int r;
  for (int i = 0; i < K; i++) {
    if (X % K == 0) {
      break;
    }
    count++;
    r = X % K;
    r *= 10;
    r += 7;
    X = r;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  vector <pair <char, ll>> v(52);
  rep(i, 4) {
    rep(j, 13) {
      if (i == 0) {
        v.at(i*13+j) = make_pair('S', 0);
      } else if (i == 1) {
        v.at(i*13+j) = make_pair('H', 0);
      } else if (i == 2) {
        v.at(i*13+j) = make_pair('C', 0);
      } else {
        v.at(i*13+j) = make_pair('D', 0);
      }
    }
  }
  ll n;
  cin >> n;
  char c;
  ll a;
  rep(i, n) {
    cin >> c >> a;
    if (c == 'S') {
      v.at(0*13+a-1).second++;
    } else if (c == 'H') {
      v.at(1*13+a-1).second++;
    } else if (c == 'C') {
      v.at(2*13+a-1).second++;
    } else {
      v.at(3*13+a-1).second++;
    }
  }
  rep(i, 52) {
    if (v.at(i).second == 0) {
      cout << v.at(i).first << ' ' << i%13+1 << endl;
    }
  }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	int N;
  	cin>>N;
  
  	ll A[N];
  
  	rep(i,N) cin>>A[i];
  	
  	sort(A,A+N,greater<ll>());
  
  	int i=1;
  	int j=1;
  	ll sum=A[0];
  
  	while(i<N-1){
      	 if(i==N-2){
           	sum+=A[j];
           	break;
         }
      	 sum+=2*A[j];
     	 i+=2;
      	 j++;
    }
  	
  	cout<<sum<<endl;
  	
}

Measured memory_bytes: 5156
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200010];
int main()
{
	int n,i,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++)
	{
		if(a[i]==a[i+1])
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	{
		printf("NO\n");
	}
	else
	{
		printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(void)

{
string s;
int a=0,b=0;
cin>>s;
for (int i =0;i<s.length();i++)
{
    if (s[i]=='A')a++;
    else b++;
}
if (a==3 || b==3)cout<<"No";
else cout<<"Yes";

}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
	double a,b;
	scanf("%lf%lf",&a,&b);
	double t=b*b;
	int s=0;
	for(int i=1;i<=a;i++)
	{
		double n,m;
		scanf("%lf%lf",&n,&m);
		if((n*n+m*m)<=t) s++;
	}
	printf("%d",s);
	return 0;	
} 
 


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

int main() {
	int n;
	cin >> n;
	vector<int> ans(n);
	vector<int> syain(n - 1);
	for(int i = 0; i < syain.size(); i++)cin >> syain.at(i);
	for(int i = 0; i < syain.size(); i++){
		ans.at(syain.at(i) - 1) += 1;
	}
	for(int i = 0; i < n; i++){
		cout << ans.at(i) <<endl;
	}
}

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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = nlong();
            B[i] = nlong();
        }
        
        long ans = 0;
        for (int i = N-1; i >= 0; i--) {
            A[i] += ans;
            long ansi = (B[i] - A[i] % B[i]) % B[i];
            ans += ansi;
        }
        System.out.println(ans);
    }
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }
    
    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }
    
    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }
    
    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }
    
    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }
    
    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }
}


Measured memory_bytes: 87700
array=[]
n=input().split()
N=int(n[0])
D=int(n[1])
for i in range(N):
    line=input().split()
    array.append(int(line[0])**2+int(line[1])**2)
list=[]
for i in array:
    if i <=D**2: 
       list.append(i)
print(len(list))


Measured memory_bytes: 21196
i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

for n in range(i):
    if l[n] == n+1:
        continue
    else:
        f = f + 1
        continue

if f == 2:
    print('YES')
elif f == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,M,Q; cin>>N>>M>>Q;
	vector<int>a(Q),b(Q),c(Q),d(Q);
	for(int i=0;i<Q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--, b[i]--;
	}
	queue<vector<int>>q;
	for(int i=1;i<=M;i++)
	 	q.push({i});
	for(int i=0;i<N-1;i++){
		int orig=q.size();
		for(int j=0;j<orig;j++){
			vector<int>cur=q.front(); q.pop();
			for(int k=cur.back();k<=M;k++){
				cur.push_back(k);
				q.push(cur);
				cur.pop_back();
			}
		}
	}
	long long ret=0;
	while(!q.empty()){
		vector<int>cur=q.front(); q.pop();
		long long score=0;
		for(int i=0;i<Q;i++){
			if(cur[b[i]]-cur[a[i]]==c[i])
				score+=d[i];
		}
		ret=max(ret,score);
	}
	cout<<ret<<'\n';	
	return 0;
}

Measured memory_bytes: 9776
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<long long> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    sort(c.begin(), c.end(), greater<long long>());

    int mod = 1000000007;
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += c[i] * (i + 2);
        res %= mod;
    }

    for (int i = 1; i < n; i++) {
        res *= 4;
        res %= mod;
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    string s, t;
    cin >> s >> t;
    vector<int> a(s.begin(), s.end()), b(t.begin(), t.end());
    for (int &i : a)
        i -= '0';
    for (int &i : b)
        i -= '0';
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    n = max(n, m);
    a.resize(n);
    b.resize(n);
    vector<int> stk, foo;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] + b[i] == 1) {
            stk.push_back(i);
            continue;
        }
        if (a[i] + b[i] == 0)
            continue;
        int xa = 1, xb = 1;
        int z = k - 1;
        a[i] = b[i] = 0;
        int j = i + 1;
        while (z >= 0) {
            if ((stk.empty() || j != stk.back()) && (xa != 1 || xb != 1)) {
                if ((int)a.size() <= j)
                    a.resize(j + 1);
                if ((int)b.size() <= j)
                    b.resize(j + 1);
                a[j] = xa;
                b[j] = xb;
                stk.push_back(j);
                break;
            }
            int step = min(z, stk.empty() ? z : stk.back() - j);
            j += step;
            z -= step;
            if (stk.empty() || stk.back() > j) {
                assert(z == 0);
                if ((int)a.size() <= j)
                    a.resize(j + 1);
                if ((int)b.size() <= j)
                    b.resize(j + 1);
                a[j] = b[j] = 1;
                break;
            }
            assert(j == stk.back());
            stk.pop_back();
            if (a[j] == 1) {
                a[j] = 0;
                if (xa == 0) {
                    if (z == 0) {
                        a[j] = b[j] = 1;
                        break;
                    }
                    --z;
                    xa = xb = 1;
                } else {
                    b[j] = xb;
                    if (xb == 1)
                        foo.push_back(j);
                    xb = 0;
                }
            } else {
                b[j] = 0;
                if (xb == 0) {
                    if (z == 0) {
                        a[j] = b[j] = 1;
                        break;
                    }
                    --z;
                    xa = xb = 1;
                } else {
                    a[j] = xa;
                    if (xa == 1)
                        foo.push_back(j);
                    xa = 0;
                }
            }
            ++j;
        }
        while (!foo.empty()) {
            stk.push_back(foo.back());
            foo.pop_back();
        }
    }
    while (a.back() == 0)
        a.pop_back();
    while (b.back() == 0)
        b.pop_back();
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for (int i : a)
        cout << i;
    cout << "\n";
    for (int i : b)
        cout << i;
    cout << "\n";
    return 0;
}

Measured memory_bytes: 29996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++) 
typedef pair<int,int> P;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int h,w,c;
int tile[10][10];
int cnt_tile() {
    bool visit[10][10] = {};
    int t = tile[0][0];
    int ret = 1;
    queue<P> que;

    que.push(P(0,0));
    visit[0][0] = true;

    while(que.size()) {
        P p = que.front(); que.pop();
        rep(i,4) {
            int y = p.first + dy[i];
            int x = p.second + dx[i];
            if(!(0<=x&&x<w && 0<=y&&y<h)) continue;
            if(visit[y][x]) continue;
            if(tile[y][x] != t) continue;
            visit[y][x] = true;
            if(tile[y][x] == c) ret++;
            que.push(P(y,x));
            
        }
    }
    return ret;
    
}
void fill_tile(int color) {
    bool visit[10][10] = {};
    int t = tile[0][0];
    tile[0][0] = color;
    queue<P> que;

    que.push(P(0,0));
    visit[0][0] = true;

    while(que.size()) {
        P p = que.front(); que.pop();
        rep(i,4) {
            int y = p.first + dy[i];
            int x = p.second + dx[i];
            if(!(0<=x&&x<w && 0<=y&&y<h)) continue;
            if(visit[y][x]) continue;
            if(tile[y][x] != t) continue;
            visit[y][x] = true;
            tile[y][x] = color;
            que.push(P(y,x));
        }
    }

}
int dfs(int depth_) {
    if(depth_ == 5) return cnt_tile();
    int ret = 0;

    for(int k=1;k<=6;k++) {
        int tmp[10][10];
        rep(i,10) rep(j,10) tmp[i][j] = tile[i][j];
        fill_tile(k);
        ret = max(ret,dfs(depth_+1));
        rep(i,10) rep(j,10) tile[i][j] = tmp[i][j];
    }

    return ret;
}
void solve() {
    rep(i,10) rep(j,10) tile[i][j] = 0;
    rep(i,h) rep(j,w) cin>>tile[i][j];
    cout<<dfs(0)<<endl;

}
int main() {
    while(cin>>h>>w>>c) {
        if(h+w+c==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void) {
	int a,b,c,i,x;
	x=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(c%i==0)x++;
	}
	printf("%d\n",x);
	return 0;
}



Measured memory_bytes: 2104
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,a,b=map(int, input().split())
    if (abs(a-b))%2==0:
        print((abs(a-b))//2)
    else:
        ue=max(a,b)-1
        sita=n-min(a,b)
        hokasita=((n-max(a,b))*2+1+abs(b-a))//2
        hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
        print(min(ue,sita,hokasita,hokaue))
resolve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 	ll a,b; cin>>a>>b;
	if(a==b) return cout<<1,0;
	ll i=60,nw=0;
 	while((a>>i&1)==(b>>i&1)) nw|=(a>>i&1)*(1ll<<i), i--;
	ll r=(1ll<<i)|nw;
	for(int j=i-1;j>=0;j--)if(b>>j&1) b|=(1ll<<(j+1))-1;
	cout<<min(b-a+1,1ll<<i)+r-a;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;
const ll INF = 1e16;

typedef pair<ll, ll> P;

vector<ll> G[3 * 100100];
ll N, M;
ll d[3*100100];

void dijkstra(ll s){
    REP(i,3*N) d[i] = INF;
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(d[s], s));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        ll v = p.second;
        ll dist = p.first;
        if(d[v] < dist) continue;
        for(auto&& n : G[v]){
            ll dist2 = dist + 1;
            if(dist2 < d[n]){
                d[n] = dist2;
                que.push(P(dist2, n));
            }
        }
    }
}

int main(){
    cin >> N >> M;
    REP(i,M){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        REP(k,3){
            G[N*k + u].push_back(N*((k+1)%3) + v);
        }
    }
    ll S, T;
    cin >> S >> T;
    S--, T--;

    dijkstra(S);
    //ll ans = d[2*N+T];
    ll ans = d[T];
    if(ans == INF)
        cout << -1 << endl;
    else
        cout << ans/3 << endl;
    return 0;
}


Measured memory_bytes: 18944
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	scanf("%d", &N);
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		scanf("%d", &A[i]);

	sort(A.begin(), A.end());

	vector<int> count(A[A.size() - 1] + 1, 0);
	for (int i = 0; i < (int)A.size(); i++) {
		for (int j = A[i]; j < (int)count.size(); j += A[i]) {
			count[j]++;
		}
	}

	int ans = 0;

	for (int i = 0; i < (int)A.size(); i++) {
		if (count[A[i]] == 1)
			ans++;
	}

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

	return 0;
}

Measured memory_bytes: 7528
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
//#define N 1000000007

using namespace std;

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

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

int main(){
    lli n,t,a,b;
    vector<lli> time;
    lli i;
    cin>>n;
    rep(i,0,n){
        cin>>t;
        time.push_back(t);
    }
    rep(i,1,n){
        a=max(time[i-1],time[i]);
        b=min(time[i-1],time[i]);
//        cout<<b<<"と"<<a<<"の最小公倍数は";
        time[i]=lcm(a,b);
//        cout<<time[i]<<endl;
    }
    cout<<time[n-1]<<endl;
}


Measured memory_bytes: 256
def main():
    N, M = list(map(int, input().split(' ')))
    digits = [-1 for _ in range(N)]
    for _ in range(M):
        s, c = list(map(int, input().split(' ')))
        if N > 1 and s == 1 and c == 0:
            print(-1)
            exit(0)
        if digits[s - 1] != -1 and digits[s - 1] != c:
            print(-1)
            exit(0)
        digits[s - 1] = c
    # non-specified digits -> 0
    for d in range(N - 1, -1, -1):
        if digits[d] == -1:
            digits[d] = 0
    # non-specified top digit -> 1
    if N > 1 and digits[0] == 0:
        digits[0] = 1
    answer = 0
    for v in digits:
        answer = answer * 10 + v
    print(answer)


if __name__ == '__main__':
    main()


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

int main()
{
	int n;
	int c[50] = {0};
	int v[50] = {0};
	int result = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> c[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if(v[i] >= c[i]){
			result = result + v[i] - c[i];
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
//#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
//#include <array>
#include <valarray>
#include <stdio.h>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")
#include <algorithm>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

long long  int nCm(long long int n, long long int m) {
	if (m == 1) {
		return n;
	}
	else {
		return n*nCm(n - 1, m - 1) / m;
	}
}

long long int npm(long long int n,long long int m) {
	if (m == 1) {
		return n;
	}
	else 
		if (m == 0) {
			return 1;
		}else {
		return n*npm(n, m - 1);
	}
}

 int main() {
	 int naka = 0;
	 int N;
	 cin >> N;
	 vector<int> An(N+1);
	 for (int i = 1; i <= N; ++i){
		 cin >> An[i];
	 }
	 for (int i = 1; i <= N; ++i) {
		 if (An[i] > i&&An[An[i]] == i) {
			 naka++;
		 }
	 }
	 cout << naka << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  vector<int> h(N); 
  rep(i,N) cin >> h[i];
  int retval = 0;
  
  while (1){
    if (*max_element(all(h))==0) break;

    int l=0;
    while (l<N){
      if (h[l]==0) l++;
      else {
        retval++;
        while (l<N && h[l]>0){
          h[l]--;
          l++;
        }
      }
    }

  }
  cout << retval << endl;
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace  std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define INF 1<<30
#define LINF 1LL<<60


class Dijkstra{
public:
    ll V;
    ll root;
    
    struct edge{
        ll u;
        ll v;
        ll cost;
        edge(){}
        edge(ll u,ll v,ll c):u(u),v(v),cost(c){}
    };
    
    vector<vector<edge>> G;
    vector<ll> dist;
    
    Dijkstra(ll V):V(V){
        G.resize(V);
        dist.assign(V, INF);
    }
    void add_edge(ll u,ll v,ll cost, bool undirected = false){
        G[u].emplace_back(edge(u,v,cost));
        if(undirected){
            G[v].push_back(edge(v,u,cost));
        }
    }
    
    void calc_dist(ll root){
        this->root = root;
        dist[root] = 0;
        queue<pll> q; q.push({root,0});
        while(!q.empty()){
            auto p = q.front(); q.pop();
            ll n = p.first;
            ll now_d = p.second;
            if(now_d > dist[n]) continue;
            for(auto e:G[n]){
                if(dist[e.v] > dist[e.u] + e.cost){
                    dist[e.v] = dist[e.u] + e.cost;
                    q.push({e.v,now_d + e.cost});
                }
            }
        }
    }
    
    inline ll get_dist(ll n) const{ return dist[n];}
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll V,E,r; cin >> V >> E >>r;
    Dijkstra dijkstra(V);
    for(int i = 0; i < E;i++){
        ll s,t,d; cin >> s >> t >> d;
        dijkstra.add_edge(s, t, d);
    }
    
    dijkstra.calc_dist(r);
    
    for(int i = 0; i < V;i++){
        ll dist = dijkstra.get_dist(i);
        if(dist != INF) cout << dist;
        else cout << "INF";
        cout <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 23620
s = input()
l = set(s)
ans = 10 ** 10
for x in l:
    cnt, cnt_max = 0, 0
    for i in s:
        if i != x:
            cnt += 1
        else:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
    cnt_max = max(cnt_max, cnt)
    ans = min(cnt_max, ans)
print(ans)


Measured memory_bytes: 8932
a,b,c,d = map(int,input().split())

ans = min(b,d) - max(a,c)
if ans < 0:
    print(0)
else:
    print(ans)
"""
if d<a:#0
    print(0)
elif c<a and a<d<b:#1
    print(d-a)
elif c<a and b<d:#2
    print(b-a)
elif a<c and d<b:#3
    print(d-c)
elif a<c<b and b<d:#4
    print(b-c)
elif b<c:#5
    print(0)
"""

Measured memory_bytes: 3064
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int a = scanInt();
		int b = scanInt();
		int c = scanInt();
		out.print(b + min(c, a + b + 1));
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 22612
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        while self.parents[x] != root:
            parent = self.parents[x]
            self.parents[x] = root
            x = parent
        return root

    def unite(self, x, y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot:
            return
        xrank = self.rank[xroot]
        yrank = self.rank[yroot]
        if xrank < yrank:
            self.parents[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        elif xrank == yrank:
            self.parents[yroot] = xroot
            self.rank[yroot] += 1
            self.size[xroot] += self.size[yroot]
        else:
            self.parents[yroot] = xroot
            self.size[xroot] += self.size[yroot]

    def len(self, x):
        return self.size[self.find(x)]

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

uf = UnionFind(N)

for _ in range(M):
    x, y, z = map(int, input().split())
    uf.unite(x - 1, y - 1)

print(len(set([uf.find(i) for i in range(N)])))

Measured memory_bytes: 64544
//#include<cstdio>
//
//using namespace std;
//
//int a;
//bool b[100];
//
//int main(){
//	scanf("%d", &a);
//	for(int i = 1; i <= 9; i++)
//		for(int j = 1; j <= 9; j++)
//			b[i*j] = 1;
//	if(a <= 81 && b[a])
//		puts("Yes");
//	else
//		puts("No");
//	return 0;
//}

#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long LL;

const LL INF = 1e16;
LL a, ans = INF;

int main(){
	scanf("%lld", &a);
	for(LL i = 1; i * i <= a; i++){
		if(a % i)	continue;
		ans = min(ans, a / i + i);
	}
	printf("%lld\n", ans - 2);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n, x[105];
long long curr, res(1e18);
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    for (int p = 1; p <= 100; ++p) {
        curr = 0;
        for (int i = 1; i <= n; ++i)
            curr += (x[i] - p) * (x[i] - p);
        res = min(res, curr);
    }
    cout << res;
    PLEC
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      Deque<Integer>  box = new ArrayDeque<>();
      for (int i = 1; i <= n; i++) {
        if(n % 2 == i % 2) {
            box.addFirst(sc.nextInt());
        } else {
            box.addLast(sc.nextInt());
        }
      }
      box.stream()
              .forEach(e -> System.out.print(e  + " "));
  }
}

Measured memory_bytes: 99648
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//確かに便利だ↑

int main(){
    //方針1
    int n;cin>>n;
    vector<vector<int>> a(n,vector<int>(n-1));
    //これで二次元配列ができるのか...
    rep(i,n){
        rep(j,n-1){
            cin>>a[i][j];
            a[i][j]--;
        }
        reverse(a[i].begin(),a[i].end());
        //末尾からの削除が速いので、
        //ひっくり返しておく.
    }
    vector<P> q;
    //↓対戦できるかのチェック
    auto check = [&](int i){
        if(a[i].size() == 0)return;
        int j = a[i].back();
        //backで末尾の要素を鳥取り出す。
        if(a[j].size() == 0)return;
        //↓のは僕と同じ考え方
        if(a[j].back() == i){
            //そして試合するメンツをqueにぶち込む
            P p(i,j);
            if(p.second < p.first) swap(p.first,p.second);
            q.push_back(p);
            //重複は後で消すのでおｋ
        }
    };
    //初期化.
    rep(i,n){
        check(i);
    }
    int day = 0;
    while(q.size() > 0){
        day++;
        sort(q.begin(),q.end());
        q.erase(unique(q.begin(),q.end()),q.end());
        vector<P> prevQ;
        swap(prevQ,q);
        for(P p:prevQ){
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for(P p:prevQ){
            //試合した奴らだけcheckすればいい.
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }
    //確かにこの方法なら、試合した時だけcheckが入るようになっている.
    //最後に全部終わったかチェック
    rep(i,n){
        if(a[i].size() != 0){
            puts("-1");
            //-1を出力するのにこんな方法があるのか....
            return 0;
        }
    }
    cout<<day<<endl;
    return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

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

        int[] a = new int[5];

        for (int i = 0; i < 5; i++) {
            a[i] = sc.nextInt();
        }
        int k = sc.nextInt();

        boolean isAns = true;
        for (int i = 0; i < 4; i++) {
            for (int j = i+1; j < 5; j++) {
                if (a[j] - a[i] > k)
                    isAns = false;
            }
        }

        System.out.println(isAns ? "Yay!" : ":(");
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
ll H, W;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    char s[55][55];
    rep(i, H)
    {
        rep(j, W)
        {
            cin >> s[i][j];
        }
    }
    rep(i, H)
    {
        rep(j, W)
        {
            if (s[i][j] == '#' && s[i + 1][j] != '#' && s[i - 1][j] != '#' && s[i][j + 1] != '#' && s[i][j - 1] != '#') {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char a,b,c;
	scanf("%c",&a);
	scanf("%c",&b);
	scanf("%c",&c);
	if(c>=97 && c<=122){
		printf("%c%c%c",c,b,a);
	}
	else{
		printf("%c%c",a,b);
	}	
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;

int main()
{
  int N, C;
  cin >> N >> C;
  vector<vector<int>> cnt(C, vector<int>(MAX + 1));
  for(int i = 0;i < N;i++){
    int s, t, c;
    cin >> s >> t >> c; c--;
    cnt[c][s * 2 - 1]++;
    cnt[c][t * 2]--;
  }
  for(int c = 0;c < C;c++){
    for(int i = 1;i <= MAX;i++){
      cnt[c][i] += cnt[c][i - 1];
    }
  }
  int res = 0;
  for(int i = 0;i <= MAX;i++){
    int tmp = 0;
    for(int c = 0;c < C;c++){
    	if(cnt[c][i]) tmp++;
    }
    res = max(res, tmp);
  }
  cout << res << endl;
}


Measured memory_bytes: 24576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] a = sc.IntArray();

        a = a.OrderBy(num => num).ToArray();

        bool[] answers = new bool[1000001];
        for (int i = 1; i <= 1000000; i++)
        {
            answers[i] = true;
        }

        int answer = 0;

        for (int i = 0; i < n; i++)
        {
            int num = a[i];
            if (answers[num] == true)
            {
                if (i == n - 1 || num != a[i + 1])
                {
                    answer++;
                }
                int remove = num;
                while (true)
                {
                    answers[remove] = false;
                    remove += num;
                    if (remove > 1000000)
                    {
                        break;
                    }
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

#define int long long

signed main()
{
  int h, w, i, y;
  int x1, x2, x3;
  int _min, _max;
  long long answer = 1e11;

  cin >> h >> w;
  if(h % 3 == 0 || w % 3 == 0)
  {
    cout << "0";
  }
  else
  {
    //1
    for(i=0; i<=h; i++)
    {
      //
      x1 = i * w;
      x2 = (h - i) * (w / 2);
      x3 = h * w - x1 - x2;
      _min = min(x1, min(x2, x3));
      _max = max(x1, max(x2, x3));
      answer = min(answer, _max - _min);
      //
      x2 = (h - i) / 2 * w;
      x3 = h * w - x1 - x2;
      _min = min(x1, min(x2, x3));
      _max = max(x1, max(x2, x3));
      answer = min(answer, _max - _min);
    }
    //2
    y = h;
    h = w;
    w = y;
    for(i=0; i<=h; i++)
    {
      //
      x1 = i * w;
      x2 = (h - i) * (w / 2);
      x3 = h * w - x1 - x2;
      _min = min(x1, min(x2, x3));
      _max = max(x1, max(x2, x3));
      answer = min(answer, _max - _min);
      //
      x2 = (h - i) / 2 * w;
      x3 = h * w - x1 - x2;
      _min = min(x1, min(x2, x3));
      _max = max(x1, max(x2, x3));
      answer = min(answer, _max - _min);
    }
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
using ll=long long;
const ll MOD=1000000007;

//最大公約数、最小公倍数(セットで導入すること)
ll gcd(ll a,ll b){
    while(b!=0){
        a%=b;
        swap(a,b);
    }
    return a;
}

int main() {
    int K;
    cin>>K;
    ll ans=0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                int a=gcd(i,j);
                int b=gcd(a,k);
                ans+=b;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648