akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

lint f(lint n){
    n *= 2;
    lint ret = 0;
    for(lint s=1; s*s<n; ++s)if(n%s == 0){
        lint t = n / s;
        if(s%2 != t%2) ++ret;
    }
    return ret;
}

int main(){
    lint s;
    scanf("%lld", &s);
    lint ans = 0;
    for(lint x=1; x*x<=s; ++x)if(s%x == 0){
        lint tmp = f(x) * f(s/x);
        ans += tmp * (x*x == s ? 1 : 2);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3220
# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
xy = [map(int, input().split()) for _ in range(Q)]
b, c = [list(i) for i in zip(*xy)]

sum_num = sum(A)
counter = collections.Counter(A)

for i in range(Q):
    sum_num -= counter[b[i]]*b[i] #counter[x]でxの個数をカウント
    sum_num += counter[b[i]]*c[i] #cで上書きされたので、c*counter[b]になる
    counter[c[i]] += counter[b[i]]
    counter[b[i]] = 0
    print(sum_num)
    


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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

int n, x, a[200];

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

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

    sort(a, a + n);

    int sol = 0;

    for (int i = 0; i < n; i++)
        if (a[i] <= x) {
            if (i == n - 1 && a[i] != x) break;
            x -= a[i];
            sol++;
        }

    cout << sol << "\n";

    return 0;
}



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

using namespace std;

int n, m;
int broken[100000 + 5];
queue<long long> que;

long long mem[100000 + 5];
long long plan(int x)
{
    if (mem[x] == 0)
    {
        for (int i = 3; i <= x; ++i)
        {
            mem[i] = (mem[i - 1] + mem[i - 2]) % 1000000007;
        }
    }
    return mem[x];
}

int main(int argc, char *argv[])
{
    //reset
    mem[1] = 1;
    mem[2] = 2;
    
    cin >> n >> m;
    
    
    for (int i = 0; i < m; ++i)
    {
        cin >> broken[i];
    }
    
    int pos = 0;
    for (int i = 0; i < m; ++i)
    {
        if (pos == broken[i])
        {
            cout << 0 << endl;
            return 0;
        }
        int dist = broken[i] - 1 - pos;
        if (dist > 0)
        {
            que.emplace(plan(dist));
            pos = broken[i] + 1;
        }
        else
        {
            pos += 2;
        }
    }
    
    if (n - pos > 0)
    {
        que.emplace(plan(n - pos));
    }
    
    long long result = 1;
    while (!que.empty())
    {
        result *= que.front();
        result %= 1000000007;
        que.pop();
    }
    cout << result % 1000000007 << endl;
}

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

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader sc = new FastReader();

        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();

        if(A < K)
        {
            K = K - A;
            A = 0;

            if(B < K)
                B = 0;
            
            else
                B = B - K;
        }
        
        else
            A = A - K;

        System.out.println(A + " " + B);
    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

Measured memory_bytes: 36872
A = gets.to_f
B = gets.to_f
C = gets.to_f
D = gets.to_f
E = gets.to_f

nokori = [0]
nokori.push(10 - A%10) unless A%10 == 0
nokori.push(10 - B%10) unless B%10 == 0
nokori.push(10 - C%10) unless C%10 == 0
nokori.push(10 - D%10) unless D%10 == 0
nokori.push(10 - E%10) unless E%10 == 0

p ((A/10).ceil*10 + (B/10).ceil*10 + (C/10).ceil*10 + (D/10).ceil*10 + (E/10).ceil*10 - nokori.max).to_i

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define X first
#define Y second
#define WIDTH 8
#define HEIGHT 8

using namespace std;

vector<string> init(){
	vector<string> map;
	for(int i = 0; i < HEIGHT; i++){
		string tmp;
		getline(cin,tmp);
		map.push_back(tmp);
	}
	return map;
}

void countNum(vector<string> map, int *count){
	int counter = -1;
	
	for(int i = 0; i < HEIGHT; i++){
		for(int j = 0; j < WIDTH ; j++){
			if(map[i][j] == '1'){
				counter++;
				if(counter == 3) return;
			}
			else{
				if(counter >= 0) count[counter]++;
			}
		}
	}

	return;
}


char decideChar(int *count){
	if(count[0] == 0 && count[1] == 6 && count[2] == 0){
		return 'A';
	}
	else if(count[0] == 7 && count[1] == 7 && count[2] == 7){
		return 'B';
	}
	else if(count[0] == 0 && count[1] == 0 && count[2] == 0){
		return 'C';
	}
	else if(count[0] == 6 && count[1] == 0 && count[2] == 6){
		return 'D';
	}
	else if(count[0] == 0 && count[1] == 7 && count[2] == 0){
		return 'E';
	}
	else if(count[0] == 7 && count[1] == 0 && count[2] == 7){
		return 'F';
	}
	else if(count[0] == 0 && count[1] == 5 && count[2] == 0){
		return 'G';
	}
}



int main(){
	
	while(1){
		if(cin.eof()) break;
		vector<string> map = init();
		int count[] = {0, 0, 0};
		countNum(map, count);
		cout << decideChar(count) << endl;
		//入力で一行改行が入ってしまうのでそれ対策
		string tmp;
		getline(cin, tmp);
	}
	return 0;
}

Measured memory_bytes: 1176
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B,C;
int main() {
	cin>>A>>B>>C;

	if(A==B)cout<<C<<endl;
	if(A==C)cout<<B<<endl;
	if(B==C)cout<<A<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
    string S; cin >> S;
    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}
    

Measured memory_bytes: 3600
#include<iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
  int N,K,i,iti,ni,iti_2,ni_2;
  char s[100];
  for( i = 0; i < 4; i++ )
  {
    cin >> s[i];
  }
  N = atoi(s);
  iti = N / 100;
  ni = N - iti * 100;
  iti_2 = iti;
  ni_2 = ni;
  if( (iti >= 0 && iti <= 99 && ni >= 1 && ni <= 12)
       && ( ni_2 >= 0 && ni_2 <= 99 && iti_2 >= 1 && iti_2 <= 12 ) )
  {
    cout << "AMBIGUOUS" << endl;
    return 0;
  }
  if( iti >= 0 && iti <= 99 && ni >= 1 && ni <= 12 )
  {
    cout << "YYMM" << endl;
    return 0;
  }else if( ni_2 >= 0 && ni_2 <= 99 && iti_2 >= 1 && iti_2 <= 12 ){
    cout << "MMYY" << endl;
    return 0;
  }

  cout << "NA" << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;



int main(int argc, char *args[]) {
	int H, W;
	int cnt = 0;
	char s[100][100];
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W - 1; j++) {
			if (s[i][j] == '#') {
				if (s[i - 1][j] != '#' &&s[i + 1][j] != '#'&&s[i][j - 1] != '#'&&s[i][j + 1] != '#') cnt++;
			}
		}
	}
	if (cnt == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(arr, start, end)for(ll i=start ; i<end ; ++i)cout << arr[i] << " ";
#define readArr(arr, start, end)for(ll i=start ; i<end ; ++i)cin >> arr[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	ll n, m, k;
	cin >> n >> m >> k;
	
	vll a(n), b(m);
	readArr(a, 0, n)
	readArr(b, 0, m)
	
	vll preA(n), preB(m);
	preA[0] = a[0];preB[0] = b[0];
	for(int i=1 ; i<n ; ++i)preA[i] = preA[i-1] + a[i];
	for(int i=1 ; i<m ; ++i)preB[i] = preB[i-1] + b[i];
	
	ll mx=0;
	for(int i=0 ; i<n ; ++i){
		if(preA[i] > k)break;
		auto it = upper_bound(all(preB), k-preA[i]);
		ll len = it - preB.begin();
		mx = max(mx, i+1+len);
	}
	for(int i=0 ; i<m ; ++i){
		if(preB[i] > k)break;
		auto it = upper_bound(all(preA), k-preB[i]);
		ll len = it - preA.begin();
		mx = max(mx, i+1+len);
	}
	
	cout << mx;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 9532
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
    int n,m;cin>>n>>m;
    vl a(n), b(n);
    fr(i,n)cin>>a[i]>>b[i];

    vector<vl> task(m+1);
    fr(i,n){
        if(a[i]<=m)task[m-a[i]].emplace_back(b[i]);
    }

    ll ans = 0;
    priority_queue<ll> pq;
    for(ll i = m; i>=0;--i){
        for(ll x:task[i])pq.emplace(x);
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 7168
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int X;
  cin >> X;
  if (X >= 1800) cout << "1" << endl;
  else if (X >= 1600) cout << "2" << endl;
  else if (X >= 1400) cout << "3" << endl;
  else if (X >= 1200) cout << "4" << endl;
  else if (X >= 1000) cout << "5" << endl;
  else if (X >= 800) cout << "6" << endl;
  else if (X >= 600) cout << "7" << endl;
  else if (X >= 400) cout << "8" << endl;
  return 0;
}

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

typedef long long int ll;
double PI = 3.14159265358979;

int main(){
 ll N;
 cin >> N;
 ll ans = 987654323456787654;
 vector<ll> A(N);
 vector<ll> L(N,0);
 ll sum = 0;
 for(ll i = 0;i < N;i++){
     cin >> A[i];
     sum += A[i];
     if(i != N-1){
        L[i+1] = L[i] + A[i];
     }
 }
 if(N == 2){
     cout << abs(A[0] - A[1]) << endl;
     return 0;
 }
 for(ll i = 1;i < N;i++){
     ll c = abs(sum - L[i] - L[i]);
     ans = min(ans,c);
 }
 cout << ans << endl;
}

Measured memory_bytes: 3328
void main() {
  problem();
}

void problem() {
  auto S = scan;
  auto N = S.length;

  bool solve() {
    auto head = S[0..(N-1)/2];
    auto tail = S[(N+3)/2-1..$];

    S.deb;
    head.deb;
    tail.deb;

    auto s = S;
    for(long i = 0; i < s.length/2; i++) {
      if (s[i] != s[$-i-1]) return false;
    }

    s = head;
    for(long i = 0; i < s.length/2; i++) {
      if (s[i] != s[$-i-1]) return false;
    }

    s = tail;
    for(long i = 0; i < s.length/2; i++) {
      if (s[i] != s[$-i-1]) return false;
    }

    return true;
  }

  writeln(solve() ? "Yes" : "No");
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 256
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
} 

const lli N = 1e3 + 1;
lli dp[N][N], n, m;
char a[N][N];

vector<vi> dir = {{1,0},{0,1}};

lli fun(lli x, lli y){
    if(x==n-1 && y==m-1) return 1;
    if(dp[x][y]!=-1) return dp[x][y];
    lli res = 0;
    NA(i,0,2){
        lli p = x + dir[i][0], q = y + dir[i][1];
        if(p>-1 && p<n && q>-1 && q<m && a[p][q]=='.'){
            res = (res + fun(p,q)) % MOD;
        }
    }
    return dp[x][y] = res;
}

void solve(){
    cin >> n >> m;  
    NA(i,0,n) NA(j,0,m) cin >> a[i][j];
    memset(dp, -1, sizeof dp);
    cout << fun(0,0);
    return;
}
int main(){
    fastIO;
    lli t = 1;
    // cin>>t;
    NA(i,0,t){
        solve();
    }
    return 0;

}


Measured memory_bytes: 9216
#include<stdio.h>
int main()
{
	int a,b,c,d,t;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;a>0&&c>0;i++)
	{
		c=c-b;
		if(c<=0)t=1;
		if(c<=0)break;
		a=a-d;
		if(a<=0)t=2;
		if(a<=0)break;
	}
	if(t==1)printf("Yes");
	if(t==2)printf("No");
	return 0;
}

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

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

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
N = int(input())
A = list(map(int, input().split()))

