akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<string, int>;
using T = tuple<string, int, int>;

int main()
{
    int n;
    cin >> n;
    T q[n];
    rep(i, n)
    {
        string s;
        int x;
        cin >> s >> x;
        //pair,tpuleの初期化はmale_pair/make_tpuleがよい
        q[i] = make_tuple(s, -1 * x, i + 1);
    }
    sort(q, q + n);
    rep(i, n) cout << get<2>(q[i]) << endl;
}

Measured memory_bytes: 3660
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sbu=new StringBuilder();
        
        while(true){
            String[] num=buf.readLine().split(" ");
            int x=Integer.parseInt(num[0]);
            int y=Integer.parseInt(num[1]);
            
            if(x == 0 && y == 0)break;
            
            for(int i=0; i<x; i++){
                for(int j=0; j<y; j++){
                    sbu.append("#");
                }
                sbu.append("\n");
            }
            sbu.append("\n");
        }
        System.out.print(sbu);
    }
}

Measured memory_bytes: 25692
package main
import (
  "fmt"
  "strconv"
)
func main() {
  var n string
  var m,x,t int
  fmt.Scan(&n)
  m = 0
  for i:=0;i<len(n);i++ {
    t,_ = strconv.Atoi(n[i:i+1])
    m += t
  }
  x,_ = strconv.Atoi(n[0:1])
  t = 9*(len(n)-1)+x-1
  if m < t { m = t }
  fmt.Println(m)
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.abs(b - a) <= w ? 0 :Math.abs(b - a) - w);

		sc.close();

	}

}

Measured memory_bytes: 35976
#include <stdio.h>

int main(void)
{
	int num[100];
	int i, j;
	int out[100];
	
	i = 0;
	j = 0;
	
	while (scanf("%d", &num[i]) != EOF){
		if (num[i] == 0){
			out[j] = num[i - 1];
			j++;
			i -= 2;
		}
		i++;
	}
	
	for (i = 0; i < j; i++){
		printf("%d\n", out[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Problem> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new Problem());
        }

        for (int i = 0; i < m; i++) {
            int num = sc.nextInt();
            String result = sc.next();
            Problem p = list.get(num-1);
            if (result.equals("AC")) {
                p.isAc = true;
            } else if (p.isAc == false) {
                p.submit++;
            }
        }

        int acNum = 0;
        int waNum = 0;
        for (int i = 0; i < n; i++) {
            Problem p = list.get(i);
            if (p.isAc) {
                acNum++;
                waNum += p.submit;
            }
        }
        System.out.printf("%d %d", acNum, waNum);
    }

    class Problem {
        int submit = 0;
        boolean isAc = false;
    }
}


Measured memory_bytes: 66116
#include <stdio.h>

int main(void)
{
  int N;
  int A[100];
  int i,j,minj;
  int count=0;
  int temp;

  scanf("%d",&N);
  for(i=0;i<N;i++)
  {
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++)
  {
    minj = i;
    for(j=i;j<N;j++)
    {
      if(A[j] < A[minj]) minj = j;
    }
    if(i != minj)
    {
      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;
      count++;
    }
  }

  for(i=0;i<N-1;i++)
  {
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);

  return 0;
}

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

public class Main {

    int[] a;
    int[] b;

    void solve() {
	int N = sc.nextInt();
	a = sc.nextIntArray(N);

	b = Arrays.copyOf(a, N);
	Arrays.sort(b);
	Map<Integer, Integer> map = new HashMap<Integer, Integer>();
	for (int i = 0; i < b.length; i++) {
	    map.put(b[i], i);
	}

	int ans = 0;
	for (int i = 0; i < a.length; i++) {
//	    System.out.println(c[a[i]]);
	    if (i % 2 == 0) {
		if (map.get(a[i]) % 2 != 0) {
		    ans++;
		}
	    }
	}
	System.out.println(ans);
    }

    void print(int[] a) {
	out.print(a[0]);
	for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
	out.println();
    }

    public static void main(String[] args) throws Exception {
	new Main().run();
    }

    MyScanner sc = null;
    PrintWriter out = null;
    public void run() throws Exception {
	sc = new MyScanner(System.in);
	out = new PrintWriter(System.out);
	for (;sc.hasNext();) {
	    solve();
	    out.flush();
	}
	out.close();
    }

    class MyScanner {
	String line;
	BufferedReader reader;
	StringTokenizer tokenizer;

