akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
using namespace std;
typedef long long ll;

const int MXN = 501;
int N, A[MXN], ANS[MXN * MXN];
pair<int,int> B[MXN];
int main() {
  cin >> N;
  FOR(x,N) cin >> A[x], B[x] = {A[x],x+1}, ANS[A[x]] = x+1;
  sort(B,B+N);
  
  int i = 1;
  FOR(x,N) {
    int tmp = B[x].second-1;
    while(i <= N * N && tmp) {
      if(ANS[i] == B[x].second) {
        cout << "No\n"; return 0;
      } else if(ANS[i] == 0) {
        ANS[i] = B[x].second; tmp--;
      }
      i++;
    }
  }
  
  vector<int> canUSE;
  FOR(x,N)
    if(B[x].first >= i)
      break;
    else {
      for(int y = 0; y < N-B[x].second; y++)
        canUSE.push_back(B[x].second);
    }
  
  while(i <= N*N) {
    if(!ANS[i]){
      if(canUSE.empty()) {cout << "No\n"; return 0;}
      ANS[i] = canUSE.back();
      canUSE.pop_back();
    } else {
      if(A[ANS[i]-1] == i) {
        for(int y = 0; y < N-ANS[i]; y++)
          canUSE.push_back(ANS[i]);
      }
    }
    i++;
  }
  cout << "Yes\n";
  FOR(x,N*N) cout << ANS[x+1] << " \n"[x+1==N*N];
}

Measured memory_bytes: 2808
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define epsilon 0.0000001
using namespace std;


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int a[n];
  MS(a, 0);
  int k = 0, l = 0;
  REP(i, n) {
    if (s[i] == '(') {
      k++;
    }
    else {
      if (k > 0) k--;
      else l++;
    }
  }

  cout << string(l, '(') + s + string(k, ')') << endl;
  return 0;
}


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

ab=[]
for _ in range(m):
    a,b=map(int,input().split())
    ab.append([a,b])

ab.sort()

ll=ab[0][0]
rr=ab[0][1]

cnt=1
#print(ab[0],ll,rr,cnt)
for item in ab[1:]:
    l=item[0]
    r=item[1]
    if l>=rr:
        cnt+=1
        ll=l
        rr=r
    else:
        if r<rr:
            rr=r
        if ll<l:
            ll=l
    #print(item,ll,rr,cnt)

print(cnt)



Measured memory_bytes: 59992
#include <iostream>

using std::cin;
using std::cout;
using std::endl;


void TorT()
{
  int n, a, b;
  cin >> n >> a >> b;
  if (n * a > b) cout << b << endl;
  else           cout << n * a << endl;
}


void cross9_9()
{
  int a, b;
  cin >> a >> b;
  if (a > 0 && a < 10 && b > 0 && b < 10) cout << a * b << endl;
  else cout << -1 << endl;
}


void calculate_circle()
{
  int r;
  cin >> r;
  cout << r * r << endl;
}
int main()
{
  //TorT();
  //cross9_9();
  calculate_circle();
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 168_b
#define ll long long
using namespace std;
int k,t;
string s;
int main(){
	cin>>k>>s;
	t=s.size();
	if(t<=k)
		cout<<s;
	else{
		string ss=s.substr(0,k);
		cout<<ss<<"...";
	}
	return 0;
}

Measured memory_bytes: 3600
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          int[] ans = ReadLine().Split(' ').Select(int.Parse).ToArray();
          WriteLine(ans[2] + " " + ans[0] + " " + ans[1]);
      }
   }
}

