akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define bs2int(bs) (int)((bs).to_ulong())
#define DEBUG(X) cerr<<"  "<<#X<<" = "<<X<<endl;
#define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl;
#define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;};
#define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;}
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

int main() {
  string s; cin>>s; s=s.substr(0,s.length()-1);
  int n = s.length();
  for (int i=n-1; i>=0; i-=2) {
    int mid = i/2;
    if (s.substr(0,mid+1) == s.substr(mid+1,mid+1)) {
      cout<<2*(mid+1)<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    deque<char> d(s.begin(), s.end());
    bool reversed = false;
    int q;
    cin >> q;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            reversed ^= 1;
        } else {
            int f; char c;
            cin >> f >> c;
            if((f == 1) ^ reversed) {
                d.push_front(c);
            } else {
                d.push_back(c);
            }
        }
    }
    string ans(d.begin(), d.end());
    if(reversed) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4016
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, read().split())

    ans = 0
    while N:
        N //= K
        ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int par[100000];
int root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = root(par[x]);
	}
}
int main() {
	int n, q, p, a, b;
	int x, y;
	set<int> se;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
	for (int j = 0; j < q; j++) {
		cin >> a >> b >> p;
		x = root(a);
		y = root(b);
		if (x != y) {
			par[x] = y;
		}
	}
	for (int k = 0; k < n; k++) {
		se.insert(root(k));
	}
	int ans = se.size();
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 5376
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

tmp=0
for a in A:
    if a==tmp+1:
        tmp+=1
print(-1 if tmp==0 else n-tmp)

Measured memory_bytes: 26140
s=input()
k=int(input())
if len(set(s))==1:
  print(len(s)*k//2)
else:
  cnt=1
  s_ans=0
  x=s[0]
  for a in s[1:]:
    if a==x:
      cnt+=1
    else:
      s_ans+=cnt//2
      x=a
      cnt=1
  s_ans+=cnt//2
  if s[0]!=s[-1]:
    print(s_ans*k)
  else:
    ss=s*2
    cnt=1
    ss_ans=0
    x=ss[0]
    for a in ss[1:]:
      if a==x:
        cnt+=1
      else:
        ss_ans+=cnt//2
        x=a
        cnt=1
    ss_ans+=cnt//2
    print(s_ans*k+(ss_ans-s_ans*2)*(k-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
 
int main(void){
  string s;cin >> s;
  int sum = 0;
  for(int i = 1;i<s.size();i++){
    if(s.at(i-1) != s.at(i)){
      sum += 1;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512
import java.util.*;
public class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double[] v = new double[N];
		double[] val = new double[N];
		double ave = 0;
		for(int i=0;i<N;i++){
			v[i] = sc.nextDouble();
		}
		Arrays.sort(v);
		ave = (v[0] + v[1])/2;
		if(N > 2){
			for(int i = 1; i < N-1; i++){
				ave = (ave + v[i+1])/2;
			}
		}
		System.out.println(ave);
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for(int i = 0; i < 1000; i++) {
		string p = to_string(i);
		while(p.size() < 3) p = '0' + p;

		int ok = 0;
		for(int j = 0; j < S.size(); j++)
			if(S[j] == p[ok]) ok++;
		if(ok == 3) ans++;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    float a, b; cin >> a >> b;
    cout << (int)ceil((b - 1)/ (a-1) ) << "\n";
    
    
    
    return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>
int main()
{
	int h,w,i;
	char c[101][101];

	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",c[i]);
		printf("%s\n%s\n",c[i],c[i]);
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
C - Candles
https://atcoder.jp/contests/abc107/tasks/arc101_a

"""
import sys


def solve(N, K, candles):
    ans = []
    for i in range(N-K+1):
        left = candles[i]
        right = candles[i+K-1]
        if left * right < 0:
            if abs(left) > abs(right):
                ans.append(abs(left) + abs(right)*2)
            else:
                ans.append(abs(left)*2 + abs(right))
        else:
            ans.append(max(abs(left), abs(right)))
    return min(ans)


def main(args):
    N, K = map(int, input().split())
    candles = [int(x) for x in input().split()]
    ans = solve(N, K, candles)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 14564
#include <iostream>

using namespace std;
const int MAXN = 20  + 5;
int v[MAXN] , c[MAXN];
int n;

int solve(int i)
{

if(i == n) return 0;

return max(solve(i + 1) , solve(i + 1) + v[i] - c[i]);
    
}

int main() {
 
cin >> n;
for(int i = 0 ; i < n ; i++) cin >> v[i];
for(int i = 0 ; i < n ; i++) cin >> c[i];

cout << solve(0) ;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(true) {
			int A=in.nextInt(),D=in.nextInt(),N=in.nextInt();
			if(A==0 && D==0)break;
			
			boolean ENE[]=new boolean[A+(D*N)*25+1];
			Arrays.fill(ENE,true); ENE[1]=false;
			
			for(int i=2;i<Math.sqrt(ENE.length);i++) {
				if(ENE[i]) {
					for(int j=i*2;j<ENE.length;j+=i)ENE[j]=false;
				}
			}
			
			List<Integer> primes=new ArrayList<>();
			for(int i=A;i<ENE.length;i++) {
				if(ENE[i] && (i-A)%D==0 )primes.add(i);
			}
			
			System.out.println(primes.get(N-1));
		}
	}

}



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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vvi v(n,vi(n));
	REP(i, n)REP(j, n)cin >> v[i][j];
	ll ans = 0;
	REP(i, n) {
		FOR(j,i, n) {
			ans += min(v[i][j], v[j][i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i+=2){
        int c = 0;
        for (int j = 1; j*j <= i; j++){
            if (i % j == 0){
                c++;
                if (j != i/j) c++;
            }
        }
        if (c == 8) ans++;
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3596
def countDigs(n):
	digs = 0
	while n > 0:
		digs += 1
		n = n // 10
	return digs

# def calcUpperLimit(n):
# 	x = 1
# 	if (n <= x**2):
# 		return int(n // 2) + 1
# 	for i in range(x, 0, -1):
# 		if (n % x == 0):
# 			return n // x + 1
# 	return int(n // 2) + 1

# def digs(n):
# 	for i in range(int((n + 0.1) ** 0.5), calcUpperLimit(n)):
# 		if (n % i == 0):
# 			print(countDigs(i))
# 			return
# 	print(countDigs(n))

def digs(n):
	for i in range(int((n + 0.1) ** 0.5), 0, -1):
		if n % i == 0:
			print(countDigs(n // i))
			return

digs(int(input()))

Measured memory_bytes: 2940
#include<stdio.h> 
int main(void){   
int a, b, c, d;   
scanf("%d %d %d", &a, &b, &c);   
if(b<a){     
d=a;     a=b;     b=d;   }        
if(c<b){     
d=b;     b=c;     c=d;     }   
if(b<a){     
d=a;     a=b;     b=d;   }       
printf("%d %d %d\n", a, b, c);         
return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;

typedef long long LL;
const int N = 2e5 + 10;
LL h[N], x[N];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		h[x[i]]++;
	}

	LL sum = 0;
	for (int k = 1; k <= N; k++) {
		if (h[k] >= 2) {
			sum += h[k] * (h[k] - 1) / 2;
		}
	}

	for (int i = 1; i <= n; i++) {
		if (h[x[i]] >= 2) {
			cout << sum - h[x[i]] + 1 << endl;
		}
		else
			cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 4736
#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 a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
               1, 5, 1, 2, 1, 14, 1, 5, 1, 5,
               2, 2, 1, 15, 2, 2, 5, 4, 1, 4,
               1, 51};
  int k;
  cin >> k;
  cout << a[k-1];
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  } else if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;   
  } else {
    cout << "Right" << endl;
  }
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main() {
  string S;
  cin >> S;
  if(S[0]==S[1] && S[2]==S[3] &&S[0]!=S[2]) cout << "Yes";
  else if(S[0]==S[2] && S[1]==S[3] &&S[0]!=S[1]) cout << "Yes";
  else if(S[0]==S[3] && S[1]==S[2] &&S[0]!=S[1]) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#[allow(dead_code)]
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)*}
    };
}

#[allow(dead_code)]
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)*}
    };

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

#[allow(dead_code)]
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: usize,
        d: usize
    }
    let d2 = 2 * d + 1;
    let result = (n as f64) / (d2 as f64);
    println!("{}", result.ceil());
}


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

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

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

int main(){
  ull k,n;
  cin >> k >> n;
  vector<ull> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  ull mdf = 99999999;
  for(int i=0;i<n;i++){
    ull diff;
    if( i == 0 ){
      diff = min( k-a.at(1)+a.at(0),a.back()-a.front());
    }else if( i == n-1 ){
      diff = min( a.at(i)-a.front(),k-a.at(i)+a.at(i-1));
    }else{
      diff = min(k-a.at(i+1)+a.at(i),k-a.at(i)+a.at(i-1));
    }
    if( mdf > diff ){
      mdf = diff;
    }
  }
  cout << mdf << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
    va[i] -= i + 1;
  }

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

  ll mid = va[va.size() / 2], ans = 0;
  for (int i = 0; i < va.size(); ++i) {
    ans += abs(va[i] - mid);
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 4796
#include <stdio.h>

void sort(int *a,int n)
{
        int i,j,max,index;
        for(i=0;i<n;i++){
                max=a[i];index=i;
                for(j=i;j<n;j++)
                        if(max<a[j]){
                                max=a[j];index=j;
                        }
                a[index]=a[i];
                a[i]=max;
        }
        return ;
}
int main(void)
{
        int n,k,i,s=0;
        scanf("%d%d",&n,&k);
        int p[n];
        for(i=0;i<n;i++)
                scanf("%d",&p[i]);
        sort(p,n);
        for(i=0;i<k;i++)
                s+=p[n-i-1];
        printf("%d\n",s);
        return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    printf("%.10f\n",(double)((double)dup(N,2)/N));
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long n,m,i,j,a,b,c,d,ans=0;
    cin>>a>>b>>c;
    if(c>=a && c<=b)cout<<"Yes";
    else cout<<"No";
    
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c,i=0;
	
	scanf("%d",&a);
	
	scanf("%d",&b);
	
	scanf("%d",&c);
	
	if (a>b){
		
		i=a;
		
		a=b;
		
		b=i;
		
	}
	
	if (b>c){
		
		i=b;
		
		b=c;
		
		c=i;
		
	}
	
	if (a>b){
		
		i=a;
		
		a=b;
		
		b=i;
		
	}
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
	
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.nextLine();
		for(int j=1;j<=n;j++){
			String s = scan.nextLine();
			int ans = Integer.parseInt(s);
			System.out.println("Case "+j+":");
			for(int i=0;i<10;i++){
				ans = ((ans*ans)%1000000)/100;
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
C = [list(map(int,input().split())) for i in range(n-1+m)]

r = -1
R = [1] * (n+1)
for i in range(len(C)):
    R[C[i][1]] = 0
for i in range(1, n+1):
    if R[i] == 1:
        r = i

# print(r)
IN = [0] * (n+1)
P = [0] * (n+1)

M = [[] for i in range(n+1)]
for i in range(n-1+m):
    M[C[i][0]].append(C[i][1])
    IN[C[i][1]] += 1

# INはその頂点を指している辺の本数のリスト

S = []
s = 0

for i in range(n):
    if IN[i] == 0:
        S.append(i)

while s < len(S):
    for x in M[S[s]]:
        IN[x] -= 1
        if IN[x] == 0:
            S.append(x)
    s += 1

for i in S:
    for j in M[i]:
        P[j] = i
for i in range(1, n+1):
    print(P[i])

Measured memory_bytes: 77676
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n; cin >> n;
  vector<int> a(n);
  int xr = 0;
  for (int &x : a) {
    cin >> x;
    xr ^= x;
  }
  for (int &x : a) {
    cout << (xr ^ x) << ' ';
  }
  cout << '\n';
}


Measured memory_bytes: 3884
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		StringBuilder s = new StringBuilder(sc.next());
		StringBuilder front = new StringBuilder();
		StringBuilder rear = new StringBuilder();
		int q = sc.nextInt();
		
		int turn = 0;
		for (int i = 0; i < q; i++) {
			int t = sc.nextInt();
			if (t == 1) {
				turn ^= 1;
			} else {
				int f = sc.nextInt();
				String c = sc.next();
				if (f == 1) {
					if (turn == 0) {
						front.append(c);
					} else {
						rear.append(c);
					}
				} else {
					if (turn == 0) {
						rear.append(c);
					} else {
						front.append(c);
					}
				}
				
			}
		}

		front = front.reverse();
		front = front.append(s.toString()).append(rear.toString());
		
		if (turn == 1) {
			front = front.reverse();
		}
		
		System.out.println(front.toString());
		
		sc.close();
	}

}


Measured memory_bytes: 120212
N, M = STDIN.gets.chomp.split(' ').map(&:to_i)

A = Array.new(0)

for i in 0..N - 1 do
  A[i] = STDIN.gets.chomp.split(' ').map(&:to_i) # 0が値段,1が個数
end

A.sort!{|a, b| a[0] <=> b[0]}

result = 0
nowM = M
for i in 0..N - 1 do
  if nowM <= A[i][1] then
    result += nowM * A[i][0]
    break 
  else
    result += A[i][0] * A[i][1]
    nowM -= A[i][1]
  end
end
  
puts result 

Measured memory_bytes: 10488
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

int main(void){
    int m,d,ans=0;
    cin>>m>>d;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            if(j<10)continue;
            int d0=j%10;
            int d1=(j-d0)/10;
            if(d0<2)continue;
            if(d1<2)continue;
            if(i==d0*d1)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！

    string str;
    int N, A, B, C, D;
    int count = 0;
    getline(cin, str);
    stringstream ss;
        ss << str;
        ss >> N;
        ss >> A;
        ss >> B;
        ss >> C;
        ss >> D;
    
    int timesX, timesY;
    timesX = N / A + (N % A != 0);
    timesY = N / C + (N % C != 0);
    
    int sumX, sumY;
    sumX =  B * timesX;
    sumY =  D * timesY;
    
    int ans;
    if(sumX < sumY)
    ans = sumX;
    else
    ans = sumY;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int X,Y;
	cin>>X>>Y;
	int ans=0;
	if(X==1){
		ans+=300000;
	}
	else if(X==2){
		ans+=200000;
	}
	else if(X==3){
		ans+=100000;
	}
	if(Y==1){
		ans+=300000;
	}
	else if(Y==2){
		ans+=200000;
	}
	else if(Y==3){
		ans+=100000;
	}
	if(X==1&&Y==1){
		ans+=400000;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int n,m,point;
  cin>>n>>m;
  ll a[50],b[50],c[50],d[50],dis[50];
  REP(i,50){
    a[i]=0,b[i]=0,c[i]=0,d[i]=0,dis[i]=10000000000;
  }
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  REP(i,m){
    cin>>c[i]>>d[i];
  }
  ll curdis=0;
  REP(i,n){

    REP(j,m){
      curdis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if (curdis<dis[i])
      {
        /* code */
        dis[i]=curdis;
        point=j+1;
      }
      
    }
    cout<<point<<endl;
  }
}


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


using namespace std;

int main() {
	string S;
	cin >> S;
	
	string s_before = S.substr(0, 2);
	string s_after = S.substr(2, 2);

	//cout << s_before << " " << s_after << endl;

	int befor_num = stoi(s_before);
	int after_num = stoi(s_after);

	//cout << befor_num << " " << after_num << endl;

	if (1 <= befor_num && befor_num <= 12) {
		//MMYY
		if (1 <= after_num && after_num <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else if (1 <= after_num && after_num <= 12) {
		//YYMM
		if (1 <= befor_num && befor_num <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "YYMM" << endl;
		}
	}
	else {
		cout << "NA" << endl;
	}
	




}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
 
int main() {
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++)
    {
      cin>>A[i];
    }
    vector<int> a = A;
    for(int t=0;t<K;t++)
    {
      vector<int> B(N+1,0);
      for(int i=0;i<N;i++)
      {
        B[max(0,i-a[i])]++;
        B[min(N,i+a[i]+1)]--;
      }
      for(int i=0;i<N;i++) B[i+1]+=B[i];
      B.pop_back();
      if(a==B)break;
      a=B;
    }
    for(int i=0;i<N;i++)
    {
      cout<<a[i]<< (i == N - 1 ? '\n' : ' ');
    }
    return 0;
}

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

#define ll long long
#define ppi pair<int, int>
#define pb push_back
#define vi vector<int>
#define fi first
#define se second
#define forn(n) for(ll i = 0; i < n; i++)
#define forx(x,n) for(ll i = x; i < n; i++)

using namespace std;
vi G[100001];
int N,M;
bool vis[100001];
int P[100001], out;

int dfs(int v, int d)
{
	vis[v] = true;
	for(auto x : G[v])
	   {
	   	  if(!vis[x])
	   	  	P[v] = max(P[v], dfs(x,v));
		  else P[v] = max(P[v], P[x]+1);
	   }
	return P[v]+1;
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	P[0] = -1;
 	cin >> N >> M;
	forn(M)
	{
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
	}
 //	forx(1,N+1) if(!B[i].size()) s.pb(i);
 	forx(1,N+1) if(!vis[i]) dfs(i, 0);
 	forx(1,N+1) out = max(P[i], out);
 	cout << out;
 	
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int32_t main(){
	char c;cin>>c;
	cout<<(char)(c+1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;

    bool flag = false;
    if (A == 5 && B == 5 && C == 7) {
        flag = true;
    } else if (A == 5 && B == 7 && C == 5) {
        flag = true;
    } else if (A == 7 && B == 5 && C == 5) {
        flag = true;
    }

    if (flag) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO"  << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library

template <class T>
struct Edge{
    int src;
    int to;
    T cost;
    Edge(int t,T c) : to(t),cost(c) {}
    Edge(int src, int t,T c) : src(src),to(t),cost(c) {}
};
template<class T> using WeightedGraph = vector<vector<Edge<T>>>;

// Complexity: O(E*V)
// Dependency: Graph Template
template <typename T>
vector<T> BellmanFord(vector<Edge<T>>& es, int v, int s){
    const auto INFD = LINF;
    vector<T> dist(v,INFD);
    dist[s]=0;
    for (int i = 0; i < 2*v; ++i){
        for(auto e: es){
            if(dist[e.src]==INFD) continue;
            if(dist[e.to]>dist[e.src]+e.cost){
                dist[e.to]=dist[e.src]+e.cost;
                if (i==v-1) dist[e.to]=-INFD;
            }
        }
    }
    if(dist[v-1]<=-INFD) return vll();
    return dist;
}
#pragma endregion library

int main(){
    int n,m; cin >> n >> m;
    vector<Edge<ll>> es;
    rep(i,m){
        int a,b;ll c; cin >> a >> b >> c;
        a--;b--;
        es.emplace_back(a,b,-c);
    }
    vll d = BellmanFord(es,n,0);
    if(d.empty()) cout << "inf" << '\n';
    else cout << -d[n-1] << '\n';
    
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3e18;

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;
}

lint modpow(lint x, lint n) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2LL; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1LL;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, a, b, c, cnt2, ans = 100000;
int l[1010];
string s;
string quat(int x) {
	string ans;
	int y = (1 << (2 * n - 2));
	while (y != 0) {
		ans += '0' + x / y;
		x %= y;
		y >>= 2;
	}
	return ans;
}

int main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);
	rep(i, n) scanf("%d", &l[i]);
	rep(i, (1 << 2 * n)) {
		s = quat(i);
		int cnt[3] = { 0,0,0 }; cnt2 = 0;
		rep(j, n) {
			if (s[j] != '3') {
				if (cnt[s[j] - '0'] != 0) cnt2 += 10;
				cnt[s[j] - '0'] += l[j];
			}
		}
		if (cnt[0] * cnt[1] * cnt[2] == 0) continue;
		ans = min(ans, cnt2 + abs(a - cnt[0]) + abs(b - cnt[1]) + abs(c - cnt[2]));
	}
	printf("%d\n", ans);
}

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

signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> w(N);
  for(int i=0;i<N;i++)w[i]=v[i];
  for(int i=0;i<N;i++)w[i]=1-w[i]%2;
  std::vector<int> x(N);
  for(int i=0;i<N;i++)x[i]=v[i];
  for(int i=0;i<N;i++){
    if(x[i]==0)x[i]=2;
    else x[i]%=2;
  }
  std::vector<int> dp1(N+1),dp2(N+1),dp3(N+1),dp4(N+1),dp5(N+1);
  dp1[0]=dp2[0]=dp3[0]=dp4[0]=dp5[0]=0;
  for(int i=0;i<N;i++){
    dp1[i+1]=dp1[i]+v[i];
    dp2[i+1]=min(dp1[i]+x[i],dp2[i]+x[i]);
    dp3[i+1]=min(dp1[i]+w[i],min(dp2[i]+w[i],dp3[i]+w[i]));
    dp4[i+1]=min(min(dp1[i]+x[i],dp2[i]+x[i]),min(dp3[i]+x[i],dp4[i]+x[i]));
    dp5[i+1]=min(min(min(dp1[i]+v[i],dp2[i]+v[i]),dp3[i]+v[i]),min(dp4[i]+x[i],dp5[i]+v[i]));
  }
  int ans=min(dp1[N],min(dp2[N],min(dp3[N],min(dp4[N],dp5[N]))));
  cout<<ans<<endl;
}


Measured memory_bytes: 12800
#include<stdio.h>

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

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  d=0;
  c=0;
  cin >> a;
  for(int i=0;i<a;i++){
  	cin>>b;
    if(b>=c){
      c = b;
      d++;
    }
  }
  cout<<d<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<string.h>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{int a,b,c,x,ans=0,v,z,n;
 cin>>a>>b>>c>>x;
 for(int v=0;v<=a;v++)
 for(int z=0;z<=b;z++)
 for(int n=0;n<=c;n++)
 if(500*v+100*z+50*n==x)
 ans++;
 cout<<ans;
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=200005;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



/************************************


 
*************************************/

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;
ll f=0,k=1;
map<pll,ll>m;
ll dp1[MAX],dp2[MAX];
ll red,blue;
ll ans;
ll dp[MAX];

ll lca(ll u,ll v){
	while(u!=v){
		ll l1,l2;
		l1 = log2(u);
		l2 = log2(v);
		//cout<<l1<<"$$"<<l2<<endl;
		if(l1<l2)
			swap(u,v);
		u /=2;
	}
	return u;
}





signed main(){
	boost;
	int t=1;
	// cin>>t;
	while(t--){
		int n;
		int a,b,c;
		cin>>a>>b>>c;
		cout<<c<<" "<<a<<" "<<b<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
/*figure.c*/

#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b) {
		printf("a < b\n");
	}else if (a > b) {
		printf("a > b\n");
	}else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
while 1:
    n = int(input())
    if n == 0:
        break
    dic = dict()
    for i in range(0,n):
        w1,w2 = input().split()
        dic[w1] = w2
    n = int(input())
    s = ""
    for i in range(0,n):
        w = input()[0]
        if dic.get(w) != None:
            s += dic.get(w)
        else:
            s += w
    print(s)


Measured memory_bytes: 5712
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 3002;

int n, a[maxn];
long long sum[maxn], f[maxn][maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i][i] = a[i];
		sum[i] = sum[i-1] + a[i];
	}

	for (int len = 2; len <= n; ++len)
		for (int i = 1; i <= n+1-len; ++i) {
			int j = i + len - 1;
			f[i][j] = sum[j] - sum[i-1] - min(f[i+1][j], f[i][j-1]);
		}

	long long ans = f[1][n] * 2 - sum[n];
	
	cout << ans << endl;

	return 0;
}

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

int main(void) {
  long n, x, ans = 0;

  cin >> n >> x;

  vector<long> a(n);

  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

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

  if(x < a.at(0)) {
    cout << 0 << endl;
    return 0;
  }

  while(x > 0 && ans < n) {
    x = x - a.at(ans);
    ans++;
  }

  if(ans == n && x > 0) {
    ans--;
  }

  if(x < 0) {
    ans--;
  }

  cout << ans << endl;

  return 0;
}


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

const ll linf = 1e18;

using Matrix = vector<vector<long long>>;

void warshall_floyd(Matrix& m)
{
    const int V = m.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main()
{
    int n, m; cin >> n >> m;
    ll l; cin >> l;
    Matrix g(n, vector<ll>(n, linf));
    for (int i = 0; i < n; i++) g[i][i] = 0;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        ll c; cin >> c;
        g[a][b] = c, g[b][a] = c;
    }

    warshall_floyd(g);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            g[i][j] = (g[i][j] <= l ? 1 : linf);
        }
    }
    warshall_floyd(g);

    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t; cin >> s >> t; s--, t--;
        if (g[s][t] >= linf) cout << -1 << '\n';
        else cout << g[s][t] - 1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define INF (1e9)
#define M 666001
using namespace std;
int P,d[6],c[6]={1,5,10,50,100,500};
int f,ans,sum,z[M];
 
int cal(int x){
  int res=0;
  for(int i=5;i>=0;i--)
    res+=x/c[i],x=x%c[i];
  return res;
}
 
int cal2(int x){
  int res=0;
  for(int i=5;i>=0;i--){
    int p=min(x/c[i],d[i]);
    res+=p;
    if(p)x-=p*c[i];
  }
  if(!x)return res;
  return -1;
}
 
int main(){
  for(int i=0;i<M;i++)
    z[i]=cal(i);
  while(1){
    cin>>P;
    f=sum=0;
    for(int i=0;i<6;i++){
      cin>>d[i],sum+=d[i]*c[i];
      if(d[i])f=1;
    }
    if(!f)break;
    ans=INF;
    for(int i=P;i<=sum;i++){
      int r=cal2(i);
      if(r!=-1)ans=min(ans,r+z[i-P]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  string s; cin >> s;
  int k=s.size();
  int S=0;
  int mi=0;
  for(int i=0;i<k;i++){
    if(s[i]=='S'){
      S++;
    }
    if(s[i]=='T'){
      if(S>0){
        S--;
        mi+=2;
      }
    }
  }
  cout << k-mi << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N, M;
  cin >> N >> M;
  if(500 * N >= M) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

using namespace std;

int main() {
  ll a[4], n;
  for (int i = 0; i < 4; i++) cin >> a[i];
  cin >> n;
  n *= 4;
  ll coeff = 8;
  vector <ll> prices;
  ll ans = 0;
  for (int i = 0; i < 4; i++) {
    ll use = coeff;
    prices.clear();
    for (int j = i; j < 4; j++) {
      prices.push_back(a[j - i] * use);
      use >>= 1;
    }
    sort(prices.begin(), prices.end());
    ll used = (n / coeff) * coeff;
    n -= used;
    ans += (used / coeff) * prices[0];
    coeff >>= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())
st = (60*h+m)/360*math.pi
lt = m/30*math.pi
sx = a*math.sin(st)
sy = a*math.cos(st)
lx = b*math.sin(lt)
ly = b*math.cos(lt)
print(math.sqrt((lx-sx)**2+(ly-sy)**2))


Measured memory_bytes: 62600
//rohitaas_15
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> o_set;
#define ll  long long
#define int ll
#define um(a,b) unordered_map<a,b>
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define f(a,b) for(ll i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define show(x) cout<<x<<"\n"
#define printvector(v,n) f(0,n-1){cout<<v[i]<<" ";}
#define input(v,n) f(0,n-1){cin>>v[i];}
#define vr vector<ll>
#define check() cout<<"hi"<<"\n"
#define MOD 1000000007
//#define endl "\n"
#define maxv(v) *max_element(all(v));
#define minv(v) *min_element(all(v));
#define sumv(v) accumulate(all(v),0)
#define test() ll t;cin>>t;while(t--)
ll search(vr arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
ll CmP(ll n, ll r, ll p=MOD){if (r==0)return 1;ll fac[n+1];fac[0] = 1;for (ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p; return (fac[n]* modInverse(fac[r], p) % p *modInverse(fac[n-r], p) % p) % p; }
/*ll constructSTUtil(vr v,ll start,ll end,int *st,ll index)
{
	if(start==end)
	{
		st[index]=v[start];
		return st[index];
	}
	ll mid=(start+end)/2;
	st[index]=constructSTUtil(v,start,mid,st,2*index)+constructSTUtil(v,mid+1,end,st,2*index+1);
	return st[index];
}
ll *constructST(vr v,ll n)
{
	ll po=(ll)(ceil(log2(n)));
	ll msize=2*power(2,po)+1;
	vr st[msize];
	constructSTUtil(v,0,n-1,st,1);
	return st;
}*/
ll ask1(ll y)
{
	cout<<1<<" "<<y<<endl;
	ll x;
	cin>>x;
	return x;
}
ll repair()
{
	cout<<2<<endl;
	return 0;
}
bool compare(pair<ll,ll> &a,pair<ll,ll> &b)
{
	return a.second<b.second;
}
signed main()
{
	/*#ifndef ONLINE_JUDGE
	 freopen("input.txt","r",stdin);
	 freopen("output.txt","w",stdout);
	 #endif
     */
	 /*ll t;
	 cin>>t;
	 while(t--)
	 {
	 	*/
	 	ll n;
	 	cin>>n;
	 	map<string,ll> freq;
	 	f(1,n)
	 	{
	 		string s;
	 		cin>>s;
	 		freq[s]++;
	 	}
	 	show(freq.size());



	
	 	
	 	
	//}
	/*cout<<"Case #"<<cccc-t<<": ";
		cout<<*/

}


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

typedef pair<int ,long long >P;

bool pairComparefir(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
bool pairComparesec(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}
int main()
{
	long long a,b,q;
	cin>>a>>b>>q;
	long long s[100002],t[100002];
	s[0]=t[0]=-100000000001;
	vector<pair<int,long long> >mem(q);
	for(int i=0;i<a;i++)
		cin>>s[i+1];
	s[a+1]=100000000001;
	for(int i=0;i<b;i++)
		cin>>t[i+1];
	t[b+1]=1000000000001;
	for(int i=0;i<q;i++)
	{cin>>mem[i].second;mem[i].first=i;}
	sort(mem.begin(),mem.end(),pairComparesec);
	vector<int>ms;
	vector<int>mt;
	int temps=0;
	int tempt=0;
	for(int i=0;i<q;i++)
	{
		for(int j=temps;j<a+2;j++)
		{
			if(mem[i].second<=s[j])
				{ms.push_back(j-1);
			temps=j;
			break;}
		}
		for(int j=tempt;j<b+2;j++)
		{
			if(mem[i].second<=t[j])
				{mt.push_back(j-1);
			tempt=j;
			break;}
		}
	}
	for(int i=0;i<q;i++)
	{
		long long ans=100000000001;
		long long ts[2];
		ts[0]=s[ms[i]];
		ts[1]=s[ms[i]+1];
		long long tt[2];
		tt[0]=t[mt[i]];
		tt[1]=t[mt[i]+1];
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				ans=min(ans,(abs(ts[j]-mem[i].second)+abs(tt[k]-ts[j])));
			}
		}
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				ans=min(ans,(abs(tt[j]-mem[i].second)+abs(tt[j]-ts[k])));
			}
		}
		mem[i].second=ans;
	}
	sort(mem.begin(),mem.end(),pairComparefir);
	for(int i=0;i<q;i++)
	{
		cout<<mem[i].second<<endl;
	}
	return 0;

}
	

Measured memory_bytes: 5492
#include <iostream>
#include <vector>
#include <cstring>
#include <cctype>
#include <string>
using namespace std;

int main(){
	int n = 0;
	string w, t;
	cin >> w;
	for (auto pw = w.begin(); pw != w.end(); ++pw){
		if (isalpha(*pw) && isupper(*pw))
			*pw = tolower(*pw);
	}
	while (1){
		cin >> t;
		if (t == "END_OF_TEXT")
			break;
		for (auto pt = t.begin(); pt != t.end(); ++pt){
			if (isalpha(*pt) && isupper(*pt))
				*pt = tolower(*pt);
		}
		if (t == w)
			n++;
	}
	cout << n<<endl;
	return 0;
}

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

typedef pair<long long, int> P;

int main(void){
    long long n,x[200001],s[200001],m=0;
    //priority_queue<P, vector<P>, greater<P>> q;
    priority_queue<P> q;
    
    cin>>n;
    s[0]=0;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>s[i];
        s[i]+=s[i-1];
        q.push(P(s[i]-x[i],i));
    }
    /*
    for(int i=0;i<n;i++){
        P p=q.top();
        cout<<p.second<<", "<<p.first<<endl;
        q.pop();
    }
    */
    for(int i=1;i<=n;i++){
        bool f=true;
        while(f){
            P p=q.top();
            if(p.second<i){
                q.pop();
            }else{
                //cout<<p.first-s[i-1]+x[i]<<endl;
                m=max(m,p.first-s[i-1]+x[i]);
                f=false;
            }
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 9072
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n);
	int sum = 0;
	ff(i, 0, n) {
		cin >> data[i];
		sum += data[i];
	}
	int ans = inf;
	int pre = 0;
	ff(i, 0, n) {
		pre += data[i];
		ans = min(abs(sum - pre*2), ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256