akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	long n = read.to!long;
	long a = read.to!long;
	long b = read.to!long;
	long c = read.to!long;
	long d = read.to!long;
	
	long h = abs(b - a);
	
	long m = -(n - 1) * d;
	long r = (h - m) % (c + d);
	long x = (n - 1) * (d - c);
	long q = (h - m - x + (c + d - 1)) / (c + d);
	
	string ans = (q <= n - 1 && r <= x)? "YES": "NO";
	
	debug "h m r x q".writeln;
	debug [h, m, r, x, q].writeln;
	ans.writeln;
	
	}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101

int main(){
  int i, j, k, n, A[N][N];

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

  for(i=0; i<n; i++){
    k=2;
    for(j=0; j<n; j++){
      if(A[i][k] == j+1){
	printf("1");
	k++;
      }
      else printf("0");
      if(j == n-1)printf("\n");
      else printf(" ");
    }
  }

  return 0;
}



Measured memory_bytes: 2112
import scipy.misc as scm

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


for i in range(1,k+1):
    #sepalate blues
    b=scm.comb(k-1,i-1,1)

    #space between reds
    r=scm.comb(n-k+1,i,1)

    print(r*b%(10**9+7))

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


int main() {
    ll x;
    cin >> x;
    ll pos = 0;
    for (int i = 1; i <= x; i++) {
        pos += i;
        if (x <= pos) {
            cout << i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n = 0;
  scanf("%d",&n);
  int c[n-1];
  int s[n-1];
  int f[n-1];
  int i = 0;
  for(i=0;i<n-1;i++){
    scanf("%d %d %d",&c[i],&s[i],&f[i]);
  }
  int t=0;
  for(i = 0; i < n-1; i++){
    int j;
    t=0;
    for(j=i;j<n-1;j++){
      if(s[j]>=t){
	t=s[j]+c[j];
      }else{
	if(t%f[j]==0){
	  t=t+c[j];
	}else{
	  t=t+f[j]-t%f[j]+c[j];
	}
      }
    }
    printf("%d\n",t);
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair

typedef long long LL;
typedef pair<int,int> PII;

const int NUM = 2000000;
int prime[NUM];
vector<int> primelist;

int gen(){	
	for(int i=0;i<NUM;i++){
		prime[i] = 1;
	}
	prime[0] = 0;
	prime[1] = 0;
	for(int i=2;i*i<=NUM;i++){
		for(int j = 2*i;j<NUM;j+=i){
			prime[j] = 0;
		}
	}
	
	for(int i=0;i<NUM;i++){
			if(prime[i] == 1)
				primelist.push_back(i);
	}
}

int main(){
	gen();

	while(true){
		int a,b;
		int keya = 0,keyb = 0;
		
		scanf("%d %d",&a,&b);
		if(a == 0)break;
		
		int k;
		for(int i = 0;primelist[i] <= a;i++){
			if(a%primelist[i]==0){
				keya -= primelist[i] ;
				k = primelist[i];
				}
		}
		keya += 2*k;
		
		for(int i = 0;primelist[i] <= b;i++){
			if(b%primelist[i]==0){
				keyb -= primelist[i] ;
				k = primelist[i];
				}
		}
		keyb += 2*k;

		if(keya<keyb)
			printf("b\n");
		else
			printf("a\n");
		
	}
	
}

Measured memory_bytes: 9408
//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 4;

int T[maxN][maxN];

int main() {
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		int A; cin >> A;
		for(int j = 0; j < A; j++) {
			int x, y; cin >> x >> y;
			x--;
			if(y) T[i][x] = 1;
			else  T[i][x] = -1;
		}
	}
	int r = 0;
	for(int msk = 0; msk < (1 << n); msk++) {
		bool valid = true;
		for(int bit = 0; bit < n; bit++) if(msk & (1 << bit))
			for(int i = 0; i < n; i++) {
				if(T[bit][i] == 1 && !(msk & (1 << i))) valid = false;
				if(T[bit][i] == -1 && (msk & (1 << i))) valid = false;
			}
		if(valid) r = max(r, __builtin_popcount(msk));
	}
	cout << r;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
	using namespace std;
	using namespace __gnu_pbds;
	typedef long long ll; 
	#define int long long
	typedef unsigned long long lu;
	typedef vector<ll> v;
	typedef vector<vector<ll> > vv;
	typedef vector<string>  vs;
	typedef vector<pair<ll,ll>> vpr;
	typedef vector<bool>vb;
	typedef vector<double>vd;
	typedef long double ld;
	#define f(i,n) for(ll i = 0; i < n; i++)
	#define ff(i,n) for(ll i=1;i<=n;i++)
	#define pb push_back
	#define mp make_pair
	#define endl "\n"
	#define fi first
	#define se second
	#define all(x) x.begin(),x.end()
	#define rall(x) x.rbegin(),x.rend()
	#define amax(x,y) if(y>x) x=y;
	#define amin(x,y) if(y<x)x=y;
	#define bg(x) x.begin()
	#define sz(x) (ll)x.size()
	#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
	#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
	#define mxt(a) *(max_element(a.begin(),a.end()))
	#define mnt(a) *(min_element(a.begin(),a.end())
	#define tc ll t;cin>>t;while(t--)
	typedef pair<ll,ll> pi;
	#define yes cout<<"YES\n";
	#define no cout<<"NO\n";
	#define yesno(f) if(f) yes else no
	const v dx = {1, -1, 0, 0};
	const v dy = {0, 0, 1, -1};
	const ld PI = 2 * acos(0.0);
	ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
	ll power(ll a,ll b,ll m)
	{
	    if(b==0)
	        return 1;
	    ll d=power(a,b/2,m);
	    d=(d*d)%m;
	    if(b&1)
	        d=(d*a)%m;
	    return d;
	}
	const ll mod=1e9+7;
	int MOD(int a)
	{
	    if(a<0)
	        a+=mod;
	    if(a>=mod)
	        a%=mod;
	    return a;
	}
	// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
	// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
	/*string operations :
	str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
	str.substr (x) : returns a substring str[x],... end of string
	str.find(qtr) : returns the first occurenece of qtr in str */
	bool c(char ch)
	{
		return ch=='R';
	}
	int32_t main()
	{
	    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	    // freopen("input.txt", "r", stdin);
	    // freopen("output.txt", "w", stdout);
	    string s;cin>>s;
	    if(c(s[0]) && c(s[1]) && c(s[2]))
	    {
	    	cout<<3<<endl;

	    }
	    else if(c(s[0]) && c(s[1]))
	    	cout<<2<<endl;
	    else if(c(s[1]) && c(s[2]))
	    	cout<<2<<endl;
	    else if(c(s[0]) || c(s[1]) || c(s[2]))
	    	cout<<1<<endl;
	    else
	    	cout<<0<<endl;

	    return 0;
	}

Measured memory_bytes: 3636
#include <iostream>

int A[3];

int main() {
  std::cin >> A[0] >> A[1] >> A[2];
  int fans = 1e9;
  for (int t = 0; t <= 50; ++t) {
    int ans = 0;
    for (int i = 0; i < 3; ++i) {
      int a = A[i];
      while (a < t) {
        ans++;
        a += 2;
      }
      while (a > t) {
        ans++;
        a--;
      }
    }
    fans = std::min(fans, ans);
  }
  std::cout << fans << "\n";

  return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n<1200)
		printf("ABC");
	else if(n<2800)
		printf("ARC");
	else
		printf("AGC");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR(i,n) for(long long i=0;i<n;i++)
#define SFOR(i,a,b) for(long long i=a;i<b;i++)
#define RFOR(i,a,b) for(long long i=b;i>a;i--)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a*b)/2<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<pair<double,string>> tama(n);
  for(int i=0;i<n;i++){
    double p;
    string con;
    cin >> p >> con;
    tama.at(i) = make_pair(p,con);
  }
  double sum=0;
  for(int i=0;i<n;i++){
    if(tama.at(i).second == "BTC"){
      sum += tama.at(i).first * 380000;
    }else{
      sum += tama.at(i).first;
    }
  }
  
  cout << sum << endl;

  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        
        int K = scanner.nextInt();
        String S = scanner.next();
        
        if(S.length()<=K){
            System.out.println(S);
        }else{
            System.out.println(S.substring(0,K)+"...");
        }
        
    }
}


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

int main()
{
  int k,c=0;
  cin>>k;
  for (int i=1;i<=k;i++)
  {
      for(int j=k;j>=1;j--)
      {
           if(i%2 == 0&& j%2!=0)
        {
          c++;
         }
      }

  }
  cout<<c;
}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    // private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int[] a = in.nextIntArray(5);

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

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 25388
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

#define INF 1000000009LL
#define MOD 1000000007LL

ll dp[3000][3000][2];//dp[i][j][k]:左i, 右j，　手番kのときのX - Yの最大値
int H, W;

int main() {
  int N; cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];

  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j < N; j++) {
      if (j < i) {
        dp[i][j][0] = dp[i][j][1] = 0LL;
      } else if (i == j) {
        dp[i][j][0] = a[i];
        dp[i][j][1] = -a[i];
      } else {
        dp[i][j][0] = max(dp[i+1][j][1] + a[i], dp[i][j-1][1] + a[j]);
        dp[i][j][1] = min(dp[i+1][j][0] - a[i], dp[i][j-1][0] - a[j]);
      }
    }
  }

  cout << dp[0][N-1][0] << endl;
  return 0;
}

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