Measured memory_bytes: 11348
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ans = 1;
        for(int i = 0; i < n; i++){
            ans = Math.min(ans + k, ans * 2);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22356
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes")
def No(): print("No")

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
L = inputILs(N)

L.sort()

R = [l%10 for l in L]

x = 0
for l in L:
  if l%10 == 0:
    continue
  else:
    x = l
    break
if sum(L)%10 == 0:
  if x == 0:
    print(x)
  else:
    print(sum(L)-x)
else:
  print(sum(L))

Measured memory_bytes: 63980
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

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

	int ans = 0;
	REP(i, 1, n - 1) {
		bool l[26], r[26];
		REP(j, 0, 26) l[j] = r[j] = false;
		REP(j, 0, i) {
			l[s[j] - 'a'] = true;
		}
		REP(j, i, n) {
			r[s[j] - 'a'] = true;
		}

		int cnt = 0;
		REP(j, 0, 26) {
			if (l[j] && r[j]) cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] str = new long[n];
		for (int i = 0; i < n; i++) {
			str[i] = scan.nextLong();
		}
		Arrays.sort(str);
		long sq = 1;
		int count = 0;
		for (int i = n - 1; i > 0; i--) {
			if (str[i] == str[i - 1]) {
				sq = sq * str[i];
				i--;
				count++;
				if (count >= 2) {
					break;
				}
			}

		}
		if (count < 2) {
			System.out.println(0);
		} else {
			System.out.println(sq);
		}

	}
}

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