	public MyScanner(InputStream stream) {
	    reader = new BufferedReader(new InputStreamReader(stream));
	    tokenizer = null;
	}
	public void eat() {
	    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		try {
		    line = reader.readLine();
		    if (line == null) {
			tokenizer = null;
			return;
		    }
		    tokenizer = new StringTokenizer(line);
		} catch (IOException e) {
		    throw new RuntimeException(e);
		}
	    }
	}
	public String next() {
	    eat();
	    return tokenizer.nextToken();
	}
	public String nextLine() {
	    try {
		return reader.readLine();
	    } catch (IOException e) {
		throw new RuntimeException(e);
	    }
	}
	public boolean hasNext() {
	    eat();
	    return (tokenizer != null && tokenizer.hasMoreElements());
	}
	public int nextInt() {
	    return Integer.parseInt(next());
	}
	public long nextLong() {
	    return Long.parseLong(next());
	}
	public double nextDouble() {
	    return Double.parseDouble(next());
	}
	public int[] nextIntArray(int n) {
	    int[] a = new int[n];
	    for (int i = 0; i < n; i++) a[i] = nextInt();
	    return a;
	}
    }
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int num = 0;
  int ans = 0;
  for(int i = 1; i < N; i++){
    string a = S.substr(0,i);
    string b = S.substr(i,N - i);
    int cnt = 0;
      for(char c = 'a'; c <= 'z'; c++){
        
        bool right = false;
        bool left = false;
         for(int j = 0; j < a.size(); j++){
           if(a[j] == c) left = true;
         }
         for(int k = 0; k < b.size(); k++){
           if(b[k] == c) right = true;
         }
         if(right && left) cnt++;

    } 
    if(ans < cnt) ans = cnt;
}

cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include<map>