ans = 0
def main(i, A):
  global N
  global ans
  if A[i] == A[i+1]:
    if i == N-2:
      ans += 1
      return ans
    else:
      return main(i+1, A)
  elif A[i] < A[i+1]:
    while i < N-1:
      if A[i] <= A[i+1]:
        i += 1
      else:
        ans += 1
        if i == N-2:
          ans += 1
          return ans
        else:
          return main(i+1, A)
    else:
      ans += 1
      return ans
  else:
    while i < N-1:
      if A[i] >= A[i+1]:
        i += 1
      else:
        ans += 1
        if i == N-2:
          ans += 1
          return ans
        else:
          return main(i+1, A)
    else:
      ans += 1
      return ans
    
if N == 1:
  print(1)
else:
  print(main(0, A))

Measured memory_bytes: 48932
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

const int MAXN = 105;

int n;
int a[MAXN];
int ans[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int T = 1;T <= n;T++)
	{
		int pos = -1;
		for (int i = 1;i <= n - T + 1;i++)
			if (a[i] == i)
				pos = i;
		if (pos == -1)
		{
			cout << -1 << endl;
			return 0;
		}
		ans[T] = pos;
		for (int i = pos;i < n - T + 1;i++)
			a[i] = a[i + 1];
	}
	for (int i = n;i >= 1;i--)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char str[3];
    int i,price=700;
    for(i=0;i<3;i++){
        scanf("%c",&str[i]);
    }
    for(i=0;i<3;i++){
        if(str[i] == 'o'){
            price+=100;
        }
    }
    printf("%d",price);
    return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())
