akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void) {
	int n, i, k, p, x;
	scanf("%d",&n);
	for (i = 1; i <= n; i++) {
		scanf("%d %d",&k,&p);
		x = k % p;
		if(x != 0)
			printf("%d\n",x);
		else
			printf("%d\n",p);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

int main(){
    char a,b;
    cin >> a >> b;
    string ans = "=";
    if(a < b) ans = "<";
    else if(a > b) ans = ">";
    cout << ans << endl;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, k;
    cin >> n >> k;
    int ans = k * pow(k - 1, n - 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a,b,c;
  int cnt=0;
  scanf("%d %d %d",&a,&b,&c);
  for(int i = a;i<=b;i++)
  {
    if(c%i==0)
        cnt++;
  }
  cout << cnt << endl;
}

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

int main(){
    int N=0;
    cin >> N;
    vector<int>dp(N);
    vector<int>a(N);
    for (int i=0; i<N; i++){
        cin >> a.at(i);
    }
    dp.at(0)=0;

    for(int i=1;i<N;i++){
        if(i-2>=0){
            dp.at(i) = min(dp.at(i-2) + abs(a.at(i)-a.at(i-2)), dp.at(i-1) + abs(a.at(i)-a.at(i-1)));
        }else{
            dp.at(i) = dp.at(i-1) + abs(a.at(i-1) - a.at(i));
        }
    }
    cout << dp.at(N-1) << endl;
} 

Measured memory_bytes: 3920
def main():
    N = int(input())
    value_temp = 0
    value = 0
    for i in range(1 , N+1) :
        if i % 3 == 0 or i % 5 == 0 :
            pass
        else :
            value_temp = i
            value = value + value_temp
    print (value)

if __name__ == '__main__':
    main()


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

int main() {
	string s, t, u;
	cin >> s >> t;
	int a, b;
	cin >> a >> b >> u;

	if (s.compare(u) == 0) {
		a--;
	}
	else {
		b--;
	}
	if (a < 0) a = 0;
	if (b < 0) b = 0;
	
	cout << a << " " << b << "\n";
	return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int x;
int main()
{
    go;
    cin>>x;
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
        if(i*j==x)
        return cout<<"Yes",0;
    cout<<"No";
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] s = Arrays.stream(sc.nextLine().split("")).mapToInt(e -> Integer.parseInt(e)).toArray();
		
		long sum = 0;
		for(int i = 0;i < (1 << s.length - 1);i++) {
			long tmp = 0;
			int p = 0;
			for(int j = 0;j < s.length;j++) {
				tmp += (long) (s[s.length - 1 - j] * mypow(10, p++));
				if((i & (1 << j)) != 0) {
					p = 0;
				}
			}
			
			sum += tmp;
		}

		System.out.println(sum);
    }
	
	private static long mypow(long a, long b) {
		long result = 1;
		for(int i = 1;i <= b;i++) {
			result *= a;
		}
		
		return result;
	}
}

Measured memory_bytes: 26708
A, B, C = list(map(int, input().split()))
K = int(input())
L=[]
L.append(A)
L.append(B)
L.append(C)


n = 0
while L[0] >= L[1]:
    L[1] = L[1]*2
    n = n+1



while L[1] >= L[2]:
    L[2] = L[2]*2
    n = n+1


if n <= K:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 9212
#include<iostream>
#include<deque>
#include<cmath>
#include<cstring>
#include<map>
#include<algorithm>
#include<vector>
#include<ios>
#include<sstream>
#include<locale>
using namespace std;
#define ive(cris) int long long 
#define in(out) long double
#define INF 100000007
int main(){
  int a[256]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin>>x>>y;
  if(a[x]==a[y]){
    cout<<"Yes"<<'\n';
  }
  else{
    cout<<"No"<<'\n';
  }
  return 0;
}


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

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

    long long ans;
    if (N == 1 && M == 1) {
        ans = 1;
    } else if (N == 1) {
        ans = M - 2;
    } else if (M == 1) {
        ans = N - 2;
    } else {
        ans = (M - 2) * (N - 2);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int A,B;
	scanf("%d %d",&A,&B);
	if(A==1){
		A=14;
	}
	if(B==1){
		B=14;
	}
	if(A>B){
		printf("Alice\n");
	}
	else if(A<B){
		printf("Bob\n");
	}
	else{
		printf("Draw\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.ArrayDeque;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Deque;
    import java.util.List;
    import java.util.Scanner;

    //
    public class Main {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int wk =0;
            int ans =0;
            ans=N/2;
            wk=N%2;
            if(wk==1){ans=ans+1;

            }

        System.out.println(ans);
        }
    }

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long 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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, M; cin >> N >> M;
    vector<int> cnt(N+1, 1);
    vector<bool> red(N+1, 0);
    red[1] = true;

    for(int i=0; i<M; ++i){
        int x, y; cin >> x >> y;
        if(cnt[x] == 1 && red[x] == true){
            red[x] = false;
            --cnt[x];
            red[y] = true;
            ++cnt[y];
        } else if(cnt[x] != 1 && red[x] == true){
            --cnt[x];
            red[y] = true;
            ++cnt[y];
        } else if(cnt[x] == 0){
            continue;
        } else {
            --cnt[x];
            ++cnt[y];
        }
    }

    int ans = 0;
    for(int i=1; i<=N; ++i) if(red[i]) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 640
h,n=map(int,input().split())
INF=10**12
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;

ll a, b, c;

/*
qa + qb < qc
a + b + 2qab < c
2qab < c - a - b
4ab < (c - a - b)^2
*/

int main(){
	scanf("%lld%lld%lld", &a, &b, &c);
	puts((4 * a * b < (c - a - b) * (c - a - b) && c - a - b > 0) ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int main() {
    int N;
    cin>>N;
    
    set<int> pre;
    pre.insert(0);
    rep(i,N){
        set<int> nxt;
        int x; cin>>x;
        
        for(auto v:pre){
            nxt.insert(v);
            nxt.insert(-(-v+x));
        }
        swap(pre,nxt);
    }
    
    for(auto v:pre){
        if(-v%10==0) continue;
        else{
            cout1(-v);
            return 0;
        }
    }
    cout1(0);
}

Measured memory_bytes: 896
# Problem - サイコロ

# input
t, s, e, w, n, b = map(int, input().split())
process = list(input())

# initialization
for p in process:
    tmp_t = t
    tmp_s = s
    tmp_e = e
    tmp_w = w
    tmp_n = n
    tmp_b = b

    if p=='S':
        s = tmp_t
        t = tmp_n
        n = tmp_b
        b = tmp_s
    elif p=='N':
        s = tmp_b
        n = tmp_t
        t = tmp_s
        b = tmp_n
    elif p=='W':
        w = tmp_t
        e = tmp_b
        t = tmp_e
        b = tmp_w
    elif p=='E':
        w = tmp_b
        e = tmp_t
        t = tmp_w
        b = tmp_e

# output
print(t)



Measured memory_bytes: 5596
#include<stdio.h>
int main(void)
{
    int n,x,i;
    long int sum=0,min=1000000,max=-1000000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        sum += x;
        if(x>max)max = x;
        if(x<min)min = x;
    }
    printf("%ld %ld %ld\n",min,max,sum);
    return(0);
}



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

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

	int w[n], v[n];
	for (int i = 0; i < n; i++) {
		scanf("%d %d", w + i, v + i);
	}

	long long int pd[100001];

	for (int i = 0; i <= 100000; i++) {
		pd[i] = 1e12 + 10;
	}
	pd[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 100000; j >= 0; j--) {
			if (j - v[i] >= 0) {
				if (w[i] + pd[j - v[i]] <= W) {
					pd[j] = min(pd[j], w[i] + pd[j - v[i]]);
				}
			}
		}
	}

	int i;
	for (i = 100000; i > 0 && pd[i] == 1e12 + 10; i--);
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main() {
	int a, b, c, d, e, sum = 0;
	cin >> a >> b >> c >> d >> e;
	if (a < 0) {
		sum += (c*(0 - a));
		a = 0;
	}
	if (a == 0) {
		sum += d;
	}
	sum += ((b - a)*e);
	cout << sum << endl;
}

Measured memory_bytes: 3052
N = int(input())
L = list(map(int, input().split()))

# print(L)

flag = 1
cnt = 0

while flag >= 1 : 
    
    left_flag = 1
    for i in range(N) : 
        if(L[i] != 0) : 
            left = i
            left_flag = 0
            break
    if(left_flag == 1) : 
        break # これでwhileから脱出
    
    right_flag = 1
    for j in range(left, N, 1) : 
        if(L[j] == 0) : 
            right = j
            right_flag = 0
            break
    if (right_flag == 1) : 
        right = N

    # print(left, right)

    for k in range(left, right, 1) : 
        L[k] -= 1
        
    # print(L)
    
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int a,b,c;
    cin >> a >> b >> c;
    if ((a + b + c) >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<vector<int > >nos(3,vector<int >(3,0));
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>nos[i][j];
  int diff0 = nos[0][1]-nos[0][0];
  int diff1 = nos[0][2]-nos[0][1];
  int diff2 = nos[0][2]-nos[0][0];
  int yes=1;
  for(int i=1;i<3;i++){
  	if(diff0 != nos[i][1]-nos[i][0]){yes=0;break;}
  	if(diff1 != nos[i][2]-nos[i][1]){yes=0;break;}
  	if(diff2 != nos[i][2]-nos[i][0]){yes=0;break;}

  
  }
  if(yes==1)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  long int N, a[200000], count = 0;
  cin >> N;
  for (int i = 0; i<N; i++){
    cin >> a[i];
  }
  sort(a, a+N, greater<int>());
  for (int j = 0; j<N; j++){
    count += a[j/2];
  }
  count -= a[0];
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 5184
#include <cstdlib>
#include<iostream>
using namespace std;
int main(void){
    int a[5],b,c=0;
  for(int i = 0;i < 5;i++){
    cin >> a[i];
  }
  cin >> b;
  
  for(int i = 0;i < 4;i++){
    for(int j = i + 1;j < 5;j++){
      if(abs(a[i] - a[j]) > b){
        cout << ":(";
        return 0;
      }
    }
  }
  cout << "Yay!";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int m=scanner.nextInt();
		int[] x=new int[m];
		for(int i=0;i<m;i++) {
			x[i]=scanner.nextInt();
		}
		if(m<=n) {
			System.out.println(0);
			return;
		}
		Arrays.sort(x);
		int[] y=new int[m];
		for(int i=1;i<m;i++) {
			y[i]=x[i]-x[i-1];
		}
		Arrays.sort(y);
		int ans=0;
		for(int i=0;i<m-1-(n-2);i++) {
			ans+=y[i];
		}
		System.out.println(ans);
	}
}

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


Measured memory_bytes: 26008
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

vi G[300005];
int vis[300005];

int main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int u, v;
		cin >> u >> v;
		G[u*3].PB(v*3+1);
		G[u*3+1].PB(v*3+2);
		G[u*3+2].PB(v*3);
	}
	int s, t;
	cin >> s >> t;
	s = s * 3;
	t = t * 3;
	vector<pi> v({{s, 0}});
	vis[s] = 1;
	for(int i=0;i<v.size();i++) {
		if(v[i].F == t) {
			cout << v[i].S/3 << endl;
			return 0;
		}
		for(int u:G[v[i].F]) {
			if(!vis[u]) {
				vis[u] = 1;
				v.EB(u, v[i].S+1);
			}
		}
	}
	cout << -1 << endl;
}



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

int main(){
  int N; cin >> N;
  string judge[4]={"AC","WA","TLE","RE"};
  int result[4]={};
  for(int i=0; i<N; i++){
    string S; cin >> S;
    for(int j=0; j<4; j++){
      if(S==judge[j]) result[j]++;
    }
  }
  for(int i=0; i<4; i++){
    cout << judge[i] << " x " << result[i] << endl;
  }
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int calory;
    double cpd;
} topping_t;

int cmp_topping_dsc(const void *a, const void *b) {
    return ((topping_t*)b)->cpd - ((topping_t*)a)->cpd;
}

int main(void) {
    int N, A, B, C, c, d, i;
    double cpd;
    topping_t t[100];

    scanf("%d", &N);
    scanf("%d%d", &A, &B);
    scanf("%d", &C);
    for (i = 0; i < N; i++) {
        scanf("%d", &(t[i].calory));
        t[i].cpd = (double)t[i].calory / B;
    }
    qsort(t, N, sizeof(topping_t), cmp_topping_dsc);

    c = C;
    d = A;
    cpd = (double)c / d;
    for (i = 0; i < N; i++) {
        if (cpd < t[i].cpd) {
            c += t[i].calory;
            d += B;
            cpd = (double)c / d;
        }
        else {
            break;
        }
    }
    printf("%d\n", (int)cpd);
    return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll inf=1e10;
int main(void){
    int n,m,R;cin>>n>>m>>R;
    ll d[n][n];
    rep(i,n)rep(j,n) d[i][j]=inf;
    vector<int> r(R);
    rep(i,R){
        cin>>r[i];r[i]--;
    }
    rep(i,m){
        int a,b;ll c;cin>>a>>b>>c;a--;b--;
        d[a][b]=c;d[b][a]=c;
    }
    sort(r.begin(),r.end());//next_permutationは事前にsortが必要（欠陥品じゃねーか）
    rep(k,n)rep(i,n)rep(j,n) chmin(d[i][j],d[i][k]+d[k][j]);
    ll res=inf;
    do{
        ll buf=0;
        rep(i,R-1) buf+=d[r[i]][r[i+1]];
        chmin(res,buf);
    }while(next_permutation(r.begin(),r.end()));
    cout<<res<<endl;
}

Measured memory_bytes: 512
N = int(input())
L = map(int, input().split())
SL = sorted(list(L))
# print('SL', SL)
import bisect

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ab = SL[i] + SL[j]
        # print(i, j)
        # print(SL[i], SL[j])
        r = bisect.bisect_left(SL, ab)
        l = j + 1
        # print('r', r)
        # print('l', l)
        # print('---')
        ans += max(0, r - l)

print(ans)

Measured memory_bytes: 3188
#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<int, int>;

int main()
{
    int n;
    cin >> n;
    int ans = 1;
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        int x = i;
        int cnt = 0;
        while (x % 2 == 0) {
            x /= 2;
            cnt++;
        }
        if (cnt > mx) {
            ans = i;
            mx = cnt;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
char s[N];
int n,f[N],sum[N],nxt[N][3],ans=0;
int main() {
    scanf("%s",s+1),n=strlen(s+1);
    int fl=1;
    for(int i=2;i<=n;i++) fl&=(s[i]!=s[i-1]);
    if(fl) return puts("1"),0;
    for(int i=1;i<=n;i++) sum[i]=(sum[i-1]+(s[i]=='a')+1)%3;
    for(int i=0;i<3;i++) nxt[n+1][i]=n+1;
    for(int i=n;i;i--) {
        for(int j=0;j<3;j++) nxt[i][j]=nxt[i+1][j];
        nxt[i][sum[i]]=i;
    }
    f[0]=1;
    for(int i=0;i<=n;i++) {
        for(int j=1;j<3;j++)
            if(nxt[i+1][(sum[i]+j)%3]<=n) inc(f[nxt[i+1][(sum[i]+j)%3]],f[i]);
        if(i&&sum[i]==sum[n]) inc(ans,f[i]);
    }
    printf("%d\n",ans);
    return 0;
}


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

signed main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
  }
  vector<int> y = X;
  map<int, int> where;
  sort(y.begin(), y.end());
  for (int i = 0; i < N; ++i) {
    where[y[i]] = i;
  }
  for (int i = 0; i < N; ++i) {
    if (where[X[i]] < N / 2) {
      cout << y[N / 2] << endl;
    } else {
      cout << y[N / 2 - 1] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int x,n; cin >> x >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));

    int d = INF;
    int ans = 0;
    for (int i=-101; i<=101; i++) {
        if (binary_search(all(p),i)) continue;
        if (d > abs(x-i)) {
            d = abs(x-i);
            ans = i;
        }
    }
    cout << ans << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int temp = N, hashad = 0;
    while (temp > 0) {
        hashad += temp % 10;
        temp /= 10;
    }
    if (N % hashad == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		String i=String.valueOf(s.charAt(k-1)).toLowerCase();
		System.out.println(s.substring(0,k-1)+i+s.substring(k,s.length()));
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = int(5003);
const int inf = int(1e18);

struct TPerson {
    int h, p;
    bool operator<(const TPerson& o) const& {
        return h + p < o.h + o.p;
    }
} p[N];
int n, f[N][N], res;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n; fill_n(&f[0][0], N * N, inf);
    for(int i = 1; i <= n; ++i) cin >> p[i].h >> p[i].p;
    sort(p + 1, p + n + 1); f[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        f[i][0] = 0;
        for(int j = 1; j <= i; ++j) {
            f[i][j] = f[i - 1][j];
            if(f[i - 1][j - 1] <= p[i].h) f[i][j] = min(f[i][j], f[i - 1][j - 1] + p[i].p);
        }
    }
    res = 0;
    for(int i = 1; i <= n; ++i) if(f[n][i] < inf) res = i;
    cout << res;
}


Measured memory_bytes: 195968
#include<iostream>
#include<cstring>

using namespace std;

const int MAX_N = 100000;
const int MAX_H = 1000000000;

int N, K;
int h[MAX_N+1], cost[MAX_N+1];

void solve() {
    for (int i=1; i<=N; i++) {
        cost[i] = MAX_H;
    }  
    for (int i = 1; i <= N; i++) {
        if (i == 1) {
            cost[i] = 0;
        } else {
            for (int j = max(1, i-K); j < i; j++) {
                cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j]));
            }
        }
    }
    cout << cost[N] << endl;
}

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    solve();
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, a, b, c) = (v[0], v[1], v[2], v[3]);
    let a = a as i64;
    let b = b as i64;
    let c = c as i64;
    let mut l = vec![0i64; n];
    for i in 0..n {
        l[i] = read::<i64>();
    }

    let mut ans = std::i64::MAX;
    for i in 0..4i32.pow(n as u32) {
        let mut i = i as usize;
        let mut a_list = Vec::new();
        let mut b_list = Vec::new();
        let mut c_list = Vec::new();
        for j in 0..n {
            let flag = i % 4;
            if flag == 1 {
                a_list.push(l[j]);
            }
            if flag == 2 {
                b_list.push(l[j]);
            }
            if flag == 3 {
                c_list.push(l[j]);
            }
            i /= 4;
        }
        if a_list.is_empty() || b_list.is_empty() || c_list.is_empty() {
            continue;
        }
        let mut temp_ans = (a_list.len() + b_list.len() + c_list.len() - 3) as i64 * 10 as i64;
        temp_ans += (c_list.iter().sum::<i64>() - c).abs();
        temp_ans += (b_list.iter().sum::<i64>() - b).abs();
        temp_ans += (a_list.iter().sum::<i64>() - a).abs();
        ans = min(ans, temp_ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0) {
      continue;
    }
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) {
    res.push_back(make_pair(n, 1));
  }
  return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; 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;
  }
}
long long COM(int n, int k){
  if(n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
  ll N, M;
  cin >> N >> M;
  COMinit();
  auto vec = prime_factorize(M);
  ll res = 1;
  for (auto pa : vec) {
    ll num = pa.second;
    ll tmp = COM(num + N -1, N - 1);
    res = (res * tmp) % MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 5120
def reconstruction(left, right):
    global pos
    if left >= right:
        return
    c = preorder[pos]
    pos += 1
    m = inorder.index(c)
    reconstruction(left, m)
    reconstruction(m + 1, right)
    postorder.append(str(c))

pos = 0
postorder = []

n=int(input())
preorder=list(map(int,input().split()))
inorder=list(map(int,input().split()))
reconstruction(0, n)
print(' '.join(postorder))


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

int main() {
    string s;
    int n;
    cin >> s;
    n=s.length();
    if (s.substr(n-1)=="s") {
        cout << s+"es";
    }
    else {
        cout << s+"s";
    }

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("Inp.txt","r", stdin);
    //freopen("Out.txt","w", stdout);

    int h,w;    cin >> h >> w;
    const int mod = 1e9+7;
    vector<int> res(w);
    res[0] = 1;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
    {
        char c;
        cin >> c;
        if (c == '#')
            res[j] = 0;
        else if(j != 0)
            res [j] = (res[j] + res[j-1])%mod;
    }
    cout << res[w-1];

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll mod=1000000007;
  ll N; ci(N)
  ll n=2*N;
  st s; ci(s)
  bl b=true;
  vll A(n);
  ll l=1;
  ll r=0;
  A[0]=1;
  FOR(i,1,n){
    if(s[i]==s[i-1]){
      A[i]=-A[i-1];
    }
    else{
      A[i]=A[i-1];
    }
    
    if(A[i]==1){
      l++;
    }
    else{
      r++;
    }
  }
  
  ll a=0;
  FOR(i,0,n){
    a+=A[i];
  }
  
  if(a!=0||s[0]=='W'||s[n-1]=='W') b=false;
  
  ll ans=1;
  l=0;
  r=0;
  FOR(i,0,n){
    if(A[i]==1){
      l++;
    }
    else{
      ans*=(l-r);
      ans%=mod;
      r++;
    }
  }
  
  FOR(i,1,N+1){
    ans*=i;
    ans%=mod;
  }
  
  if(b){
    co(ans)
  }
  else{
    co(0)
  }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

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

  in(int, n);
  V<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n) {
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      ++ans;
    }
  }
  out(ans);
}


Measured memory_bytes: 3676
-- acrostic.hs --- Acrostic

-- author: Seong Yong-ju <sei40kr@gmail.com>

solve :: String -> Int -> String
solve s w = map (s !!) $ filter ((== 0) . (`mod` w)) [0 .. (length s - 1)]

main :: IO ()
main = do
  s <- getLine
  w <- (read :: String -> Int) <$> getLine
  putStrLn $ solve s w


Measured memory_bytes: 636
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,a=0;
  cin>>n;
  for(int i=1;i<n+1;i++){
    if(i%3!=0&&i%5!=0){
      a+=i;
    }
  }
  cout << a<< endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
using namespace std;

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

  int b_max = (int)sqrt(X); //bの上限

  int tmp_max = 1; //べき乗数の現在の最大値
  for(int i = b_max;i>=2;i--){
    int tmp = i * i;

    while(tmp*i <= X){
      tmp *= i;
    }

    if (tmp > tmp_max) {
      tmp_max = tmp;
    }
  }

  cout << tmp_max << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()

# Greedyアルゴリズム
S = S[::-1]

S = S.replace("resare","")
S = S.replace("esare","")
S = S.replace("remaerd","")
S = S.replace("maerd","")

if S == "":
        print("YES")
else:
        print("NO")







Measured memory_bytes: 3188
def main():
	import collections
	s = int(input())
	a = list(map(int,input().split()))
	ac = collections.Counter(a)
	ans = 0
	for i in set(ac):
		at = ac[i]
		ans += (at * (at-1))/2
	for t in a:
		ans_print = ans -((ac[t] * (ac[t] -1))/2) + (((ac[t]-1) * ((ac[t]-1)-1))/2)
		print(int(ans_print))
if __name__ == '__main__':
	main()

Measured memory_bytes: 94924
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,cnt=0;
    bool b=true;
    cin>>n;
    map<string,ll>mp;
    while (n--){
        string s;
        cin>>s;
        if (mp.find(s)==mp.end())mp[s]=1;
        else mp[s]++;
        cnt=max(cnt,mp[s]);
    }
    for (auto it:mp){
        if (it.second==cnt){
            cout<<it.first<<'\n';
        }
    }
    
}