using namespace std;
int main()
{    
    int N; cin >> N;
    int A[N];
    map<int,int> mp;
    for(int a = 0;a < N;a++){
        cin >> A[a];
        if(mp.find(A[a]) != mp.end()){
            mp[A[a]] += 1;
        }else{
            mp[A[a]] = 1;
        }
    }
    int ans = 0;
    for(pair<int,int> a : mp){
        if(a.first > a.second){
            ans += a.second;
        }else{
            ans += a.second - a.first;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    ll sum = 0;
    for(int i = 0 ; i <= n ; i++){
        int t = i;
        int s = 0;
        while(t){
            s += t % 10;
            t /= 10;
        }
        if(s <= b && s >= a){
            sum += i;
        }
    }
    cout << sum << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 
const int INF = 1e9;
vector<int> dx = {0, -1, 1, 0};
vector<int> dy = {1, 0, 0, -1};

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	forn(i, h) cin >> v[i];
	int mx = 0;
	
	forn(i, h) {
		forn(j , w) {
			if(v[i][j] == '#') continue;
			vector<vector<int>> seen(h, vector<int>(w, INF));
			queue<pii> q;
			q.push({i,j});
			seen[i][j] = 0;

			while(!q.empty()) {
				pii p = q.front();
				q.pop();
				forn(k, 4) {
					int f = p.fi + dx[k];
					int	s = p.se + dy[k];
				   	if(f < 0 || f > h-1 || s < 0 || s > w-1) continue;
					if(v[f][s] == '#' || seen[f][s] != INF) continue;
					q.push({f,s});
					seen[f][s] = seen[p.fi][p.se] + 1;

				}
			}

			forn(i, h)
			   	forn(j, w)
			   		if(v[i][j] != '#') mx = max(mx, seen[i][j]);
		}
	}

	cout << mx << endl;
	return 0;
}



Measured memory_bytes: 3644
import qualified Data.IntSet as IntSet
import           Data.Maybe  (fromJust)

main :: IO ()
main = do
  n <- readLn
--  print $ solve n 0
  print $ solve'' n

solve :: Int -> Int -> Int
solve 0 i = i
solve n i = solve (n - k) (i + 1)
  where
   k = maximum . filter (n >= ) $ candidates

candidates = a ++ b ++ c
a = [1]
b = filter (<= 10^5) (map (6^) [1..6])
c = filter (<= 10^5) (map (9^) [1..9])

solve' :: Int -> Int
solve' 0 = 0
solve' n
  | elem n candidates = 1
  | otherwise = 1 + (solve' (last next))
  -- | otherwise = 1 + (minimum $ map solve' next)
    where
      next = filter (0 <) . map (n - ) $ candidates
-- maximum . map (\m -> 1 + solve' m) . filter (0 <) . map (n - ) $ candidates

solve'' :: Int -> Int
solve'' n = bfs 0 $ IntSet.singleton n
  where
    bfs i visited
      | IntSet.member 0 visited = i
      | otherwise = bfs (i + 1) $ visit candidates visited

    visit :: [Int] -> IntSet.IntSet -> IntSet.IntSet
    visit as vs = IntSet.fromList $ [v - a | a <- as, v <- (IntSet.elems vs), v - a >= 0]


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

int main()
{
        int N;
        cin >> N;
        int D,X;
        cin >> D >> X;
        int ans = 0;
        int A;
        for (;cin>>A;){
                ans += (D-1)/A + 1;
        }
        ans += X;
        cout << ans << "\n";
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc157/tasks/abc157_e

from string import ascii_lowercase
from bisect import bisect_left, insort
from collections import defaultdict

N = int(input())
S = list(input())
Q = int(input())

locs = {c: [] for c in ascii_lowercase}
for i in range(N):
    locs[S[i]].append(i + 1)

for _ in range(Q):
    qt, l, r = input().split()
    l = int(l)
    if int(qt) == 1:
        if S[l - 1] != r:
            locs[S[l - 1]].remove(l)
            S[l - 1] = r
            insort(locs[r], l)
    else:
        count = 0
        r = int(r)
        for ch in ascii_lowercase:
            if len(locs[ch]) > 0:
                left = bisect_left(locs[ch], l)
                if left != len(locs[ch]):
                    if locs[ch][left] <= r:
                        count += 1

        print(count)

Measured memory_bytes: 107512
// Problem : F - Intervals on Tree
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define plii pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void solve(){
	int a,b;
	int n;
	rd(n);
	// error(n);
	int ans=0;
	FOR(i,n){
		ans+=(i+1)*(n-i);
	}
	FOR(i,n-1){
		rd(a,b);
		a--,b--;
		ans-=(min(a,b)+1)*(n-max(a,b));
	}
	cout<<ans;
	return;	
}


int32_t main() {
    // fint{
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

int i,j;

struct edge {
    int to;
    int cost;
};

typedef long long ll;
using namespace std;
using P = pair<int, int>;

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second > b.second;
}

int main(void) {
    int a,p,ans;
    cin >> a >> p;
    cout << (a*3+p)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  
  int p;
  
  p=0;
 
   cin >> S >> T;
  
  for ( int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i) ) {
      p++;
    }
  }
    cout << p << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]

p = 10 ** 9 + 7

s = sum(A) % p
X = [s]
for i in range(N):
    s = s + p - A[i]
    s %= p
    X.append(s)
# print(X)

ans = 0
for i in range(N-1):
    #for j in range(i+1, N):
    #    ans += A[i] * A[j]
    #    ans %= p
    ans += A[i] * X[i+1]
    ans %= p
print(ans)


Measured memory_bytes: 31504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int n, m;
    cin >> n >> m;
    
    //sum = 1 + n*m - n;
    int sum = 1;
    
    int i = 0;
    for(i; sum<m; i++){
        sum += n -1;
    }
    
    int ans = i;
    
    cout << ans << endl;
    return 0;
}


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

int main(){
	int data[31];
	int w,n;
	cin >> w >> n;
	for(int i=1;i<=w;i++)
		data[i] = i;
		
	while(n--){
		int a,b;
		scanf("%d,%d\n",&a,&b);
		swap(data[a],data[b]);
	}
	for(int i=1;i<=w;i++)
		cout << data[i] << endl;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    int x, b, f, r, v, arr[4][3][10];
    for(int i = 0; i < 4; i++)
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 10; k++)
                arr[i][j][k] = 0;
    cin >> x;
    for(int i = 0; i < x; i++){
        cin >> b >> f >> r >> v;
        arr[b-1][f-1][r-1] += v;
    }

    for(int i = 0; i < 4; i++){
        if (i != 0) cout << "####################" << endl;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++)
            cout << " " << arr[i][j][k];
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3116
// Author: Wenxing Mei
//   File: c.cpp
//   Date: 2019-04-05 10:01
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vi l(n);
    rep(i, 0, n) cin >> l[i];
    std::function<int(int, int, int, int, int)> dfs =
        [&](int idx, int la, int lb, int lc, int gc) -> int {
        if (idx == n) {
            if (!la || !lb || !lc) return 1e9;
            return abs(a - la) + abs(b - lb) + abs(c - lc) + 10 * (gc - 3);
        }
        int ret = 1e9;
        ret = min(ret, dfs(idx + 1, la + l[idx], lb, lc, gc + 1));
        ret = min(ret, dfs(idx + 1, la, lb + l[idx], lc, gc + 1));
        ret = min(ret, dfs(idx + 1, la, lb, lc + l[idx], gc + 1));
        ret = min(ret, dfs(idx + 1, la, lb, lc, gc));
        return ret;
    };
    cout << dfs(0, 0, 0, 0, 0) << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
#define Graph vector<vector<int>>
using namespace std;

main()
{
        int n,t; cin>>n>>t;

        vi v(n);
        rep(i,n)cin>>v[i];

        vi u(n);
        rep(i,n)
        {
                if(i==0)u[i]=v[i];
                else u[i]=min(u[i-1],v[i]);
        }

        map<int,int> m;
        rep(i,n)m[v[i]-u[i]]++;

        int tmp=0;
        int ans;
        each(it,m)
        {
                if(it.first>tmp)
                {
                        tmp=it.first;
                        ans=it.second;
                }
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    double r; cin >> r;
    double ans = 2 * r * M_PI;
    cout << setprecision(10) << ans << endl;
}



Measured memory_bytes: 3788
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define ll long long
#define ull unsigned long long
//#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 1e5 + 123;
int n,q;
int a[N];
main(){
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n , a;
	cin >> n >> a;
	cout << 3ll * (n - __gcd(n , a));
	

}     

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    //for (int i =0;i<s.size()/2+1;i++){
    //    cout<<s[i*2];
    //} 違いが分からない
    //cout<<endl;
    //for (int i = 0; i < s.length(); i++) {
    //if (i % 2 == 0) cout << s[i];
  	//cout<<endl;
  	for (int i =0;i<s.size();i+=2){cout << s[i];}
  cout<<endl;
  }
  




Measured memory_bytes: 512
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
void dfs(ll now, ll use, ll &n, ll &cnt)
{
    if (now > n)
    {
        return;
    }
    if (use == 7)
    {
        cnt++;
    }
    dfs(now * 10 + 3, use | 0b100, n, cnt);
    dfs(now * 10 + 5, use | 0b010, n, cnt);
    dfs(now * 10 + 7, use | 0b001, n, cnt);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll k = 0;
    V res;
    while (n != 0)
    {
        ll temp = 1;
        if (k % 2 == 1)
        {
            temp *= -1;
        }
        ll t = pow(2, k);
        if (abs(n) % (t*2)!= 0)
        {
            n -= temp * t;
            res.push_back(1);
        }
        else
        {
            res.push_back(0);
        }
        k++;
      //  cout<<n<<" "<<t<<endl;
    }
    if(res.empty()){
        cout<<0<<endl;
        return 0;
    }
    reverse(all(res));
    for(auto i:res){
        cout << i;
    }
    cout << endl;
}


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

int dp[40][1<<14];
int v[40];

inline int pnt(int c){
    return c>0?50+c*10:0;
}

int toBit(int c[7],int p){
    int bit=0;
    for(int i=1;i<7;i++){
        bit=(bit<<2)|c[i];
    }
    bit=(bit<<2)|(~v[p+7]?v[p+7]:0);
    return bit;
}

void solve(){
    memset(v,-1,sizeof(v));
    for(int i=0;i<25;i++)cin>>v[i],v[i]--;
    memset(dp,-1,sizeof(dp));
    int start=0;
    for(int i=0;i<7;i++)start=(start<<2)|(~v[i]?v[i]:0);
    dp[0][start]=0;
    for(int i=0;i<25;i++){

        for(int S=0;S<(1<<14);S++){
            if(dp[i][S]==-1)continue;
            int c[7];
            for(int j=0;j<7;j++)c[6-j]=S>>(j*2)&3;

            int to=((S<<2)&((1<<14)-1))|(~v[i+7]?v[i+7]:0);
            if(i%5==4||i>=20){
                dp[i+1][to]=max(dp[i+1][to],dp[i][S]+pnt(c[0]));
                continue;
            }
            for(int j=0;j<4;j++){
                to=toBit(c,i);
                dp[i+1][to]=max(dp[i+1][to],dp[i][S]+pnt(c[0]));

                if(~v[i])c[0]=(c[0]+1)%4;
                if(~v[i+1])c[1]=(c[1]+1)%4;
                if(~v[i+5])c[5]=(c[5]+1)%4;
                if(~v[i+6])c[6]=(c[6]+1)%4;
            }

        }
    }

    int ans=0;
    for(int i=0;i<(1<<14);i++)ans=max(ans,dp[25][i]);

    cout<<ans<<endl;

}

int main(){
    int n;cin>>n;
    while(n--)solve();
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,m,s,c;
    long long  arr[3][200];
    cin>>n;
    for(i=0;i<2;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>arr[i][j];
        }
    }

    c=-10000;
    k=0;
    l=0;
    for(k=0;k<n;k++)
    {
        s=0;
        for(i=k,j=0;i>=0;i--)
        {
            s+=arr[j][i];
        }
        for(i=k,j=1;i<n;i++)
        {
            s+=arr[j][i];
        }
        if(s>c)
        {
            c=s;
        }
    }
    if(c<0)
    {
        c=0;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
      p: [Usize1; n],
      c: [i64; n]
   }

   let mut ans = c[0];
   for i in 0..n {
      let mut s = vec![c[i]];
      let mut now = p[i];
      let mut tot = c[i];
      while now != i {
         s.push(c[now]);
         tot += c[now];
         now = p[now];
      }

      let l = s.len();
      let mut res = 0;
      for i in 0..l {
         res += s[i];
         if i + 1 > k {
            break;
         }
         if tot > 0 {
            ans = max(ans, res + ((k - i - 1) / l) as i64 * tot);
         } else {
            ans = max(ans, res);
         }
      }
   }
   println!("{}", ans);
}


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

int main() {

    int n,k;
    cin >> n >> k;

    long long value = 0;
    rep(i,n){

        if(i==0) value = k;
        else     value*= (k-1);
    }

    cout << value << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false)
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
    return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}


int main(){
	string s; cin >> s;
	int n = s.size();
	string s1 = s.substr(0, ((n-1)/2));
	string s2 = s.substr((n+3)/2 -1);
	string rs1 = s1; reverse(rs1.begin(), rs1.end());
	string rs2 = s2; reverse(rs2.begin(), rs2.end());
	string rs = s; reverse(s.begin(), s.end());
	if (s == rs && s1 == rs1 && s2 == rs2) puts("Yes");
	else puts("No");

    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
#include "stdarg.h"
#include "math.h"
#include "limits.h"

#define SWAP(type,a,b) do{type c=a;a=b;b=c;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define DEBUG(format,a) do{printf(#a" : "#format,a);}while(0)


int main() {
	long int k, a, b, ans;
	scanf("%ld%ld%ld", &a, &b,&k);
  
    if(k>=a){
      k-=a;
      a=0;
     b=(k>=b)?0:b-k;
    }else{
      a-=k;
    }
	//DEBUG(%d,k);
	printf("%ld %ld", a, b);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
bool hh(int n,int m,int k)
{
	if(n>m)
		swap(n,m);
	if(k==0)
		return true;
	if(k==n||k==m)
		return true;
	if(k%n==0||k%m==0)
		return true;
	return false;
}
 
int main()
{
	int n,m,k,f=0;
	cin>>n>>m>>k;
	for(int i=0;i<=m;i++)
		for(int j=0;j<=n;j++)
			if(i*n+j*m-2*(i*j)==k)
				f=1;
	if(f)
		cout<<"Yes";
	else
		cout<<"No";
 
 
	return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
x.sort()
min_d = 10**18
if x[0] != x[n-1]:
    for p in range(x[0],x[n-1]):
        sm = 0
        for j in range(n):
            sm += (x[j] - p)**2
        else:
            min_d = min(min_d,sm)
    print(min_d)
else:
    print(0)



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){

	int A,B,C,D,P;
	
	cin >> A >> B >> C >> D >> P;
		
	int planX, planY;

	planX = A * P;

	if(C > P)
		planY = B;
	else
		planY = B + D * (P - C);

	if(planX < planY)
		cout << planX << endl;
	else
		cout << planY << endl;

	/*
	int A,B,C,D,E;
	cin >> A >> B >> C >> D >> E;

	int answer;
	if(A < 0){
		answer = -A * C + D + B * E;
	}
	if(A > 0){
		answer = (B - A) * E;
	}
	cout << answer << endl;
	*/

	return 0;
}


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

Measured memory_bytes: 1156
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int x,a;
  cin >> x >> a;
  if(x < a) printf("0\n");
  else printf("10\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B), X(Q);
  REP(i, A) { cin >> s[i]; }
  REP(i, B) { cin >> t[i]; }
  REP(i, Q) { cin >> X[i]; }
  s.push_back(-INF);
  s.push_back(INF);
  t.push_back(-INF);
  t.push_back(INF);
  sort(ALL(s));
  sort(ALL(t));

  REP(i, Q) {
    ll x = X[i];

    auto s_i = lower_bound(ALL(s), x);
    auto t_i = lower_bound(ALL(t), x);

    ll LL = max(abs(*(s_i - 1) - x), abs(*(t_i - 1) - x));
    ll RR = max(abs(*(s_i)-x), abs(*(t_i)-x));

    ll LR_s = min(2 * abs(*(s_i - 1) - x) + abs(*(t_i)-x),
                  2 * abs(*(s_i)-x) + abs(*(t_i - 1) - x));

    ll LR_t = min(2 * abs(*(t_i - 1) - x) + abs(*(s_i)-x),
                  2 * abs(*(t_i)-x) + abs(*(s_i - 1) - x));

    ll ans = min(min(min(LL, RR), LR_s), LR_t);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3680
package main

import "fmt"

func main() {
	var a, n, k, q int
	fmt.Scan(&n, &k, &q)
	temp := make(map[int]int, n)
	for i := 0; i < q; i++ {
		fmt.Scan(&a)
		temp[a]++
	}

	for i := 1; i <= n; i++ {
		if q-temp[i] < k {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

Measured memory_bytes: 6144
// DP

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)

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

int main() {
  int n; cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

// 無限大の値
  const long long INF = 1LL << 60;

// DP テーブル
  long long dp[100010];

// DP テーブル全体を初期化 (最小化問題なので INF に初期化)
  for (int i = 0; i < 100010; ++i) dp[i] = INF;

// 初期条件
  dp[0] = 0;

// ループ
  for (int i = 0; i < n-1; ++i) {
    chmin( dp[i+1], dp[i] + abs(h[i]-h[i+1]) );
    if(i>0)
    chmin( dp[i+1], dp[i-1] + abs(h[i-1]-h[i+1]) );
  }

// 解を得て出力
  cout << dp[n-1] << endl;
  
}

Measured memory_bytes: 4556
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll x, k, d;
    cin >> x >> k >> d;
    
    x = abs(x);

    ll c = abs(x) / d;

    if (k >= c) {
        x %= d;
        if ((k - c) % 2 == 1) print(abs(d - x));
        else print(abs(x));
    } else {
        print(abs(x) - k * d);
    }
    
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(ll i = b; i < e; i++)
#define forg(i, b, e, m)  for(ll i = b; i < e; i+=m)
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e18);
#define tam 320000
#define tamlog 61
#define ptr nodo*

typedef pair<ii,ll> iii;
int sum[tam];
void update(int pos,int valor)
{
    for(int i=pos;i<tam;i+=(i&-i))
    {
        sum[i]+=valor;
    }
}
int query(int pos)
{
    int tot=0;
    for(int i=pos;i>0;i-=(i&-i))
        tot+=sum[i];
    return tot;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);    
    int n,m;
    cin>>n>>m;
    vector<ii> lst;
    int iz,der;
    forr(i,0,n)
    {
        cin>>iz>>der;
        lst.pb(ii(der-iz,iz));
    }
    sort(lst.begin(),lst.end());
    int pos=0;
    forr(d,1,m+1)
    {
        while(pos<lst.size() && lst[pos].F+1<d)
        {
            iz=lst[pos].S;
            der=iz+lst[pos].F;            
            update(iz,1);
            update(der+1,-1);
            pos++;
        }
        int auxans=lst.size()-pos;
        for(int j=d;j<=m;j+=d)
        {
            auxans+=query(j);
        }
        cout<<auxans<<endl;
    }


}
// PLUS ULTRA!

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

typedef pair<int,int> P;

int w, h, sx, sy;
char t[22][22];

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

void solve(){
  stack<P> open;
  int ans = 0;

  open.push(P(sx, sy));
  t[sy][sx] = '#';

  while(!open.empty()){
    P p = open.top();
    open.pop();
    ans++;

    for(int i = 0; i < 4; i++){
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];

      if(nx < 0 || w <= nx || ny < 0 || h <= ny || t[ny][nx] != '.') continue;
      t[ny][nx] = '#';
      open.push(P(nx, ny));
    }
  }

  cout << ans << endl;
}

int main(){
  while(cin >> w >> h, w || h){
    for(int i = 0; i < h; i++){
      cin >> t[i];
      for(int j = 0; j < w; j++){
        if(t[i][j] == '@'){
          sx = j;
          sy = i;
          t[i][j] = '.';
        }
      }
    }
    solve();
  }
}

Measured memory_bytes: 1204
import java.util.*;
public class Main {
 
    public void doIt(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n != 0){
            //ハッシュを用意する
            HashMap<Integer,Long> list = new HashMap<Integer,Long>();
            //入力順を記憶する配列
            ArrayList<Integer> inputlist = new ArrayList<Integer>();
            for(int i=0; i < n; i++){
                int num = sc.nextInt();
                long sales = sc.nextLong();
                long price = sc.nextLong();
                long sum = sales * price;
                //すでにあるのならカウント追加
                if(list.containsKey(num)){
                    list.put(num, (list.get(num) + sum ));
                }
                else{
                    list.put(num, sum);
                    //配列に格納
                    inputlist.add(num);
                }
            }
 
            boolean flg = false;
            for(int key: inputlist){
                if(list.get(key) >= 1000000){
                    System.out.println(key);
                    flg = true;
                }
            }
            if(!flg){
                System.out.println("NA");
            }
 
            n = sc.nextInt();
        }
 
    }
    public static void main(String[] args) {
        Main obj = new Main();
        obj.doIt();
 
    }
 
}

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

int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a==0){
    cout << "1";
  }
  if(b==0){
    cout << "2";
  }
  if(c==0){
    cout << "3";
  }
  if(d==0){
    cout << "4";
  }
  if(e==0){
    cout << "5";
  }
}

Measured memory_bytes: 3532
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {
    ll N, K;
    cin >> N;
    cin >> K;
    int a[N];
    rep(i, 0, N){
        cin >> a[i];
    }

    int ans = 1;
    int remain = N - K;
    ans += (remain + K - 2)/ (K - 1);
    cout << ans << endl;

}

Measured memory_bytes: 640
k = int(input())
pair = []
if 2 <= k <= 100:
    for i in range(1, k + 1):
        if 0 == i % 2:
            for j in range(1, k + 1):
                if 1 == j % 2:
                    pair.append((i, j))
                else:
                    continue
        else:
            continue
    #print(pair)
    print(len(pair))
else:
    print('hoge!')

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		int num = S.length();
		int i = 0;
		StringBuilder ans = new StringBuilder();
		while (i < num) {
			ans.append("x");
			i++;
		}

		System.out.println(ans);

	}

}

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