cur = []
kur = []
pen=0
ans=0
for i in range (n+1): cur.append(0)
for i in range (n+1): kur.append(0)
for i in range (m):
    a, b = input().split()
    a = int(a)
    if b=="AC":
        if cur[a]==0:
            pen+=kur[a]
            ans+=1
        cur[a]=1
    else: kur[a]+=1;
print(ans, pen, sep=' ')

Measured memory_bytes: 4760
# coding: utf-8
# Your code here!
while True:
    n=int(input())
    if 0<=n<1000:
        if n==0:
            break
        else:
            sum=0
            
            sum+=(1000-n)//500
            sum+=(1000-n)%500//100
            sum+=(1000-n)%500%100//50
            sum+=(1000-n)%500%100%50//10
            sum+=(1000-n)%500%100%50%10//5
            sum+=(1000-n)%500%100%50%10%5//1
            
    print(sum)


Measured memory_bytes: 5588
def exec():
    arr = map(int, input().split())
    a,b,c = sorted(arr)

    t1 = c - b
    t2 = c - (t1+a)
    if t2 % 2 == 0:
        t1 += int(t2/2)
    else:
        t1 += int(t2/2) + 1 + 1
    print(t1)


if __name__ == "__main__":
    exec()


Measured memory_bytes: 3060
def main():
    h,w,k = map(int,input().split())
    Map = []
    for i in range(h):
        tmp = list(input())
        Map.append(tmp)
    ans = 0
    
    for i in range(2**h-1):
        for j in range(2**w-1):
            black = 0
            for y in range(h):
                for x in range(w):
                    if ((i>>y)&1==0) and ((j>>x)&1==0) and Map[y][x]=='#':
                        black += 1
            if black==k:
                ans += 1
    print(ans)
                        