int main(void){
    int n;
    cin >> n;
    char last;
    string s;
    vector<string> log(n);
    cin >> s;
    log.at(0) = s;
    last = s.at(s.size() - 1);
    for (int i = 1; i < n; i++)
    {
        cin >> s;
        log.at(i) = s;
        if(last!=s.at(0)){
            cout << "No" << endl;
            return 0;
        }
            last = s.at(s.size()-1);
    }

    for (int i = 0; i < n-1;i++){
        for (int j = i+1; j < n;j++){
            if(log.at(i)==log.at(j)){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int limN = 1e5 + 5;

int W = 0 ;
int minW[limN];

int main() {
    int n ;
    scanf("%d", &n);
    for(int i=0, a, k; i<n; i++) {
        scanf("%d", &a);
        k = lower_bound(minW, minW+W, a) - minW;
        minW[k] = a;
        W = max(W, k+1);
    }
    printf("%d\n", W);
}



Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	
	//
	string s; cin>>s;
	set<char> set;
	for(char ch: s){
		set.insert(ch);
	}
	cout<<(sz(set) == sz(s) ? "yes" : "no")<<endl;
}


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

int main() {
	long long n,ans=0,bulk=0;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
	    if(a[i])bulk+=a[i];
	    else{
	        ans+=(bulk/2);
	        bulk=0;
	    }
	}
	ans+=(bulk/2);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

signed main()
{
	int X, Y;
	cin >> X >> Y;

	bool v = false;
	for (int i = 0; i <= 100; i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			if (i + j == X && i * 2 + j * 4 == Y)
			{
				v = true;
			}
		}
	}
	YesNo(v);
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <map>

using namespace std;
int main()
{
	map<string,int> table;
	string S;
	int mostAppear = 0;
	string mostAppearW;
	int maxSize = 0;
	string maxSizeW;
	while(cin >> S)
	{
		if (table.count(S))
		{
			table[S]++;
		}
		else
		{
			table[S] = 1;
		}

		if (table[S] > mostAppear)
		{
			mostAppear = table[S];
			mostAppearW = S;
		}		

		if (S.size() > maxSize)
		{
			maxSize = S.size();
			maxSizeW = S;
		}
	}

	cout << mostAppearW << " " << maxSizeW << endl;

	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    // freopen("1.txt", "r", stdin);
    int x, n, pi;
    cin >> x >> n;
    unordered_set<int> vis;
    for (int i = 0; i < n; ++i) {
        cin >> pi;
        vis.insert(pi);
    }

    int res = 0;
    for (int d = 0; d <= x; ++d) {
        int val = x - d;
        if (vis.find(val) == vis.end()) {
            res = val;
            break;
        }
        val = x + d;
        if (vis.find(val) == vis.end()) {
            res = val;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#define pi acos(-1.0)
using namespace std;
void task()
{
  int w,s;
  cin>>s>>w;
  if(w>=s)
    cout<<"unsafe"<<endl;
  else
    cout<<"safe"<<endl;
}
int main()
{

   task();

   return 0;

}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    int ans = 700;
    REP(i,S.size()){
        if(S[i] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int q,a,b,c,d,k,l,r,mid;
int min(int x,int y) {return x<y?x:y;}
int max(int x,int y) {return x>y?x:y;}
bool ck(int x) {return b-(x-1)/k<=(a-x+1ll)*k;}
int main()
{
	for(scanf("%d",&q);q--;)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		k=(a+b)/(min(a,b)+1);
		for(l=0,r=a;l<r;ck(mid=l+r+1>>1)?l=mid:r=mid-1);
		a-=l; b-=(l-1)/k; l+=(l-1)/k; r=l+b-a*k+1;
		fo(i,c,min(l,d)) putchar(65+(i%(k+1)==0));
		fo(i,max(l+1,c),d) putchar(66-((i-r)%(k+1)==0));
		puts("");
	}
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
#define MOD 1000000007
#define ll long long
#define ld long double
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main() {
	fast;
	int d, t, s;
	cin >> d >> t >> s;
	if(s * t >= d) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3592
let _ = readLine()
let W = readLine()!.characters.split(" ").map{Int(String($0))!}
var S1 = 0
var S2 = W.reduce(0){$0+$1}
var ans = S2
for i in W {
    S1 += i
    S2 -= i
    ans = min(abs(S1-S2), ans)
}
print(ans)

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

typedef long long int ll;

int c[404][404];
int c2[404][404];

void rec(int y, int x, ll &white, ll &black, const int H, const int W) {
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (0 <= xx && xx < W && 0 <= yy && yy < H) {
      if (c[y][x] + c[yy][xx] == 1) {
        if (c2[yy][xx] == 0) {
          c2[yy][xx] = 1;
          if (c[yy][xx] == 1) black++;
          else white++;
          rec(yy, xx, white, black, H, W);
        }
      }
    }
  }
}

ll solve(int y, int x, const int H, const int W) {
  ll white = 0, black = 0;
  c2[y][x] = 1;
  if (c[y][x] == 1) black++;
  else white++;
  rec(y, x, white, black, H, W);
  return white * black;
}

int main(void) {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    char s[404] = "";
    cin >> s;
    for (int j = 0; j < W; ++j) {
      if (s[j] == '#') c[i][j] = 1;
    }
  }
  ll ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (c2[i][j] == 0) {
        ans += solve(i, j, H, W);
      }
    }
  }
  cout << ans << endl;
}


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


int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -LLONG_MAX;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define SORT(v) sort(v.rbegin() , v.rend())
#define si(n) scanf( "%d" , &n)
#define sii(n , m) scanf( "%d %d" , &n , &m)
#define sl(n) scanf( "%lld" , &n)
#define sll(n , m) scanf( "%lld %lld" , &n, &m)
#define ss(cad) scanf( "%s" , cad)
#define sz(x) (int)x.size()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl
#define M 11092019
#define N_MAX 1000010
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vp;

char cad[1200], cad2[1200];

int main(){
	ss(cad);
	ss(cad2);
	int n = strlen(cad);
	int m = strlen(cad2);
	int ans = n;
	for(int i = 0; i+m-1 < n; i++){
		int cnt = 0;
		for(int j = 0; j < m; j++){
			if(cad[i+j] != cad2[j])
				cnt++;
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 3828
import sys
H,W=map(int,input().split())
L=[0]*26
for i in range(H):
  A=str(input())
  for j in range(W):
    L[ord(A[j])-97]+=1

fours0=0
fours1=0
fours2=0
fours3=0
for i in range(26):
  if L[i]%4==0:
    fours0+=1
  if L[i]%4==1:
    fours1+=1
  if L[i]%4==2:
    fours2+=1
  if L[i]%4==3:
    fours3+=1

if W%2==0 and H%2==0:
  if fours1+fours2+fours3==0: print("Yes")
  else: print("No")
elif W%2==1 and H%2==1:
  if fours1+fours3<=1 and fours1+fours3+2*fours2<=W+H-1:
    print("Yes")
  else: print("No")
elif W%2==1: 
  if fours1+fours3==0 and fours2*2<=H:
    print("Yes")
  else: print("No")
else: 
  if fours1+fours3==0 and fours2*2<=W:
    print("Yes")
  else: print("No")

Measured memory_bytes: 3192
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll gcd(ll a, ll b) { return b == 0LL ? a : gcd(b, a % b); }

ll N, M; string S, T;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M >> S >> T;

    ll u = gcd(N, M);
    ll L = N / u * M;
    ll A = L / M, B = L / N;

    bool ok = true;

    for (int i = 0; i < (int)max(N, M); ++i)
        if (S[A * i % N] != T[B * i % M]) ok = false;

    cout << (ok ? L : -1) << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}

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

using namespace std;

struct LinkCutTree {
  vector<int>left,right,parent;

  LinkCutTree(int n):left(n,-1),right(n,-1),parent(n,-1){}

  bool is_root(int id){
    return parent[id]<0 || (left[parent[id]]!=id && right[parent[id]]!=id);
  }

  void connect(int ch, int p, bool isL){
    (isL ? left : right)[p] = ch;
    if(ch >= 0)parent[ch] = p;
  }

  void rotate(int id){
    int p = parent[id], q = parent[p];
    bool isL = id==left[p], isRoot = is_root(p);

    connect((isL ? right : left)[id], p, isL);
    connect(p, id, !isL);

    if(!isRoot)connect(id,q,p==left[q]);
    else parent[id]=q;
  }

  void splay(int id){
    while(!is_root(id)){
      int p = parent[id];
      if(!is_root(p))rotate( (id==left[p])^(p==left[parent[p]]) ? p : id );
      rotate(id);
    }
  }

  int expose(int id){
    int last = -1;
    for(int y=id; y>=0; y=parent[y])
      splay(y), left[y]=last, last=y;
    splay(id);
    return last;
  }

  int find_root(int id){
    expose(id);
    while(right[id]!=-1)id=right[id];
    return id;
  }

  void link(int ch, int p){
    expose(ch);
    if(right[ch]>=0)return;
    parent[ch]=p;
  }

  void cut(int id){
    expose(id);
    if(right[id]<0)return;
    parent[right[id]]=-1;
    right[id]=-1;
  }

  int lca(int ch, int p){
    //if(find_root(ch)!=find_root(p))return -1;
    expose(ch);
    return expose(p);
  }
};

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

  LinkCutTree tree(n);
  
  for(int i=0;i<n;i++){
    int k,t;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      tree.link(t,i);
    }
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int u,v;
    cin >> u >> v;
    cout << tree.lca(u,v) << endl;
  }
   
  return 0;
}

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

int main(){
	static int n,t,s,a,b,dp[3000+2][3000+2]={0};
	scanf("%d%d%d",&n,&t,&s);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a,&b);
		for(int j=1;j<=t;j++){
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(j>=b&&!(j-b<s&&j>s))dp[i][j]=max(dp[i][j],dp[i-1][j-b]+a);
		}
	}
	printf("%d\n",dp[n][t]);
}

Measured memory_bytes: 36360
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
dest = list(map(int, input().split()))

index_map = {}

step = 0
next_index = 0
while 0 < k:
  k -= 1  
  next_index = dest[next_index] - 1

  if next_index in index_map:
    period = step - index_map[next_index]
    skip = k % period
    for j in range(0, skip):
      next_index = dest[next_index] - 1
    break

  index_map[next_index] = step
  step += 1

print(next_index + 1)  

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

struct equation {
    ll a, b; // y = a * x + b

    ll y(ll x0){return a * x0 + b;}
    ld intersect(equation o){return (ld) (o.b - b) / (a - o.a);}
};

struct CHT {
    deque<equation> hull;
    void add(const equation &e) {
        while (hull.size() > 1 and hull.rbegin()[1].intersect(e) < hull.rbegin()[1].intersect(hull.rbegin()[0]))
            hull.pop_back();
        hull.push_back(e);
    }
    ll get(ll x0) {
      assert(!hull.empty());
      while (hull.size() > 1 and hull[0].y(x0) > hull[1].y(x0))
            hull.pop_front();
      return hull[0].y(x0);
    }
};

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

  int n; ll c;
  cin >> n >> c;
  vector<ll> a(n);
  trav(i, a) cin >> i;

  CHT cht;
  vector<ll> dp(n);
  cht.add({-2 * a[0], dp[0] + a[0] * a[0]});
  rep(i, 1, n) {
    dp[i] = cht.get(a[i]) + c + a[i] * a[i];
    cht.add({-2 * a[i], dp[i] + a[i] * a[i]});
  }
  cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 5632
import java.util.Scanner;

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

    while(true){
      int a = scan.nextInt();
      int b = scan.nextInt();
      if(a==0 && b==0) break;

      for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
          System.out.print("#");
        }System.out.println();
      }System.out.println();
    }
  }
}