Measured memory_bytes: 23808
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10);x/=10;}reverse(all(res)); return res;}

void solve(){
  ll h,n;
  cin>>h>>n;
  ll p=0;
  rep(i,n){
    ll a;
    cin>>a;
    p+=a;
  }
  YesNo(p>=h);
}

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


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

int h,w;
bool grid[100][100];

void dfs(int y,int x){
  grid[y][x] = 0;
  int dx[] = {0,1,1,1,0,-1,-1,-1};
  int dy[] = {-1,-1,0,1,1,1,0,-1};

  for(int i=0;i<8;i++){
    int ty = y+dy[i], tx = x+dx[i];
    if(ty<0 || tx<0 || h<=ty || w<=tx)continue;
    if(grid[ty][tx])dfs(ty,tx);
  }
}

int main(){
  while(cin >> w >> h ,w||h){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> grid[i][j];

    int ans = 0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(grid[i][j]){
	  dfs(i,j);
	  ans++;
	}

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
s=list(input())
n=len(s)
ans=0
for i in range(2**(n-1)):
  ball=s[0]
  for j in range(n-1):
    if (i>>j)&1:
      ball+="+"+s[j+1]
    else:
      ball+=s[j+1]
  ans+=eval(ball)
print(ans)

Measured memory_bytes: 8912
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  string s; cin>>s;
  vector<ll> v(s.size(),0), v2(s.size(), 0), ans(s.size(),0);
  ll n=s.size();
  rep(i,0,n){
    ll j=i;
    if(s[i]=='R'){
      while(s[i]==s[j]) j++;
      v[j-1] = j-i;
      i=j-1;
    }
  }
  reverse(all(s));
  rep(i,0,n){
    ll j=i;
    if(s[i]=='L'){
      while(s[i]==s[j]) j++;
      v2[j-1] = j-i;
      i=j-1;
    }
  }
  reverse(all(v2));
  rep(i,0,n-1){
    if(v[i]>0){
      ans[i] += (v[i]+1)/2 + v2[i+1]-(v2[i+1]+1)/2;
      ans[i+1] += (v2[i+1]+1)/2 + v[i]-(v[i]+1)/2;
    }
  }
  rep(i,0,n){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3072
while True:
    H,W = [int(i) for i in input().split()]
    if H == 0 and W == 0:
        break
    else:
        for j in list(range(1, H+1, 1)):
            for i in list(range(1, W+1, 1)):
                if i == W:
                    print("#")
                else:
                    print("#", end = "")
        print("")


Measured memory_bytes: 7048
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{

  int n;
  int tab[100000],x;
  cin >>n;
  for (int i=1;i<=n ;i++){
    cin >>x;
    tab[x]=i;
  }
  for(int i=1;i<=n;i++)cout<<tab[i]<<" ";

  return 0 ;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main (){
  int A,B;
  cin >>A>>B;
  int z= (A+B)%2;
  int x=(A+B)/2; 
  if(z==0){
    cout<<x<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}
    
 

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


int m, n, k;
string buf;
int J[1003][1003], O[1003][1003], I[1003][1003];

int main() {

	cin >> m >> n >> k;
	for (int i = 0; i < m; i++) {
		cin >> buf;
		for (int j = 0; j < n; j++) {
			if (buf[j] == 'J') J[i + 1][j + 1] += 1;
			if (buf[j] == 'O') O[i + 1][j + 1] += 1;
			if (buf[j] == 'I') I[i + 1][j + 1] += 1;
			J[i + 1][j + 1] += J[i][j + 1] + J[i + 1][j] - J[i][j];
			O[i + 1][j + 1] += O[i][j + 1] + O[i + 1][j] - O[i][j];
			I[i + 1][j + 1] += I[i][j + 1] + I[i + 1][j] - I[i][j];
		}
	}

	while(k--) {
		int a, b, c, d; cin >> a >> b >> c >> d, a--, b--, c--, d--;
		int j = J[c + 1][d + 1] - J[a][d + 1] - J[c + 1][b] + J[a][b];
		int o = O[c + 1][d + 1] - O[a][d + 1] - O[c + 1][b] + O[a][b];
		int i = I[c + 1][d + 1] - I[a][d + 1] - I[c + 1][b] + I[a][b];
		cout << j << " " << o << " " << i << endl;
	}

	return 0;
}




Measured memory_bytes: 14748
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    if(a==b && b==c){
        cout<<"1"<<endl;
    }
    else if(a==b || b == c || c==a){
        cout<<"2"<<endl;
    }
    else{
        cout<<"3"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
meals = []
a = 0

for i in range(5) :
    meal = int(input())
    if meal % 10 == 0 :
        meals.append(meal)
    else :
        if 10 - (meal % 10) > a :
            a = 10 - (meal % 10)
        meals.append(meal + 10 - (meal % 10))

print(sum(meals) - a)

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

const int INF = 1LL << 60;
const int CONST = 1e15;

int YEN[201010],SNUUK[201010];
int year[201010];

signed main(void){
  
  int N,M,s,t; cin >> N >> M >> s >> t; s--; t--;
  vector<vector<int>> to(N),yen(N),snuuk(N);
  
  for(int i = 0; i < M; i++){
    int u,v,a,b; cin >> u >> v >> a >> b;
    u--; v--;
    to[u].push_back(v);
    to[v].push_back(u);
    
    yen[u].push_back(a);
    yen[v].push_back(a);
    
    snuuk[u].push_back(b);
    snuuk[v].push_back(b);
    
  }
  
  for(int i = 0; i < N; i++){ 
    YEN[i] = INF; SNUUK[i] = INF;
  }
  // 到達できるのに必要な最小の円/スヌークを格納
  
  //Dijksta
  priority_queue<pint,vector<pint>,greater<pint>> Q;
  
  Q.push({0,s}); //先ずは始点sから各点までの距離を求める
                 // まずはYENで行くことに注意
  YEN[s] = 0;
  
  while(!Q.empty()){
    
    int p = Q.top().second; int weight = Q.top().first;
    
    Q.pop();
    
    if( YEN[p] < weight ){ continue;}
    
    for(int i = 0; i < (int)to[p].size(); i++){
      
      int q = to[p][i];
      
      if(  YEN[q] > YEN[p]+yen[p][i] ){ 
        
        YEN[q] = YEN[p]+yen[p][i];
        
        Q.push({YEN[q],q});
        
      }
    }//for
    
  } //while-Q
  
  Q.push({0,t}); //次は終点tから探す
  
  SNUUK[t] = 0;
  
  while(!Q.empty()){
    
    int p = Q.top().second; int weight = Q.top().first;
    
    Q.pop();
    
    if( SNUUK[p] < weight ){ continue;} 
      
    for(int i = 0; i < (int)to[p].size(); i++){
      
      int q = to[p][i];
      
      if(SNUUK[q] > SNUUK[p]+snuuk[p][i] ){ 
        
        SNUUK[q] = SNUUK[p]+snuuk[p][i];
        
        Q.push({SNUUK[q],q});
        
      }
    }
  }

  for(int i = 0; i < N; i++){ year[i] = INF;}
  
  for(int i = 0; i < N; i++){
    //都市i(0-indexed)は年i(1-indexed)まで使える(i+1年以降使えない)
    year[i] = min(year[i],YEN[i]+SNUUK[i]);
  }
  
  for(int i = N-1; i > 0; i--){
    
    year[i-1] = min(year[i-1],year[i]);
    
  }
  
  for(int i = 0; i < N; i++){ 
    
    cout << CONST-year[i] << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 23668
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long dp[N];
int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	dp[n] = 1e9+7;
	for(int i = 0; i < n; ++i)
		cin >> arr[i];
	for(int i = n-2; i >= 0; --i)
		dp[i] = min(abs(arr[i] - arr[i+1]) + dp[i+1], abs(arr[i] - arr[i+2]) + dp[i+2]);
	cout << dp[0];
	return 0;
}


Measured memory_bytes: 1408