main()

Measured memory_bytes: 9148
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int maxn = 1e5+10;
const ll INF = 1e13;
int n,l,t;
int a[maxn];
int b[maxn];
int c[maxn];
ll m;
int wk(int x,int y)
{
	if(x>=y) 
	{
		x-=y;
		return x;
	}
	y-=x+1; m--;
	int tmp=y/l;
	m-=(ll)tmp;
	y-=tmp*l;
	return l-1-y;
}
int main()
{
	scanf("%d%d%d",&n,&l,&t);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++)
	{
		if(b[i]==1)
		{
			c[i-1]=(a[i]+t)%l;
			m+=(ll)((a[i]+t)/l);
		}
		else
			c[i-1]=wk(a[i],t);
	}
	sort(c,c+n);
	m=(m+(ll)n*(ll)INF)%(ll)n;
	int tmp=(int)m;
	for(int i=0;i<n;i++) printf("%d\n",c[(i+m)%n]);
	return 0;
}

Measured memory_bytes: 2304
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;



ll f(ll n,ll x,vector<ll>a,vector<ll>p){
    //レベルnバーガーの下からX層に含まれるパティの数
    if(n==0 and x==0) return 0;
    if(n==0 and x>=1) return 1;
    if(x<=1){ return 0;
    }else if(x<=1+a[n-1]){ return f(n-1,x-1,a,p);
    }else if(x==2+a[n-1]){ return p[n-1] +1;
    }else if(x<=2+2*a[n-1]){ return 1+p[n-1]+f(n-1,x-2-a[n-1],a,p);
    }else{ return 2*p[n-1]+1;}
}

int main(){
    ll N,X;cin>>N>>X;
    vector<ll>a(N,1),p(N,1);
    //aはレベルiバーガーの厚さ
    //pはレベルiバーガーに含まれるパティの総数
    for(ll i = 1; i < N; i++)
    {
        a[i] = 2LL * a[i-1] + 3LL;
        p[i] = 2LL * p[i-1] + 1LL;
    }
    ll ans = f(N,X,a,p);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,H;
	cin >> N>>H;
	ll a[N], b[N];
	for (ll i = 0; i < N; ++i)cin>>a[i]>>b[i];
 
	// 解法
	sort(a, a+N, greater<ll>());
	sort(b, b+N, greater<ll>());
	ll score = 0;
	ll count = 0;
	REP(i,N){
		if (b[i]<=a[0])break;
		score += b[i];
		count++;
		if (score>=H)break;
	}
	// printf("%lld\n", score);
	// printf("%lld\n", H-score);
	// printf("%lld\n", (H-score-1)/a[0]);
	if (score<H) count += (H-score-1)/a[0]+1;
	//出力
	cout << count << endl;
}


Measured memory_bytes: 1792
n = int(input())
dp = [float('Inf')]*(n+1)
np = [9**i for i in range(1, 6)]
sp = [6**i for i in range(1, 7)]
dp[0] = 0
for i in range(1, len(dp)):
  
  for j in np:
    if j > i:
      break
    dp[i] = min(dp[i], dp[i-j]+1)
    
  for j in sp:
    if j > i:
      break
    dp[i] = min(dp[i], dp[i-j]+1)
  
  dp[i] = min(dp[i], dp[i-1]+1)

