akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,k;cin>>n>>k;
  vector<int> score(n+1,0);
  while(k-->0){
    int d;cin>>d;
    for(int i=0;i<d;i++){
      int a;cin>>a;
      score[a]++;
    }
  }
  int ans=0;
  for(int i=1;i<n+1;i++){
    if(score[i]==0){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
N=int(input())
A=list(map(int, input().split()))
A.sort()
B=[1]*(10**6+1)
counter=0

if N==1:
  print(1)
  exit()
  
if N==2:
  if A[0]==A[1]:
    print(0)
  elif A[1]%A[0]==0:
    print(1)
  else:
    print(2)
  exit()
  
for i in range(N):
  if 0<i<N-1 and (A[i]==A[i-1] or A[i]==A[i+1]):
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==0 and A[i]==A[i+1]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==N-1 and A[i-1]==A[i]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  
  if B[A[i]]==1:
    counter+=1
    j=2
    while A[i]*j<=10**6:
      B[A[i]*j]=0
      j+=1
print(counter)

Measured memory_bytes: 97600
N = int(input())
S = [int(input()) for _ in range(N)]

S = sorted(S)

if sum(S) % 10 != 0:
    print(sum(S))
    exit()

mod_list = [i%10 for i in S]

#print(mod_list)

if sum(mod_list) == 0:
    print(0)
    exit()

for i in range(len(mod_list)):
    if mod_list[i] != 0:
        print(sum(S) - S[i])
        exit()


Measured memory_bytes: 3064
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i64> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn read_int_tuple() -> (i64, i64, i64, i64) {
    let v = read_vec();
    (v[0], v[1], v[2], v[3])
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    let (A, B, C, D) = read_int_tuple();
    let lcm = C*D/gcd(C, D);
    let ans = (B-(A-1)) - (B/C-(A-1)/C) - (B/D-(A-1)/D) + (B/lcm-(A-1)/lcm);
    println!("{}", ans);

}


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

struct kmp
{
  string pat;
  int len;
  vector<int> tbl;
  kmp(const string& s) : pat(s), len(s.size()), tbl(s.size())
  {
    tbl[0] = -1;
    tbl[1] = 0;
    for (int i = 2, j = 0; i < len;) {
      if (pat[i-1] == pat[j]) {
        tbl[i] = j+1;
        i++; j++;
      } else if (j > 0) {
        j = tbl[j];
      } else {
        tbl[i] = 0;
        i++;
      }
    }
  }

  pair<bool,int> search(const string& s) const
  {
    const int L = s.size();
    int i = 0;
    for (int m = 0; m+i < L;) {
      if (pat[i] == s[m+i]) {
        i++;
        if (i == len) {
          return make_pair(true, m);
        }
      } else {
        m = m + i - tbl[i];
        if (i > 0) {
          i = tbl[i];
        }
      }
    }
    return make_pair(false, i);
  }
};

int main()
{
  int N;
  while (cin >> N && N != 0) {
    vector<string> v;
    for (int i = 0; i < N; i++) {
      string s;
      cin >> s;
      v.push_back(s);
    }
    vector<kmp> cities;
    for (int i = 0; i < N; i++) {
      kmp k(v[i]);
      for (int j = 0; j < N; j++) {
        if (i != j && k.search(v[j]).first) {
          goto SKIP;
        }
      }
      cities.push_back(k);
SKIP:
      ;
    }
    N = cities.size();

    vector<vector<int> > memo(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i == j) {
          continue;
        }
        const pair<bool,int> r = cities[j].search(cities[i].pat);
        memo[i][j] = cities[j].pat.size() - r.second;
      }
    }

    static const int INF = 10000000;
    vector<vector<int> > dp(1<<N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) {
      dp[1<<i][i] = cities[i].pat.size();
    }
    for (unsigned s = 1; s < (1<<N); s++) {
      for (int i = 0; i < N; i++) {
        if (!(s & (1<<i))) {
          continue;
        }
        for (int j = 0; j < N; j++) {
          if (s & (1<<j)) {
            continue;
          }
          int& dp_next = dp[s|(1<<j)][j];
          dp_next = min(dp_next, dp[s][i] + memo[i][j]);
        }
      }
    }
    int ans = INF;
    for (int i = 0; i < N; i++) {
      ans = min(ans, dp[(1<<N)-1][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cout << setprecision(10) << fixed;
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans = max(max(b * d, b * c), max(a * d, a * c));
	cout << ans << '\n';
}

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

int main() {
	int N;
	cin >> N;
	vector<int>A(N + 1);
	for (int n = 0; n < N + 1; ++n) {
		cin >> A[n];
	}
	vector<int>B(N);
	for (int n = 0; n < N ; ++n) {
		cin >> B[n];
	}
	long long ans = 0;
	for (int n = 0; n < N; ++n) {
		long long tmp = min(A[n],B[n]);
		A[n] -= tmp;
		B[n] -= tmp;
		ans += tmp;
		tmp = min(A[n+1],B[n]);
		A[n + 1] -= tmp;
		B[n] -= tmp;
		ans += tmp;
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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

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

  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 3632
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

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

using namespace std;
using namespace std::chrono;

/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
    vector<char*> v({token});
    while(token = strtok(NULL,", ")) v.push_back(token);
    return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
    debug() << " [" << args.back() << ": " << H << "] ";
    args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
int mod=1000000007;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    int n,i;
    ll k;
    cin>>n>>k;
    set<int> st;
    int a[n+1];
    REP(i,1,n)  cin>>a[i];
    vi v;
    st.insert(1);
    int pos=1,fpos,lpos;
    v.EB(pos);
    while(st.find(a[pos])==st.end()){
        v.EB(a[pos]);
        st.insert(a[pos]);
        pos=a[pos];
        //dbg(pos);
    }
    REP(i,0,v.size()-1)
        if(v[i]==a[pos]) break;
    fpos=i;
    lpos=v.size()-1;
    //dbg(v,fpos,lpos);
    int temp=0;
    temp=lpos-fpos+1;
    if(k<v.size()) cout<<v[k];
    else{
        k-=fpos;
        k=k%temp;
        cout<<v[fpos+k];
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> cnt(7);
    int x = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if(a>=3200) x++;
        else cnt[a/400]++;
    }
    int mn = 0;
    rep(i,8) {
        if(cnt[i]!=0) mn++;
    }
    if(mn==0){ cout << 1 << " " << x << endl; return 0;}
    cout << mn << " " << mn+x << endl;
    return 0;
}   

Measured memory_bytes: 3596
## coding: UTF-8
N = int(input())
A = [int(x) for x in input().split()]

#print(N)
#print(A)

count = 0

def hantei(l): # listを引数とし，全て偶数かどうか判定する関数。奇数の数をカウントして返す
    odd_count = 0
    for i in range(N):
        if (l[i] % 2 == 1):
            odd_count += 1
    return odd_count # これが0なら全て偶数。1以上なら奇数が含まれている

def split(l): #リストの全要素を2で割る関数
    return [int(p / 2) for p in l]

#print(hantei(A))
#print(split(A))

while True:
    if(hantei(A) == 0):
        A = split(A)
        #print(A)
        count += 1
        #print(count)
    else:
        break

print(count)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define MAX 300
int getparent(int i)
{
	return i/2;
}
int getleft(int i)
{
	return 2*i;
}
int getright(int i)
{
	return 2*i+1;
}
int main()
{
	int h,i,heap[MAX];	
	scanf("%d",&h);
	for(i=1;i<=h;i++)
		scanf("%d",&heap[i]);
	for(i=1;i<=h;i++)
	{
		printf("node %d: key = %d, ",i,heap[i]);
		if(getparent(i)>=1)
			printf("parent key = %d, ",heap[getparent(i)]);
		if(getleft(i)<=h)
			printf("left key = %d, ",heap[getleft(i)]);
		if(getright(i)<=h)
			printf("right key = %d, ",heap[getright(i)]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2028
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let (a, b): (u32, u32) = stdin.lock().gets().split(' ').values();
    let diff = b - a;
    let depth = diff * (diff + 1) / 2 - b;
    println!("{}", depth);
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


Measured memory_bytes: 4352
r = ['NA', 'MMYY', 'YYMM', 'AMBIGUOUS']
s = STDIN.gets

p = 0
if (1..12) === s[0..1].to_i
  p += 1
end

if (1..12) === s[2..3].to_i
  p += 2
end

puts r[p]

Measured memory_bytes: 1788
#!/usr/bin/env python3
#ABC128 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
lst = [LI() for _ in range(m)]
p = LI()
ans = 0
for i in range(2**n):
    switch = [0]*n
    for j in range(n):
        if (i>>j) & 1:
            switch[j] = 1
    for j in range(m):
        k = lst[j][0]
        tmp = 0
        for l in range(k):
            if switch[lst[j][l+1]-1] == 1:
                tmp += 1
        if tmp % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 41072
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI as(n);
  FOR(a,as) {
    cin >> a;
  }
  sort(as.rbegin(), as.rend());
  int score[] = {0, 0};
  REP(i,0,n) {
    score[i%2] += as[i];
  }
  cout << score[0] - score[1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define int long long
using namespace std;
const int maxn = 2e5+5;
typedef pair<int,int> pii;

int dp[maxn][105] = {};
pii item[maxn];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w, sum = 0;
	cin >> n >> w;
	for (int i = 0; i <maxn; i++) {
		for (int j = 0; j < 105; j++) {
			dp[i][j] = 1e18;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) cin >> item[i].Y >> item[i].X, sum += item[i].X;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum; j++) {
			dp[j][i] = dp[j][i-1];
			if (j >= item[i].X) {
				dp[j][i] = min(dp[j][i-1], dp[j-item[i].X][i-1] + item[i].Y);
			}	
		}
	}
	int ans = 0;
	for (int i = 0; i <= sum; i++) {
		if (dp[i][n] <= w) ans = i;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 167644
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

L = list(map(int, read().decode("utf-8").split()))

last_ = L[0] % 10
last_index = 0
for i, t in enumerate(L):
    if 0 < t % 10 < last_:
        last_ = t % 10
        last_index = i

ans = 0
for i, t in enumerate(L):
    if i != last_index:
        ans += t
        if t % 10:
            ans += 10 - (t % 10)
ans += L[last_index]
print(ans)

Measured memory_bytes: 9092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a=0;
    for(int i=0;i<4;i++){
        int temp = n%10;
        if(temp==2){
            a++;
        }
        n=n/10;
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int,int> P;
string itos(int n){
  stringstream ss;
  ss<<n;
  return ss.str();
}

int main(){
  vector<string> cand;
  FOR(n,123,10000){
    string s = itos(n);
    if(s.size() < 4) s = "0" + s;
    set<char> cnt;
    REP(i,4)cnt.insert(s[i]);
    if(cnt.size() == 4)cand.push_back(s);
  }
  int N;
  while(cin>>N, N){
    vector<string> input(N);
    vector<int> hit(N),brow(N);
    REP(i,N)cin>>input[i]>>hit[i]>>brow[i];
    vector<string> ans;
    FORIT(it, cand){
      bool ok = true;
      REP(i,N){
        int h = 0, b = 0;
        REP(j,4)REP(k,4)if((*it)[j]==input[i][k]){
          if(j == k) h++;
          else b++;
        }
        if(h != hit[i] || b != brow[i]){
          ok = false;
          break;
        }
      }
      if(ok){
        ans.push_back(*it);
      }
    }
    string ans2 = "";
    if(ans.size() > 25) goto OUTPUT;
    FORIT(it, cand){
      bool used[5][5] = {};
      bool ok = true;
      REP(i,ans.size()){
        int h = 0, b = 0;
        REP(j,4)REP(k,4)if((*it)[j]==ans[i][k]){
          if(j == k) h++;
          else b++;
        }
        if(!used[h][b])used[h][b] = true;
        else {
          ok = false;
          break;
        }
      }
      if(ok){
        ans2 = *it;
        break;
      }
    }
OUTPUT:
    if(ans.size() == 1) cout<<ans.front()<<endl;
    else if(ans2 != "") cout<<ans2<<endl;
    else cout<<"????"<<endl;
  }

  return 0;
}

Measured memory_bytes: 1132
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  int N, M, v;
  pair<int,int> vote_area[110];
  while (cin >> N >> M && M >0) {
    //ペアの初期化
    for (int j = 0; j < M; ++j)
    {
      vote_area[j].first = 0;
      vote_area[j].second = j+1;/* code */
    }

    for (int i = 0; i < N; ++i)
    {
      for (int j = 0; j < M; ++j)
      {
        cin >> v;/* i人目の人が場所jに行きたいかどうか */  
        vote_area[j].first -= v;
        // cout << vote_area[j].first;
      }
      // cout << endl;
    }

//あるタイミングで整列する
    sort(vote_area, vote_area+M);
    // reverse(vote_area, vote_area+M);
    for (int i = 0; i < M; ++i)
    {
      cout << vote_area[i].second;
      if (i<M-1)
      {
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*A[N-1]から見ていって、B[N-1] > A[N-1]ならans += B[N-1]-A[N-1]
B[N-1] == A[N-1]ならans += 0, B[N-1] < A[N-1]ならans += (A/B + 1)*B - B
A[N-2]以降について、A[i] += ans として同様の操作を行う
*/


int main() {
 ll N;
 cin >> N;
 vector<ll> A(N);
 vector<ll> B(N);
 rep(i,N){
     cin >> A[i];
     cin >> B[i];
 }

 ll ans = 0;
 for(int i = N-1;i>=0;i--){
     A[i] += ans;
     if(A[i]%B[i] == 0) ans += 0;
     else if(B[i] > A[i]) ans += B[i]-A[i];
     else if(B[i] < A[i]) ans += (A[i]/B[i] + 1)*B[i] - A[i];
 }
 cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

minA = 0
sumA = 0
# 奇数項を正としたときの操作回数minA 
for i in range(n):
  sumA += a[i]
  if i%2 == 0:        
    if sumA <= 0:
      minA += abs(sumA)+1
      sumA += abs(sumA)+1
  else:
    if sumA >= 0:
      minA += abs(sumA)+1
      sumA -= abs(sumA)+1
temp = 0
# 偶数項を正としたときの操作回数minB
minB = 0
sumB = 0
for i in range(n):
  sumB += a[i]
  if i%2 != 0:
    if sumB <= 0:
      minB += abs(sumB)+1
      sumB += abs(sumB)+1
  else:
    if sumB >= 0:
      minB += abs(sumB)+1
      sumB -= abs(sumB)+1
print(min(minA, minB))      

Measured memory_bytes: 14468
#include<stdio.h>
int main (){
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: 2104
using System;
class ITP1_1
{
    static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //System.Console.SetIn(exStdIn);

        //int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<String, int>(s => int.Parse(s)));

        int input = int.Parse(Console.ReadLine());

        int h = input / 3600;
        int m = input % 3600 / 60;
        int s = input % 3600 % 60;

        Console.WriteLine(String.Format("{0}:{1}:{2}",h,m,s));
    }
}

Measured memory_bytes: 9176
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int H, A;
	cin >> H >> A;
	int ans = 0;
	while (ans*A < H) ans++;
	cout << ans << endl;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		long long n, k;
		cin >> n >> k;
		if(2*k-1 > n){
			cout << "-1\n";
			return;
		}
		vector<vector<long long>> ans(n, vector<long long>(3, 0));
		for(int i=0; i < n; i++)ans[i][2] = k + 2*n + i;
		int x = k + n;
		for(int i=0; i<n; i+=2, x++)ans[i][1] = x;
		for(int i=1; i<n; i+=2, x++)ans[i][1] = x;
		x = k;
		for(int i=1; i<n; i+=2, x++)ans[i][0] = x;
		for(int i=0; i<n; i+=2, x++)ans[i][0] = x;
		for(int i=0; i < n; i++){
			for(int j=0; j<3; j++)cout << ans[i][j] << " ";
			cout << "\n";
		}
		return;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

int main() {
  ll a,b;cin>>a>>b;
  for(int i=1;i<=a;i++){
    if(b*i%a==0){
      cout<<b*i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3500
def jumpCost(array):
    size = len(array)

    memo = [99999999999] * (size)

    memo[0] = 0

    for i in range(size):
        j = i+1

        while j < i + 2 + 1 and j < size:
            memo[j] = min(memo[j], memo[i] + abs(array[i] - array[j]))

            j += 1

    return memo[size - 1]


if __name__ == '__main__':
    n = int(input())

    a = list(map(int, input().rstrip().split()))
    print(jumpCost(a))

Measured memory_bytes: 20424
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
U_MAP mp;

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

  cin >> n;
  ans = 1;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == 0) cnt++;
    mp[a[i]]++;
    if (a[i] == 0) continue;
    ans *= mp[a[i] - 1];
    ans %= MOD;
    mp[a[i] - 1]--;
  }
  if (cnt == 3) ans *= 6;
  if (cnt == 1) ans *= 3;
  if (cnt == 2) ans *= 6;
  if (cnt == 0) ans *= 0;
  if (cnt >= 4) ans *= 0;
  ans %= MOD;
  Cout(ans);
  return 0;
}


Measured memory_bytes: 5156
import sys
s=input()
k=int(input())
distinct=0
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    distinct=1
    first=i
    break
if distinct==0:
  print((len(s)*k)//2)
  sys.exit()
for i in range(len(s)-1,0,-1):
  if s[i]!=s[i-1]:
    last=i
    break
ans=(first+1)//2
ans+=((len(s)-last)//2)
count=1
for i in range(first+1,last):
  if s[i]!=s[i+1]:
    ans+=k*(count//2)
    count=1
  else:
    count+=1
if s[0]==s[-1]:
  ans+=((len(s)+first+1-last)//2)*(k-1)
else:
  ans+=((len(s)-last)//2+(first+1)//2)*(k-1)
print(ans)

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int[] a=new int[n];
		int ans=0;
		for(int i=0;i<n;i++){
			a[i]=scan.nextInt();
		}
		
		Arrays.sort(a);
		
		for(int i=0;i<n;i++){
			if(a[i]>=n-i && n-i>ans){
				ans=n-i;
			}
		}
		System.out.println(ans);
	}
}



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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


void ans(LL n) {
  LL res = 1;
  if (n == 0) res = 0;
  REP (i, n) {
    res = res * 2 % int(1e9 + 7);
  }
  cout << res << endl;
  exit(0);
}

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

  vector<int> v(n);
  REP (i, n) scanf("%d", &v[i]);

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

  if (n == 1) {
    cout << 1 << endl;
    exit(0);
  }

  int i = 0;
  if (n % 2 == 1) {
    if (v[0] != 0) ans(0);
    i = 1;
  }
  while (i < n) {
    if (v[i] != v[i + 1] || v[i] != i + 1) ans(0);
    i += 2;
  }
  ans(n / 2);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
int main(){
    long long a,b,c,d,ans;
    cin >> a >> b >> c >> d;
    if(a < b) {
        ans += a;
    }else{
        ans += b;
    }
    if(c < d) ans +=c;
    else ans += d;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

 int N,K,number,c;
cin>>N>>K; 
  number=1;
  c=0;
for(int i=0;i<N;i++){ 
  if(number*2>number+K){
  number=number+K;
  }
  else{
  number=number*2;
  }
}  
  cout<<number;
}

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

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

void solve8b(string a) {
    int s = 0;
    REP(i,a.size()) {
        s += a[i] - '0';
    }
    cout << s << endl;
}

int main() {
    string a;
    while(cin >> a) {
        if (a == "0") break;
        solve8b(a);
    }
    return 0;
}

Measured memory_bytes: 1196
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w,k = LI()
    a = []
    st = None
    for i in range(h):
        s = S()
        if 'S' in s:
            st = [i, s.index('S')]
        a.append([c=='#' for c in s])

    def ns(k):
        i,j = k
        r = []
        if i < h-1:
            r.append((i+1,j))
        if j < w-1:
            r.append((i,j+1))
        if i > 0:
            r.append((i-1,j))
        if j > 0:
            r.append((i,j-1))
        return r


    def search(ss,tk):
        d = collections.defaultdict(lambda: inf)
        q = []
        for s in ss:
            d[s] = 0
            heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if k >= tk:
                break
            if v[u]:
                continue
            v[u] = True

            for nu in ns(u):
                if v[nu] or a[nu[0]][nu[1]]:
                    continue
                vd = k + 1
                if d[nu] > vd:
                    d[nu] = vd
                    if nu[0] == 0 or nu[1] == 0 or nu[0] == h-1 or nu[1] == w-1:
                        return d
                    heapq.heappush(q, (vd, nu))

        return d

    d = search([tuple(st)],k)
    r = inf
    hs = []
    ws = []
    for g in d.keys():
        if 0 < g[0] < h-1 and 0 < g[1] < w-1:
            hs.append(g[0])
            ws.append(g[1])
            continue
        return 1

    return (min(min(hs),min(ws),h-max(hs)-1,w-max(ws)-1) + k - 1) // k + 1

print(main())


Measured memory_bytes: 22968
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v) { cout << v << endl; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

const ll MOD = 1000000007;

ll intpow(int a, ll n) {
  if (n == 0) return 1;
  ll x = intpow(a, n/2);
  x *= x;
  x %= MOD;
  if (n&1) { x *= a; x %= MOD; }
  return x;
}

ll inv(ll n) {
  return intpow(n, MOD-2);
}

ll com(int n, int k) {
  ll x = 1, y = 1;
  loop(i,0,k) {
    x *= n-i;
    x %= MOD;
    y *= i+1;
    y %= MOD;
  }
  
  return (x * inv(y)) % MOD;
}

int main() {
  int n, k; in(n),in(k);
  loop(i,1,k+1) {
    print((com(k-1, i-1) * com(n-k+1, i)) % MOD);
  }
  return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int s = sc.nextInt();
		int h = s / 3600;
		
		s %= 3600;
		
		int m = s / 60;
		
		s %= 60;
		
		System.out.println(h + ":" + m + ":" + s);

		sc.close();

	}

}

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

const int vmax=10010;
const int inf=1023456789;

int N,M;
typedef tuple<double,int,int> node;
vector<node> graph;

int par[vmax];
void init(){rep(i,vmax) par[i]=i;}
int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
void unite(int a,int b){a=find(a),b=find(b);par[a]=b;}
bool same(int a,int b){return find(a)==find(b);}

double kruskal(){
	init();
	sort(begin(graph),end(graph));
	reverse(begin(graph),end(graph));
	double res=0;
	for(auto &e:graph){
		int a,b;
		double c;
		tie(c,a,b)=e;
		if(!same(a,b)) unite(a,b),res+=c;
	}
	return res;
}

complex<double> p[vmax];

int main(void){
	cin >> N >> M;
	rep(i,N){
		double x,y;
		cin >> x >> y;
		p[i]={x,y};
	}
	double sum=0.0;
	rep(i,M){
		int a,b;
		cin >> a >> b;
		a--,b--;
		double c=abs(p[a]-p[b]);
		sum+=c;
		graph.push_back(node(c,a,b));
	}
	cout.precision(10);
	cout << fixed << sum-kruskal() << endl;
	return 0;
}

Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(n) cerr << #n << ':' << n << endl;


ll gcd(ll x,ll  y){
  if(y == 0)return x;
  return gcd(y, x % y);
}


int main(){
  ll a,b,c,d;cin >> a >> b >> c >> d;
  if(c > d)swap(c,d);

  ll x = a/c;
  if(x * c < a)x++;
  ll y = b/c;
  if(y * c <= b)y++;
  
  ll ans1 = y - x;
  
  x = a/d;
  if(x * d < a)x++;
  y = b/d;
  if(y * d <= b)y++;

  ll ans2 = y - x;

  ll z = c * d / gcd(c,d);

  x = a/z;
  if(x * z < a)x++;
  y = b/z;
  if(y * z <= b)y++;

  ll ans3 = y - x;

  ll cnt = ans1+ans2-ans3;
  
  cout << b-a+1-cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

int main(){
	int N, A, B, C, D;
	string S;

	bool IsRock = false;
	bool FirstSpace = false;
	bool SecondSpace = false;
	bool Escapable = false;
	bool UnPossible = false;

	cin >> N;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	cin >> S;

	if (C < B) {
		//岩２連の詰み探索
		for (int i = A + 1; i <= C; i++) {
			if (S[i-1]=='#') {
				if (!IsRock) {
					IsRock = true;
				}else if (IsRock) {
					UnPossible = true;
					break;
				}
			}else {
				IsRock = false;
			}
		}

		if (UnPossible){
			cout << "No" << endl;
		}else{
			//岩２連の詰み探索
			for (int i = B + 1; i <= D; i++) {
				if (S[i - 1] == '#') {
					if (!IsRock) {
						IsRock = true;
					}
					else if (IsRock) {
						UnPossible = true;
						break;
					}
				}else {
					IsRock = false;
				}
			}
			
			if (UnPossible) {
				cout << "No" << endl;
			}else {
				cout << "Yes" << endl;
			}

		}


	}else if (C < D) {
		//岩２連の詰み探索
		for (int i = A + 1; i <= D; i++) {
			if (S[i - 1] == '#') {
				if (!IsRock) {
					IsRock = true;
				}
				else if (IsRock) {
					UnPossible = true;
					break;
				}
			}
			else {
				IsRock = false;
			}
		}

		if (UnPossible) {
			cout << "No" << endl;
		}else {
			cout << "Yes" << endl;
		}

	}else if (D < C) {
		//空きマス3連探索
		for (int i = B-1 ; i <= D + 1; i++) {
			if (S[i - 1] != '#') {
				if (!FirstSpace) {
					FirstSpace = true;
				}else if (!SecondSpace) {
					SecondSpace = true;
				}else {
					Escapable = true;
					break;
				}
			}else {
				FirstSpace = false;
				SecondSpace = false;
			}
		}
		//岩２連の詰み探索
		if (Escapable){
			for (int i = A + 1; i <= C; i++) {
				if (S[i - 1] == '#') {
					if (!IsRock) {
						IsRock = true;
					}else if (IsRock) {
						UnPossible = true;
						break;
					}
				}else {
					IsRock = false;
				}
			}
		}else {
			UnPossible = true;
		}
		

		if (UnPossible) {
			cout << "No" << endl;
		}else if (!UnPossible) {
			cout << "Yes" << endl;
		}

	}
}

Measured memory_bytes: 640
a[99],b[99];main(i,n){for(;scanf("%d",&n),n;){
	for(i=0;i<=n;i++)scanf("%d",a+i);
	for(i=1;i<=n;i++)b[i]=a[i]-a[i-1];
	if(b[1]==b[2]&&b[2]==b[3]&&b[3]==b[4]){
		for(i=5;i<=n;i++)if(b[i]!=b[1])break;
		printf("%d\n",a[i]);
	}
	else if(b[2]==b[3]&&b[3]==b[4])printf("%d\n",a[0]);
	else if(b[1]==b[2]&&b[2]==b[3])printf("%d\n",a[4]);
	else if(a[2]-a[0]==b[3]&&b[3]==b[4])printf("%d\n",a[1]);
	else if(b[1]==b[2]&&b[2]==a[4]-a[2])printf("%d\n",a[3]);
	else if(b[1]==a[3]-a[1]&&b[1]==b[4])printf("%d\n",a[2]);
	else exit(1);
}exit(0);}

Measured memory_bytes: 600
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

int a[40][40];

int main()
{
	int k=38;int n=k*(k-1)+1;
	printf("%d %d\n",n,k);
	for (int i=1;i<=k;i++) printf("%d%c",i,i<k ? ' ' : '\n');
	for (int i=1;i<=k-1;i++)
		for (int j=1;j<=k-1;j++)
			a[i][j]=k+(i-1)*(k-1)+j;
	for (int i=1;i<k;i++)
		for (int j=1;j<=k-1;j++)
		{
			printf("%d",i);
			for (int p=1;p<=k-1;p++) printf(" %d",a[((i-1)*(p-1)+j-1)%(k-1)+1][p]);
			puts("");
		}
	for (int j=1;j<=k-1;j++)
	{
		printf("%d",k);
		for (int p=1;p<=k-1;p++) printf(" %d",a[p][j]);
		puts("");
	}
	return 0;
}



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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

string s;
int K;

int main() {
	cin >> s >> K;
	int n = s.size();

	rep(i, n) {
		int c = s[i] - 'a';

		if (i == n - 1) {
			s[i] = 'a' + (c + K) % 26;
		} else {
			int ns = c == 0 ? 0 : 26 - c;
			if (K >= ns) {
				K -= ns;
				s[i] = 'a';
			}
		}
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    char a, b;
    bool p[3] = { true, false, false };
    while( scanf( "%c,%c\n", &a, &b ) != -1 ) {
        swap( p[a-'A'], p[b-'A'] );
    }

    for( int i=0; i<3; ++i ) {
        if ( p[i] ) {
            cout << static_cast<char>( i + 'A' ) << endl;
            break;
        }
    }
}

Measured memory_bytes: 1148
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] str1 = br.readLine().split(" ");
        String[] str2 = br.readLine().split(" ");
        int[] x = new int[n];
        int[] y = new int[n];
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double p_infi = 0;

        for(int i = 0; i < n; i++){
            x[i] = Integer.parseInt(str1[i]);
            y[i] = Integer.parseInt(str2[i]);
        }

        for(int i = 0; i < n; i++){
            p1 += Math.abs(Math.pow(x[i] - y[i], 1));
            p2 += Math.abs(Math.pow(x[i] - y[i], 2));
            p3 += Math.abs(Math.pow(x[i] - y[i], 3));
            double tmp = Math.abs(x[i] - y[i]);
            if(tmp > p_infi){
                p_infi = tmp;
            }
        }
        p2 = Math.sqrt(p2);
        p3 = Math.cbrt(p3);

        System.out.println(p1 + "\n" + p2 + "\n" + p3 + "\n" + p_infi);
    }
}

Measured memory_bytes: 24636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[100005];
int main()
{
    int n;
    scanf("%d",&n);
    ll ans=0;
    for(int i=0;i<n;i++)
	{
        int x,y;
        scanf("%d%d",&x,&y);
        a[i]=x+y;
        ans-=y;
    }
    sort(a,a+n);
    bool cur=1;
    for(int i=n-1;i>=0;i--)
	{
        if(cur)
			ans+=a[i];
        cur=!cur;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str1 = sc.next();
    String str2 = sc.next();
    if(str1.charAt(0) < str2.charAt(0)){
      System.out.println('<');
    }else if(str1.charAt(0) > str2.charAt(0)){
      System.out.println('>');
    }else{
      System.out.println('=');
    }
  }
}

Measured memory_bytes: 21844
package main

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

type ByValue []float64

func (s ByValue) Len() int           { return len(s) }
func (s ByValue) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s ByValue) Less(i, j int) bool { return s[i] < s[j] }

func input() string {
	var s string
	fmt.Scan(&s)
	return s
}

func inputLn() string {
	var s string
	fmt.Scanln(&s)
	return s
}

func inputByScanner(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func inputLongLine() string {
	rdr := bufio.NewReaderSize(os.Stdin, 1000000)
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func convListStrToInt(strList []string) []int {
	intList := make([]int, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = intV
	}
	return intList
}

func convListStrToFloat(strList []string) []float64 {
	intList := make([]float64, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = float64(intV)
	}
	return intList
}

func main() {
	n, _ := strconv.Atoi(input())
	hList := make([]int, n)
	for i := 0; i < n; i++ {
		num, _ := strconv.Atoi(input())
		hList[i] = num
	}

	for i := 1; i < n; i++ {
		if hList[i-1] > hList[i] {
			fmt.Println("No")
			return
		} else {
			if hList[i] != hList[i-1] {
				hList[i] = hList[i] - 1
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    vl l(m),r(m);
    rep(i,m){
        ll x,y;cin >> x >>y;x--;y--;
        l[i]=x;r[i]=y;
    }
    ll ans=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(i==j)continue;
            uf.merge(l[j],r[j]);
        }
        if(uf.size(0)!=n)ans++;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v;
    int a;
    while(cin >> a) {
        v.push_back(a);
    }
    sort(v.begin(), v.end(), greater<>());
    ll result = 0;
    for (int i=0; i<(n+1)/2; i++) {
        result += v[i]*2;
    }
    result -= v[0];
    if (n%2 == 1) {
        result -= v[(n-1)/2];
    }
    cout << result << endl;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
struct edge{
    int to,weight,next;
}e[50005];
int n,m,p,tot,dis[50005],vis[50005],head[50005];
void add(int a,int b,int c){
    e[++tot].to=b;
    e[tot].weight=c;
    e[tot].next=head[a];
    head[a]=tot;
}
void spfa(int u){
    vis[u]=1;
    for(int i=head[u];i;i=e[i].next){
        int v=e[i].to;
        if(dis[v]<dis[u]+e[i].weight&&dis[v]<1e9){
            dis[v]=dis[u]+e[i].weight;
            if(vis[v]==1) dis[v]=1e9;
            spfa(v);
        }
    }
    vis[u]=0;
} 
int main(){
    cin>>n>>m>>p;
    for(int i=1;i<=n;i++){
        dis[i]=-1e9;
    }
    dis[1]=0;
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        add(u,v,w-p);
    }
    spfa(1);
    if(dis[n]>5e8) cout<<-1<<endl;
    else cout<<max(dis[n],0)<<endl;
}

Measured memory_bytes: 512