Measured memory_bytes: 34568
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////



string s;

string t;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s>>t;
    t.erase(s.size(),1);
    Yes(s==t);
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

int main() {
  int n, i;
  scanf("%d", &n);
  int a, b, c, aa, bb, cc;
  for (i = 0; i < n; i += 1) {
    scanf("%d %d %d", &a, &b, &c);
    aa = a * a;
    bb = b * b;
    cc = c * c;

    if(aa == bb + cc || bb == cc + aa || cc == aa + bb) {
      printf("YES\n");
    } else {
      printf("NO\n");
    };                                                                                                                                                                     
  };
  return 0;
} 

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

using namespace std;

#define all(v) begin(v), end(v)
#define inf 1<<25

struct PrimalDual {
  struct edge {
    int to, cap, cost, rev;
    edge(){}
    edge(int to, int cap, int cost, int rev)
      :to(to), cap(cap), cost(cost), rev(rev){}
  };
  vector< vector<edge> > graph;
  vector<int> h, mincost, prevv, preve;
  PrimalDual(){}
  PrimalDual(int V):graph(V), h(V), mincost(V), prevv(V), preve(V){}
  void add_edge(int from, int to, int cap, int cost) {
    graph[from].emplace_back(to, cap, cost, graph[to].size());
    graph[to].emplace_back(from, 0, -cost, graph[from].size()-1);
  }
  int min_cost_flow(int s, int t, int f) {
    fill(all(h), 0);
    fill(all(prevv), -1);
    fill(all(preve), -1);
    typedef pair<int, int> P;
    int res = 0;
    while(f > 0) {
      fill(all(mincost), inf);
      priority_queue<P, vector<P>, greater<P> > que;
      que.emplace(0, s);
      mincost[s] = 0;
      while(que.size()) {
	P p = que.top(); que.pop();
	int v = p.second;
	if(mincost[v] < p.first) continue;
	for(int i = 0; i < graph[v].size(); i++) {
	  edge&e = graph[v][i];
	  int cost = mincost[v] + e.cost + h[v] - h[e.to];
	  if(e.cap > 0 && cost < mincost[e.to]) {
	    mincost[e.to] = cost;
	    que.emplace(cost, e.to);
	    prevv[e.to] = v;
	    preve[e.to] = i;
	  }
	}
      }
      if(mincost[t] < 0) return -1;
      for(int v = 0; v < graph.size(); v++) h[v] += mincost[v];
      int d = f;
      for(int v = t; v != s; v = prevv[v])
	d = min(d, graph[prevv[v]][preve[v]].cap);
      f -= d;
      res += d * h[t];
      for(int v = t; v != s; v = prevv[v]) {
	edge& e = graph[prevv[v]][preve[v]];
	e.cap -= d;
	graph[e.to][e.rev].cap += d;
      }
    }
    return res;
  }
};

