akhauriyash/Code-Regression huggingface dataset:
import sys 
sys.setrecursionlimit(10**6)
N=int(input())
A=[[]for i in range(N)]
X=[list(map(int, input().split())) for _ in range(N-1)]
for i in range(N-1):
  a=X[i][0]
  b=X[i][1]
  a-=1
  b-=1
  A[a].append(b)
  A[b].append(a)
D=list(map(int, input().split()))
D=sorted(D)[::-1]
from collections import deque
d=deque(D)
E=[-1]*N
def f(now,pre):
  for i in A[now]:
    if i!=pre and E[i]==-1:
      E[i]=d.popleft()
      f(i,now)
E[0]=d.popleft()
f(0,0)
print(sum(D[1:]))
print(*E)


Measured memory_bytes: 16392
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int C = scanner.nextInt();
    int[][] D = new int[C][C];
    for (int i = 0; i < C; i++) {
      for (int j = 0; j < C; j++) {
        D[i][j] = scanner.nextInt();
      }
    }

    int[][] c  = new int[N][N];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) c[i][j] = scanner.nextInt() - 1;

    int[][] sum = new int[3][C];
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < C; j++) {
        for (int x = 0; x < N; x++) {
          for (int y = 0; y < N; y++) {
            if ((x + y) % 3 == i) {
              sum[i][j] += D[c[x][y]][j];
            }
          }
        }
      }
    }

    int min = 1_000_000_000;
    for (int i = 0; i < C; i++) {
      for (int j = 0; j < C; j++) {
        for (int k = 0; k < C; k++) {
          if (i == j || j == k || i == k) continue;
          min = Math.min(min, sum[0][i] + sum[1][j] + sum[2][k]);
        }
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 93324
#include <stdio.h>

int main(void)
{
    int n=0,a=0;
    int order[100010]={};
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        order[a]=i;
    }
    for(int i=1;i<=n;i++){
        printf("%d ",order[i]);
    }
    return 0;
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin>>x;
  int a=x/500;
  int ans=a*1000;
  a=x%500;
  a=a/5;
  ans+=a*5;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = list(map(int, input().split()))
A.append(B[0])
for i in range(N - 2):
    if B[i] > B[i + 1]:
        A.append(B[i + 1])
    else:
        A.append(B[i])
A.append(B[-1])
print(sum(A))

Measured memory_bytes: 3064
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    c0 = 0
    c4 = 0

    for ai in a:
        if ai % 2 != 0:
            c0 += 1
        if ai % 4 == 0:
            c4 += 1
    if c0 + c4 == n and c0 == c4 + 1:
        print('Yes')
    elif c0 > c4:
        print('No')
    else:
        print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;

int main(int argc, char const *argv[]) {
        int n, m, l;
        cin >> n >> m >> l;
        long long int matrix1[100][100], matrix2[100][100], matrix3[100][100];

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                        cin >> matrix1[i][j];
                }
        }

        for(int i = 0; i < m; i++) {
                for(int j = 0; j < l; j++) {
                        cin >> matrix2[i][j];
                }
        }

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < l; j++) {
                        matrix3[i][j]=0;
                        for(int k = 0; k < m; k++) {
                                matrix3[i][j] += matrix1[i][k]*matrix2[k][j];
                        }
                }
        }

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < l; j++) {
                        if(j) cout << " ";
                        cout << matrix3[i][j];
                }
                cout << endl;
        }

        return 0;
}



Measured memory_bytes: 3300
#include <iostream>

using namespace std;

int main(){

    int N = 0;
    int M = 0; 

    cin >> N;

    M = N % 1000;

    if(0 == M){
        cout << "0" << endl;
    }else{
        cout << 1000 - M << endl;
    }

    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    double r = 0;
    double area = 0.0, circle = 0.0;

    cin >> r;

    area = M_PI * r * r;
    circle = 2*M_PI*r;

    cout << fixed << setprecision(6) << area << " " << circle <<endl;
    
    return 0;
}