print(dp[-1])

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e,on,hun;
	cin >> a >> b >> c >> d >> e;
	on = a;
	hun = 0;
	if (a <= 0) {
		while (on != 0) {
			on = on + 1;
			hun = hun + c;
		}
		hun = hun + d;
	}
	while (on != b) {
		on = on + 1;
		hun = hun + e;
	}
	cout << hun << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>

int main()
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, a[123];
    cin >> n;
    int i = 0;
    while(i < n){
        cin >> a[i++];
    }
    sort(a, a+n);
    int sum = 0;
    i = 0;
    while(i < n-1){
        sum += a[i++];
    }
    if(a[n-1] < sum) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

############### TESTCASE ###############
test = ""
#test = \
"""

"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
################# MAIN ################# 

x = input2()
lowers = [chr(i) for i in range(ord("a"), ord("z")+1)]
xi = lowers.index(x)
print(lowers[xi+1])


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

const int N = 3005, mod = 1000000007, i2 = mod + 1 >> 1;
typedef long long LL;

int n, q, dp[N][N], tmp[N][N], x, y, A[N];

void copy(int x, int y) { tmp[x][y] = dp[x][y]; }
void update(int X, int Y) {
	int tx = X, ty = Y;
	if (tx == x) tx = y; else if (tx == y) tx = x;
	if (ty == x) ty = y; else if (ty == y) ty = x;
	dp[X][Y] = (LL) i2 * (tmp[X][Y] + tmp[tx][ty]) % mod;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> q;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] = A[i] > A[j];
	for (int i = 1; i <= q; ++i) {
		std::cin >> x >> y;
		for (int j = 1; j <= n; ++j)
			copy(x, j), copy(j, x), copy(y, j), copy(j, y);
		for (int j = 1; j <= n; ++j)
			update(x, j), update(j, x), update(y, j), update(j, y);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			ans += dp[i][j] - mod, ans += ans >> 31 & mod;
	for (int i = 1; i <= q; ++i)
		ans += ans - mod, ans += ans >> 31 & mod;
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




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


typedef struct edge {

	ll to;
	ll cost;

}EDGE;

void dijkstra(int n, vector<vector<EDGE> >& G, int x, vector<ll>& prev, vector<ll>& d) {
	/*頂点の個数、辺の情報、始点となる頂点、直前の頂点の情報、最短距離の情報*/

	/*最終的にdは経由点からの最短距離が格納される、その過程では暫定的な最短距離が格納され、最短距離が見つかれば、その都度更新される*/

	//vector<ll> d(n,INF);/*最終的な最短距離を保持、初期化はINF*/
	d[x] = 0;
	priority_queue<pll, vector<pll>, greater<pll> > que;/*vectorのpriority_queueで暫定的な最短距離が小さい順に取り出す*/
	que.push(pll(0, x));/*経由点からダイクストラを適用するので経由点の暫定的な最短距離のコストは0*/

	while (!que.empty()) {/*queが空になれば最短距離が全て探索できたことになる*/

		pll p = que.top();/*最短距離の１番小さいものの取り出し*/
		que.pop();/*取り出したので調べたとみなし、queから出す*/
		int v = p.second;/*取り出した頂点の番号*/
		if (d[v] < p.first) {
			/*取り出した頂点からの最短距離よりも短い経路があるので更新の必要はない*/
			continue;
		}

		for (int i = 0; i < G[v].size(); i++) {
			/*取り出した頂点から辺でつながっている頂点への最短距離を調べて現在の値より短ければ更新する*/
			EDGE e = G[v][i];/*取り出した頂点からつながっている頂点を1つ取り出す*/
			if (d[e.to] > d[v] + e.cost) {
				/*現在の最短距離よりも、現在の頂点を経由する経路のほうが最短距離が短い場合は最短距離を更新し、次の頂点を調べる*/
				d[e.to] = d[v] + e.cost;/*最短経路の更新*/
				que.push(pii(d[e.to], e.to));/*先の頂点を調べるためqueに格納*/
				prev[e.to] = v;
			}
		}
	}
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--;
	t--;

	auto Graph = make_v<EDGE>(n + 10, 0);

	for (int i = 0; i < m; i++)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--;
		b--;
		c--;
		Graph[a].push_back(EDGE{ b,d });
		Graph[b].push_back(EDGE{ a,d });

		Graph[a].push_back(EDGE{ c,d });
		Graph[c].push_back(EDGE{ a,d });


		Graph[b].push_back(EDGE{ c,d });
		Graph[c].push_back(EDGE{ b,d });
	}
	vector<ll> dd(n + 10,INF);
	vector<ll> prev(n + 10);

	dijkstra(n, Graph, s, prev, dd);



	cout << dd[t] << endl;




	return 0;
}



Measured memory_bytes: 24288
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
up_trend = a[0] < a[1]
array = []
array << a[0] if (up_trend)

for i in 1...a.size do
  if (up_trend)
    if (a[i] < a[i-1])
      array << a[i-1]
      up_trend = false
    end
  else
    if (a[i] > a[i-1])
      array << a[i-1]
      up_trend = true
    end
  end
end

if (array[-1] && array[-1] < a[-1])
  array << a[-1]
end

okane = 1000
kabu = 0
buy = true
array.each do |price|
  if (buy)
    kazu = okane / price
    kabu += kazu
    okane -= price * kazu
    buy = !buy
  else
    okane += kabu * price
    kabu = 0
    buy = !buy
  end
end
puts okane

Measured memory_bytes: 14284
import heapq
N,M = map(int,input().split())
Alist = list(map(int,input().split()))
newA = list(map(lambda x: x*(-1),Alist))
heapq.heapify(newA)
for i in range(M):
    current = -heapq.heappop(newA)
    heapq.heappush(newA,-(current//2))
cost = 0
print(-sum(newA))

Measured memory_bytes: 73068
n=int(input())
H=[int(i) for i in input().split()]
dev=[0]*(n-1)
count=int(0)
count_max=0

for i in range(n-1):
  if H[i] - H[i+1] >=0:
    count+=1
  else:
    if count > count_max:
      count_max=count
    count=0

if count > count_max:
  count_max=count

print(count_max)

Measured memory_bytes: 14252
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define inf 10000000001LL
#define MAX 100001
using namespace std;

//ifstream in("input.txt");
//ofstream out("output.txt");

int T;
int N, M, W;
string s;


int main() {
	cin >> N;
	cout << "ABC" << N;
}

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

int main(void){

    int i,j,k,l;
    int hypo,ang;
    int ang_tmp=0;
    double x,y;

    while(1){
        scanf("%d,%d",&hypo,&ang);
        if(hypo==0&&ang==0)break;
        
        x+=sin(ang_tmp*3.14159265358/180)*hypo;
        y+=cos(ang_tmp*3.14159265358/180)*hypo;
        
        ang_tmp+=ang;
    }
    printf("%d\n",(int)x);
    printf("%d\n",(int)y);

    return(0);
}

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

int main() {
  int N, K,x = 1;
  cin >> N>>K;

  for (int i = 0; i < N; i++) {
    if(2*x <= x+K){
      x *= 2;
    }
    else{
      x += K;
    }
  }
    cout << x  << endl;
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.System.*;
public class Main {

    static class State implements Comparable<State>{
        int x, y, lr;
        int cost;
        State(int x, int y, int lr, int cost){
            this.x = x;
            this.y = y;
            this.lr = lr;
            this.cost = cost;
        }
        public int compareTo(State st){
            return this.cost - st.cost;
        }
    }
    static int w, h;
    static char[][] t;

    static int[][] dx;
    static int[][] dy;

    static {
        dx = new int[2][9];
        dy = new int[2][9];
        int cnt = 0;
        for(int i=1;i<=3;i++){
            for(int j=-2;j<=2;j++){
                if(Math.abs(i) + Math.abs(j) <= 3){
//                    out.println(i+" "+j);
                    dx[0][cnt] = i;
                    dy[0][cnt] = j;
                    dx[1][cnt] = i*(-1);
                    dy[1][cnt] = j;
                    cnt++;
                }
            }
        }
    }

    static void solve(){
        PriorityQueue<State> open = new PriorityQueue<State>();
        boolean[][][] closed = new boolean[h][w][2];
        State st = null;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(t[i][j] != 'S') continue;
                st = new State(j, i, 0, 0);
                open.add(st);
                st = new State(j, i, 1, 0);
                open.add(st);
            }
        }

        while(!open.isEmpty()){
            st = open.poll();
            if(closed[st.y][st.x][st.lr]) continue;
            closed[st.y][st.x][st.lr] = true;

            if(t[st.y][st.x] == 'T'){
                out.println(st.cost);
                return;
            }

            for(int i=0;i<9;i++){
                int nx, ny, nc;

                nx = st.x + dx[st.lr][i];
                ny = st.y + dy[st.lr][i];
                if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
                nc = st.cost + t[ny][nx] - '0';

                if(t[ny][nx] == 'X') continue;
                if(t[ny][nx] == 'S' || t[ny][nx] == 'T') nc = nc - t[ny][nx] + '0';

                State ns = new State(nx, ny, (st.lr+1)%2, nc);

                open.add(ns);
            }
        }
        out.println(-1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(in);
        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w == 0 && h == 0) break;
            t = new char[h][w];

            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    t[i][j] = sc.next().charAt(0);
                }
            }

            solve();
        }

    }

}

Measured memory_bytes: 13000
N, M = map(int, input().split())

masks = []
for i in range(M):
    x = input().split()
    k = int(x[0])
    s = x[1:]
    m = 0
    for b in s:
        m += 2**(int(b)-1)
    masks.append(m)

p = list(map(int, input().split()))

# print(masks)
# print(p)

# N, M = 2, 2
# masks = [3, 2]
# p = [0, 1]

# N, M = 2, 3
# masks = [3, 1, 2]
# p = [0, 0, 1]

# N, M = 5, 2
# masks = [19, 6]
# p = [1, 0]

combinations = 0
for b in range(2**N):
    all_on = True
    for m, c in zip(masks, p):
        if bin(b&m).count("1")%2 != c:
            all_on = False
            break
    if all_on:
        combinations += 1

print(combinations)

Measured memory_bytes: 3188
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main = getLine >> readLine >>= print . solve 

solve :: [Int] -> Int
solve = count 0 . zip [1..]
    where
        count acc ((i, x) : (j, y) : zs)
            | i == x && j == y = count (acc + 1) zs
            | i == x = count (acc + 1) zs
            | otherwise = count acc $ (j, y) : zs
        count acc ((i, x) : _)
            | i == x = acc + 1
            | otherwise = acc
        count acc _ = acc

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
    char str[100005];
    cin>>str;
    int N=strlen(str);
    int cand1=0; int cand2=0;
    for(int i=0;i<N;i++){
        if(i%2==0&&str[i]=='0'){cand1++;}
        if(i%2==0&&str[i]=='1'){cand2++;}
        if(i%2==1&&str[i]=='0'){cand2++;}
        if(i%2==1&&str[i]=='1'){cand1++;}
    }
    if(cand1<cand2){cout<<cand1;}
    else cout<<cand2;
    return 0;
}


Measured memory_bytes: 384
#include <stack>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[50][50]; bool vis[50];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll x, y;
	cin >> x >> y;
	ll res = INF;
	rep(i, 4) {
		if (i == 0) {
			if (y - x >= 0) chmin(res, y - x);
		}
		else if (i == 1) {
			x *= -1;
			if (y - x >= 0) chmin(res, y - x + 1);
			x *= -1;
		}
		else if (i == 2) {
			y *= -1;
			if (y - x >= 0) chmin(res, y - x + 1);
			y *= -1;
		}
		else if (i == 3) {
			x *= -1; y *= -1;
			if (y - x >= 0) chmin(res, y - x + 2);
			x *= -1; y *= -1;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int a,b,c,A,B,C,x,y,z,i,n;
for(i=0;i<3;i++){
cin>>a>>b>>c>>A>>B>>C;
n=(3600*A+60*B+C)-(3600*a+60*b+c);
x=n/3600;
y=(n-3600*x)/60;
z=n-(3600*x+60*y);
cout<<x<<' '<<y<<' '<<z<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
int main()
{
    ll n,a,b,c,d;
    ll ans;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
    if(n % 2 == 0){
        ll t;
        t = min(min(min((8*a),(4*b)),(c*2)),d);
        ans = t*(n/2);
        printf("%lld\n",ans);
    }
    else{
        ll x;
        x = min(min((4*a),(2*b)),c);
        ans = min(min(min((x*n),((n/2)*d+c)),((n/2)*d+2*b)),((n/2)*d+4*a));
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 256
#ナップサック問題
#dp[i][w]=i番目までのお菓子で、リュックの中身の重さがw以下となる、選び方の価値の最大値

n,w=map(int,input().split())
weight=[0]
value=[0]
for i in range(n):
    f,s=map(int,input().split())
    weight.append(f)
    value.append(s)
dp=[[0 for i in range(w+1)]for j in range(n+1)]
for i in range(1,n+1):
    for j in range(w+1):
        dp[i][j]=dp[i-1][j]#選ばないときはi-1の価値を受け継ぐ
        if j-weight[i]<0:
            continue
        else:
            dp[i][j]=max(dp[i][j],dp[i-1][j-weight[i]]+value[i])
print(max(dp[n]))


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

using namespace std;

int main(void)
{
    int series_length;
    vector<int> p_perm;
    vector<int> q_perm;

    cin >> series_length;

    for(int i = 0; i < series_length; i++){
        int p;
        cin >> p;
        p_perm.push_back(p);
    }

    for(int i = 0; i < series_length; i++){
        int q;
        cin >> q;
        q_perm.push_back(q);
    }

    vector<int> perm;
    for(int i = 1; i <= series_length; i++){
        perm.push_back(i);
    }

    int p_pos;
    int q_pos;
    int current_pos = 1;
    do{
        if(perm == p_perm){
            p_pos = current_pos;
        }
        if(perm == q_perm){
            q_pos = current_pos;
        }
        current_pos += 1;
    }while(next_permutation(perm.begin(), perm.end()));

    cout << abs(q_pos - p_pos);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
   
    int N;cin>>N;
    vector<int> ans(N+1,0),S(N+1);
    for(int i=0;i<N;i++){
        cin>>S[i+1];
    }
    for(int i=N;i>=1;i--){
        int sum=0;
        for(int j=i;j<=N;j+=i){
            sum+=ans[j];
        }
        if(sum%2!=S[i]) ans[i]=1;
    }
    
    int cnt=0;
    
    for(int i=1;i<=N;i++){
        if(ans[i]==1) cnt++;
    }
    
    cout<<cnt<<endl;
    
    bool ok=false;
    
    for(int i=1;i<=N;i++){
        if(ans[i]==1){
            if(!ok){
                ok=true;
                cout<<i;
            }else cout<<" "<<i;
        }
    }
    if(cnt) cout<<endl;
}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

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); }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

bool used[100010];
int dp[100010];
vector<PII> g[100010];
bool flag;

void dfs(int x) {
  // cout << "x:" << x << endl;
  used[x] = true;
  for(PII i: g[x]) {
    // cout << "i:" << i.first << endl;
    if(!used[i.first]) {
      dp[i.first] = dp[x] + i.second;
      // cout << "dp:" << dp[i.first] << endl;
      if(dp[i.first] > 1e9) {
        flag = false;
        break;
      }
      dfs(i.first);
    } else {
      if(dp[i.first] != dp[x] + i.second) {
        flag = false;
        break;
      }
    }
  }
}

//グラフの隣接リスト
VI G[100010];
//頂点の入次数を管理
int h[100010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    g[l].PB({r, d});
    G[l].PB(r);
    h[r]++;
  }

  int v = n;
  //入次数が0の頂点の集合
  stack<int> st;

  //入次数が0の頂点であればstに追加
  REP(i, v) if(h[i] == 0) st.push(i);

  //ソートされた後のグラフ
  VI ans;
  //stがなくなるまでループ
  while(st.size()) {
    //stの集合のから一つ取り出す
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(auto& j: G[i]) {
      //隣接する頂点の入次数をマイナス1
      h[j]--;
      //これによって入次数が0になればstに追加
      if(h[j] == 0) st.push(j);
    }
  }

  // //ansを順に出力
  // for(int i: ans) cout << i << " ";
  // cout << endl;
  if(ans.size() != n) {
    cout << "No" << endl;
    return 0;
  }

  REP(i, n) {
    if(!used[ans[i]]) {
      flag = true;
      dp[ans[i]] = 0;
      dfs(ans[i]);
      if(!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 16888
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int a[20][20],ans,n,m,judge;

void dfs(int x,int y)
{
    if (x>n)
    {
        int sum=0;
        for (int i=1;i<=n;i++) sum+=a[i][y];
        if (sum!=judge) return;
        y++;x=y+1;
    }
    if (y==n)
    {
        int sum=0;
        for (int i=1;i<=n;i++) sum+=a[i][y];
        if (sum==judge) ans++;
        return;
    }

    if (a[x][y]==0)
    {
        a[x][y]=2;a[y][x]=-1;
        dfs(x+1,y);
        a[x][y]=-1;a[y][x]=2;
        dfs(x+1,y);
        a[x][y]=a[y][x]=0;
    }
    else dfs(x+1,y);
}

int main()
{
    std::ios::sync_with_stdio(false);
    while (cin>>n)
    {
        if (n==0) break;
        cin>>m;
        memset(a,0,sizeof(a));
        for (int i=1;i<=n;i++) a[i][i]=3;
        while (m--)
        {
            int x,y;
            cin>>x>>y;
            a[x][y]=2;a[y][x]=-1;
        }

        ans=0;judge=n/2+3;
        dfs(2,1);
        cout<<ans<<endl;
    }

    return 0;
}



Measured memory_bytes: 3128