akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;


 int main()
 {
   int c[500+5],s[500+5],f[500+5];
   int n;
   while(cin>>n)
   {
     for(int i=0;i<(n-1);i++) cin>>c[i]>>s[i]>>f[i];
     for(int i=0;i<n;i++)
     {
       if(i==(n-1)) cout<<"0"<<endl;
       else
       {
         int sum=0;
         for(int j=i;j<(n-1);j++)
         {
           if(j==i) sum=s[j]+c[j];
           else
           {
             if(sum<s[j]) sum=(s[j]+c[j]);
             else
             {
               if((sum%f[j])==0) sum=sum;
               else sum=sum+(f[j]-(sum%f[j]));
               sum=sum+c[j];    
             }    
           }        
         }    
         cout<<sum<<endl;
       }        
     }            
   }
   return 0;
 }
 

        


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a,b;
    cin>>a>>b;
    
    if(a>0&&b>0){
        cout<<"Positive"<<endl;
    }else if(a<=0&&b>=0){
        cout<<"Zero"<<endl;
    }else if(a<0&&b<0){
        if(a==b)cout<<"Positive"<<endl;
        else if(abs(a-b)==1)cout<<"Positive"<<endl;
        else if((a-b)%2==0)cout<<"Negative"<<endl;
        else cout<<"Positive"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin >> n;
  int sum = 0;
  ll m = n;
  while(m>0){
    sum += m%10;
    m /= 10;
  }

  if(n%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, beg, end, step) for (int i = beg; i <= end; i += step)

int main()
{
    int k, a, b;
    cin >> k;
    cin >> a >> b;

    rep(i, a, b, 1)
    {
        if (i % k == 0)
        {
            cout << "OK";

            return 0;
        }
    }
    cout << "NG";

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int n, a; vector<int> x[6];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a;
		x[to_string(a).size()].push_back(a);
	}
	for(int i = 1; i <= 5; i++) {
		sort(x[i].begin(), x[i].end());
	}
	int cnt = 0;
	for(int i = 2; i <= 10; i++) {
		int cnt2 = cnt;
		for(int j = max(i - 5, 0); j <= min(i - 1, 5); j++) {
			if(j != i - j) cnt2 += x[j].size() * x[i - j].size();
			else cnt2 += x[j].size() * (x[j].size() - 1);
		}
		if(cnt < 2 && cnt2 >= 2) {
			int rem = 3 - cnt;
			vector<int> w;
			for(int j = max(i - 5, 0); j <= min(i - 1, 5); j++) {
				int cnt3 = 0;
				for(int k = 0; k < x[j].size() && cnt3 < rem; k++) {
					for(int l = 0; l < x[i - j].size() && cnt3 < rem; l++) {
						if(j == i - j && k == l) continue;
						w.push_back(stoi(to_string(x[j][k]) + to_string(x[i - j][l])));
						cnt3++;
					}
				}
			}
			sort(w.begin(), w.end());
			cout << w[rem - 1] << endl;
			break;
		}
		cnt = cnt2;
	}
	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

struct Tag {
    int x, y;
    int cost;
    Tag() {}
    Tag(int x, int y, int c) : x(x), y(y), cost(c) {}
};

inline bool inRange(int a, int x, int b) {
    return a <= x && x < b;
}

int main() {
    while(true) {
        int W, H;
        cin >> W >> H;
        if(!W && !H) break;

        int v[W*2][H*2];
        memset(v, 0, sizeof(v));
        for(int i = 0; i < H*2-1; ++i) {
            if(i % 2 == 0) { //cÇ
                for(int j = 0; j < W-1; ++j) {
                    int w;
                    cin >> w;
                    v[j*2+1][(i/2)*2] = w;
                }
            }
            else {
                for(int j = 0; j < W; ++j) {
                    int w;
                    cin >> w;
                    v[j*2][(i/2)*2+1] = w;
                }
            }
        }

        for(int y = 0; y < H*2; ++y) v[W*2-1][y] = 1;
        for(int x = 0; x < W*2; ++x) v[x][H*2-1] = 1;
        /*
        for(int y = 0; y < H*2; ++y) {
            for(int x = 0; x < W*2; ++x) {
                cout << v[x][y] << ' ';
            }
            cout << endl;
        }
        */

        int ans = 0;
        int visited[W*2][H*2];
        int dt[][2] = {{0, -2}, {2, 0}, {0, 2}, {-2, 0}};
        memset(visited, 0, sizeof(visited));
        queue<Tag> q;
        q.push(Tag(0, 0, 0));
        while(!q.empty()) {
            const Tag t = q.front();
            q.pop();

            if(t.x == W*2-2 && t.y == H*2-2) {
                ans = t.cost+1;
                break;
            }

            for(int i = 0; i < 4; ++i) {
                int nx = t.x + dt[i][0];
                int ny = t.y + dt[i][1];
                int jx = t.x + dt[i][0]/2;
                int jy = t.y + dt[i][1]/2;
                if(inRange(0, nx, W*2) && inRange(0, ny, H*2) && 
                        !visited[nx][ny] && !v[jx][jy]) {
                    q.push(Tag(nx, ny, t.cost+1));
                    visited[nx][ny] = 1;
                }
            }
        }

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

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

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    static final int MAX = 100;
    int size;
    int[] R = new int[MAX+2];
    int[][] C = new int[MAX+1][MAX+1], B = new int[MAX+1][MAX+1];
    private void solv() {
        Scanner input = new Scanner(System.in);
        size = input.nextInt();
        for (int i = 1; i <= size+1; i++) {
            R[i] = input.nextInt();
            R[i+1] = input.nextInt();
        }
        compute();
        System.out.println(C[1][size]);
    }
    
    int INFTY = (1 << 21);
    void compute(){
        for ( int i = 1; i <= size; i++ )
        for ( int j = 1; j <= size; j++ ) C[i][j] = INFTY;
        
        for ( int i = 1; i <= size; i++ ) C[i][i] = 0;
        
        for ( int j = 1; j <= size - 1; j++ ){
            for ( int i = 1; i <= size - j; i++ ){
                for ( int k = i + 1; k <= i + j; k++ ){
                    // C[i][i+j] = min( C[i][i+j], 
                    //                  C[i][k-1] + C[k][i+j] + R[i]*R[k]*R[i+j+1]);
                    int cost = C[i][k-1] + C[k][i+j] + R[i]*R[k]*R[i+j+1];
                    if ( cost < C[i][i+j] ){
                        C[i][i+j] =  cost;
                        B[i][i+j] = k;
                    }
                    
                }
            }
        }
    }
    void swap(int[] A, int x, int y) {
        int temp = A[x];
        A[x] = A[y];
        A[y] = temp;
    }
    
}

class Scanner {
    BufferedReader r;
    StreamTokenizer st;
    
    public Scanner(InputStream in) {
        r = new BufferedReader(new InputStreamReader(in));
        st = new StreamTokenizer(r);
    }
    
    public String next() {
        nextToken();
        return st.sval;
    }
    
    public Integer nextInt() {
        nextToken();
        return (int)st.nval;
    }
    
    private int nextToken() {
        int token = st.TT_EOF;
        try {
            token = st.nextToken();
        } catch (IOException e) {
        }
        return token;
    }
}

Measured memory_bytes: 19184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct dice{
    int s[6];
    void roll(char c) {
        int tmp;
        if (c == 'E') {
            tmp = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = s[2];
            s[2] = tmp;
        } else if (c == 'W') {
            tmp = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = s[3];
            s[3] = tmp;
        } else if (c == 'N') {
            tmp = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = s[4];
            s[4] = tmp;
        } else {
            tmp = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = s[1];
            s[1] = tmp;
        }
    }
    int top() {
        return s[0];
    }
    int front() {
        return s[1];
    }
    int right() {
        return s[2];
    }
    int left() {
        return s[3];
    }
    int back() {
        return s[4];
    }
    int bottom() {
        return s[5];
    }
};

int main()
{
    dice d;
    rep(i, 0, 6) cin >> d.s[i];
    int q;
    cin >> q;
    rep(i, 0, q) {
        int x, y;
        cin >> x >> y;
        if (d.front() != y) {
            if (d.right() != y && d.left() != y) {
                rep(j, 0, 3) {
                    d.roll('N');
                    if (d.front() == y) break;
                }
            } else {
                d.roll('E');
                rep(j, 0, 3) {
                    d.roll('N');
                    if (d.front() == y) break;
                }
            }
        }
        if (d.top() != x) {
            rep(j, 0, 3) {
                d.roll('E');
                if (d.top() == x) break;
            }
        }
        cout << d.right() << endl;
    }
    return 0;
}



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

using namespace std;
using ll = long long;

int main() {
  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> correct(N + 1, 0);
  for (ll i = 1; i < Q + 1; ++i) {
    ll A_i;
    cin >> A_i;
    correct[A_i] += 1;
  }

  for (ll i = 1; i < N + 1; ++i) {
    if (K - Q + correct[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	string s1, s2;
	cin >> s1 >> s2;
	if ((s1 == "H" && s2 == "H") || (s1 == "D" && s2 == "D")) cout << "H" << endl;
	else cout << "D" << endl;
	return 0;
}

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

const int n=1001;

int main(){
	int v, d;
	int f[1001];
	
	while(cin >> v >> d){
		memset(f, 0, sizeof(f));
		int a, b, c;
		c=b=1;
		
		for(int i=0; i<v; ++i){
			a=(b+c)%n;
			f[a]++;
			c=b;
			b=a;
		}
		
		int pre=0, ans=1;

		while(f[pre]==0) pre++;
		
		for(int i=pre+1; i<=1000; ++i){					
			if(f[i]>0){
				//printf("%d\n", i);	
				
				if(i-pre>=d) ++ans;

				pre=i;
			}
		}	
		
		printf("%d\n", ans);		
	}
}	

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

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int kansu(int k){
    int i=0,j=0,m=0,sum=0,a=0;
    for(i=1;i<=k;i++){
        for(j=1;j<=k;j++){
            for(m=1;m<=k;m++){
                a = gcd(i,j);
                sum += gcd(a,m);
            }
        }
    }
    return sum;
}

int main(){
    int k=0;
    cin >> k;
    cout << kansu(k) << endl;
    return 0;
}

Measured memory_bytes: 3636
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(s));
}

fn solve(s: String) -> String {
    let mut chars: Vec<char> = s.chars().collect();
    for i in 0..chars.len() {
        chars[i] = match chars[i] {
            '1' => '9',
            '9' => '1',
            _ => unreachable!(),
        }
    }
    chars.into_iter().collect()
}

#[test]
fn example1() {
    assert_eq!("991", solve("119".to_owned()))
}

#[test]
fn example2() {
    assert_eq!("111", solve("999".to_owned()))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int a;
int main()
{
	rep(i,5)
	{
		cin>>a;
		if(a==0) re(i+1)
	}
	return 0;}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    if(n%k == 0) cout << 0 << endl;
    else {
        cout << 1 << endl;
    }

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from heapq import heappush, heappop, heapify

INF = float("inf")


def main():
    Q = int(input())
    bottom = [INF]                 # 最大ヒープ
    top = [INF]               # 最小ヒープ
    bottom_total = 0
    top_total = 0

    btot = 0
    for i in range(Q):
        q = input()
        if q[0] == "1":
            _, a, b = map(int, q.split())
            # print("a, b", a, b)
            btot += b
            if top[0] < a:
                # 必ずtopに加えるパターン
                heappush(top, a)
                top_total += a
            elif -bottom[0] < a:
                # どちらでも良いパターン
                heappush(bottom, -a)
                bottom_total += a
            else:
                # 必ずbottomに加えるパターン
                heappush(bottom, -a)
                bottom_total += a

            # バランスをとる
            # topの方が多いなら調整
            while len(top) - len(bottom) > 0:
                heappush(bottom, -top[0])
                bottom_total += top[0]
                top_total -= heappop(top)
            # bottomの方が1よりも多いなら調整
            while len(bottom)-len(top) > 1:
                heappush(top, -bottom[0])
                top_total += -bottom[0]
                bottom_total -= -heappop(bottom)
        else:
            tot = btot
            tot += (len(bottom)*(-bottom[0]) - bottom_total)
            tot += (top_total - len(top)*(-bottom[0]))
            print(-bottom[0], tot)
        # print("長さ", len(bottom), len(top))
    # print(bottom, top)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 89436
#include<bits/stdc++.h>
using namespace std;
int main(){
  int inf=1000000007;
  int n,m;
  cin >> n >> m;
  int a;
  cin >> a;
  vector<int> step(n+1);
  step[0] = 1;
  if(a != 1)step[1] = 1;
  else cin >> a;
  for(int i=2; i<=n; i++){
    if(a == i){
      cin >> a;
      continue;
    }
    step[i] = (step[i-1] + step[i-2])%inf;
  }
  cout << step[n]%inf;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
typedef __int128_t uint128;
using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
	{
		return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
	}
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
	{
		x=0;static char ch;T f=1;
		for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
		for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		x*=f;
	}

	template<typename T>inline void write(T x,char ch='\n')
	{
		if(!x)*nowps++='0';
		if(x<0)*nowps++='-',x=-x;
		static uint32 sta[111],tp;
		for(tp=0;x;x/=10)sta[++tp]=x%10;
		for(;tp;*nowps++=sta[tp--]^48);
		*nowps++=ch;
	}
}
using namespace IO;

const int MAXN=5e3+7,mod=1e9+7;

static int n;

vector<int>ed[MAXN];

inline void init()
{
	read(n);
	static int u,v;
	Rep(i,1,n-1)read(u),read(v),ed[u].pb(v),ed[v].pb(u);
}

static int sz[MAXN],dp[MAXN][MAXN],s[MAXN],g[MAXN];

static int f[MAXN];

inline int ad(int u,int v){return(u+=v)>=mod?u-mod:u;}

void dfs(int u,int fr)
{
	dp[u][sz[u]=1]=1;
	for(int v:ed[u])if(v^fr)
	{
		dfs(v,u);
		Rep(i,1,sz[u]+sz[v])f[i]=0;
		Rep(i,1,sz[u])f[i]=(uint64)dp[u][i]*s[v]%mod;
		Rep(i,1,sz[u])Rep(j,1,sz[v])
			f[i+j]=ad(f[i+j],(uint64)
				dp[u][i]*dp[v][j]%mod);
		sz[u]+=sz[v];
		Rep(i,1,sz[u])dp[u][i]=f[i];
	}
	Rep(i,1,sz[u]>>1)
		s[u]=ad(s[u],(uint64)g[i]*dp[u][i<<1]%mod);
	s[u]=ad(mod,-s[u]);
}

inline void solve()
{
	g[1]=1;
	Rep(i,2,n>>1)
		g[i]=(uint64)g[i-1]*(2*i-1)%mod;
	dfs(1,0);
	printf("%d\n",ad(mod,-s[1]));
}

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

Measured memory_bytes: 97536
# coding: utf-8
S=list(input())
flg=True

for i in range(len(S)):
    if i%2==0:
        if S[i]!="h":
            flg=False
    else:
        if S[i]!="i":
            flg=False
if len(S)%2==1:
    flg=False

if flg:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

vector<int> num(4, 0);

int search(int i = 0) {
    if (i == 8) return 0;

    int res = num[0];
    vector<int> i_array = { (i & 1),  ((i >> 1) & 1),  ((i >> 2) & 1) };
    rep(j, 3) {
        if (i_array[j]) res += num[j+1];
        else                res -= num[j+1];
    }
    
    if (res == 7) {
        cout << num[0];
        rep(j, 3) {
            if (i_array[j]) cout << "+";
            else cout << "-";

            cout << num[j + 1];
        }
        cout << "=" << 7 << endl;
        return 1;
    }
    else {
        search(i + 1);
    }
    return 0;


}

int main()
{
    string s;
    cin >> s;
    rep(i, 4) {
        num[i] = s[i] - '0';
    }

    search();

    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
cnt = 0

for l in a:
    tmp = 0
    for i in range(m):
        tmp += b[i]*l[i]
    tmp += c
    if tmp > 0:
        cnt += 1

print(cnt)

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

int main() {
  long long n,m;
  cin >>n>>m;
  if(n==1){
    if(m==1){
      cout<<1<<endl;
    }else if(m==2){
      cout<<0<<endl;
    }else{
      cout<<m-2<<endl;
    }
  }else if(n==2){
    cout<<0<<endl;
  }else {
    if(m==1){
      cout<<n-2<<endl;
    }else if(m==2){
      cout<<0<<endl;
    }else{
      cout<<(n-2)*(m-2)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
#answer = [int(x) for x in range(1, N+1)]
count = 0
for i in range(1, N+1):
  if P[i-1] != i:
    count += 1
if count <= 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9112
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX=100005;
int parent[MAX];
void unite(int x,int y){
	int rx=x,ry=y,p;
	while(parent[rx]!=-1) rx=parent[rx];
	while(parent[ry]!=-1) {
		int temp=ry;
		ry=parent[ry];
		parent[temp]=rx;
	}
	if(rx!=ry)parent[ry]=rx;
}
bool isSame(int x,int y){
	while(parent[x]!=-1) x=parent[x];
	while(parent[y]!=-1) y=parent[y];
	return x==y;
}
int main(){
	memset(parent,-1,sizeof(parent));
	int cmd,n,q,x,y;
	cin>>n>>q;
	for(int i=0;i<q;i++){
		cin>>cmd>>x>>y;
		if(!cmd)unite(x,y);
		else cout<< isSame(x,y)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3488
def combinations(iterable, r):
    # combinations('ABCD', 2) --> AB AC AD BC BD CD
    # combinations(range(4), 3) --> 012 013 023 123
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)


laa = []
N = int(input())
A = map(int, input().split())
for i in combinations(A,2):
    a, b = i
    c = abs(a-b)
    laa.append(c)

print(max(laa))

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

int main() {

  int N,sum;
  cin >> N;

  sum = 0;
  
  for (int i=0; i<N; i++){
  	int l,r,x;
    cin >> l >> r;
    x =  r-(l-1);
    sum += x;
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 3596
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		
	    Scanner sc = new Scanner(System.in);
		
	    while(true){
			
	        //縦Hと横Wの値を受け取る
		String s1 = sc.next();
	        int H = Integer.parseInt(s1);
	        String s2 = sc.next();
	        int W = Integer.parseInt(s2);
	        
	        //値が条件（３００以下であるか）にあっているか確認
	        if(H <= 300 && W <= 300){
	        
	        	//０と０が入力された時プログラムは終了する
	            if(H == 0 && W == 0){
	        	    break;
	            }
	        
	            //縦H個、横W個　”＃”を表示させる
	            for(int i = 1; i <= H; i++){
	        	    for(int j = 1; j <= W; j++){
	        		    System.out.print("#");
	        	    }
	        	    System.out.println("");
	            }
                    System.out.println("");
	        }
	    }
	}
}

Measured memory_bytes: 25812
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str_scan = scan.nextLine();
    var ans = 0;

    var num = str_scan.split(" ");

    var H = Integer.parseInt(num[0]);
    var W = Integer.parseInt(num[1]);
    var K = Integer.parseInt(num[2]);

    String[] str2_scan = new String[H];
    String[][] str = new String[H][W];

    for (var i = 0; i < H; i++) {
      str2_scan[i] = scan.nextLine();
      for (var j = 0; j < W; j++) {
        str[i][j] = String.valueOf(str2_scan[i].charAt(j));
      }
    }

    for (var mask_row = 0; mask_row < (1 << H) - 1 ; mask_row++) {
      for(var mask_line = 0; mask_line < (1 << W) - 1; mask_line++) {
	    var black_cnt = 0;
	    //選択された行or列かどうか確認するため、右シフトしつつ1のけたが0かどうかを確認
	    for (var m = 0; m < H; m++){
	      for (var n = 0; n < W; n++){
	        if (((mask_row >> m) & 1) == 0  && ((mask_line >> n) & 1) == 0 ){
              if (str[m][n].equals("#")) {
	            black_cnt++;
	          }
	        }
	      }
	    }
	    if (black_cnt == K) {
	      ans++;
	    }
      }
    }

    System.out.println(ans);
    scan.close();
  }
}

Measured memory_bytes: 36352
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int k = s.nextInt();
		int q = s.nextInt();
		int a[] = new int[n];
		while(q--!=0) {
			int m = s.nextInt()-1;
			if(m==0) {
				a[1]--;
			}
			else if(m==n-1) {
				a[0]--;
				a[m]++;
			}
			else {
				a[0]--;
				a[m]++;
				a[m+1]--;
			}
		}
		for(int i=1;i<n;i++) {
			a[i]+=a[i-1];
		}
		for(int i=0;i<n;i++) {
			if((a[i]+k)>0) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
		
	}
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int s4 = 0, s2 = 0, s1 = 0;
  int c = n * m;
  if (n % 2 != 0 && m % 2 != 0) {
    s1 = 1;
    c--;
  }
  if (n % 2 != 0) {
    s2 += m/2;
    c -= (m/2)*2;
  }
  if (m % 2 != 0) {
    s2 += n/2;
    c -= (n/2)*2;
  }
  s4 = c/4;
  map<char, int> cnt;
  for (int i = 0; i < n; i++) {
    vector<int> row;
    for (int j = 0; j < m; j++) {
      char t;
      cin >> t;
      cnt[t]++;
    }
  }
  for (auto& c : cnt) {
    if (c.second >= 4 && s4> 0) {
      if ((c.second/4) > s4) {
        s4 = 0;
        cnt[c.first] -= s4 * 4;
      } else {
        s4 -= c.second / 4;
        cnt[c.first] %= 4;
      }
    }
    if (c.second >= 2 && s2 > 0) {
      if ((c.second/2) > s2) {
        s2 = 0;
        cnt[c.first] -= s2 * 2;
      } else {
        s2 -= c.second / 2;
        cnt[c.first] %= 2;
      }
    }
    if (c.second >= 1 && s1 != 0) {
      s1 = 0;
      cnt[c.first]--;
    }
  }
  for (auto& c : cnt) {
    if (c.second != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  string S; cin>>S;
  int N	= S.size();
  vector<int> ans(N,0);
  int ll = 0, lr = 0, rl = 0, rr = 0;
  while(rl < N) {
    rr = rl;
    while(rr < N && S[rr] == 'R') {
      rr++;
    }
    rr--;
    ll = rr+1;
    lr = ll;
    //    cout << ll << " " << lr << endl;                                                  
    while(lr < N && S[lr] == 'L') {
      lr++;
    }
    lr --;
    //    cout << rl << " " << rr << " " << ll << " " << lr << endl;                        
    //                                                                                      
    for(int i = rl; i <= rr; i++) {
      if((rr-i) % 2 == 0) ans[rr]++;
      else ans[ll]++;
    }
    for(int i = ll; i <= lr; i++) {
      if((i-ll) % 2 != 0) ans[rr]++;
      else ans[ll]++;
    }
    //                                                                                      
    rl = lr + 1;
  }
  pp(ans, ans.size());
  return 0;
}


Measured memory_bytes: 1472
import java.util.*;
public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int total = 100*a +10*b +c;
    if(total % 4 ==0){
    	System.out.println("YES");
    }else{
    	System.out.println("NO");
    }  
  }
}

Measured memory_bytes: 21076
#include<stdio.h>
int search(int ,int);
int n,e[50];

int main(){
  int Exhaus,i,j;
  scanf("%d", &n);
  for ( i=0; i<n; i++){
    scanf("%d",&e[i]);
  }

  scanf("%d", &j);
  for ( i = 0; i<j; i++ ){

    scanf("%d", &Exhaus);
    if ( search(0,Exhaus) )
     printf("yes\n");
    else 
     printf("no\n");

  }

  return 0;
}

int search(int x ,int y){
  if ( x>=n )
   return 0;
  if ( e[x]==y )
   return 1;
  if ( search(x+1, y) ) 
   return 1;
  if ( search(x+1, y-e[x]) )
   return 1;

  return 0;
}


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

int main() {
    int N, K;

    bool is_prime[1000001];
    for (int i = 0; i <= 1000000; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 0; i <= 1000000/2; i++) {
        if (is_prime[i])
            for (int j = 2; j * i <= 1000000; j++) {
                is_prime[i * j] = false;
            }
    }

    while (cin >> N >> K, N || K) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;

        vector<bool> dp(K+1, false);
        dp[0] = true;
        int ans = -1;
        for (int i = 0; i < K; i++) {
            if (dp[i]) {
                for (auto j : v) {
                    if (i + j <= K) dp[i + j] = true;
                    if (i + j <= K && is_prime[i+j])
                        ans = max(ans, i + j);
                }
            }
        }

        if (ans >= 0) cout << ans << endl;
        else cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 4184
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
long long A[200000];
long long B[200000];
int main(){
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  sortA_L(N,A);
  sortA_L(N,B);
  if(N%2==1){
    wt_L(B[N/2]-A[N/2]+ 1);
    wt_L('\n');
  }
  else{
    wt_L(B[N/2]+B[(N-1)/2]-A[N/2]-A[(N-1)/2]+ 1);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N;
// ll A[2d5], B[2d5];
// {
//   rd(N,(A,B)(N));
//   sortA(N,A);
//   sortA(N,B);
//   wt(if[N%2==1, B[N/2]-A[N/2], B[N/2]+B[(N-1)/2]-A[N/2]-A[(N-1)/2]] + 1);
// }


Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
int a,b,c;
int main(void){
    cin>>a>>b>>c;
    if(a+b+c<=21){
        cout<<"win"<<endl;
    }else{
        cout<<"bust"<<endl;
    }
    
    
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  long long array[100005];
  long long mul=1;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  sort(array,array+n);
  if(array[0]==0){
    cout<<0<<endl;
    return(0);
  }
  for(int i=0;i<n;i++){
    if(1000000000000000000LL/mul<array[i]){
      cout<<-1<<endl;
      return(0);
    }
    mul*=array[i];
  }
  cout<<mul<<endl;
  return(0);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

const int nmax = 8;

bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){
 
    bool all_visited = true;
 
    for(int i = 0; i < N; i++){
        if(visited[i] == false){
            all_visited = false;
            break;
        }
    }
 
    if(all_visited){
        return 1;
    }
 
    int ret = 0;
 
    for(int i = 0; i < N; i++){
        if(graph[v][i] == false) continue;
        if(visited[i]) continue;
 
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
 
    return ret;
}

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N,M;
    cin>>N>>M;

    rep(i,M)
    {
        int A,B;
        cin>>A>>B;
        graph[A-1][B-1] = graph[B-1][A-1] = true;
    }

    bool visited[nmax];
    rep(i,N)
    {
        visited[0] = false;
    }

    visited[0] = true;

    cout<<dfs(0,N,visited)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  string s; cin >> s;
  for(int i = 0; i < s.sz; i++){
    if(s[i] == '?') s[i] = 'D';
  }
  cout << s << endl;
  // ll ans = 0;
  // for(int i = 0; i < s.sz; i++){
  //   if(i < s.sz - 1){
  //     if(s[i] == 'P' and s[i + 1] == 'D') ans++;
  //   }
  //   if(s[i] == 'D') ans++;
  // }
  // cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3756
def is_unique(seq):
    return len(seq) == len(set(seq))
  
s = int(input())
lists=[]
lists.append(s)
for x in range(1,1000000):
  if lists[x-1] % 2 == 0:
    lists.append(int(lists[x-1]/2))
  else:
    lists.append(int(lists[x-1]*3+1))
  if not is_unique(lists):
    print(x+1)
    break

Measured memory_bytes: 3060
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e8+7;


void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
 
  
int main()
{
    ll n;
    lscf(n);
    
    string a;
    
    while(n>0)
    {
        n--;
        
        a+=('a'+ n%26);
        
        n/=26;
    }
    
    reverse(all(a));
    
    cout<<a<<endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>

int c()
{
    long long a, b, c;
    std::cin >> a >> b >> c;
    
    long long left = (c - a - b) * (c - a - b);
    long long right = 4 * a * b;
    
    if(c - a - b <= 0)
    {
        std::cout << "No";
    }
    else if(0 < left - right)
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }
    
    return 0;
}


int main(int argc, const char * argv[])
{
    c();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int A = sc.nextInt();
		for(int i=1;H>0;i++) {
			H-=A;
			if(H<=0) {
				System.out.println(i);
			}
		}
	}

}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X, long long Y, long long Z){
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << " " << Z << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[51],s=0;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
    }
    for (int i=1;i<=n;++i)
    {
        for (int j=i+1;j<=n;++j)
            s+=a[i]*a[j];
    }
    cout<<s;
}

int main()
{
    nhap();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    str N;cin>>N;
    cout<<"ABC"<<N<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector< PII >
#define VVI vector< VI >
#define PB push_back
#define F first
#define S second
const int INF=1e9;
const int MOD=1e9+7;
int n,a[10],dp[10][2];
long long f(int x,int y){
    if(x>=n)return y;
    if(dp[x][y]!=-1)return dp[x][y];
    long long ret=0;
    for(int i=a[x]-1;i<=a[x]+1;i++){
        ret+=f(x+1,y|((i%2==0)?1:0));
    }
    return dp[x][y]=ret;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    memset((dp),-1,sizeof(dp));
    long long ans=f(0,0);
    printf("%lld\n",ans);
    return 0;
}

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

int main(void)
{
	char n,a,b;
	char p;
	char count[3]={},min=100;
	int i;


	scanf("%hhd",&n);
	scanf("%hhd %hhd",&a,&b);

	for (i=0;i<n;i++) {
		scanf("%hhd",&p);
		if (p <= a) {
			count[0]++;
		} else if (p <= b) {
			count[1]++;
		} else {
			count[2]++;
		}
	}
	
	for (i=0;i<3;i++) {
		if (min > count[i]) {
			min = count[i];
		}
	}
	
	printf("%d\n",min);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define i64 long long
using namespace std;
i64 fastPow(i64 b, i64 p){
	i64 res = 1;
	while(p){
		if(p&1) res*=b;
		b=b*b;
		p/=2LL;
	}
	return res;
}
int main() {
	// your code goes here
	i64 n,k;
	cin>>n>>k;
	printf("%lld\n", k*fastPow(k-1,n-1));
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
import numpy as np

N = int(readline())
XY = [[] for _ in range(N)]
for i in range(N):
    A = int(readline())
    for _ in range(A):
        x,y = map(int,readline().split())
        XY[i].append((x-1,y))

A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)
for i in range(N):
    for x,y in XY[i]:
        bl = (~A[:,i]) | (A[:,x] == bool(y))
        A = A[bl]

answer = A.sum(axis = 1).max()
print(answer)

Measured memory_bytes: 18424
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
const char newl = '\n';

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

  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) {cin >> a[i]; a[i]--;}
  
  vb checked(n, 0);
  ll K=k, num=0, num2=0, r=0;
  while(k && !checked[num]) {
    checked[num] = 1;
    k--;
    num = a[num];
  }
  if(k==0) {cout << num+1 << newl; return 0;}
  
  while(num2!=num) {
    r++;
    num2 = a[num2];
  }
  
  ll l=K-k-r;
  k %= l;
  
  while(k) {
    k--;
    num=a[num];
  }
  cout << num+1 << newl;
}

Measured memory_bytes: 4784
import numpy as np

W, H, N = map(int, input().split())
Map = np.zeros([W, H], dtype=int)

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    Map[:x] = 1
  elif a == 2:
    Map[x:] = 1
  elif a == 3:
    Map[:, :y] = 1
  else:
    Map[:, y:] = 1

print(H*W - Map.sum())

Measured memory_bytes: 20764
#include <bits/stdc++.h>
using namespace std;
int a[110], b[110][110], n, m;
int main(){
	cin >> n >> m;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			cin >> b[i][j];
	for(int i=1; i<=m; i++)
		cin >> a[i];
	long long ans = 0;
	for(int i=1; i<=n; i++){
		ans = 0;
		for(int j=1; j<=m; j++)
			ans += a[j]*b[i][j];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>

#define ff first
#define ss second

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

struct ITEM{
    int price;
    int ticket;
    const int value() const
    {
        return this->price/(1<<this->ticket);
    }
    bool operator<(const ITEM& i) const
    {
        return this->value()<i.value();
    }
};

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

    priority_queue<ITEM> pq;
    int n,m;
    cin>>n>>m;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        pq.push({a,0});
    }
    for(int i=0; i<m; i++){
        ITEM item=pq.top();
        if(item.value()==0) break;
        pq.pop();
        item.ticket+=1;
        pq.push(item);
    }
    ll answer=0;
    while(!pq.empty())
    {
        answer+=pq.top().value();
        pq.pop();
    }
    cout<<answer;

    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    int ans = 0;
    auto check = [](string s){
        REP(i,s.size()){
            if(s[i]!='A'&&s[i]!='C'&&s[i]!='G'&&s[i]!='T') return false;
        }
        return true;
    };
    REP(i,S.size()){
        REP(j,S.size()-i){
            if(check(S.substr(j,i+1))) ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>

bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first > another.first;
}

int main()
{
    int64_t a,b,c,d;
    std::cin>> a;

    b = a % 100;
    c = b / 5;
    d = a / 100;
    
    if( b % 5 != 0 )
    {
        c += 1;
    }
    
    if( ( c <= d )
          || ( b == 0 ) )
    {
        std::cout<< 1;
    }
    else
    {
        std::cout<< 0;
    }
}


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int n;
int a[N];
int cnt[N];
int res;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; --i) {
        int Cnt = 0;
        for (int j = i + i; j <= n; j += i) {
            Cnt += cnt[j];
        }
        Cnt %= 2;
        if (a[i] != Cnt) {
            ++res;
            cnt[i] = 1;
        }
    }
    cout << res << endl;
    for (int i = 1; i <= n; ++i) {
        if (cnt[i]) {
            cout << i << ' ';
        }
    }
    if (res)
        cout << endl;
    return 0;
}


Measured memory_bytes: 5080
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
string s;
int p[2 << 18];

int win[20][2 << 18];


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

	cin >> n;
	cin >> s;
	rep(i, 1 << n)cin >> p[i];
	rep(i, 1 << n)p[i + (1 << n)] = p[i];

	rep(i, 2 << n)win[0][i] = p[i];

	rep(i, n) {
		rep(j, 2 << n) {
			if (j + (1 << i) >= (2 << n))break;
			int x = win[i][j];
			int y = win[i][j + (1 << i)];

			win[i + 1][j] = s[abs(x - y) - 1] == '0' ? min(x, y) : max(x, y);
		}
	}
	rep(i, 1<<n) {
		cout << win[n][i] << '\n';
	}


	return 0;
}


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

int main(){
    //入力
    int N;
    cin >> N;
    
    //処理
    int count_max=0;
    int count,ans,i_cur;
    ans=1;
    count_max=0;
    for(int i=0;i<=N;i+=2){
        i_cur=i;
        count=0;
        while(i_cur%2==0&&i_cur!=0){
            i_cur=i_cur/2;
            count++;
        }
        if(count>count_max){
            count_max=count;
            ans=i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

def permutations_count(n, r):
    if n <= 1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m = map(int,input().split())

print(permutations_count(n,2) + permutations_count(m,2))

Measured memory_bytes: 3060
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(let* ((n (read))
       (m (read))
       (v1 (make-array n :initial-element nil))
       (vn (make-array n :initial-element nil)))
  (loop repeat m
        do (let ((s (read))
                 (g (read)))
             (cond ((= s 1) (setf (aref v1 (1- g)) t))
                   ((= g 1) (setf (aref v1 (1- s)) t))
                   ((= s n) (setf (aref vn (1- g)) t))
                   ((= g n) (setf (aref vn (1- s)) t)))))
  (format t "~A~%" (if (loop for i below n
                             if (and (aref v1 i)
                                     (aref vn i))
                             return t)
                       'POSSIBLE
                       'IMPOSSIBLE)))

Measured memory_bytes: 61864