int main(){
  int a, b, c, d, temp;
  cin >> a >> b >> c >> d;
  if(a > c){
    temp = a;
    a = c;
    c = temp;
    temp = b;
    b = d;
    d = temp;
  }
  if(b <= c) cout << 0 << endl;
  else if(d <= b) cout << d - c << endl;
  else cout << b - c << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
   
int par[100000];
   
void init(int);
int dep(int);
int inp(void);
  
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
  
int main(){
  int n,i,j,id,k,c;
  
  fread(in,sizeof(in),1,stdin);  
  p = in;
  
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
   
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
      
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
  
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
  
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
  
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
  
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}

Measured memory_bytes: 4072
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)

template<typename T> inline T sqr(T x){return x * x;}
template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}

int N, M;

int next_combination(int x){
    int l = x & -x;
    int m = x + l;
    int ls = x & ~m;
    return m | ((ls / l) >> 1);
}

double solve(vector<double>& L, vector<double>& a, vector<double>& b){
    if(M == 0)return 0.0;
    double res = 0.0;
    for(int S=(1<<M)-1; S<(1<<N); S=next_combination(S)){
        double total = 0.0;
        rep(i, N)if(S >> i & 1){
            rep(j, i)if(S >> j & 1){
                total += sqr(L[i] - L[j]) + sqr(a[i] - a[j]) + sqr(b[i] - b[j]);
            }
        }
        chmax(res, total);
    }
    return res;
}

