akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  if (s[0] == '0' || s.back() == '1') {
    cout << -1 << endl;
    return 0;
  }
  rep (i, (n-1)/2) {
    if (s[i] != s[n-2-i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int p = 1;
  for (int i = 2; i <= n; i++) {
    cout << p << ' ' << i << endl;
    if (s[i-2] == '1')
      p = i;
  }
  return 0;
}

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

int main(void){
  int a, b, k, i;
  cin >> a >> b >> k;
  for(i = 0; i < min(k, b-a+1); i++){
    cout << a+i << endl;
  }

  i = max(a+k, b-k+1);
  if(i < 0) return 0;
  for(; i <= b; i++){
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　int a = 0;
bool p=false,g=false,w=false,y=false;
            a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            for(int i = 0;i < str.Length;i++)
{
 if(str[i] == "Y" && !y)
y = !y;
if(str[i] == "G" && !g)
g = !g;
 if(str[i] == "W" && !w)
w = !w;
if(str[i] == "P" && !p)
p = !p;

}
            bool c = p&w&y&g;
if(c)
　　　　　　　Console.Write("Four");//改行なし出力
           else
Console.Write("Three");
 }
 }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int dp[n + 1];
    rep(i, 0, n + 1) dp[i] = INF;
    dp[0] = 0;
    rep(i, 1, n + 1) {
        for (int pow6 = 1; pow6 <= i; pow6 *= 6) {
            dp[i] = min(dp[i], dp[i - pow6] + 1);
        }
        for (int pow9 = 1; pow9 <= i; pow9 *= 9) {
            dp[i] = min(dp[i], dp[i - pow9] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
	int w, a, b;
	cin >> w >> a >> b;
	if (b - (a + w)>0)
    cout<< b - (a + w);
	else if ((b + w) >= a) cout << "0";
	else cout <<a - (b + w);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
row_even = []
row_odd = []

while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i % 2 == 0:
            for j in range(W):
                if j % 2 == 0:
                    row_even.append('#')
                else:
                    row_even.append('.')
            print(*row_even, sep='')
            row_even.clear()
        else:
            for k in range(W):
                if k % 2 != 0:
                    row_odd.append('#')
                else:
                    row_odd.append('.')
            print(*row_odd, sep='')
            row_odd.clear()
    print()


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    
    ll ans;
    ans = (A + (N-1)*B) - ((N-1)*A + B) + 1;
    if(ans < 0)
        ans = 0;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pii pair<int ,int > 
#define pb push_back
#define mo 1000000007
 
int main()
{
	ios ; 
ll r , d , x; cin>>r>>d>>x; 
for(int i =1; i<=10 ; i++)
{
	x = x*r-d; 
	cout<<x<<endl;
}
	return(0);
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int ans1 = 0;
	rep(i, s.size()) {
		char c;
		if (i % 2 == 0) {
			c = '0';
		}
		else
		{
			c = '1';
		}
		if (s[i] != c) {
			ans1++;
		}
	}
	int ans2 = 0;
	rep(i, s.size()) {
		char c;
		if (i % 2 == 0) {
			c = '1';
		}
		else
		{
			c = '0';
		}
		if (s[i] != c) {
			ans2++;
		}
	}
	cout << min(ans1, ans2) << endl;

	return 0;
}



Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("sse4.2")

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

int n;
vector<ll> x, y, p, ans;
vector<vector<ll> > m;

void calcScore(int next, int count) {
  if (next < n) {
    for (int i = 0; i < n; i++) m[next+1][i] = m[next][i];
    calcScore(next+1, count);
    for (int i = 0; i < n; i++) {
      m[next+1][i] = m[next][i];
      if (abs(x[i] - x[next]) < m[next+1][i]) m[next+1][i] = abs(x[i] - x[next]);
    }
    calcScore(next+1, count+1);
    for (int i = 0; i < n; i++) {
      m[next+1][i] = m[next][i];
      if (abs(y[i] - y[next]) < m[next+1][i]) m[next+1][i] = abs(y[i] - y[next]);
    }
    calcScore(next+1, count+1);
  }
  else {
    ll score = 0;
    for (int i = 0; i < n; i++) score += p[i] * m[n][i];
    if (score < ans[count]) ans[count] = score;
  }
}

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

  cin >> n;
  x = vector<ll>(n);
  y = vector<ll>(n);
  p = vector<ll>(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> p[i];

  m = vector<vector<ll> >(n+1, vector<ll>(n));
  for (int i = 0; i < n; i++) m[0][i] = min(abs(x[i]), abs(y[i]));

  ans = vector<ll>(n+1, (ll) 9e18);
  calcScore(0, 0);

  for (auto &z: ans) cout << z << endl;

  return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string s;
  cin >> s;
  int left = 0;
  int right = s.size() - 1;
  int ans = 0;
  while (left <= right) {
    if (s[left] == s[right]) {
      left++;
      right--;
    } else if (s[left] == 'x') {
      left++;
      ans++;
    } else if (s[right] == 'x') {
      right--;
      ans++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
int main(){
	std::string s;
	std::cin  >> s;
	std::vector<int> v(100,0);
	
	for(auto i:s){
		v[i] += 1; 
	}

	int count = 0;
	for(auto i: v){
		if(i == 2){
			count++;
		}
	}

	if(count == 2){
		std::cout << "Yes";
	}else{
		std::cout << "No";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,M,result=0;
    cin >> N >> M;
    int H[N];
    for(int i=0; i<N; i++) cin >> H[i];
    int A[M],B[M];
    vector <int> han(N,1);
    for(int i=0; i<M; i++) cin >> A[i] >> B[i];

    for(int i=0; i<M; i++){
        if(H[A[i]-1] > H[B[i]-1]){
            han[B[i]-1] = 0;
        }
        else if(H[B[i]-1] > H[A[i]-1]){
            han[A[i]-1] = 0;
        }
        else{
            han[A[i]-1] = 0;
            han[B[i]-1] = 0;
        }
    }

    for(int i=0; i<N; i++){
      result += han[i];
    }
    cout << result << endl;

    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 10 * b;
    while (ans < 1010)
    {
        if (int(ans * 0.08) == a && int(ans * 0.1) == b)
            break;
        ++ans;
    }
    if (ans == 1010)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int k,n,i;
    cin>>k>>n;
    int arr[n];
    for(i=0;i<n;i++)
    cin>>arr[i];
    int dif[n];

    for(i=0;i<n-1;i++)
    {
        dif[i]=arr[i+1]-arr[i];
    }
    dif[i]=k+arr[0]-arr[n-1];
    int out=*max_element(dif,dif+n);
   out=k-out;
    cout<<out<<'\n';
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	long long int n,m,a,b,some,count=0,some1[2000000],some2[2000000];
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		if(a==1){
			some1[b]=1;
		}
		else if(b==n){
			some2[a]=1;
		}
	}
	for(int i=2;i<n;i++){
		if(some1[i]==1 && some2[i]==1){
			count++;
		}
	}
	printf("%s\n",(count>0)? "POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 7040
### constant

#         0    1     2    3     4    5    6     7    8     9    10   11
TONES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
EXTS = ['', '7', 'M7', 'm', 'm7']

CMPNTS = [
  [0, 4, 7],	 # C   = C,E,G
  [0, 4, 7, 10], # C7  = C,E,G,A#
  [0, 4, 7, 11], # CM7 = C,E,G,B
  [0, 3, 7],	 # Cm  = C,D#,G
  [0, 3, 7, 10]	 # Cm7 = C,D#,G,A#
]

#           0    1     2      3     4      5      6     7     8
TNSNS0 = ['-9', '9', '+9', '-11', '11', '+11', '-13', '13', '+13']
#          C#    D    D#      E     F     F#     G#     A     A#
TADDS  = [  1,   2,    3,     4,    5,     6,     8,    9,    10]

TNSNS1 = ['-5', '+5']
#          F#    G#
TMODS  = [ -1,    1]

NT = TONES.length
NE = EXTS.length
NTNS0 = TNSNS0.length
NTNS1 = TNSNS1.length

### global variables

### subroutines

def cmpntstr(cmpnt)
  cmpnt.map{|t| TONES[t]}.sort.join
end

### main

chash = Hash.new

for root in (0...NT)
  for ext in (0...NE)
    base = TONES[root] + EXTS[ext]
    cmpnt = CMPNTS[ext].map{|t| (root + t) % NT}
    cstr = cmpntstr(cmpnt)

    chash[cstr] = [] if chash[cstr].nil?
    chash[cstr] << base
    #p [base, cstr]
    
    for tns0 in (0...NTNS0)
      cname0 = base + '(' + TNSNS0[tns0] + ')'
      cmpnt0 = cmpnt + [(root + TADDS[tns0]) % NT]
      cstr0 = cmpntstr(cmpnt0)

      chash[cstr0] = [] if chash[cstr0].nil?
      chash[cstr0] << cname0
      #p [cname0, cstr0]
    end

    for tns1 in (0...NTNS1)
      cname1 = base + '(' + TNSNS1[tns1] + ')'
      cmpnt1 = cmpnt.clone
      cmpnt1[2] = (cmpnt1[2] + TMODS[tns1]) % NT
      cstr1 = cmpntstr(cmpnt1)
      
      chash[cstr1] = [] if chash[cstr1].nil?
      chash[cstr1] << cname1
      #p [cname1, cstr1]
    end
  end
end
#p chash; exit 0
#p chash['CEG']; exit 0

n = gets.to_i

n.times do
  cols = gets.strip.split
  cols.shift

  cnames = chash[cols.sort.join]
  if cnames.nil?
    puts 'UNKNOWN'
  else
    puts cnames.join(' ')
  end
end

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

int main(){
  int N,cou=0;
  cin>>N;
  string A;
  vector<string> item(N);
  for(int i=0;i<N;i++){
    cin>>A;
    item[i]=A;
  }
  cou=N;
  sort(item.begin(),item.end());
  for(int i=0;i<N-1;i++){
    if(item[i]==item[i+1]){
      cou--;
    }
  }
  cout<<cou<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  int ans=1;
  if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)&&s.at(0)=='R') ans=3;
  else if(s.at(0)==s.at(1)&&s.at(0)=='R') ans=2;
  else if(s.at(1)==s.at(2)&&s.at(1)=='R') ans=2;
  else if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)&&s.at(0)=='S') ans=0;

  cout << ans;
}

Measured memory_bytes: 3624
use std::io;
use std::str::FromStr;
use std::cmp::max;

struct Item {
    weight: u64,
    value: u64
}

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn dp (i: usize, items: &Vec<Item>, weight: u64, cache: &mut Vec<Vec<u64>>) -> u64 {
    if i == items.len() {
        return 0;        
    }
    // println!("{}, {}", i, weight);
    if cache[i][weight as usize] != 0 {
        // println!("cache hit: {}, {}", i, weight);
        return cache[i][weight as usize];
    }

    if items[i].weight > weight {
        let val = dp(i+1, items, weight, cache);
        cache[i][weight as usize] = val;
        return val;
    }
    let val = max(
        dp(i+1, items, weight - items[i].weight, cache) + items[i].value,
        dp(i+1, items, weight, cache));
    cache[i][weight as usize] = val;
    val
}

fn main() {
    let (n, w) = input_tuple();
    let mut caches: Vec<Vec<u64>> = vec![vec![0; 100_001usize]; (n+1) as usize];
    let mut items: Vec<Item> = Vec::new();
    for _ in 0..n {
        let (w, v) = input_tuple();
        items.push(Item {weight: w, value: v});
    }
    println!("{}", dp(0, &items, w, &mut caches));
}


Measured memory_bytes: 106748
#include<bits/stdc++.h> 
using namespace std; 
int main() 
{ 
  int n,m,k; 
  cin>>n; 
  m=n/500; 
  m=1000*m; 
  k=n/5; 
  k=k*5;
  n=n%500; 
  m+=(n/5)*5; 
  cout<<max(m,k)<<endl;
}

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

int main(){
	string in[1000];
	int max=0;
	string ml_str;
	int tmp;
	string ans;
	int i=0;
	for(i=0;cin>>in[i];i++){
		if(in[i].size()>max){
			max=in[i].size();
			ml_str=in[i];
		}
	}
	sort(in,in+i);
	tmp=1;
	max=0;
	for(int j=1;j<i;j++){
		if(in[j]==in[j-1]){
			tmp++;
		}else{
			if(max<tmp){
				max=tmp;
				ans=in[j-1];
				tmp=1;
			}
		}
	}
	cout<<ans<<" "<<ml_str<<endl;
}

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

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

    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    rep(i,n) cin >> s[i];

    vector<int> a;

    s.push_back('2');
    int i = 0;
    int cnt = 1;
    while(i < n){
        if(s[i] == s[i+1]) cnt++;
        else {
            a.push_back(cnt);
            cnt = 1;
        }
        i++;
    }

    for(int j = 1; j < a.size(); j++){
        a[j] += a[j-1];
    }

    int ans = 0;
    int m = a.size();
    for(int j = 0; j < m; j++){
        int res = 0;
        if(s[0] == '0' && j == 0){
            res = a[min(j + 2 * k - 1,m - 1)];
        } else {
            if(j == 0) res = a[min(j + 2 * k,m - 1)];
            else res = a[min(j + 2 * k,m - 1)] - a[j - 1];
            j++;
        }
        ans = max(res,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1020
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007


ll X,Y;

int main() {
    cin >> X >> Y;
    ll ans = 1;
    while(X*2 <= Y){
        ans++;
        X *= 2;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    int K, N;  // 円周と家の軒数
    cin >> K >> N;

    vector<int> A;  // 家の位置の配列
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    // 考え方メモ
    // 1, 時計回り
    // 2, 反時計回り <- 反時計周りは考える必要がない！！ -> 時計回りの長さを全て列挙すれば、反時計回りの長さも同様に列挙されるから。（長さなので無向だから）
    // 5 10 15
    // 時計回り：
    // 5を始点 -> 15 - 5 = 10
    // 10を始点 -> (20 - 10) + (0 + 5) = 15
    // 15を始点 -> (20 - 15) + (0 + 10) = 15

    int minOfMoving = K;
    for (int i = 0; i < N; i++) {  // 始点にする点

        // 時計回り
        if (i == 0) {
            minOfMoving = min(minOfMoving, A[N - 1] - A[i]);
        } else {
            minOfMoving = min(minOfMoving, K - A[i] + A[i - 1]);
        }

    }

    cout << minOfMoving << endl;

    return 0;
}

Measured memory_bytes: 1400
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        n:i32,
        l:i32
    }

    let mut taste: Vec<i32> = Vec::new();

    for i in 0..n{
        taste.push(i+l);
    }

    let total_taste:i32 = taste.iter().sum();
    let mut temp = 999;
    let mut keep_index = 0;
    
    for (index, j) in taste.iter().enumerate(){
        let a_taste = taste[..index].iter().sum::<i32>();
        let b_taste = taste[index+1..].iter().sum::<i32>();

        let result:i32 = total_taste - (a_taste+b_taste);

        if  result.abs() < temp{
            temp = result.abs();
            keep_index = index;
        }

    }

    taste.remove(keep_index);

    println!("{}", taste.iter().sum::<i32>());

    //println!("{:?}", total_taste)
}

Measured memory_bytes: 4352
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String[] s1 = new String[3];
        s1[0] = "Sunny";
        s1[1] = "Cloudy";
        s1[2] = "Rainy";
        String s2 = sc.next();
        
        int jadge = 0;
        if(s2.equals(s1[0])) jadge = 1;
        if(s2.equals(s1[1])) jadge = 2;
        if(s2.equals(s1[2])) jadge = 0;
        System.out.println(s1[jadge]);
    }
}



Measured memory_bytes: 21716
def b_harshad(N):
    num = [int(x) for x in list(str(N))]  # 数値Nを1桁ごとにバラす
    tmp = sum(num)
    ans = (N % tmp == 0)
    if ans:
        return 'Yes'
    else:
        return 'No'

N = int(input())
print(b_harshad(N))

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            int n = sc.nextInt();
            int min = Integer.MAX_VALUE;
            int max = 0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                min = Math.min(min, a);
                max = Math.max(max, a);
            }
            System.out.println(max - min);
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll R,G,B,N;

int main(){
	FAST;
	ll ans=0;
	cin >> R >> G >> B >> N;
	rep(r,N+1) {
		rep(g,N+1) {
			ll b = N-r*R-g*G;
			if (b%B==0 && b>=0) ans++;
		}
	}
	cout << ans << LF;

	return 0;
}

Measured memory_bytes: 256
s=input()
n, m = map(int, s.split(' '))
h = []

s=input().split(' ')
for i in s:
    h.append(int(i))

# a = b = []
roads_ob = []  # ある展望台Hiが一本の道をたどって行ける道の集合
for i in range(n):
    roads_ob.append(set())

for i in range(m):
    s=input().split(' ')
    a = int(s[0])
    b = int(s[1])
    roads_ob[a-1].add(b-1)
    roads_ob[b-1].add(a-1)
    # a.append(int(s[0]))
    # b.append(int(s[1]))

good = 0
for i, roads in enumerate(roads_ob):
    # print(roads)
    better_than = 0
    for road in roads:
        if h[i] > h[road]:
            better_than += 1
        else:
            # not good
            break
    if len(roads) == better_than:
        good += 1

print(good)


Measured memory_bytes: 45964
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        n: u64,
        m: u64,
    }
    let mut i = 1;
    let mut div = vec![];
    while i * i <= m {
        if m % i == 0 {
            div.push(i);
            div.push(m / i);
        }
        i += 1;
    }
    let mut ma = 0;
    for d in div {
        if d <= m / n { ma = max(d, ma); }
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

typedef pair<int,int> P;

struct UnionFind{
	std::vector<int> data;
	UnionFind(int size): data(size, -1){ }
	// ?????????????????????
	bool unite(int x, int y){
		x=root(x); y=root(y);
		if( x != y ) data[y] = x;
		return x!=y;
	}
	// ??????????????????????????????
	bool find(int x, int y){
		return root(x) == root(y);
	}
	// ??????????????\???????????????
	int root(int x){
		// ???????????????????????????????????????????????????
		return (data[x] < 0)? x : data[x]=root(data[x]);
	}
};

int N, M, a[50000], b[50000], c[50000];
vector<P> vh, vc;

int solve2(UnionFind &uf, const vector<int> &l, int z){
	int sum = 0;
	UnionFind ufl = uf;
	for(auto t: l){
		ufl.unite( z, t );
	}
	for(auto c: vc){
		int i = c.second;
		if( uf.find(a[i], b[i]) ) continue;
		if( !ufl.find(z, a[i]) ) continue;
		if( !ufl.find(z, b[i]) ) continue;
		uf.unite( a[i], b[i] );
		sum += c.first;
	}
	return sum;
}

int solve(int limit){
	int now = limit;
	int z = vh[0].second;
	int ans = 0;
	UnionFind uf(205);
	vector<int> l;
	for(auto v: vh){
		//if( v.first < limit ) continue;
		//if( now == 0 ) now = v.first;
		if( v.first >= limit && now != v.first ){
			ans += solve2(uf, l, z);
			//cout << v.first << " " << ans << endl;
			l.clear();
		}
		l.push_back( v.second );
		now = max( v.first, limit );
	}
	return ans;
}

int calc(){
	int limit = 0;
	while(1){
		int nx = vh.size()-1;
		bool sink[205]={}; sink[0] = true;
		while(limit <= vh[nx].first){
			sink[ vh[nx].second ] = true;
			nx--;
			if( nx <= 0 ) break;
		}
		if( nx <= 0 ) break;
//		cout << "ok" << nx << endl;

		UnionFind uf(205);
		int z = vh[0].second;
		for(auto c: vc){
			int i = c.second;
			if( sink[ a[i] ] || sink[ b[i] ] ) continue;
			uf.unite( a[i], b[i] );
		}
		bool f = false;
		rep(i,N+1) if( !sink[i] && !uf.find(z,i) ) f = true;
		if(f) break;
		limit = vh[nx].first;
	}
	return limit;
}

int main(){
	while(cin >> N >> M, N|M){
		vh.clear(); vc.clear();
		rep(i,N){
			int h;
			cin >> h;
			vh.emplace_back( -h, i+1 );
		}
		vh.emplace_back(0,0);
		sort( vh.begin(), vh.end() );
		rep(i,M){
			cin >> a[i] >> b[i] >> c[i];
			vc.emplace_back( c[i], i );
		}
		sort( vc.begin(), vc.end() );
		//cout << calc() << endl;
		cout << solve( calc() ) << endl;
	}
	return 0;
}

Measured memory_bytes: 3464
#include<stdio.h>
int L[500000],R[500000];
int cnt;

void merge(int A[],int n,int left,int mid,int right){
    int n1,n2;
    int i,j,k;
    n1=mid-left;
    n2=right-mid;
    for(i=0;i<n1;i++){
        L[i]=A[left+i];
    }
    for(i=0;i<n2;i++){
        R[i]=A[mid+i];
    }
    L[n1]=R[n2]=2000000000;
    i=0;j=0;
    for(k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }
        else{
            A[k]=R[j++];
        }
    }
}

void mergeSort(int A[],int n,int left,int right){
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    int A[500000],n,i;
    cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    mergeSort(A,n,0,n);
    for(i=0;i<n-1;i++){
        if(i){
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf(" %d\n",A[i]);
    printf("%d\n",cnt);
    return 0;
}


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




int main() {

    int n;cin>>n;
    int count=0;
    while(n!=0){
        if(n<3){
            n=0;
        }
        else if(n-3 >= 3){
            n-=3;
            count++;
        }
        else
        {
            n=0;
            count++;
        }

    }
    cout<<count;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	a := make([]int, N, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}
	var ans int64 = 0
	maxi := a[0]
	for i := 1; i < N; i++ {
		if a[i] < maxi {
			ans += int64(maxi - a[i])
		} else {
			maxi = a[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5856
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

ll good_mod(ll value, ll base) {
    return ((value % base) + base) % base;
}

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    unordered_map<char, vector<ll>> next;
    unordered_set<char> t_chars;
    for (char c : t) {
        t_chars.insert(c);
    }
    for (char c : t_chars) {
        next[c] = vector<ll>(s.size(), -1);
        ll first_idx = -1;
        for (ll i = 0; i < s.size(); i++) {
            if (s[i] == c) {
                first_idx = i;
                break;
            }
        }
        if (first_idx == -1) {
            cout << -1 << endl;
            return 0;
        }
        ll count = 0;
        for (ll j = 0; j < s.size(); j++) {
            ll idx = first_idx - j;
            idx = good_mod(idx, s.size());
            if (s[idx] == c) {
                count = 0;
            }
            next[c][idx] = count;
            count++;
        }
    }
    ll ans = -1;
    for (char c : t) {
        ans += 1;
        ans += next[c][good_mod(ans, s.size())];
    }
    ans++;
    cout << ans << endl;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1000000007;
Int dp[100001][2];
int main()
{
    string L; cin >> L;
    dp[0][0] = dp[0][1] = 1;
    for (int i = 1; i <= L.size(); i++) {
        if (L[L.size()-i] == '0') {
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1] + 2 * dp[i-1][1];
        } else {
            dp[i][0] = dp[i-1][1] + 2 * dp[i-1][0];
            dp[i][1] = dp[i-1][1] + 2 * dp[i-1][1];
        }
        dp[i][0] %= MOD;
        dp[i][1] %= MOD;
    }
    cout << dp[L.size()][0] << '\n';
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int a[200006], b[200006];
int main () {
	cin.tie(0);
	long long int N, K;
	cin >> N >> K;
	for (int i=1; i<=N; i++) {
		cin >> a[i];
	}
    int c, w=1;
    int time_stamp = 1;
	for (int i=1; i<=K; i++) {
        if (i==1) {
            c=a[i];
        }
        else {
            c=a[c];
        }
        if (b[c]==0) {
            b[c]=time_stamp;
            time_stamp++;
        }
        else {
            w=time_stamp-b[c];
            break;
        }
    }
    for (int i=0; i<(K-time_stamp)%w; i++) {
    		 c=a[c];
    }
    cout << c << endl;
}

Measured memory_bytes: 5148
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct edge{
	int to;
	int cost;
};

vector<edge> graph[100010];
int come[100010];
struct edge e;

int search(int x){
	int i;

	come[x]=1;

	for(i=0;i<graph[x].size();i++){
		e=graph[x][i];
		if(come[e.to]==-1){
			search(e.to);
		}
	}

	return 0;
}

int main(void)
{
	//変数の宣言
	int n,m;
	int l[100010];
	int r[100010];

	//よく使う変数
	int i,j,k;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;



	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


	for(i=0;i<m;i++){
		scanf("%d %d",&l[i],&r[i]);
//		scanf_s("%d %d",&l[i],&r[i]);
	}


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	min=0;
	max=INFINT;

	for(i=0;i<m;i++){
		min=max(min,l[i]);
		max=min(max,r[i]);
	}



	//	printf("計算部分終了\n");

	//出力

	//printf("%d %d",min,max);

	printf("%d",max(0,max-min+1));

	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 3328
"""
セグメント木
"""

INF = 10 ** 20
n, q = map(int, input().split())

size = 1
while size < n:
  size *= 2
size = size * 2 - 1

seg_tree = [(INF, 0) for _ in range(size)]

def update(a, v):
  ind = (size - 1) // 2 + a
  prea, prev = seg_tree[ind]
  seg_tree[ind] = (a + 1, prev + v)
  while ind > 0:
    ind = (ind - 1) // 2
    ca1, cv1 = seg_tree[ind * 2 + 1]
    ca2, cv2 = seg_tree[ind * 2 + 2]
    if cv1 >= cv2:
      seg_tree[ind] = (ca1, cv1)
    else:
      seg_tree[ind] = (ca2, cv2)
      

for i in range(q):
  a, v = map(int, input().split())
  a -= 1
  update(a, v)
  print(seg_tree[0][0], seg_tree[0][1])


Measured memory_bytes: 158060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BHomework {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = in.nextArrInt(m);
            long t = 0;
            for (int i = 0; i < m; i++)
                t += a[i];
            out.println(n - t < 0 ? -1 : n - t);
            //out.print("Case #"+ testNumber + ": ");
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextArrInt(int n) {
            int[] a = new int[n];
            for (int i = 0; i < a.length; i++)
                a[i] = nextInt();
            return a;
        }

    }
}



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

int main() {
int   p,i;
double x,a,b;
	cin >>  a>>b;
  vector<double> vecx(a);
  vector<double> vecy(a);
  for (i = 0; i < a; i++) {
    cin >> vecx.at(i)>> vecy.at(i);
  }
	p=0;
  for (i = 0; i < a; i++) {
   x=vecx.at(i)*vecx.at(i)+vecy.at(i)*vecy.at(i);
	x=sqrt(x);
if(x<=b){
p=p+1;
}
	}
cout << p << endl;
}

Measured memory_bytes: 6428
while(1):
    try:
        n=int(raw_input())
        if n==1:
            print 1
        else:
            A=[0 for i in range(n/2)]
            A[0]=1
            for i in range(1,n/2):
                A[i]=1+sum(A[:i])*2
            ans=sum(A)*2
            if n%2:
                ans+=1+sum(A)*2
            print ans
            
    except:
        break

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return x;}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in<string>();

	out(N.substr(0,3));
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int a[4], n; cin >> n;
	a[0] = n / 1000; a[1] = (n % 1000) / 100; a[2] = (n % 100) / 10; a[3] = n % 10;
	int sum = 0;
	Rep(i, 4){ sum += a[i]; }
	string op[3];
	for(int i = 0; i < (1 << 4); i++){
		int t = sum;
		for(int j = 0; j < 3; j++){
			if((i >> j) & 1){
				t -= a[j+1] * 2;
				op[j] = "-";
			}else{
				op[j] = "+";
			}
		}
		if(t == 7){
			break;
		}
	}
	cout << a[0] << op[0] << a[1] << op[1] << a[2] << op[2] << a[3] << "=" << 7 << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
D = [map(int, input().split()) for _ in range(N)]

flg = False
cnt = 0
for di, dj in D:
    if (di == dj):
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        flg = True
        break
if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
#include <cstdio>
int N, Q, x, y, cur, a[200009], c[200009], s[200009];
int main() {
	scanf("%d %d", &N, &Q);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]), c[a[i]]++;
	for (int i = 1; i <= N; i++) s[i]--, s[i > c[i] ? i - c[i] : 0]++;
	for (int i = 0; i < N; i++) {
		s[i + 1] += s[i];
		if (s[i] == 0) cur++;
	}
	for (int i = 0; i < Q; i++) {
		scanf("%d %d", &x, &y); x--;
		if (a[x] - c[a[x]] >= 0) {
			s[a[x] - c[a[x]]]--;
			if (s[a[x] - c[a[x]]] == 0) cur++;
		}
		c[a[x]]--;
		a[x] = y;
		c[a[x]]++;
		if (a[x] - c[a[x]] >= 0) {
			if (s[a[x] - c[a[x]]] == 0) cur--;
			s[a[x] - c[a[x]]]++;
		}
		printf("%d\n", cur);
	}
	return 0;
}

Measured memory_bytes: 3712
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}

const MAX = 2000

type Stack struct {
	container [MAX]int
	top       int
}

func (s *Stack) isEmpty() bool {
	if s.top == 0 {
		return true
	}
	return false
}

func (s *Stack) push(n int) {
	s.top++
	s.container[s.top] = n
}

func (s *Stack) pop() (int, bool) {
	if s.isEmpty() {
		return -1, false
	}
	n := s.container[s.top]
	s.top--
	return n, true
}

func main() {
	s := scanString()
	arr := strings.Split(s, " ")

	stack := Stack{}
	for _, e := range arr {
		switch e {
		case "+":
			x, ok1 := stack.pop()
			y, ok2 := stack.pop()
			if ok1 && ok2 {
				stack.push(y + x)
			}
		case "-":
			x, ok1 := stack.pop()
			y, ok2 := stack.pop()
			if ok1 && ok2 {
				stack.push(y - x)
			}
		case "*":
			x, ok1 := stack.pop()
			y, ok2 := stack.pop()
			if ok1 && ok2 {
				stack.push(y * x)
			}
		case "/":
			x, ok1 := stack.pop()
			y, ok2 := stack.pop()
			if ok1 && ok2 {
				stack.push(y / x)
			}
		default:
			n, _ := strconv.Atoi(e)
			stack.push(n)
		}
	}

	ans, _ := stack.pop()
	fmt.Println(ans)
}



Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<iterator>

using namespace std;
bool sortit(pair<int,int>a, pair<int,int>b){
	return (a.first < b.first);
}
int main(){
	int n,m;
	cin >> n >> m;
  	// insertion into two arrays
  	long int arr1[n], arr2[n];
  vector<pair<long int,long int>> vec;
  	for (int i = 0 ; i < n; i++)
    {
      cin >> arr1[i] >> arr2[i];
      vec.push_back(make_pair(arr1[i],arr2[i]));
    }
  	// sorting vector on basis of first element
  	sort(vec.begin(), vec.end(), sortit);
  // main code
  long long int res =0;
  int i = 0;
  while (m != 0){
  	if(vec[i].second < m) {
    	res += (vec[i].first)*(vec[i].second);
      m = m - vec[i].second;
    }
    else {
    	res += (vec[i].first)*m;
      	m = 0;
    }
    ++i;
  }
  cout << res<<'\n';
  return 0;
}

Measured memory_bytes: 3444
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A, B = [0], [0]
for i in range(n):
    A.append(a[i]+A[i])
for i in range(m):
    B.append(b[i]+B[i])

ans, j = 0, m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 47648