int N, M, K;
int a[101];
int b[101][101];
int T[101];

int main() {
  cin >> N >> M >> K;
  for(int i = 0; i < N; i++) cin >> a[i];
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) cin >> b[i][j];
  }
  for(int i = 0; i < M; i++) cin >> T[i];
  int dummy = N + M, s = dummy + 1, s2 = s + 1, t = s2 + 1, V = t + 1;
  PrimalDual graph(V);
  graph.add_edge(s, s2, N-K, 0);
  graph.add_edge(s, dummy, N, 0);
  for(int i = 0; i < M; i++) {
    graph.add_edge(s2, i, T[i], 0);
    for(int j = 0; j < N; j++) {
      graph.add_edge(i, M+j, 1, 100-b[i][j]);
    }
  }
  for(int i = 0; i < N; i++) {
    graph.add_edge(dummy, M+i, 1, 100-a[i]);
    graph.add_edge(M+i, t, 1, 0);
  }
  cout << 100*N-graph.min_cost_flow(s, t, N) << endl;
  return 0;
}

Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
int w1[110],v[110];
const int inf=0x3f3f3f3f;
#define ll long long 
int dp[110][110][330];
ll ans;
int main(){
    int n,w,i,j,k;
    scanf("%d%d",&n,&w);
    for(i=1;i<=n;i++)
         cin>>w1[i]>>v[i];
    
    for(i=1;i<=n;i++)
    
        for(j=0;j<=i;j++)
          for(k=0;k<=3*j;k++)
          
        {
           dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
           dp[i+1][j+1][k+w1[i]-w1[1]]=max(dp[i+1][j+1][k+w1[i]-w1[1]],dp[i][j][k]+v[i]);
        }
    int ans=0 ;
    for (int i=0;i<=n;i++)
    for (int j=0;j<=3*i;j++){
        ll W= (ll) w1[1]*i+j;
        if (W<=w) ans=max(ans,dp[n+1][i][j]) ;
    }
    printf("%d",ans) ;
    return 0 ;

}