#define int long long

#define PB push_back
#define PPB pop_back
#define MK make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;

static const int INF = 1LL << 61;
static const int MOD = 1000000007;
static const int MAX_N = 100005;

int h[MAX_N], t[MAX_N], a[MAX_N], n;

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

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> t[i];
    for (int i = 1; i <= n; ++i) cin >> a[i];
    fill(h, h + MAX_N, -1);
    h[0] = h[n + 1] = 0;

    for (int i = 1; i <= n; ++i) {
        if (t[i] != t[i - 1]) h[i] = t[i];
    }

    {
        int mx = 0;
        for (int i = n; 0 < i; --i) {
            if (a[i] != a[i + 1]) {
                if (h[i] != -1 && h[i] != a[i]) {
                    cout << 0 << endl;
                    return 0;
                }
                h[i] = a[i];
            }
            mx = max(mx, h[i]);
            if (a[i] < mx) {
                cout << 0 << endl;
                return 0;
            }
            if (h[i] != -1 && t[i] < h[i]) {
                cout << 0 << endl;
                return 0;
            }
        }
        if (mx != a[1] || mx != t[n]) {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (0 < h[i]) continue;
        int tmp = min(a[i], t[i]);
        ans *= tmp;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> vec(N);
    ll wa = 0,lo = 0;
    rep(i,N){
        cin >> vec[i];
        wa += vec[i];
        chmax(lo,vec[i]);
    }
    if(lo * 2 < wa)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=(m);i<(n);i++)
#define sz(x) ((x).size())

typedef vector<long long> vi;
typedef vector<vi> mat;

int N,M,A,B,C,T,S[55];

mat mul(mat& A,mat& B){
	int n=sz(A);
	mat C(n,vi(n));
	rep(i,n)rep(j,n){
		rep(k,n)C[i][j]+=A[i][k]*B[k][j];
		C[i][j]%=M;
	}
	return C;
}

mat pow(mat A,int e){
	int n=sz(A);
	mat B(n,vi(n));
	rep(i,n)B[i][i]=1;
	while(e){
		if(e&1)B=mul(B,A);
		A=mul(A,A);
		e>>=1;
	}
	return B;
}

int main2(){
	mat a(N,vi(N));
	rep(i,N){
		if(i>0)a[i][i-1]=A;
		a[i][i]=B;
		if(i<N-1)a[i][i+1]=C;
	}
	a=pow(a,T);
	rep(i,N){
		long long res=0;
		rep(j,N)res+=S[j]*a[i][j];
		cout<<res%M<<(i==N-1?"\n":" ");
	}
}

int main(){
	while(cin>>N>>M>>A>>B>>C>>T && N){
		rep(i,N)cin>>S[i];
		main2();
	}
}

Measured memory_bytes: 1300
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string>
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    string w[N];
    char a, b;
    cin >> w[0];
    int y = 0;
    for(int i = 0; i<N-1;i++){
        cin >> w[i+1];
        
        if(w[i].back()!=w[i+1].front()){
            
            y = 1;
            break;
        }
      for(int j = 0;j<=i;j++){
          if(w[j]==w[i+1]){
              
              y = 1;
              break;
          }
      }
        
       
 
 
    }
    if(y==0){
        cout << "Yes";
    }else{
     cout << "No";
    }
    
    return 0;
}
        

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int n;
int a[2][100];
int d[2][100];
int dx[2]={1,0};
int dy[2]={0,1};

