akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	public static void main(String[] args) {
		long Q=stdIn.nextInt();
		long H=stdIn.nextInt();
		long S=stdIn.nextInt();
		long D=stdIn.nextInt();
		long N=stdIn.nextInt();
		if(Q*2<H)
			H=Q*2;
		if(H*2<S)
			S=H*2;
		if(S*2<=D)
			System.out.println(N*S);
		else
			if(N%2==0)
				System.out.println((N/2)*D);
			else
				System.out.println((N/2)*D+S);
	}
}


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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int now,n,k;


int main(){
  ll ans=0;
  cin >> n;
  vector<ll> a(n),b(n);
  ll mkz=0;
  REP(i,n){
    cin>>a[i];
    if (a[i]<0)
      mkz++;
  }
  REP(i,n) b[i]=abs(a[i]);
  ll mi=b[0];
  REP1(i,n) mi=min(b[i],mi);
  
  REP(i,n) ans+=b[i];
  
  if (mkz%2==0){
    cout<<ans<<endl;
  }else{
    cout<<(ans-mi*2)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1792
h,w = map(int, input().split())
a = ["#"*(w+1)] + ["#"+input() for i in range(h)]
mod = 10 ** 9 + 7
dp = [[0]*(w+1) for i in range(h+1)]
dp[1][1] = 1
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j] == ".":
      dp[i][j] += (dp[i-1][j] + dp[i][j-1])
      dp[i][j] %= mod
print(dp[h][w])

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

int main()
{
   int n, nb, ret = 0;
   cin >> nb;
   n = nb;
   while(nb){
      ret += nb%10;
      nb /= 10;
   }
   if (n % ret != 0)
   {
      cout << "No" << endl;
   }
   else
   {
      cout << "Yes" << endl;
   }
}


Measured memory_bytes: 256
def main():
    import sys
    from fractions import gcd
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            ppr = prime[pr]
            pppr = pp[pr]
            if ppr < pppr:
                prime[pr] = pppr

    M = 1
    for pr in prime.keys():
        M = (M * pow(pr, prime[pr], mod))%mod

    ans = 0
    for a in A:
        ans = (ans + (M * pow(a, mod-2, mod))%mod)%mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9308
line1 = input()
a, b, m = line1.split(" ")
line2 = input()
a_list = line2.split(" ")
a_list = [int(a) for a in a_list]
line3 = input()
b_list = line3.split(" ")
b_list = [int(b) for b in b_list]

min_val = min(a_list) + min(b_list)

for i in range(int(m)):
    line = input()
    x, y, c = line.split(" ")
    x = int(x)
    y = int(y)
    c = int(c)
    if min_val > a_list[x-1] + b_list[y-1] - c:
        min_val = a_list[x-1] + b_list[y-1] - c
print(min_val)

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

const int ms = 2e2 + 18;
int c[10][10];

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

    int h, w;
    int answer = 0;
    cin >> h >> w;

    for(int i = 0; i <= 9; ++i)
    {
        for(int j = 0; j <= 9; ++j)
            cin >> c[i][j];
    }


    for(int k = 0; k <= 9; ++k)
    {
        for(int i = 0; i <= 9; ++i)
        {
            for(int j = 0; j <= 9; ++j)
            {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    for(int i = 1; i <= h; ++i)
    {
        for(int j = 1; j <= w; ++j)
        {
            int temp;
            cin >> temp;

            if(temp != -1)
                answer += c[temp][1];
        }
    }



    cout << answer << '\n';

}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}



fn solve(tower: &Vec<i32>) -> i32 {
    let n = tower.len();
    let (mut kind, mut cnt) = (tower[0], 1);
    let mut k: Vec<(i32, i32)> = Vec::new();
    for i in 1..n {
        if kind == tower[i] {
            cnt += 1;
        } else {
            k.push((kind, cnt));
            kind = tower[i];
            cnt = 1;
        }
    }
    k.push((kind, cnt));
    let k = k;

    let mut stack: Vec<(i32, i32)> = Vec::new();
    for (kind, cnt) in k {
        let m = stack.len();
        if cnt >= 4 {
            continue;
        }
        if stack.len() == 0 || stack[m - 1].0 != kind || stack[m - 1].1 + cnt < 4 {
            stack.push((kind, cnt));
        } else {
            stack.pop();
        }
    }

    let mut ans = 0;
    for (_, cnt) in stack {
        ans += cnt;
    }

    ans
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n: usize = sc.read();
        if n == 0 {
            break;
        }
        let mut t: Vec<i32> = vec![0; n];
        for i in 0..n {
            t[i] = sc.read();
        }

        let mut ans = INF;
        for i in 0..n {
            let tmp = t[i];
            for j in 1..4 {
                if tmp == j {
                    continue;
                }
                if i != 0 && t[i - 1] == j || i != n - 1 && t[i + 1] == j {
                    t[i] = j;
                    ans = min(ans, solve(&t));
                }
            }
            t[i] = tmp;
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 5048
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);


        int n = sc.nextInt();
        String s = sc.next();
        StringBuilder sb = new StringBuilder(s);
        int k = sc.nextInt();
        String key = s.substring(k - 1, k);



        int i;
        for(i = 0; i < s.length(); i++){
            String tmp = s.substring(i, i + 1);
            if(tmp.equals(key)){

            }else{
                sb.setCharAt(i, '*');
            }


        }
        System.out.println(sb.toString());


    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;

    for (int i = 0; i < 2; i++) {
        if (a >= b) {
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import deque, defaultdict

INF = float('inf')
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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


# UnionFind
class UnionFind:
    # 負: ルートで値は木の深さを表す
    # 正: 子で値は次のノードを表す
    def __init__(self, size: int) -> None:
        self.nodes = [-1] * size  # 初期状態では全てのノードがルート

    def find(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.find(self.nodes[x])
            return self.nodes[x]

    def unite(self, x: int, y: int) -> None:
        root_x, root_y = self.find(x), self.find(y)
        if root_x != root_y:
            if self.nodes[root_x] != self.nodes[root_y]:  # グラフの高さが異なる場合
                # 木のランクが高い方のルートに併合させる
                # 併合後にランクの変動はない
                if self.nodes[root_x] < self.nodes[root_y]:
                    self.nodes[root_y] = root_x
                else:
                    self.nodes[root_x] = root_y
            else:
                # ランクが等しい木同士を併合させるので
                # 併合後は木のランクが1つ上がる
                self.nodes[root_x] += -1
                self.nodes[root_y] = root_x

    def same(self, x, y):
        return self.find(x) == self.find(y)



def main():
    n, m = LI()

    uf = UnionFind(n)
    res = deque()
    res.append(n * (n - 1) // 2)
    cnt = [1] * n
    AB = [LI_() for _ in range(m)]
    AB.reverse()
    for a, b in AB:
        if uf.same(a, b):
            res.append(res[-1])
            continue
        ca = cnt[uf.find(a)]
        cb = cnt[uf.find(b)]
        tmp = res[-1] - ca * cb
        # print(a+1, b+1, res[-1], ca, cb)
        if tmp < 0:
            tmp = 0
        res.append(tmp)
        uf.unite(a, b)
        cnt[uf.find(a)] = ca + cb
        # print(cnt[uf.find(a)], cnt[uf.find(b)])

    res.reverse()
    res.popleft()
    print(*res, sep='\n')


main()


Measured memory_bytes: 110940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<=a){
    print(k);
  }
  else if(k<=a+b){
    print(a);
  }
  else{
    print(a - k + a + b);
  }
}

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

ans = 0

a_goketi = sum(a)
b = []

for i in range(n):
    b.append(a_goketi - a[i])
    a_goketi -= a[i]

    ans += a[i] * b[i] 

ans %= 1000000007
print(ans)

Measured memory_bytes: 31580
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
    ll n,i,c,d;
    cin>>n;
    ll p[n];
    for(i=0;i<n;i++){
        cin>>p[i];
    }
    d=p[0];c=1;
    for(i=1;i<n;i++){
        if(p[i]<=d){
            c++;d=p[i];
        }
    }
    cout<<c<<endl;return;
}
int main()
{
    solve();
}

Measured memory_bytes: 5032
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cassert>
using namespace std;

#define sz(a) int((a).size())
#define rep(i, s, n)  for(int i = s; i <= (n); ++i)
#define rev(i, n, s)  for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 100005;


int main() {
#ifdef loc
  if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
    assert(0);
  }
  freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
#endif
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll a, b, c;
  cin >> a >> b >> c;
  ll res = 0;
  if ((a & 1) && (b & 1) && (c & 1)) {
    res = min(a*b, min(b*c, c*a));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <deque>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
		int N, M;
		cin >> N >> M;

        vector<pair<bool, int>> table(N, pair<bool, int>(false, 0));

        for (int i = 0; i < M; i++) {
            int pi;
            string Si;
            cin >> pi;
            cin >> Si;
						if (Si == "AC") {
                            table[pi - 1].first = true;
                        }
												else {
													if (!table[pi - 1].first) {
                                                        table[pi - 1].second++;
                                                    }
                                                }
        }

        int ac = 0;
        int wa = 0;
        for (int i = 0; i < N; i++) {
            if (table[i].first) {
                ac++;
                wa += table[i].second;
            }
        }
        cout << ac << ' ' << wa << endl;

        return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> w;
  int ans=-1;
  for(int i=0;i<N;i++){
    int input;
    cin >> input;
    w.push_back(input);
  }
  bool isValid=true;
  while(isValid){
    ans++;
    for(int i=0;i<N;i++){
      if(w[i]%2==1){
        isValid=false;
		break;
      }
      w[i]/=2;
    }
  }
  cout << ans;
}
    
      

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

int main() {
    int N;
    string S;
    cin >> N >> S;

    for (int i = 0; i < S.size(); i++) {
        int ascii = S[i] - 'A';
        ascii = (ascii + N) % 26;
        S[i] = char('A' + ascii);
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll x,k,d;
		cin>>x>>k>>d;
		x = abs(x);
		ll step =  x/d;
		if(k <= step) {
			cout<<x-k*d<<"\n";
		}
		else {
			x = x - step*d;
			k -= step;
//			cout<<step<<" "<<k<<" "<<x<<" ";
			if(k%2) {
//				cout<<"@!";
				cout<<abs(x-d)<<"\n";
			}
			else {
				cout<<x<<"\n";
			}
		}
 	}
 	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double pai=3.14159265358979323846;
    double i=(double)(min(abs(360-(30*h+30*(m/60)-6*m)),abs(30*h+30*(m/60)-6*m)))/360*2*pai;
    cout<<setprecision(15)<<endl;
    cout<<sqrt(a*a+b*b-2*a*b*cos(i))<<endl;
return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <deque>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n, r;
  while(cin>>n>>r) {
    int c[r];
    REP(i,r)
      cin >> c[i];
    deque<int> A,B;
    vector<int> C(n);
    REP(i, n)
      C[i] = i;
    REP(cnt, r) {
      for (int i=n/2; i<n; ++i)
        A.push_back(C[i]);
      REP(i, n/2)
        B.push_back(C[i]);
      C.clear();
      
      // FOR(it,A)
      //   cout << *it << " ";
      // cout << endl;
      // FOR(it,B)
      //   cout << *it << " ";
      // cout << endl;

      while(!A.empty()||!B.empty()) {
        REP(i,c[cnt]) {
          if (!A.empty()) {
            C.push_back(A.front());
            A.pop_front();
          }
        }
        // FOR(it,C)
        //   cout << *it << " ";
        // cout << endl;
        REP(i,c[cnt]) {
          if (!B.empty()) {
            C.push_back(B.front());
            B.pop_front();
          }
        }
        // FOR(it,C)
        //   cout << *it << " ";
        // cout << endl;
      }
    }
    cout << C.back() << endl;
  }
}

Measured memory_bytes: 0
n, m = input().split()

list = input().split()

m = int(m)
list = [int(i) for i in list]
list.sort(reverse=True)

M = m
i = 0
while 1:
    if m == 0:
        break
    
    if list[i] >= sum(list)/(4*M):
        ans = "Yes"
    else:
        ans = "No"
        
    m-=1
    i+=1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int n;
  int i;
  int card[4][13]={{}};
  cin >> n;
  char a;
  int b;
  for(i=0;i<n;i++) {
    cin >> a >> b;
    switch(a){
    case 'S':
      card[0][b-1]=1;
      break;
    case 'H':
      card[1][b-1]=1;
      break;
    case 'C':
      card[2][b-1]=1;
      break;
    case 'D':
      card[3][b-1]=1;
      break;
    }
  }
  for(i=0;i<52;i++) {
    switch(i/13){
    case 0:
      if(card[0][i%13]==0) cout << "S " << i+1 << endl;
      break;
    case 1:
      if(card[1][i%13]==0) cout << "H " << i%13+1 << endl;
      break;
    case 2:
      if(card[2][i%13]==0) cout << "C " << i%13+1 << endl;
      break;
    case 3:
      if(card[3][i%13]==0) cout << "D " << i%13+1 << endl;
      break;
    }
  }
   
  return 0;
}


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

struct Recipe{
	int index, stuff[100], size;
};

int main(){
	int n;
	while(std::cin >> n, n){
		std::map<std::string, int> indexes;
		int items[100];//items[index]: index番目の値段
		for(int i=0;i<n;i++){
			std::string name;
			int price;
			std::cin >> name >> price;
			indexes[name] = i;
			items[i] = price;
		}
		Recipe r[100];//recipe[n][0]には材料の数

		int m;
		std::cin >> m;
		for(int i=0;i<m;i++){
			std::string name;
			int stuff_n;
			std::cin >> name >> stuff_n;

			r[i].size = stuff_n;
			r[i].index = indexes[name];

			for(int j=0;j<stuff_n;j++){
				std::string stuff;
				std::cin >> stuff;
				r[i].stuff[j] = indexes[stuff];
			}
		}

		while(true){
			bool update = false;
			for(int i=0;i<m;i++){
				int price = 0;
				for(int j=0;j<r[i].size;j++){
					price += items[r[i].stuff[j]];
				}
				if(price < items[r[i].index]){
					items[r[i].index] = price;
					update = true;
				}
			}
			if(!update)break;
		}

		std::string want;
		std::cin >> want;
		std::cout << items[indexes[want]] << std::endl;
	}
}

Measured memory_bytes: 1236
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto a123 = readln.split.to!(int[]);

    sort(a123);

    int cst;
    for (int i = 0; i < 2; ++i) {
        cst += abs(a123[i] - a123[i+1]);
    }
    writeln(cst);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int add(int x,int y)
{
    return (x + y)%MOD;
}

int sub(int x,int y)
{
    return (x+MOD-y)%MOD;
}

int mul(int x,int y)
{
    return (ll)x*y%MOD;
}

int dp[302][302][302];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    dp[0][1][0] = 1;
    rep(i,m){
        for(int j=1;j<=n;j++){
            for(int k=0;k<=n-j;k++){
                dp[i+1][j][k] = add(dp[i+1][j][k],mul(k,dp[i][j][k]));
                dp[i+1][j][k+1] = add(dp[i+1][j][k+1],mul(n-j-k,dp[i][j][k]));
                dp[i+1][j+k][0] = add(dp[i+1][j+k][0],mul(j,dp[i][j][k]));
            }
        }
    }
    cout << dp[m][n][0] << "\n";
    return 0;
}


Measured memory_bytes: 107136
import java.util.*;
public class Main {
    public static void main(String [] args){
     Scanner sc  = new Scanner(System.in);
     String S = sc.next();
     int opt = 10000000;
     int n=753;
     for(int a=0;a<S.length()-2;a++){
         String num = S.substring(a,a+3);
         int num2 = Integer.parseInt(num);
         if(Math.abs(n-num2)<=opt) opt =Math.abs(n-num2);
     }
        System.out.println(opt);
    }
}

Measured memory_bytes: 23764
#写経
#https://atcoder.jp/contests/abc168/submissions/13358850
from collections import deque

def resolve():
    N,M, *AB = map(int, open(0).read().split())
    graph = [[] for _ in range(N+1)]
    for a,b in zip(*[iter(AB)] * 2):
        graph[a].append(b)
        graph[b].append(a)

    queue = deque([1])
    signposts = [0] * (N+1)
    signposts[1] = 1
    while queue:
        u = queue.popleft()
        for v in graph[u]:
            if not signposts[v]:
                signposts[v] = u
                queue.append(v)

    if all(signposts[2:]):
        print("Yes")
        print("\n".join(map(str,signposts[2:])))
    else:
        print("No")
resolve()

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a + b) == c || (a + c) == b || (b + c) == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i=0; i<N; i++) {
        cin >> A[i];
    }
    ll count = 0;
    for (ll i=1; i<N; i++) {
        if (A[i]<A[i-1]) {
            count += A[i-1]-A[i];
            A[i] = A[i-1];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 4728
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val s = sc.next
//  val h = List.fill(n)(sc.nextInt)

  val alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  val ans = s.map { c => alp((alp.indexOf(c) + n) % 26)}

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 28076
n,x,y=map(int,input().split())
x,y=x-1,y-1

ans=[0]*(n+1)



for i in range(n):
    for j in range(i+1,n):
        a=abs(i-j)
        b=abs(i-x)+1+abs(y-j)
        c=abs(y-i)+1+abs(x-j)
        ans[min(a,b,c)]+=1
for i in range(1,n):
    print(ans[i])
    

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

S = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

dp = [0] * 100010
dp[0] = 1
for i in range(len(S)):
    if dp[i]==0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1


if dp[len(S)] == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9784
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<Integer> hSet = new HashSet<Integer>();
        int[] hArray = new int[N+1];
        int M = sc.nextInt();
        hArray[0] = 1000000000;
        for (int i=1; i<=N;i++) {
            hSet.add(i);
            hArray[i] = sc.nextInt();
        }

        for(int i=0;i<M;i++){
            int A = sc.nextInt();
            int B = sc.nextInt();
            if(hArray[A] >= hArray[B]){
                hSet.remove(B);
            }
            if(hArray[B] >= hArray[A]){
                hSet.remove(A);
            }

        }


        System.out.println(hSet.size());

    }

}