int main(){
    while(cin >> N >> M){
        vector<double> L(N), a(N), b(N);
        rep(i, N)cin >> L[i] >> a[i] >> b[i];
        cout << fixed << setprecision(16) <<  solve(L, a, b) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1292
S = input()
YY = int(S[0:2])
MM = int(S[2:4])

if 0 < YY <= 12 and 0 < MM <= 12:
    print("AMBIGUOUS")
elif 0 <= YY <= 99 and 0 < MM <= 12:
    print("YYMM")
elif 0 < YY <= 12 and 0 <= MM <= 99:
    print("MMYY")
else:
	print("NA")


Measured memory_bytes: 2940
sa = input()
sb = input()
sc = input()

turn = 0
aidx = 0
bidx = 0
cidx = 0
while True:
    if turn == 0:
        if len(sa) <= aidx:
            print("A")
            break

        nxt = sa[aidx]
        aidx += 1
    elif turn == 1:
        if len(sb) <= bidx:
            print("B")
            break

        nxt = sb[bidx]
        bidx += 1
    else:
        if len(sc) <= cidx:
            print("C")
            break

        nxt = sc[cidx]
        cidx += 1
    
    if nxt == 'a':
        turn = 0
    elif nxt == 'b':
        turn = 1
    else:
        turn = 2

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

class Main{
    int[] A, W;
    int N, a, w;
    List<Integer> R, L;

    int solve(){
        if ( R.size() == 0 || L.size() == 0 ) return 0;
        Collections.sort(R);
        Collections.sort(L);
        return R.get(0) + L.get(0);
    }

    void init() {
        A = new int[10];
        W = new int[10];
        R = new ArrayList<Integer>();
        L = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();

        for ( int i = 0; i < N; i++ ) A[i] = sc.nextInt();
        for ( int i = 0; i < N; i++ ) W[i] = sc.nextInt();
        for ( int i = 0; i < N; i++ ){
            if ( A[i] == 0 ) R.add(W[i]);
            if ( A[i] == 1 ) L.add(W[i]);
        }
        System.out.println(solve());
    }

    public static void main(String[] a){ new Main().init(); }

}




Measured memory_bytes: 26388
#include<stdio.h>
#include<string.h>


typedef struct  {
    int first;
    int second;
    int third;
    int forth;
    int fifth;
    int sixth;
} Dice;

int main() {
	Dice one;
	int q, i;

	scanf("%d ", &one.first);
    scanf("%d ", &one.second);
    scanf("%d ", &one.third);
    scanf("%d ", &one.forth);
    scanf("%d ", &one.fifth);
    scanf("%d", &one.sixth);

    scanf("%d\n", &q);

    for(i = 0; i < q; ++i) {
    	int a[2];
    	scanf("%d %d", &a[0], &a[1]);
    	
    	if(a[0] == one.first){
			if(a[1] == one.second) printf("%d\n", one.third);
			if(a[1] == one.third) printf("%d\n", one.fifth);
			if(a[1] == one.forth) printf("%d\n", one.second);
			if(a[1] == one.fifth) printf("%d\n", one.forth);
		}
		if(a[0] == one.second){
			if(a[1] == one.first) printf("%d\n", one.forth);
			if(a[1] == one.third) printf("%d\n", one.first);
			if(a[1] == one.forth) printf("%d\n", one.sixth);
			if(a[1] == one.sixth) printf("%d\n", one.third);
		}
		if(a[0] == one.third){
			if(a[1] == one.second) printf("%d\n", one.sixth);
			if(a[1] == one.first) printf("%d\n", one.second);
			if(a[1] == one.sixth) printf("%d\n", one.fifth);
			if(a[1] == one.fifth) printf("%d\n", one.first);
		}
		if(a[0] == one.forth){
			if(a[1] == one.second) printf("%d\n", one.first);
			if(a[1] == one.sixth) printf("%d\n", one.second);
			if(a[1] == one.first) printf("%d\n", one.fifth);
			if(a[1] == one.fifth) printf("%d\n", one.sixth);
		}
		if(a[0] == one.fifth){
			if(a[1] == one.first) printf("%d\n", one.third);
			if(a[1] == one.third) printf("%d\n", one.sixth);
			if(a[1] == one.forth) printf("%d\n", one.first);
			if(a[1] == one.sixth) printf("%d\n", one.forth);
		}
		 if(a[0] == one.sixth){
			if(a[1] == one.second) printf("%d\n", one.forth);
			if(a[1] == one.third) printf("%d\n", one.second);
			if(a[1] == one.forth) printf("%d\n", one.fifth);
			if(a[1] == one.fifth) printf("%d\n", one.third);
		}
    }
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  bool ok = true;
  if(s[0] != 'A') {
    ok = false;
  }
  int ccnt = 0;
  srep(k,2,sz(s)-1) {
    if(s[k] == 'C') ccnt++;
  }
  if(ccnt != 1) {
    ok = false;
  }
  if(!(s[1] >= 'a' && s[1] <= 'z')) {
    ok = false;
  }
  srep(k,2,sz(s)) {
    if(s[k] == 'C') continue;
    if(!(s[k] >= 'a' && s[k] <= 'z')) {
      ok = false;
    }
  }
  if(ok) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

n = input()
sort_list = list()

sort_list = map(int, raw_input().split())

for i in range(0,n):
    
    
    tmp = sort_list[i]
    j = i - 1
    while j >= 0 and sort_list[j] > tmp:
        sort_list[j+1] = sort_list[j]
        j = j - 1

    sort_list[j+1] = tmp


    for k in range(0,n):
        sys.stdout.write(str(sort_list[k]))
        if k is not n - 1:
            sys.stdout.write(" ")
        elif i is not n - 1:
            sys.stdout.write("\n")
            
print("")



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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
}
int main(void)
{
    solve();
}

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

int main()
{
	int a, b; cin >> a >> b;
	
	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}

	int cnt = 1;
	int tmp = a;
	while (true) {
		if (b <= tmp) {
			break;
		}
		cnt++;
		tmp += a;
		tmp -= 1;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int dice[10]; cin >> dice[1] >> dice[2] >> dice[3] >> dice[4] >> dice[5] >> dice[6];
	short int q; cin >> q;
	for (short int i = 0; i < q; i++){
		short int a, b; cin >> a >> b;
		if (dice[1] == a) {
			if (dice[2] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[5];
			else if (dice[5] == b)cout << dice[4];
			else cout << dice[2];
		}
		else if (dice[2] == a) {
			if (dice[6] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[4];
			else cout << dice[6];
		}
		else if (dice[3] == a) {
			if (dice[6] == b)cout << dice[5];
			else if (dice[5] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[2];
			else cout << dice[6];
		}
		else if (dice[4] == a) {
			if (dice[6] == b)cout << dice[2];
			else if (dice[2] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[5];
			else cout << dice[6];
		}
		else if (dice[5] == a) {
			if (dice[6] == b)cout << dice[4];
			else if (dice[4] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[3];
			else cout << dice[6];
		}
		else if (dice[6] == a) {
			if (dice[5] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[2];
			else if (dice[2] == b)cout << dice[4];
			else cout << dice[5];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    vector<vector<bool>> used(h, vector<bool>(w));
    ll ans = 0;
    REP(i, h){
        REP(j, w){
            if(used[i][j]) continue;
            
            used[i][j] = true;
            queue<pair<pair<ll, ll>, char>> que;
            que.push({{i, j}, s[i][j]});
            ll p_cnt = 0, s_cnt = 0;
            while(!que.empty()){
                auto tmp = que.front(); que.pop();
                ll y = tmp.first.first, x = tmp.first.second, e = tmp.second;
                if(s[y][x] == '.') p_cnt++;
                else s_cnt++;
                REP(k, 4){
                    ll yy = y + dy[k], xx = x + dx[k];
                    if(yy >= 0 && yy < h && xx >= 0 && xx < w && s[yy][xx] != s[y][x] && !used[yy][xx]){
                        used[yy][xx] = true;
                        que.push({{yy, xx}, s[yy][xx]});
                    }
                }
            }
            
            ans += s_cnt * p_cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

using int64 = long long;

vector< int64 > divisor(int64 n)
{
    vector< int64 > ret;
    for(int64 i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return(ret);
}

int main(){
    int N, M;
    cin >> N >> M;
    auto divisors = divisor(M);
    for(int i = 0; i < divisors.size(); i++){
        if(M / divisors[i] < N){
            cout << divisors[i - 1] << endl;
            return 0;
        }
    }
    cout << M << endl;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dfs(ll n,ll x,vl s,vl S){ //層の段,残り層数
    if(n==0)return 1;
    else if(x==1)return 0;
    else if(x>1 && x<= 1+s[n-1])return dfs(n-1,x-1,s,S);
    else if(x==2+s[n-1])return (1+S[n-1]);
    else if(x>2+s[n-1] && x<3+2*s[n-1])return S[n-1]+1+dfs(n-1,x-2-s[n-1],s,S);
    else return (1+2*S[n-1]);
}
signed main()
{   
    gearup;
    string s;cin >> s;
    int n = s.size();
    int res = INF;
    for(int i=0;i+2<n;i++){
        int m = stoi(s.substr(i,3));
        res = min(res,abs(m-753));
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

using ll = long long;
const int mod = 1e9 + 7;
const ll INF = 1e18L + 5;
int main()
{
	fast();
	int n;
	cin >> n;
	//cout << __gcd(15, 5);
	ll ans = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int k = 1; k <= n; ++k){
				ans += __gcd(__gcd(i, j), k);
			}
		}
	}
	cout << ans;
}			

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

int main() {
    int n;

    cin >> n;

    vector<ll> a(n);

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

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

    int tmp_a = 0;
    bool ok = true;
    for ( int i = 0; i < n; i++ ) {
        if ( tmp_a == a[i] ) {
            ok = false;
        }
        tmp_a = a[i];
    }

    if ( ok ) cout << "YES" << endl;
    else      cout << "NO" << endl;

    return 0;

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		string ans=s.substr(0,1);
		int c=0;
		while(1){
			// cout<<s[c]<<endl;
			if(c>=s.size()-1) break;
			string t=s.substr(c+1,2);
			if(t=="->"&&ans[ans.size()-1]==s[c]){
				ans=ans+s.substr(c+3,1);
			}
			else if(t=="<-"&&ans[0]==s[c]){
				ans=s.substr(c+3,1)+ans;
			}
			c+=3;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

/*
白…白黒…黒　にすればよい
*/

signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi a(n),b(n);
    rep(i,n)a[i] = s[i] == '#', b[i] = s[i] == '.';
    rep(i,n-1)a[i+1] += a[i];
    for(int i = n-1; i > 0; i--)b[i-1] += b[i];
    int ans = min(a.back(), b.front());
    loop(i,1,n){
        //[0,i)を白、[i,n)を黒にする
        int t = a[i-1] + b[i];
        ans = min(ans, t);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3716
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int a[] = IntStream.range(0, sc.nextInt()).map(i -> sc.nextInt()).toArray();
        int temp[] = Arrays.stream(a).sorted().toArray();
        int a_max = temp[temp.length - 1];
        int a_second = temp[temp.length - 2];

        for (int i = 0; i < a.length; i++ ) {
            if (a[i] == a_max) System.out.println(a_second);
            if (a[i] != a_max) System.out.println(a_max);
        }
        sc.close();
    }
}

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

int main()
{
  long long n;
  cin >> n;

  if(n%2!=0){
    cout << "0" << endl;
  }else{
    long long count=0ll;
    long long i = 10ll;
    for(;;){
      if(i>n)break;
      else{
        count += n / i;
        i = i * 5;
      }
    }

    cout << count << endl;
  }

  return 0;
}


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

ll solve() {
    ll N;
    cin >> N;
    double x;
    int k2 = 52, k5 = 23;
    vector<vector<ll>> m(k2, vector<ll>(k5));  // 2^(i-9) * 5^(j-9)
    for ( int i = 0; i < N; i++ ) {
        cin >> x;
        ll b = (ll)(x*(ll)(1e9) + 0.5);
        ll p2 = 0, p5 = 0;
        while ( b % 2 == 0 ) {
            p2++;
            b /= 2;
        }
        while ( b % 5 == 0 ) {
            p5++;
            b /= 5;
        }
        m[p2][p5]++;
    }
    ll ans = 0;
    for ( int i2 = 0; i2 < k2; i2++ ) {
        for ( int i5 = 0; i5 < k5; i5++ ) {
            for ( int j2 = 0; j2 < k2; j2++ ) {
                if ( i2 + j2 < 18 ) continue;
                for ( int j5 = 0; j5 < k5; j5++ ) {
                    if ( i5 + j5 < 18 ) continue;
                    if ( i2 == j2 && i5 == j5 ) {
                        ans += m[i2][i5] * (m[i2][i5] - 1);
                    } else {
                        ans += m[i2][i5] * m[j2][j5];
                    }
                }
            }
        }
    }
    ans /= 2;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,d; cin>>a>>b>>c>>d;
	long long a1=1ll*a*c,a2=1ll*a*d,a3=1ll*b*c,a4=1ll*b*d;
	cout<<max(a1,max(a2,max(a3,a4)))<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int d, t, s;
  cin >> d >> t >> s;
  if (t * s >= d) puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 3604
#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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int n,m;
int mn[100010];
vector<vector<int>> v(100010);
queue<int> q;

void bfs(){
    while(!q.empty()){
        int s=q.front();
        q.pop();
        for(int e:v[s]){
            if(mn[e]==-1){
                mn[e]=s+1;
                q.push(e);
            }
        }
    }
}

int main() {
    cin >> n >> m;
    rep(i,n)mn[i]=-1;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    mn[0]=1;
    q.push(0);
    bfs();
    cout << "Yes" << endl;
    for(int i=1;i<n;i++)cout << mn[i] << endl;
    
}

Measured memory_bytes: 10272
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int hyou[10][10];
	int sum;
	int n;

	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int s[10] = {0};

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

		for (int i = 0; i < n; i++) {
			sum = 0;
			for (int j = 0; j < n; j++) {
				printf("%5d",hyou[i][j]);
				sum += hyou[i][j];
				s[j] += hyou[i][j];
			}
			printf("%5d\n",sum);
		}
		sum = 0;
		for (int i = 0; i < n; i++) {
			printf("%5d",s[i]);
			sum += s[i];
		}
		printf("%5d\n",sum);
	}

	return 0;


}

Measured memory_bytes: 1160
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];

    bool match = false;

    for (int i = 0; i <= N-M; i++) {
        for (int j = 0; j <= N-M; j++) {
            bool flag = true;
            for (int x = 0; x < M; x++) {
                for (int y = 0; y < M; y++) {
                    if (A[i+x][j+y] != B[x][y]) flag = false;
                }
            }
            if (flag) match = true;
        }
    }

    cout << (match ? "Yes" : "No") << '\n';
    
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3652
n = int(input())
s = input()
a = [str(c) for c in s]

x = a.count('E')
if a[0] == 'E':
    x -= 1
y = x
for i in range(n-1):
    if a[i] == 'W':
        if a[i+1] == 'W':
            x += 1
        else:
            x = x
    else:
        if a[i+1] == 'W':
            x = x
        else:
            x -= 1
    if y > x:
        y = x
        



print(y)
        
        
        
    

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


int main(){
  string s;
  string h = "hi";
  cin >>s;
  if(s.size()%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  bool flag =true;
  for(int i =0;i<s.size();i++){
    char x =s.at(i);
    if(i%2==0){
      if(x != 'h')flag =false;
    }
    if(i%2==1){
      if(x != 'i')flag =false;
    }
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

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

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N);
  for(int i=0; i<N; ++i) cin >> A[i];

  long long X = 0;
  for(int i=41; i>=0; --i) {
    long long cnt = 0;
    for(int j=0; j<N; ++j) {
      if((A[j] >> i) & 1) ++cnt; 
    }
    if(cnt < N - cnt && X + (1LL << i) <= K) X += (1LL << i);
  }
  
  long long sum = 0;
  for(int j=0; j<N; ++j) sum += X^A[j];
  cout << sum << endl;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];

    int sum = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            sum += vec[i]*vec[j];
        }
    }
    cout << sum << endl;
}

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

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define i64 long long int
#define MEM(a,x) memset(a,x,sizeof(x))
#define INF 1000000000
#define mod 998244353

using namespace std ;

typedef pair<int,int> pi ;

#define maxn 100005

vector <int> g[maxn] ;
int vis[maxn] , qc[maxn] , ans[maxn] , qd[maxn] , qv[maxn] ;

int main()
{
    int i , j , k , l , m , n , q ;

    memset(vis,-1,sizeof(vis)) ;
    memset(ans,0,sizeof(ans)) ;

    scanf("%d %d",&n,&m) ;

    for(i=1 ; i<=m ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    scanf("%d",&q) ;
    for(i=1 ; i<=q ; i++)
    {
        scanf("%d %d %d",&qv[i],&qd[i],&qc[i]) ;
    }

    for(i=q ; i>=1 ; i--)
    {
        if( vis[qv[i]] >= qd[i] ) continue ;

        queue < int > Q ;

        Q.push( qv[i] ) ;
        vis[ qv[i] ] = qd[i] ;

        while( !Q.empty() )
        {
            int u = Q.front() ;
            int d = vis[u] ;
            Q.pop() ;

            if( ans[u]==0 ) ans[u] = qc[i] ;

            for(j=0 ; j<g[u].size() ; j++)
            {
                int v = g[u][j] ;
                if( vis[v] < d-1 )
                {
                    vis[v] = d-1 ;
                    Q.push( v ) ;
                }
            }
        }
    }

    for(i=1 ; i<=n ; i++) printf("%d\n",ans[i]) ;

    return 0 ;
}


Measured memory_bytes: 8824
n,m = map(int,input().split())
l = []
r = []

for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b)


if min(r) >= max(l):
    print(min(r) - max(l) + 1)
else:
    print(0)

Measured memory_bytes: 10996
def solve(n ,s)
    table = {"A"=> 0,"B"=> 1,"C"=>2,"D"=>3,"E"=>4,
    "F"=>5,"G"=>6,"H"=>7,"I"=>8,"J"=>9,
    "K"=>10,"L"=>11,"M"=>12,"N"=>13,"O"=>14,
    "P"=>15,"Q"=>16,"R"=>17,"S"=>18,"T"=>19,
    "U"=>20,"V"=>21,"W"=>22,"X"=>23,"Y"=>24,
    "Z"=>25}
    mapped_l = s.chars.map do |c|
        idx = (table[c] + n) % table.length
        table.keys[idx]
    end
    mapped_l.join
end

def main()
    n = gets.to_i
    s = gets.chomp
    ans = solve(n ,s)
    puts ans
end

main()

Measured memory_bytes: 4092
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(!(h == 0 && w == 0)){
                for(int i=0;i<h;i++){
                    for(int j=0;j<w;j++){
                        System.out.print("#");
                    }
                    System.out.println("");
                }
                System.out.println("");
            }else{
                break;
            }
        }
    }
}


Measured memory_bytes: 37872
import sys
sys.setrecursionlimit(200000000)

N = int(input())
NUMS = [int(input()) for _ in range(N)]
NUMS = list(set(NUMS))

def gcd(num1, num2):
    if num2 == 0:
        return num1
    else:
        return gcd(num2, num1 % num2)


res = NUMS[0]
for num in NUMS[1:]:
    res = res * num // gcd(res, num)

print(int(res))

Measured memory_bytes: 3188
from itertools import permutations


def solve(n, m, r):
    ans = 10**18
    d = [[10**18]*n for _ in range(n)]
    rx = list(i-1 for i in map(int, input().split()))

    for i in range(m):
        s, t, length = map(int, input().split())
        d[s-1][t-1] = length
        d[t-1][s-1] = length

    for i in range(n):
        d[i][i] = 0

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dt = d[i][k] + d[k][j]
                if dt < d[i][j]:
                    d[i][j] = dt

    for p in permutations(rx):
        from_p1_to_pr = 0
        for p_j,  p_next in zip(p, p[1:]):
            from_p1_to_pr += d[p_j][p_next]
        if from_p1_to_pr < ans:
            ans = from_p1_to_pr

    return ans


if __name__ == '__main__':
    n, m, r = map(int, input().split())
    print(solve(n, m, r))


Measured memory_bytes: 4648
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))


# 地点の平均気温を計算しListHに格納
for i in range(N):
    H[i] = T - (abs(H[i]) * 0.006)

# 目的の平均気温との差をListHに格納
for k in range(N):
    H[k] = abs(H[k] - (A))

# 差が最も小さいもののリスト番号に1を足して出力
print((H.index(min(H)))+1)

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

int main(){
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for(int i=0;i<n;i++)	cin >> a[i];
  sort(a,a+n);
  ll sum=0;
  for(int i=0;i<k;i++)	sum+=a[i];
  cout << sum << endl;
  return 0;
}

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

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

const ll INF = 1LL << 60;

struct Item {
    ll w, v;
};

vector<vector<ll>> dp(110, vector<ll>(100010, 0));

int main() {
    int N, W;
    cin >> N >> W;
    vector<Item> I(N + 1);
    for (int i = 1; i <= N; i++) {
        scanf("%lld %lld", &I[i].w, &I[i].v);
    }
    
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= W; j++) {
            if (j - I[i].w >= 0) {
                chmax(dp[i][j], dp[i - 1][j - I[i].w] + I[i].v);
            }
            chmax(dp[i][j], dp[i - 1][j]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 87296
S = input()
if S == "SUN":
    print("7")
if S == "MON":
    print("6")
if S == "TUE":
    print("5")
if S == "WED":
    print("4")
if S == "THU":
    print("3")
if S == "FRI":
    print("2")
if S == "SAT":
    print("1")




Measured memory_bytes: 38256
N = int(input())
p = [int(input()) for i in range(N)]
A = 0
max=99

for i in range(N):
    if p[i] > max:
        max = p[i]
        m = i

p[m] = p[m]/2


for i in range(N):
    A += p[i]

print(int(A))   

Measured memory_bytes: 3064
n = int(input())
d = list(map(int, input().split())) 
SUM = sum(d)
sn = []
for i in range(n-1):
	for j in range(n-i-1):
		sn.append(d[i]*d[i+j+1])
#print(sn)
print(sum(sn))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,count=0;
  cin>>n>>m;
  int a[m][n],b[m],point[100]={0};
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  for(int i=0;i<m;i++){
    count=0;
    for(int j=0;j<n;j++){
      cin>>a[i][j];
      if(a[i][j]==b[i]){
	point[j]++;
      }
      else{
	count++;
      }
    }
    point[b[i]-1]+=count;
  }
  for(int i=0;i<n;i++){
    cout<<point[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll ans = 1e9, tmp;
    REP(i, N){
        cin >> tmp;
        ll j = 0;
        while(tmp % 2 == 0){
            j++;
            tmp /= 2;
        }
        ans = min(ans, j);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7


REDN = N - K
ans = 1
for i in range(1, K + 1):
    # REDN + 1 C i * K C i - 1 を求める
    ans *= REDN + 1 + 1 - i
    ans //= i
    if i == 1:
        ans *= 1
    else:
        ans *= K + 1 - i
        ans //= i - 1
    print(ans % MOD)



Measured memory_bytes: 3316