void bfs(){
	queue<PII> q;
	rep(i,2)rep(j,n) d[i][j]=0;
	d[0][0]=a[0][0]; q.push(MP(0,0));
	while(!q.empty()){
		PII p=q.front(); q.pop();
		rep(i,2){
			PII next=MP(p.first+dx[i],p.second+dy[i]);
			if(next.first>=2||next.second>=n) continue;
			if(d[next.first][next.second]<d[p.first][p.second]+a[next.first][next.second]){
				d[next.first][next.second]=d[p.first][p.second]+a[next.first][next.second];
				q.push(next);
			}
		}
	}
}

signed main(){
	cin>>n;
	rep(i,2)rep(j,n) cin>>a[i][j];
	bfs();
	cout<<d[1][n-1]<<endl;


  return 0;
}


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

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

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

int A, B;

bool ask(int a, int b) {
	printf("? %d %d\n", a, b);
	fflush(stdout);
	char c[4];
	scanf("%s", c);
	return (c[0] == 'Y');
}

int main() {
	cin >> A >> B;

	if (A <= B) {
		puts("Impossible");
		return 0;
	}

	vi vec;
	int zan = B + 1;
	int cur = 0;

	while (vec.size() < zan) {
		if (vec.size() == 0) {
			vec.pb(cur++);
			continue;
		}
		bool f = ask(vec.back(), cur);

		if (!f) {
			--zan;
			vec.pop_back();
		} else {
			vec.pb(cur);
		}
		cur++;
	}

	int u = vec.back();
	string ans = "! ";

	rep(i, A + B) {
		int f = ask(u, i);
		ans.pb(f ? '1' : '0');
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int x, y, z;

void input()
{
  cin >> x;
  cin >> y;
  cin >> z;
}

void solve()
{
  int res = 0;
  for(int i = z; i <= x-(y+z); i += y+z)
  {
    res++;
  }
  cout << res;
}

int main()
{
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];

    sort(a, a+N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    rep(i, N) {
        if (i % 2 == 0) Alice += a[i];
        else Bob += a[i];
    }
    cout << Alice - Bob << endl;

    return 0;
}


Measured memory_bytes: 256