Measured memory_bytes: 67964
#include <bits/stdc++.h>
using namespace std;
const int m=1e9;

int main() {
 int n;
  cin>>n;
  set<int>a;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a.insert(x);
  }
  if(a.size()<n) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

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



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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//String g = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		//String buff="Christmas";
		long count=0;
		long[] array=new long[3];

		/*for(long i=n;i<25;i++) {
			buff+=" Eve";
		}*/
		Arrays.sort(array);
		/*if(n==3||n==5||n==7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}*/
		System.out.println(1.0*n/m);
		//System.out.println(Math.abs(array[2]-array[1])+Math.abs(array[1]-array[0]));
	}
}




Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  long long s=0,a,b,n,m,i,j,d[100010],M=1e9+7;
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  for(i=0;i<n;i++){
    for(j=a=b=0;j<i;j++){
      if(d[j]<d[i])a++;
    }
    for(j=i;j<n;j++){
      if(d[i]>d[j])b++;
    }
    //printf("%lld %lld\n",a,b);
    s=(s+(a*(((m)*(m-1)/2)%M))%M+(b*((m)*(m+1)/2%M))%M)%M;
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    char tmp;
    string S;
    cin >> A;
    // ans = max(A*B, C*D);
    
    // cout <<ans<<endl;
    
    if(A < 1200)
    	cout << "ABC"<<endl;
    else
    	cout <<"ARC"<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
    	
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	string input;
	int len;

	cin >> len;
	cin >> input;

	if (input.size() > len) {
		cout <<input.substr(0, len) + "..." << endl;
	}
	else {
		cout << input << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int H, W; cin >> H >> W;
	vvi a(H, vi(W));
	REP(i,H) REP(j,W) {
		cin >> a[i][j];
	}
	int res_n = 0;
	vvi res;
	REP(i,H) REP(_j,W) {
		if (i == H - 1 && _j == W - 1) break;
		int j, ni, nj;
		if (i % 2 != 0) j = W - 1 - _j;
		else j = _j;
		if (_j != W - 1) {
			ni = i;
			nj = j + 1 * (i % 2 != 0 ? -1 : 1);
		} else {
			ni = i + 1;
			nj = j;
		}

		if (a[i][j] % 2 != 0) {
			a[i][j]--;
			a[ni][nj]++;

			res_n++;
			res.push_back({ni + 1, nj + 1, i + 1, j + 1});
		}
	}
	// debug(a);
	cout << res_n << endl;
	for (vi res_xys : res) {
		cout << res_xys[0] << " " << res_xys[1] << " " << res_xys[2] << " " << res_xys[3] << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 10800
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;


vector<int> parent;
vector<int> tree_size;

void make_set(int i) {
	parent[i] = i;
	tree_size[i] = 1;
}

int find(int i) {
	while (parent[i] != i) {
		i = parent[i];
	}
	return i;
}

void union_tree(int i, int j) {
	i = find(i);
	j = find(j);
	if (tree_size[i] >= tree_size[j]) {
		parent[j] = i;
		tree_size[i] += tree_size[j];
	}
	else {
		parent[i] = j;
		tree_size[j] += tree_size[i];
	}
}

int main()
{
	int N;
	cin >> N;

	vector<pair<int, int>> X(N);
	vector<pair<int, int>> Y(N);
	parent = vector<int>(N);
	tree_size = vector<int>(N);


	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;

		X[i] = make_pair(x, i);
		Y[i] = make_pair(y, i);
	}

	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());

	vector<pair<int, pair<int, int>>> E;

	for (int i = 0; i < N - 1; ++i) {

		int value = abs(X[i].first - X[i + 1].first);

		E.emplace_back(make_pair(value, make_pair(X[i].second, X[i + 1].second)));

		value = abs(Y[i].first - Y[i + 1].first);

		E.emplace_back(make_pair(value, make_pair(Y[i].second, Y[i + 1].second)));
	}

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

	for (int i = 0; i < N; ++i) {
		make_set(i);
	}

	int total = 0;

	for (pair<int, pair<int, int>> e : E) {
		if (find(e.second.first) != find(e.second.second)) {
			union_tree(find(e.second.first), find(e.second.second));
			total += e.first;
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 7284
// B - Trained?
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi A(N); rp(i, 0, N){cin>>A[i]; --A[i];}
	set<int> visited;
	for(int t=0, a=0; visited.find(a)==visited.end(); a=A[a], ++t){
		visited.insert(a);
		if(a == 1){
			cout<< t <<endl;
			return 0;
		}
	}
	cout<< -1 <<endl;
}

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

using namespace std;

#define ll long long

void solve() {
	int a, b;
	cin >> a >> b;
	cout << b + (b-a) << "\n" ;
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3580
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<stdlib.h>

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>

#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=2500010;//maxn*maxs
int main()
{
    int n;
    cin>>n;
    int flag=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        if(a==b){
            ans++;
            if(ans>=3) 
                flag=1;
        }
        else
            ans=0;
    }
    if(flag)
         cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
    system("pause");
    return 0;
}
	



Measured memory_bytes: 3184
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;
 
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}

 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {}
    ll n,k;
    cin>>n>>k;
    ll a[200005]={0};
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        if(k>=n)
        {cout<<"0"<<endl;}
        else
        {
            ll j=n-1-k;
            ll s=0;
            for(ll i=0;i<=j;i++)s+=a[i];
            cout<<s<<endl;
        }
        
    
    
    return 0;
}












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

using namespace std;

int N;
int A[200];

void solve() {
    int i = 0;
    for (;;) {
        for (int j = 0; j < N; j++) {
            if (A[j] % 2 == 0) {
                A[j] = A[j] / 2;
            } else {
                printf("%d\n", i);
                return;
            }
        }
        i++;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main(){
  	long long K;
  	cin >> K;
  	if(K%2 == 0 || K%5 == 0){
      	cout << -1 << endl;
      	return 0;
    }
  	long long L = 9*K;
  	if(K%7 == 0) L/=7;
  	long long i = 0, res = 10;
  	while(1){
      	++i;
      	long long ama = res % L;
      	if(ama == 1) break;
      	else res = ama*10;
    }
  	cout << i << endl;
}

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

int main() {
  string S;
  cin >> S;
  int n = S.length();

  long long res = 0;
  for(int i = 0; i< (1 << (n - 1)); i++) {
    long long tmp = 0;
    for(int j = 0; j<n; j++) {
      tmp = tmp * 10 + S[j] - '0';
      if(i & (1 << j)) {
        res += tmp;
        tmp = 0;
      }
    }
    res += tmp;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
ylist = list(map(int,input().split()))
p = list(range(0,max(ylist)+1))
anslist = []
for i in p:
  ansl = sum((p[i]-ylist[j])**2 for j in range(0,n))
  anslist.append(ansl)
print(min(anslist))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
const string c = "ox";

signed main()
{
  ios::sync_with_stdio(false);
  string s;

  for (;cin >> s;){
    string res = "d";
    REP(i, 2){
      for (int j = 0; j < 9; j += 3){
        if (c[i] == s[j] && c[i] == s[j + 1] && c[i] == s[j + 2]){
          res = c[i];
          break;
        }
      }
      for (int j = 0; j < 3; j++){
        if (c[i] == s[j] && c[i] == s[j + 3] && c[i] == s[j + 6]){
          res = c[i];
          break;
        }
      }
      if (c[i] == s[0] && c[i] == s[4] && c[i] == s[8]){
        res = c[i];
      }
      if (c[i] == s[2] && c[i] == s[4] && c[i] == s[6]){
        res = c[i];
      }
    }
    print(res);
  }

  return (0);
}

Measured memory_bytes: 1180
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
char a[100001];
int n, l, r, mid;
string s;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    l=0; r=n;
    cout<<0<<'\n';
    cout.flush();
    cin>>s;
    a[0]=s[0];
    if(s[0]=='V') return 0;
    while(r-l>=1){
        mid=(r+l)/2;
        cout<<mid<<'\n';
        cout.flush();
        cin>>s;
        a[mid]=s[0];
        if(s[0]=='V') return 0;
        if(((mid-l)%2==0 && a[mid]==a[l]) || ((mid-l)%2==1 && a[mid]!=a[l])){
            l=mid;
        }
        else r=mid;
    } cout<<l;
    cout.flush();
    cin>>s;
    if(s[0]=='V') return 0;
    cout<<r;
    cout.flush();
    cin>>s;
    return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    long ret = 0;
    long leftW = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'W'){
            ret += i - leftW;
            leftW++;
        }
    }
    cout << ret;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

  string s1, s2, s3, s;
  cin >> s1 >> s2 >> s3;

  s = toupper(s1[0]);
  s += toupper(s2[0]);
  s += toupper(s3[0]);
  
  cout << s << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}
/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin>>n;
if(n==1) cout << n;
else if(n<4) cout << 2;
else if(n<8) cout << 4;
else if(n<16) cout << 8;
else if(n<32) cout << 16;
else if(n<64) cout << 32;
else cout << 64;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  long a, b=0, c=0;
  string s;
  cin >> a >> s;
  rep(i,0,a){
    if(s[i]=='I') b++;
    else b--;
    c=max(b, c);
  }
  co(c);
  
  return 0;
}


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

using namespace std;

int gacha(int a){
    if(a == 0)  return -1;
    int x;
    vector<int>data;
    data.resize(a);
    for(int i = 0; i < a; i++){
        cin >> x;
        data.push_back(x);
    }
    sort(data.begin(),data.end(),greater<int>());
    if(data[0] <= 1){
        cout << "NA" << endl;
        return 1;
    }
    int cnt = 0;
    for(int i = 0; i < a; i++){
        if(data[i] >= 1)    cnt++;
    }
    return cnt + 1;
}

int main(void){
    int N,judge;
    while(1){
        cin >> N;
        judge = gacha(N);
        if(judge == -1){
            return false;
        }else if(judge == 1){
        }else{
        cout << judge << endl;
        }
    }
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    map<ll, ll> s;
    rep(i, n) {
        ll a; cin >> a;
        s[a]++;
    }
    bool ans;
    if(s.size() > 3) ans = false;
    else if(s.size() == 3) {
        if(n % 3 == 0 && (*s.begin()).second == n/3 && 
        (*next(s.begin())).second == n/3 && 
        ((*s.begin()).first ^ (*next(s.begin())).first ^ (*next(next(s.begin()))).first) == 0) ans = true;
        else ans = false;
    }
    else if(s.size() == 2) {
        if(n % 3 == 0 && s.count(0) && s[0] == n/3) ans = true;
        else ans = false;
    }
    else {
        if(s.count(0) && s[0]) ans = true;
        else ans = false;
    }
    cout << (ans ? "Yes" : "No") << endl;
}


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

int main(int, char**) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);

    string str;
    cin >> str;
    list<char> s;
    for (char c : str)
        s.push_back(c);
    
    int Q = 0;
    cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; ++i) {
        int T;
        cin >> T;
        if (T == 1) {
            rev ^= 1;    
        } else if (T == 2) {
            int F;
            char C;
            cin >> F >> C;
            F -= 1;
            F = (F + rev) % 2;
            if (F == 0)
                s.push_front(C);
            else
                s.push_back(C);
        }
    }
    
    if (rev) {
        s.reverse();
    } 
    
    for (char c : s)
        cout << c;
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 10064
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
total = 0