Measured memory_bytes: 3284
#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 all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	vi a={4,6,9,11};
	int x,y; cin>>x>>y;
	int s=1,t=1;
	rep(i,0,4){
		if(a[i]==x) s=3;
		if(a[i]==y) t=3;
	}
	if(x==2) s=2;
	if(y==2) t=2;
	if(x==y || s==t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define INF 0x7fffffff
#define MAXN 100010
#define MOD 1000000007
#define int long long
using namespace std;
inline int read(){
	int ret=0,pos=1;char c=getchar();
	while(!isdigit(c) && c!='-' ) c=getchar();
	if(c=='-')	pos=-1,c=getchar();
	while(isdigit(c))ret=(ret<<3)+(ret<<1)+c-48,c=getchar();
	return pos*ret;
}
inline int fst_pow(int a,int b){
	int ret=1;
    for(;b;b>>=1,a=(a*a)%MOD)	if(b&1)	ret=a*ret%MOD;
    return ret;
}
int a[MAXN];
int n,k,ans;
signed main(){
	n=read(),k=read();
    while(n) {
        n/=k;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node {
  int p,l,r;
};

Node T[MAX];
int n;
void preParse(int u) {
  if (u==NIL) {
    return;
  }
  cout<<" "<<u<<flush;
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u) {
  if (u==NIL) {
    return;
  }
  inParse(T[u].l);
  cout<<" "<<u<<flush;
  inParse(T[u].r);
}
void postParse(int u) {
  if (u==NIL) {
    return;
  }
  postParse(T[u].l);
  postParse(T[u].r);
  cout<<" "<<u<<flush;
}
int main() {
  scanf("%d",&n);
  for (int i=0; i<n; i++) {
    T[i].p=NIL;
  }
  int v,l,r;
  for (int i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if (l!=NIL) {
      T[l].p=v;
    }
    if (r!=NIL) {
      T[r].p=v;
    }
  }
  int root=0;
  for (int i=0; i<n; i++) {
    if (T[i].p==NIL) {
      root=i;
    }
  }
  cout<<"Preorder"<<endl;
  preParse(root);
  cout<<endl;
  cout<<"Inorder"<<endl;
  inParse(root);
  cout<<endl;
  cout<<"Postorder"<<endl;
  postParse(root);
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    string S; cin >> S;
    int ans = 0;
    for (int i  = 0; i < S.length(); i++) {
        if (S[i] != S[S.length() - 1 - i]) {
            ans++;
        }
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = ii()

cnt = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
from fractions import gcd
def gen(x):
    i = 1
    while i * i <= x:
        yield i
        i += 1

def main():
    a,b = map(int,input().split())
    g = gcd(a,b)
    gl = []
    for i in gen(g):
        if (g % i) == 0:
            gl.append(i)
            gl.append(g // i)
    gl =set(gl)
    p = []
    for i in gl:
        b = True
        for j in gen(i):
            if j == 1:continue
            if (i % j) == 0:
                b = False
                break
        if b:
            p.append(i)
    
    print(len(p))
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 5944
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll d[1000];
    ll j=0;
	for(ll i=c;;i+=b){
		d[j]=i%a;
		if(i%a==0){
			cout << "YES"<<endl;
			return 0;
		}
		j++;
		for(int w=0;w<j-1;w++){
			for(int r=w+1;r<j;r++){
				if(d[w]==d[r]){
					cout << "NO" <<endl;
					return 0;
				}
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= c && b >= c){
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
    int N; cin >> N;
    vector<int> A(3*N);
    for(int &a:A)
        cin >> a;
    vector<ll> L(N+1);
    vector<ll> R(N+1);
    
    priority_queue<int, vector<int>, greater<>> LQ;
    priority_queue<int> RQ;
    
    ll LS = 0;
    ll RS = 0;
    for(int i=0; i<N; i++){
        LQ.push(A[i]);
        LS += A[i];
    }
    for(int i=3*N-1; i>=2*N; i--){
        RQ.push(A[i]);
        RS += A[i];
    }
    
    L[0] = LS;
    R[N] = RS;
    
    for(int i=0; i<N; i++){
        LQ.push(A[N + i]);
        L[i+1] = L[i] + A[N + i];
        L[i+1] -= LQ.top();
        LQ.pop();
    }
    
    for(int i=N-1; i>=0; i--){
        RQ.push(A[N + i]);
        R[i] = R[i+1] + A[N + i];
        R[i] -= RQ.top();
        RQ.pop();
    }
    
    ll ans = -(1LL << 60);
    for(int i=0; i<N+1; i++){
        ans = max(ans, L[i] - R[i]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4088
#include <cstdio>
#include <cstring>
#define MAXN 200010
#define ll long long int

int C[10][10];

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

        memset( C, 0, sizeof(C) );
        int base = 1;
        int a,b;

        for( int i = 1; i <= n; i++ ){
                b = i % 10;
                a = i / base;
                if( a >= 10 ){
                        a /= 10;
                        base *= 10;
                }

                C[a][b]++;
        }

        ll res = 0;
        for( int i = 1; i <= 9; i++ ){
                for( int j = 1; j <= 9; j++ ){
                        res += C[i][j] * C[j][i];
                }
        }
        printf("%lld\n", res);

        return 0;
}


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

int main() {
    int a, b;
    char sa, sb, op;
    
    do {
        // cin >> sa;
        // if (sa == '?') {
        //     break;
        // } else {
        //     cin >> op >> sb;
        // }
        
        cin >> a >> op >> b;
        
        // a = atoi(sa); b = atoi(sb);
        if (op == '+') cout << a + b << endl;
        if (op == '-') cout << a - b << endl;
        if (op == '*') cout << a * b << endl;
        if (op == '/') {
            if (b == 0) {
                continue;
            } else {
                cout << a / b << endl;
            }
        }
        // if (sa == '?' || op == '?') break;
        if (op == '?') break;
    } while (1);
    
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

int main() {
	int N, M;
	cin >> N >> M;
	dsu d(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		d.merge(A - 1, B - 1);
	}
	cout << d.groups().size() - 1 << endl;
}


Measured memory_bytes: 9016
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  lli N, K;
  scanf("%lld %lld", &N, &K);

  lli ans = 0;
  for ( lli b = 1; b <= N; b++ ) {
    lli r = N % b;
    lli p = N / b;
    ans += max(r - K + 1, 0);
    ans += max(b - K, 0) * p;
    if ( K == 0 ) ans--;
  }
  printf("%lld\n", ans);
  return 0;
}


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

const int N = 410;
const int mod = 998244353;

typedef long long LL;

inline int Pow(int x, int y) {
    int res = 1;
    for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
    return res;
}    

int dp[2][N][N][N], A[N], B[N], C[N][N];

int main() {
    int n, s = 0; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", &A[i], &B[i]), s = (s + A[i]) % mod;
    for (int i = 0; i <= 400; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    }
    for (int i = 1, t = 0, t1 = 0; i <= n; t += B[i] - 1, t1 += A[i], i++) 
        for (int j = 0; j <= t; j++) 
            for (int k = 0; k <= t1; k++) {
                dp[0][i][j][k] = (dp[0][i][j][k] + dp[0][i - 1][j][k]) % mod;
                dp[1][i][j][k] = (dp[1][i][j][k] + dp[1][i - 1][j][k]) % mod;
                int p = (LL)k * Pow(k + A[i], mod - 2) % mod, p1 = Pow(p, j);
                for (int l = 0; l < B[i]; l++) {
                    int w = (LL)C[j + l][j] * p1 % mod * Pow(1 + mod - p, l) % mod;
                    dp[0][i][j + l][k + A[i]] = (dp[0][i][j + l][k + A[i]] + (LL)dp[1][i - 1][j][k] * w) % mod;
                    dp[1][i][j + l][k + A[i]] = (dp[1][i][j + l][k + A[i]] + (LL)dp[0][i - 1][j][k] * w) % mod;
                    if (k == 0 && j == 0) dp[1][i][l][A[i]] = (dp[1][i][j + l][A[i]] + w) % mod;
                }
            }
    int ans = 0;
    for (int t = 0; t <= 1; t++) 
        for (int j = 0; j <= 400; j++)
            for (int k = 0; k <= 400; k++) {
            	int w = (LL)dp[t][n][j][k] * s % mod * Pow(k, mod - 2) % mod;
            	if (t & 1) ans = (ans + w) % mod;
				else ans = (ans - w + mod) % mod; 
			}
    printf("%d\n", ans);
    return 0;    
}

Measured memory_bytes: 527232
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	let n: i32 = vec[0].parse().unwrap();
	let m: i32 = vec[1].parse().unwrap();
	println!("{}", (n - 1) * (m - 1));
}

Measured memory_bytes: 4352
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	}


Measured memory_bytes: 23252
N= int(input())
A= list(map(int, input().split()))
Q= int(input())
tmpDic = {}
res = sum(A)

for i in range(N):
    if A[i] in tmpDic:
        tmpDic[A[i]] += 1
    else:
        tmpDic[A[i]] = 1

for i in range(Q):
    B, C= list(map(int, input().split()))
    if B in tmpDic and tmpDic[B] > 0:
        tmp = tmpDic[B]
        tmpDic[B] = 0
        res += (C - B)* tmp
        
        if C in tmpDic:
            tmpDic[C] += tmp
        else:
            tmpDic[C] = tmp
    print(res)

Measured memory_bytes: 20836
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct Dinic{
  static const Int INF=1<<28;
  
  struct edge {
    Int to,cap,rev;
    edge(){}
    edge(Int to,Int cap,Int rev):to(to),cap(cap),rev(rev){}
  };

  Int n;
  vector<vector<edge> > G;
  vector<map<Int,int> > M;
  vector<Int> level,iter;

  Dinic(){}
  Dinic(Int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(Int from,Int to,Int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(Int s){
    fill(level.begin(),level.end(),-1);
    queue<Int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      Int v=que.front();que.pop();
      for(Int i=0;i<(Int)G[v].size();i++){
	edge &e = G[v][i];
	if(e.cap>0&&level[e.to]<0){
	  level[e.to]=level[v]+1;
	  que.push(e.to);
	}
      }
    }
  }
  
  Int dfs(Int v,Int t,Int f){
    if(v==t) return f;
    for(Int &i=iter[v];i<(Int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
	Int d = dfs(e.to,t,min(f,e.cap));
	if(d>0){
	  e.cap-=d;
	  G[e.to][e.rev].cap+=d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  Int flow(Int s,Int t,Int lim){
    Int fl=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return fl;
      fill(iter.begin(),iter.end(),0);
      Int f;
      while((f=dfs(s,t,lim))>0){
	fl+=f;
	lim-=f;
      }
    }
  }

  Int flow(Int s,Int t){
    return flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(Int s,Int t,Int from, Int to){
    for(Int i=0;i<(Int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
	if(e.cap==0&&flow(from,to,1)==0) {
	  flow(from,s,1);
	  flow(t,to,1);
	  return 1;
	}
      }
    }
    return 0;
  }
};


signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];
  Int dy[]={0,0,1,-1};
  Int dx[]={1,-1,0,0};
  Dinic flow(h*w*2+2);
  Int S=h*w*2,T=h*w*2+1;
  auto idx=[&](Int i,Int j,int k){return h*w*k+i*w+j;};
  auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      flow.add_edge(idx(i,j,0),idx(i,j,1),1);
      if(s[i][j]=='X')
	flow.add_edge(S,idx(i,j,1),Dinic::INF);
      if(i==0||i==h-1||j==0||j==w-1)
	flow.add_edge(idx(i,j,1),T,Dinic::INF);
      
      for(Int k=0;k<4;k++){
	Int ny=i+dy[k],nx=j+dx[k];
	if(in(ny,nx)) flow.add_edge(idx(i,j,1),idx(ny,nx,0),1);
      }	
    }
  }
  Int ans=flow.flow(S,T);
  cout<<(ans>h*w?-1:ans)<<endl;
  return 0;
}


Measured memory_bytes: 13884
//スギノキさんの写経コード
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	int N , C , K ;
	cin >> N >> C >> K ;
	vector<int> T(N);
	rep(i,N) cin >> T[i];
	SORT(T);
	int bus = 1;
	int count  = 0; //乗客数カウント
	int time =  0 ;//一人目の客の乗車時刻
	for(int i = 0 ; i < N ; i++){
		if(count == C){
			bus ++ ;
			count = 0;
		}
		if(count == 0){
			time = T.at(i);
			count ++ ;
		}else{
			if( T.at(i) <= time + K) count ++;
			else{
				bus ++ ;
				count = 1;
				time = T.at(i);
			}
		}
	}
	cout << bus << endl;
	
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==1) cout<<"ACL"<<endl;
  else if(n==2) cout<<"ACLACL"<<endl;
  else if(n==3) cout<<"ACLACLACL"<<endl;
  else if(n==4) cout<<"ACLACLACLACL"<<endl;
  else if(n==5) cout<<"ACLACLACLACLACL"<<endl;
  }

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

using namespace std;

typedef long long ll;

const int unit[5] = {20 * 20 * 18 * 20, 20 * 18 * 20, 18 * 20, 20, 1};
const int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool is_leap(int y)
{
    if (y % 400 == 0) return 1;
    if (y % 100 == 0) return 0;
    if (y % 4 == 0) return 1;
    return 0;
}

// ?\???? -> ??????
void a2m(vector<int> &v)
{
    int y = v[0], m = v[1], d = v[2];
    if (y == 2012 && m == 12 && 21 <= d && d <= 31) {
        cout << "0.0.0.0." << d - 21 << endl;
        return;
    }
    
    ll day = 10LL;
    for (int i = 2013; i < y; i++) {
        day += (is_leap(i) ? 366LL : 365LL);        
    }
    for (int i = 1; i < m; i++) {
        ll md = month[i];
        if (is_leap(y) && i == 2) md++;        
        day += md;
    }
    
    day += d;
    day %= 1872000LL;
    
    for (int i = 0; i < 5; i++) {
        if (i > 0) cout << ".";
        cout << day / unit[i];
        day %= unit[i];
    }
    cout << endl;
}

// ?????? -> ?\????
void m2a(vector<int> &v)
{
    int day = 0;
    for (int i = 0; i < 5; i++) {
        day += v[i] * unit[i];
    }

    int y = 2012, m = 12, d = 21;
    for (int i = 0; i < 11; i++) {
        if (day == 0) break;
        day--; d++;
    }
    
    if (d == 32) y++, d = 1, m = 1;
    
    bool update = 1;
    while (update) {
        update = 0;
        if (is_leap(y)) {
            if (day >= 366) {
                day -= 366;
                y++;
                update = 1;
            } 
        } else {
            if (day >= 365) {
                day -= 365;
                y++;
                update = 1;
            }            
        }
    }
    
    for (int i = 1; i <= 12; i++, m++) {
        int md = month[i];
        if (is_leap(y) && i == 2) md++;
        if (day >= md) {
            day -= md;
        } else {
            break;
        }
    }
    
    cout << y << "." << m << "." << d + day << endl;
}

int s2i(string &s)
{
    stringstream ss(s);
    int num;
    ss >> num;
    return num;
}

int main()
{
    string s;
    while (cin >> s, s != "#") {
        stringstream ss(s);
        vector<int> v;
        while (getline(ss, s, '.')) {
            v.push_back(s2i(s));
        }
        (v.size() == 3 ? a2m(v) : m2a(v));
    }
    return 0;
}

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

int main() {
  int high[10];
  for(int i = 0; i < 10; ++i) {
    cin >> high[i];
  }
  sort(high, high+10);
  for(int i = 0; i < 3; ++i) {
    cout << high[9-i] << endl;
  }
  return 0;
}

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

Measured memory_bytes: 3064
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::iter::{Sum};
#[allow(unused_imports)]
use std::mem::{swap,};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        d: u32,
        n: i32,
    }
    let mut n = n;
    if n == 100 { n += 1; }
    println!("{}", n * 100i32.pow(d));
}


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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

const int inf=100000000;



int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int C[3][3];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>C[i][j];
        }
    }

    int a[3], b[3];
    a[0] = 0;
    b[0] = C[0][0] - a[0];
    b[1] = C[0][1] - a[0];
    b[2] = C[0][2] - a[0];
    a[1] = C[1][0] - b[0];
    a[2] = C[2][0] - b[0];

    bool ans = true;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) ans &= C[i][j] == a[i] + b[j]; //bit
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 700000, mo=998244353;
ll n,a,b,k,fac[N],ifac[N];
int power(int a, int n) {
	int res=1;
	while (n){if (n&1)res=1LL*res*a%mo; a=1LL*a*a%mo; n>>=1;}
	return res;
}
int inv(int a) {return power(a,mo-2);}
int C(int n, int m) {
	if (m<0||m>n)return 0;
	return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;
}
int main() {
	read(n);read(a);read(b);read(k);
	fac[0]=1;rep(i,1,2*n)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[2*n]=inv(fac[2*n]);per(i,2*n-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
	ll res=0;
	rep(x,0,n){
		ll tmp=k-x*a,y=tmp/b; if (y*b!=tmp) continue; //||y<0||x+y>n
	//	printf("%d %lld\n",x,y);
		res+=1LL*C(n,x)*C(n,y)%mo;
	}
	cout<<res%mo;
	return 0;
}


Measured memory_bytes: 10496
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var k = nk[1];
        var v = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long max = 0;
        for (int i = 0; i <= v.Length; i++)
        {
            for (int j = 0; j <= v.Length; j++)
            {
                var remainOps = k - (i + j);
                if (remainOps < 0 || v.Length < i + j) continue;

                List<long> gems = new List<long>();
                for (int front = 0, count = 0; count < i; front++, count++) gems.Add(v[front]);
                for (int back = v.Length - 1, count = 0; count < j; back--, count++) gems.Add(v[back]);
                var taked = gems.OrderBy(x => x).TakeWhile(x => x < 0).Take(remainOps).Sum();
                max = Max(max, gems.Sum() - taked);
            }
        }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 13524
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>


int main(){
	int n, m;
	std::cin>>n>>m;

	std::vector<std::vector<int>> sList(m);
	std::vector<int> pList(m);

	for(int i=0; i<m; i++){
		int iter;
		std::cin>>iter;
		sList[i].resize(iter);

		for(int j=0; j<iter; j++)
			std::cin>>sList[i][j];		
	}
	
	for(int i=0; i<m; i++)
		std::cin>>pList[i];

	int pattern= 1;

	for(int i=0; i<n; i++)
		pattern*=2;

	int ans= 0;
	std::vector<int> isSwitchOn(n, 0);
	for(int i=0; i<pattern; i++){
		int tmp= i;
		for(int j=0; j<n; j++){
			isSwitchOn[j]= tmp%2;
			tmp= tmp/2;
		}

		bool isSame= true;
		for(int j=0; j<m; j++){
			int numOn=0;
			for(int k=0; k<sList[j].size(); k++)
				numOn+= isSwitchOn[sList[j][k]-1];

			if(numOn%2!=pList[j])
				isSame= false;
		}

		if(isSame)
			ans++;
	}


	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	V a(n);
	rep(i,n){
		cin>>a[i];
	}
	sort(all(a),greater<ll>());
	V dis;
	int I=0;
	for(I=1;I<n;I++){
		if(a[I] == a[I-1]){
			dis.pb(a[I]);
			I+=1;
		}
	}
	if(dis.size()<2){
		cout<<0<<endl;
	}else{
	cout<<dis[0]*dis[1]<<endl;
}
}

Measured memory_bytes: 4608
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		try{
			String s,t;
			while((s=reader.readLine()) !=null &&(t=reader.readLine()) !=null){
				double n=Integer.parseInt(s);
				double m=Integer.parseInt(t);
				if(n ==0 &&m==0){
					break;
				}
				double x=n*n;
				double l=Math.sqrt(m*m+n*n/4);
				double y=2*n*l;
				System.out.println(x+y);
			}
		}catch(IOException e){
			System.exit(0);
		}
	}
}

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i = l; i <= r; i++)
        if(i % d == 0)
            cnt++;
    cout << cnt;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll x, y; cin >> x >> y;
    ll X = x;
    while(1){
        X += x;
        if(X%y != 0){
            cout << X << endl;
            return;
        }
        if(x%y == 0){
            cout << -1 << endl;
            return;
        }
    }
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long n;
    cin>>n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    long long x=1000;
    for(int i=1; i<n; i++)
    {
        if(a[i]>a[i-1])
        {
            long long stocks = x/a[i-1];
            x+=stocks*(a[i]-a[i-1]);
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

struct mint { // auto MOD int
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}  //コンストラクタ
  mint operator-() const { return mint(-x);} //符号変換
  //算術演算子
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  mint pow(ll n) const {  //繰り返し累乗
    if (!n) return 1;
    mint a = pow(n>>1);
    a *= a;
    if (n&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD-2); } // for prime mod
  //代入演算子
  mint& operator+=(const mint a){ if((x+=a.x) >= MOD) x-=MOD;  return *this; }
  mint& operator-=(const mint a){ if((x+=MOD-a.x) >= MOD) x-=MOD;  return *this; }
  mint& operator*=(const mint a){ (x *= a.x) %= MOD;  return *this; }
  mint& operator/=(const mint a){ return (*this) *= a.inv(); }
  friend ostream& operator<<(ostream &stout, const mint &tmp){ stout << tmp.x; return stout; }
};

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  mint dp[n+1];
  dp[0] = 1;
  rep(i,n){
    if(3 <= i) dp[i+1] += dp[i];
    if(i+3 <= n) dp[i+3] += dp[i];
  }
  cout << dp[n];
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll S[3];
    scanf("%lld%lld%lld",&S[0],&S[1],&S[2]);
    sort(S,S+3);
    if(S[0]==5&&S[1]==5&&S[2]==7)printf("YES");
    else printf("NO");

    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2000000000
#define PI 3.1415926535897932
using ll = long long;
using Graph = vector<vector<int>>;
//二項係数を求める。

int main(){
  int a,b;cin>>a>>b;
  if(a<=9&&b<=9)cout<<a*b<<endl;
  else cout<<-1<<endl;
  return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

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

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

ll N;
ll A[100010]={};
ll L[100010]={};
ll R[100010]={};

int main(int argc, char **argv)
{
	cin >> N;
	REP(i, N) cin >> A[i];

	for (ll i = 0; i < N; ++i) L[i+1] = gcd(L[i], A[i]);
	for (ll i = N; i > 0; --i) R[i-1] = gcd(R[i], A[i-1]);


	ll res{0};
	REP(i, N)
	{
		// std::cout << "L : " << L[i] << std::endl;
		// std::cout << "R : " << R[i+1] << std::endl;
		res = max(res, gcd(L[i], R[i+1]));
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N= 2e5+5;
int n,t,m;
int b,k,x;

vector<int>a(N);
vector<int>tele;



int32_t main()
{
	IOS;
	cin>>n>>k;

	for(int i=1;i<=n;i++)
		cin>>a[i];
	map<int, int> mp;
	mp[1]++;
	tele.push_back(1);
	if(k<=n){
		int p=1, coun=0;
		while(coun<k){
			p=a[p];
			coun++;
		}
		cout<<p<<endl;
		return 0;
	}
	int flag=0;
	int i=a[1];

	while(1<=i<=n){
		
		if(mp[i]>0){
			flag=i;
			break;
		}
		mp[i]++;
		tele.push_back(i);
		//cout<<i<<" ";
		i=a[i];
		
	}
	
	int cycle=0, dis=0;
	for(int i=0;i<tele.size();i++){
		if(tele[i]!=flag)
			dis++;
		else{
			cycle= tele.size()-i;
			break;
		}
	}
	//cout<<dis<<" "<<cycle<<endl;
	k-=dis;
	int idx= k%cycle;
	//cout<<idx<<endl;
	cout<<tele[dis+idx]<<endl; 
}
	 

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

long K, N, a, Max, M, sum;
vector<long> A, dists;

int main(){
	cin >> K >> N;
  	for (int i = 0; i < N; i++){
      	cin >> a;
    	A.push_back(a);
    }
  	Max = A[A.size()-1];
  	for (int i = 0; i < N-1; i ++){
    	dists.push_back(A[i+1]-A[i]);
    }
  	dists.push_back(K-Max+A[0]);
  	
  	M = dists[0];
  	sum = dists[0];
  	for (int i = 1; i < N; i ++){
      	sum += dists[i];
    	if (dists[i] > M){
        	M = dists[i];
        }
    }
  	cout << sum - M << endl;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define BIG 2'000'000'000
#define VERYBIG 1'000'000'000'000'000'000
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

int dp[61][2][2][2]; // dp[digit][L<=x?][y<=R?][same digit?]

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

  int L, R; cin >> L >> R;
  dp[60][0][0][0] = 1;
  for(int i = 59; i >= 0; i--){
    int ld = L>>i & 1, rd = R>>i & 1; //  (2進で)下からi桁目だけ見る (0-indexed)
    REP(j, 2) REP(k, 2) REP(s, 2){
      int tmp = dp[i+1][j][k][s];
      REP(x, 2) REP(y, 2){ // x, yの下からi桁目
        if(x and !y) continue; // x=1, y=0 はアウト

        int nj = j, nk = k, ns = s;
        if(!s and x!=y) continue; // 桁が揃わないのでアウト
        if(x and y) ns = 1;
        // j :  L<=x ?
        if(!j and !x and ld) continue; // x < L が確定するのでアウト
        if(x and !ld) nj = 1;
        // k :  y<=R ?
        if(!k and y and !rd) continue; // R < r が確定するのでアウト
        if(!y and rd) nk = 1;

        dp[i][nj][nk][ns] += tmp;
        dp[i][nj][nk][ns] %= MOD;
      }
    }
  }
  int ans = 0;
  REP(j, 2)REP(k, 2)REP(s, 2){
    // j==0 -> x==L, j==1 -> L<=x
    // k==0 -> y==R, k==1 -> y<=R
    // s==0 -> 全部桁同じ, s==1 -> 最上位が揃う
    ans += dp[0][j][k][s];
    ans %= MOD;
  }
  cout << ans << endl;
}

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

ll DP[20004];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int H, N; cin >> H >> N;
    memset(DP, 15, sizeof DP);
    DP[0] = 0;
    while(N--) {
        int dam, cos; cin >> dam >> cos;
        iter(i, dam, 20000) DP[i] = min(DP[i], DP[i-dam]+cos);
    }
    ll mi = DP[20000];
    iter(v, H, 20000) mi = min(mi, DP[v]);
    cout << mi << endl;
}

Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
dp=[[0]*(n+2) for _ in range(n+2)]
# aiからajのX−Yの最大値
# [左端,右端)=[l,r)からの遷移    
# 左をとる[l+1,r)、右をとる[l,r−1)の2通り

for len in range(1,n+1):
  for i in range(n+1-len):
    j=i+len
    #先手の番
    if (n-len)%2==0:
      dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
    #後手の番
    else:
      dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])
#print(dp)
print(dp[0][n])
    

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

int main(){
	int n; cin>>n;
	map<ll,ll> mp;
	ll sum=0;
	rep(i,n){
		int a; cin>>a;
		mp[a]++;
		sum+=a;
	}

	int q; cin>>q;
	rep(i,q){
		int b,c; cin>>b>>c;
		if(mp.find(b)==mp.end()) cout<<sum<<endl;
		else{
			sum=sum-b*mp[b]+c*mp[b];
			mp[c]+=mp[b];
			mp.erase(b);
			cout<<sum<<endl;
		}
	}
}

Measured memory_bytes: 7524
#include <stdio.h>
 
int main(void)
{
    double r, menseki, enshu, pi;
    pi = 3.141592653589;
    scanf("%lf", &r);
    menseki = r * r * pi;
    enshu = 2 * r * pi;
 
    printf("%f %f\n", menseki, enshu);
 
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int i ,x = 0,max = 0;
  for(i=0;i<s.size();i++){
    if(s[i]=='I') x++;
    else x--;
    if(max<x) max=x;
  }
  cout << max << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const long long mo=1000000007;
const int maxn=200010;

int n,m,gs,x[maxn],y[maxn];
long long c[maxn*10],sum[maxn],xx[maxn*10],yy[maxn*10],op[maxn*10],id[maxn*10];

void qsort2(int l,int r)
{
	int i=l;int j=r;
	int m=yy[(i+j)/2];
	int m1=xx[(i+j)/2];
	while (i<=j)
	{
		while ((yy[i]<m) || (yy[i]==m && xx[i]<m1)) i++;
		while ((yy[j]>m) || (yy[j]==m && xx[j]>m1)) j--;
		if (i<=j)
		{
			swap(yy[i],yy[j]);
			swap(xx[i],xx[j]);
			i++;j--;
		}
	}
	if (l<j) qsort2(l,j);
	if (r>i) qsort2(i,r); 
}

void qsort(int l,int r)
{
	int i=l;int j=r;
	int m=yy[(i+j)/2];
	int m1=xx[(i+j)/2];
	while (i<=j)
	{
		while ((yy[i]<m) || (yy[i]==m && xx[i]<m1)) i++;
		while ((yy[j]>m) || (yy[j]==m && xx[j]>m1)) j--;
		if (i<=j)
		{
			swap(yy[i],yy[j]);
			swap(xx[i],xx[j]);
			i++;j--;
		}
	}
	if (l<j) qsort(l,j);
	if (r>i) qsort(i,r); 
}

void qsort1(int l,int r)
{
	int i=l;int j=r;
	int m=op[(i+j)/2];
	while (i<=j)
	{
		while (op[i]<m) i++;
		while (op[j]>m) j--;
		if (i<=j)
		{
			swap(op[i],op[j]);
			swap(id[i],id[j]);
			i++;j--;
		}
	}
	if (l<j) qsort1(l,j);
	if (r>i) qsort1(i,r); 
}


int lowbit(int x)
{
	return x&(-x);
}

void modify(int i,long long k)
{
	while (i<=gs)
	{
		c[i]=(c[i]+k)%mo;
		i+=lowbit(i);
	}
}

long long getans(int i)
{
	long long gg=0;
	int kk=0;
	while (i>0)
	{
		gg=(gg+c[i])%mo;
		kk=lowbit(i);
		i-=kk;
	}
	return gg;
}

int main()
{
//	freopen("data.in","r",stdin);
	scanf("%d%d",&n,&m);
	int zd=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
		zd=max(zd,x[i]);
	}
	for (int i=1;i<=m;i++)
	{
		scanf("%d",&y[i]);
		zd=max(zd,y[i]);
	}
	int l=1;
	gs=2;
	xx[1]=1;yy[1]=1;
	xx[2]=zd+1;yy[2]=zd+1;
	for (int i=1;i<=n;i++)
	{
		while (x[i]>y[l] && l<=m) l++;
		if (l>m) break;
		if (l>1 && x[i]>y[l-1] && x[i]<y[l])
		{
			gs++;
			xx[gs]=x[i]-y[l-1]+1;
			yy[gs]=y[l]-x[i]+1;
		}
	}
	qsort(1,gs);
	for (int i=1;i<=gs;i++)
	{
		op[i]=xx[i];
		id[i]=i;
	}
	qsort1(1,gs);
	int js=0;
	for (int i=1;i<=gs;i++)
	{
		if (op[i]!=op[i-1]) js++;
		xx[id[i]]=js;
	}
	modify(1,1);
	l=2;
	int r=2;
	int jss=0;
	for (int i=2;i<=gs;i++)
	{
		if (xx[i]==xx[i-1] && yy[i]==yy[i-1])
		{
			xx[i-1]=2000000000;
			yy[i-1]=2000000000;
			jss++;
		}
	}
	qsort2(1,gs);
	gs-=jss;
	while (l<gs)
	{
		while (yy[l]==yy[l+1])
		{
			sum[l]=getans(xx[l]-1);
			l++;
		}
		if (yy[l]!=yy[l+1])
		{
			sum[l]=getans(xx[l]-1);
			l++;
		}
		while (r<l)
		{
			modify(xx[r],sum[r]);
			r++;
		}
	}
	printf("%lld\n",getans(xx[gs]));
}

Measured memory_bytes: 18048
#include "bits/stdc++.h"
using namespace std;

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

  	sort(T, T + N);
  	int c = C - 1, k = K;
  	int bus = 1;
  	for (int i = 1; i < N; i++)
    {
      	if (k - (T[i] - T[i - 1]) >= 0 and c > 0)
        {
     		k -= (T[i] - T[i - 1]);
            c--;
        }
      	else
        {
          	k = K;
            c = C - 1;
            bus++;
        }
    }

    cout << bus;
  	return 0;
}

Measured memory_bytes: 640