Measured memory_bytes: 12800
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>

int main() {
	int n;
	char N[10000],x[2];
	int i;
	while (~fscanf(stdin, "%d", &n),n!=-1) {
		memset(x, '\0', sizeof(x));
		memset(N, '\0', sizeof(N));
		if(n==0) N[0]='0';
		while (n) {
			sprintf(x, "%d", n % 4);
			strcat(N, x);
			n /= 4;
		}
		for (i = strlen(N)-1; i >= 0; --i)fprintf(stdout, "%c", N[i]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 648
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int med1,med2;
    int ans;
    if(n%2==1){
        med1=a[n/2];
        med2=b[n/2];
        ans=med2-med1+1;
    }
    else{
        med1=a[n/2-1]+a[n/2];
        med2=b[n/2-1]+b[n/2];
        ans=med2-med1+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4824
//#define NDEBUG

#pragma region cp_template

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';
template <class T> T ceildiv(const T &l, const T &r) {
  return l / r + (l % r != 0 ? 1 : 0);
}

} // namespace n91

#pragma endregion cp_template

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  u64 a, b, c;
  std::cin >> a >> b >> c;
  usize k;
  std::cin >> k;
  for (const usize i : rep(0, k)) {
    if (a >= b) {
      b *= 2;
    } else if (b >= c) {
      c *= 2;
    }
  }
  std::cout << (a < b && b < c ? "Yes" : "No") << eoln;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;


int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    int sum = 0;
    rep(i, n) sum += a[i];

    if (sum >= h){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 892
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

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


bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;

#define int long long
ll dp[101][100001];
int knapSack(int W, int wt[], int val[], int n) {

    if (n == 0 || W == 0)
        return 0;
    
    if (dp[n][W] != -1) return dp[n][W];

    if (wt[n-1] > W)
        return dp[n][W] = knapSack(W, wt, val, n-1);

    else
        return dp[n][W] = max( val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),
                               knapSack(W, wt, val, n-1) );
}
void go() {
    ll n , w;
    cin >> n >> w;
    ll wt[n] , p[n];
    for (int i = 0; i < n; ++i)cin >> wt[i] >> p[i];
    memset(dp , -1 , sizeof dp);
    cout << knapSack(w,wt,p,n);
}


int32_t main() {
    fio
    go();
}


Measured memory_bytes: 79232
N = input()
A = map(int, raw_input().split())

M = {}
s = 0
for a in A:
  s += a
  if s not in M:
    M[s] = 0
  M[s] += 1

ans = 0
s = 0
for a in A:
  if s in M:
    ans += M[s]
  s += a
  M[s] -= 1
print ans


Measured memory_bytes: 31620
import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int N = fs.nextInt();
    char[] S = fs.next().toCharArray();
    for (int i = 0; i < S.length; i++) S[i] = (char)('A' + (S[i] - 'A' + N) % 26);
    System.out.println(S); 
  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
    return buffer[ptr++];
    else
    return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
    ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
    throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
    throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
      throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
    throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 21588
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <map>

using namespace std;
int main(void)
{

  int a = 1;
  long long int n, d, dd, b, c, K, count = 0, com = 0;
  cin >> n;

  vector<long long int> vec(n + 1, 0);
  map<long long int, long long int> m;

  cin >> K;
  for (long long int i = 1; i <= n; i++)
  {
    cin >> m[i];
  }

  d = 1;
  for (long long int j = 1; j <= K; j++)
  {
    d = m[d];
    vec[d]++;
    if (a == 1)
    {
      if (vec[d] == 2)
      {
        dd = d;
        a = 2;
        if (j == K)
        {
          cout << d << endl;
          return 0;
        }
        continue;
      }
      if (j == K)
      {
        cout << d << endl;
        return 0;
      }
    }
    if (a == 2)
    {
      com++;
      if (j == K)
      {
        cout << d << endl;
        return 0;
      }
      if (dd == d)
      {
        c = ((K - j) % com);
        for (int o = 0; o < c; o++)
        {
          d = m[d];
        }

        cout << d << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 17124
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)
#define int long long

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}

int n, a, b,ans;
signed main() {
	cin >> n >> a >> b;
	ans =1+ ((b - a) * (n - 2));
	if (ans < 0)ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())-1

ans=''
last=0

keta=1

while True:
    if last+26**keta>n:
        for i in range(keta):
            idx=n%26
            n//=26
            ans+=chr(97+idx)
        break
    n-=26**keta
    keta+=1
print(ans[::-1])

Measured memory_bytes: 9208
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const int N = 4e5 + 10, M = 2e7 + 100, mod = 1e9 + 7;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll a, b, n;
    cin >> n >> a >> b;
    if(!a){
        cout << 0;
        return 0;
    }
    ll blue = n / (a + b) * a;
    n %= (a + b);
    blue += min(a, n);
    cout << blue << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

struct edge
{
  ll to;
  ll cost;
  edge() {}
  edge(ll to, ll cost) : to(to), cost(cost){};
};
int main()
{
ll n , m ;
cin >> n >> m ;
vector<vector<edge>> g(n);
rep(i, m)
{
  ll a, b, c;
  cin >> a >> b >> c;
  g[a - 1].emplace_back(b - 1, c);
  g[b - 1].emplace_back(a - 1, -c); 
}
vector<ll> dist(n,INF);
vector<ll> see(n);
queue<ll> q;
rep(i,n){
  if(see[i])continue;
  dist[i]=0;
  see[i]=1;
  q.push(i);
  while(!q.empty()){
    auto p=q.front();
    q.pop();
    for(auto r:g[p]){
      if(dist[r.to]==INF)dist[r.to]=dist[p]+r.cost;
      else if (dist[r.to] != dist[p] + r.cost)
      {
        cout << "No" << endl;
        return 0;
      }
      if(see[r.to]!=0)continue;
      see[r.to]=1;
      q.push(r.to);
    }
  }
}
cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

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

Measured memory_bytes: 256
program sum_of_product_of_pairs
  implicit none
  integer(8), parameter :: m = 1000000007
  integer :: n, i
  integer(8) :: a(200000) = 0, s = 0, x = 0
  read(*,*) n
  read(*,*) a(1:n)
  s = a(n)
  do i = n - 1, 1, -1
    x = mod(x + s * a(i), m)
    s = mod(s + a(i), m)
  end do
  write(*,'(i0)') x
end program sum_of_product_of_pairs

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int n,m,c;
    cin >> n >> m >> c;
    int A[n][m],B[m];

    FOR(i,0,m)
        cin >> B[i];

    FOR(i,0,n){
        FOR(j,0,m)
            cin >> A[i][j];
    }

    int res=0;

    FOR(i,0,n){
        int cal=0;
        FOR(j,0,m){
            cal+=A[i][j]*B[j];
        }
        cal+=c;
        if(cal>0)
            res++;
    }

    cout << res << endl;

    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            long a = Long.parseLong(str[0]);
            long b = Long.parseLong(str[1]);
            if (a * b % 2 == 0) {
                System.out.println("Even");
            } else {
                System.out.println("Odd");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 21076
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;
constexpr int d[] = {-1, 0, 1, 0};

string s[25];
int seen[25][25];

int n, m;


void bfs(int x, int y) {
    seen[x][y] = 0;
    queue< pair< int, int>> q;
    q.emplace(x, y);

    while (!q.empty()) {
        x = q.front().first, y = q.front().second;
        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + d[i];
            int ny = y + d[i ^ 1];
            if (nx < 0 or ny < 0 or nx >= n or ny >= m) continue;
            if (s[nx][ny] == '#') continue;
            if (seen[nx][ny] != -1) continue;
            seen[nx][ny] = seen[x][y] + 1;
            q.emplace(nx, ny);
        }
    }
}

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

    cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> s[i];

    int result = 0;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) for (int k = 0; k < n; k++) for (int l = 0; l < m; l++) {
        if (i == k and j == l) continue;
        if (s[i][j] == '#' or s[k][l] == '#') continue;
        memset(seen, -1, sizeof seen);
        bfs(i, j);
        result = max(result, seen[k][l]);
    }
    cout << result << endl;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    let ans = 1+2+3-a-b;
    println!("{}", ans);
}

Measured memory_bytes: 4352
class p
    shared sub main()
        dim n = Integer.Parse(Console.ReadLine())
        dim a = 1
        for i as Integer = 1 To 32
            for j as Integer = 2 To 32
                dim t = i ^ j
                if t <= n then
                    a = Math.Max(t, a)
                else
                    exit for
                end if
            next
        next
        Console.WriteLine(a)
    end sub
end class


Measured memory_bytes: 20312
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cou = 0
for j,k in zip(a,b):
  if j<k:
    cou += (k-j)//2
  elif j>k:
    cou -= (j-k)
if cou>=0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 10276
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c;
    cin >> a >> b >> c ;
    //*/
    
    /*
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    */
    
    //*
    if( a == b ){
        cout << c << endl;
    } else if (b == c){
        cout << a << endl;
    } else {
        cout << b << endl;
    }
    //*/
    
    //cout << a * a - b << endl;

    return 0; 
}


Measured memory_bytes: 3628