for i in range(N-2):
    li = l_list[i]
    a = l_list.count(li)
    if l_list[i] == l_list[i-1]:
        a = 0
    
    for j in range(i+1,N-1):
        lj = l_list[j]
        b = l_list.count(lj)
        if li == lj or lj == l_list[j-1]:
            b = 0
        for k in range(j+1,N):
            lk = l_list[k]
            c = l_list.count(lk)
            if lk == lj or lk == l_list[k-1]:
                c = 0 
            if li + lj > lk:
                total += a*b*c

print(total)

Measured memory_bytes: 9128
from itertools import permutations

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

a = [[0] * C for _ in range(3)]
for y in range(N):
    for x in range(N):
        t = ((x + 1) + (y + 1)) % 3
        a[t][c[y][x] - 1] += 1

result = float('inf')
for b in permutations(range(C), 3):
    t = 0
    for i in range(3):
        ai = a[i]
        bi = b[i]
        for j in range(C):
            t += ai[j] * D[j][bi]
    result = min(result, t)
print(result)


Measured memory_bytes: 5620
// ※※※ 解答不能 ※※※
// sugim48氏.
// https://atcoder.jp/contests/cf16-final/submissions/992126
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
vector<vector<int>> X(101010);

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    vector<int> a(N);
    rep(i, N) scanf("%d", &a[i]);
    vector<int> b(100001);
    rep(i, N) b[a[i]]++;
    vector<int> c(M), d(M);
    rep(x, 100001){
        c[x % M] += b[x];
        d[x % M] += b[x] / 2;
    }
    int ans = 0;
    rep(x, M / 2 + 1){
        if(x == 0 || x * 2 == M){
            ans += c[x] / 2;
            continue;
        }
        int y = M - x;
        if(c[x] > c[y]){
            swap(c[x], c[y]);
            swap(d[x], d[y]);
        }
        ans += c[x] + min(d[y], (c[y] - c[x]) / 2);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4224