akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
typedef vector<pair<ll,ll> > vpii;
typedef vector<ll> vi;
const ll INF=1e14+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}
//ll x[100001]={0};
ll a[200001]={0};
//ll b[200001]={0};
//ll b[200001]={0};
//bool c[100001]={0};
//vector<pair<ll,ll> > adj[100001];
//vector<ll> adj[100001];
//vpii edges;
//bool visited[100001]={0};
//bool color[100001]={0};
//ll dist[100001]={0};
ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res=(res*a)%INF;
        a=(a*a)%INF;
        b/=2;
    }
    return res%INF;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void tree_dfs(ll curr,ll prev){
    for(auto u:adj[curr]){
        if(u!=prev){
            tree_dfs(u,curr)+1;
        }
    }
}*/

/*void dfs(ll x,ll y){
    if(x<0 || y<0 || x>=n || y>=m)return;
    if(visited[x][y])return;
    visited[x][y]=true;
    dfs(x+1,y);dfs(x-1,y);dfs(x,y+1);dfs(x,y-1);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/
//ll grid[1001][1001]={0};

/*void dfs(ll s,bool colr){
    if(visited[s])return;
    visited[s]=true;
    color[s]=colr;
    for(auto u:adj[s]){
        dfs(u,!colr);
    }
}*/
//set<pair<ll,ll> >edges;
/*vector<ll> z(string s) {
    ll n=s.length();
    vector<ll> z(n);
    ll x=0,y=0;
    for(ll i=1;i<n;i++) {
        z[i]=max(0ll,min(z[i-x],y-i+1));
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]){
            x = i; y = i+z[i]; z[i]++;
        }
     }
    return z;
}*/

void solve(){
    input(a,5);

    for(ll i=0;i<5;i++){
        if(a[i]==0){
            cout<<i+1;
            break;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(100001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


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

#define int long long

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

int N;
int imos_u[100]={}, imos_d[100]={};

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> imos_u[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> imos_d[i];
    }
    for(int i=1;i<N;i++){
        imos_u[i]+=imos_u[i-1];
    }
    for(int i=N-2;i>=0;i--){
        imos_d[i]+=imos_d[i+1];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans=max(ans,imos_u[i]+imos_d[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
char F[102][102];
void DFSMI(int Y,int X){
	if(F[Y][X]!='@')
		return;
	F[Y][X]='.';
	DFSMI(Y-1,X);
	DFSMI(Y,X+1);
	DFSMI(Y+1,X);
	DFSMI(Y,X-1);
}
void DFSRI(int Y,int X){
	if(F[Y][X]!='#')
		return;
	F[Y][X]='.';
	DFSRI(Y-1,X);
	DFSRI(Y,X+1);
	DFSRI(Y+1,X);
	DFSRI(Y,X-1);
}
void DFSKA(int Y,int X){
	if(F[Y][X]!='*')
		return;
	F[Y][X]='.';
	DFSKA(Y-1,X);
	DFSKA(Y,X+1);
	DFSKA(Y+1,X);
	DFSKA(Y,X-1);
}

int main(){
while(1){
	int count=0;
	int H,W;
	cin>>H;
	if(H==0)
		count++;
	cin>>W;
	if(W==0)
		count++;
	if(count==2)
		return 0;
	for(int y=1;y<=H;y++){
		for(int x=1;x<=W;x++){
			cin>>F[y][x];
			
		}
	}
	int cnt=0;
	for(int y=1;y<=H;y++)
		for(int x=1;x<=W;x++){
			if(F[y][x]=='@'){
				cnt++;
				DFSMI(y,x);
			}
			else if(F[y][x]=='#'){
				cnt++;
				DFSRI(y,x);
			}
			else if(F[y][x]=='*'){
				cnt++;
				DFSKA(y,x);
			}
		}
	cout<<cnt<<endl;
	}
return 0;
}

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

int main(){
  ll N,K;
  cin >> N >> K;

  vector<ll> A(N);
  rep(i,N) cin >> A[i];

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());

  vector<ll> F(N);
  rep(i,N) cin >> F[i];
  sort(F.begin(),F.end());

  //binary_search() -1は0である場合を考慮
  ll left = -1, right = pow(10,18);
  while((right - left) > 1) {
    bool canRes = true; 
    ll reqK = 0;
    ll mid = (right + left) / 2;

    rep(i,N){
      if(A[i] > (mid / F[i])){
        reqK += A[i] - (mid / F[i]);
      }
      
      if(reqK > K){
        canRes = false;
        break;
      }
    }
    
    if (canRes == true){
      right = mid;
    }else{
      left = mid;
    }  
  }

  ll ans = right;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
while dataset = gets do

  if dataset.chomp! == ''
    break
  end

  dataArray = Array.new
  dataArray = dataset.split(' ')

  a = dataArray[0].to_i
  b = dataArray[1].to_i
  c = dataArray[2].to_i
  d = dataArray[3].to_i
  e = dataArray[4].to_i
  f = dataArray[5].to_i

  x = 1.0/(a*e-b*d)*(e*c-b*f)
  y = 1.0/(a*e-b*d)*(-d*c+a*f)

  x = (x*1000).round/1000.0
  y = (y*1000).round/1000.0

  printf("%.3f %.3f\n",x,y)
end

Measured memory_bytes: 6156
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] D = nextIntArray(sc, K);

		sc.close();
		Set<Integer> deny = new HashSet<>();
		Set<Integer> allow = new HashSet<>();
		for (int i = 0; i < D.length; i++) {
			deny.add(D[i]);
		}
		for (int i = 0; i <= 9; i++) {
			if (!deny.contains(i)) {
				allow.add(i);
			}
		}
		int ans = 0;
		for (int i = N; i <= 100000; i++) {
			Set<Integer> u = new HashSet<>();
			String s = String.valueOf(i);
			for (char c : s.toCharArray()) {
				u.add(c - '0');
			}
			if (allow.containsAll(u)) {
				ans = i;
				break;
			}
		}
		out.println(ans);
	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 38864
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

string solve(string s, int k)
{
	int n=s.length();
	if(k==0) return s;
	string t=s;
	int ptr=n-1;
	while(ptr-1>=0&&s[ptr-1]==s[n-1]) ptr--;
	reverse(t.begin(),t.end());
	s+=t;
	if(k==1) return s.substr(ptr,n);
	s=s.substr(n-ptr,n);
	return solve(s,k-1);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	string s; cin>>s;
	char c='z';
	for(int i=0;i<n;i++) c=min(c,s[i]);
	if(k>=18)
	{
		for(int i=0;i<n;i++)
		{
			cout<<c;
		}
		cout<<'\n'; return 0;
	}
	string ans;
	for(int i=0;i<n;i++) ans+="z";
	string t=s;
	reverse(t.begin(),t.end());
	s+=t;
	for(int i=0;i<=n;i++)
	{
		string res = solve(s.substr(i,n),k-1);
		if(res<ans) ans=res;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 512
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	string A, B, C;
	cin >> A >> B >> C;
	char dir = 'A' - 'a';
	printf("%c%c%c\n",A[0]+dir,B[0]+dir,C[0]+dir);
	return 0;
}

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

int main() {
    int N,M;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin >> s.at(i);
    }
    cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++){
        cin >> t.at(i);
    }
    string searched = "";
    int answer = 0;
    for(int i=0;i<N;i++){
        int search = 0;
        string keyword = s.at(i);
        if(searched.find(keyword) == string::npos){
            searched += (s.at(i) + "/");
            for(int j=i;j<N;j++){
                if(s.at(j) == keyword){
                    search++;
                }
            }
            for(int j=0;j<M;j++){
                if(t.at(j) == keyword){
                    search--;
                }
            }
            if(search > answer){
                answer = search;
            }
        }
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
# ABC 157 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
a=[list(map(int, input().split())) for i in range(3)]
n=int(input())
b=[]
for i in range(n):
    bb=int(input())
    b.append(bb)

mat=[[0]*3 for _ in range(3)]

for bb in b:
    for i in range(3):
        for j in range(3):
            if bb==a[i][j]:
                mat[i][j]=1
a1=mat[0][0]+mat[1][0]+mat[2][0]
a2=mat[0][1]+mat[1][1]+mat[2][1]
a3=mat[0][2]+mat[1][2]+mat[2][2]
# a1=mat[0][0]+mat[0][1]+mat[0][2]
# a2=mat[1][0]+mat[1][1]+mat[1][2]
# a3=mat[2][0]+mat[2][1]+mat[2][2]
a4=mat[0][0]+mat[1][1]+mat[2][2]
a5=mat[0][2]+mat[1][1]+mat[2][0]
if a1==3 or a2==3 or a3==3 or a4==3 or a5==3:
    print('Yes')
    exit()

# print(a)
# print(b)
# print(mat)
for mm in mat:
    if sum(mm)==3:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s[2][3];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> s[i][j];
		}
	}
	if (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
string b;
  cin>>b;
  
  if(b=="A"){
  cout<<"T"<<endl;
  }
    if(b=="T"){
  cout<<"A"<<endl;
  }
      if(b=="C"){
  cout<<"G"<<endl;
  }
        if(b=="G"){
  cout<<"C"<<endl;
  }
}

Measured memory_bytes: 256
N, M , X = map(int, input().split())
C = [0 for i in range(N)]
A = [[]for i in range(N)]


for i in range(N):
    temp = list(map(lambda x:int(x), input().split()))
    C[i] = temp[0]
    A[i] = temp[1:]

def solve():
    ans = float('inf')
    # Total: O(2^N*N*M)
    total = 1 << N
    for mask in range(total):  #O(2^N)
        L = [0 for i in range(M)]
        cost = 0
        
        for i in range(N):  #O(N)
            if (mask >> i) & 1:
                cost += C[i]
                for j in range(M): #O(M)
                    L[j] += A[i][j]
            
        ok = True
        for i in range(M):
            if L[i] < X: 
                ok = False
        #print(L, cost, ok)
        if ok:
            ans = min(ans,cost)

    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
solve()


Measured memory_bytes: 9300
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
  
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
  
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
  
typedef pair<int, int> pii;
typedef long long ll;
  
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
pair<int, int> dp[510][510];
const pair<int, int> INFII(INF, -1);
  
void update(pair<int, int> &A, pair<int, int> B) {
    B.first = B.first + 1;
    if(A.first > B.first) A = B;
    else if(A.first == B.first) {
        (A.second += B.second) %= MOD;
    }
}
 
struct Elem {
    int x, y, ans, cnt;
};
 
signed main() {
    int R, C, sx, sy, tx, ty; cin >> R >> C >> sx >> sy >> tx >> ty;
    fill(dp[0], dp[R], INFII);
    dp[sx][sy] = make_pair(0, 1);
 
    queue<Elem> que;
    que.push(Elem{sx, sy, 0, 1});
 
    const int ex[] = {-1, 0, -1, R-1};
    const int ey[] = {0, -1, C-1, -1};
    for(int step=0; step<R+C; step++) {
        set< pair<int, int> > checked;
        while(que.size()) {
            Elem cur = que.front(); que.pop();
            // 隣接
            for(int k=0; k<4; k++) {
                int nx = cur.x + dx[k], ny = cur.y + dy[k];
                if(nx < 0 || ny < 0 || nx >= R || ny >= C) continue;
                if(dp[nx][ny].first < dp[cur.x][cur.y].first + 1) continue;
                update(dp[nx][ny], dp[cur.x][cur.y]);
                checked.insert(make_pair(nx, ny));
            }
 
            // テレポート
            for(int k=0; k<4; k++) {
                int nx = (ex[k] < 0 ? cur.x : ex[k]);
                int ny = (ey[k] < 0 ? cur.y : ey[k]);
                if(dp[nx][ny].first < dp[cur.x][cur.y].first + 1) continue;
                update(dp[nx][ny], dp[cur.x][cur.y]);
                checked.insert(make_pair(nx, ny));
            }
        }
         
        for(auto x : checked) {
            int nx, ny; tie(nx, ny) = x;
            int vl, vr; tie(vl, vr) = dp[nx][ny];
            que.push(Elem{nx, ny, vl, vr});
        }
    }
 
    int ans1, ans2;
    tie(ans1, ans2) = dp[tx][ty];
    printf("%lld %lld\n", ans1, ans2);
    return 0;
}


Measured memory_bytes: 7120
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int selectionSort(vector<int> &A)
{
    int cnt = 0;
    for (std::vector<int>::size_type i = 0; i < A.size(); i++)
    {
        std::vector<int>::size_type minj = i;
        for (std::vector<int>::size_type j = i; j < A.size(); j++)
        {
            if (A.at(j) < A.at(minj))
            {
                minj = j;
            }
        }
        if (i != minj)
        {
            cnt++;
            swap(A.at(i), A.at(minj));
        }
    }
    return cnt;
}
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int cnt = selectionSort(A);

    for (std::vector<int>::size_type i = 0; i < A.size() - 1; i++)
    {
        cout << A.at(i) << ' ';
    }
    cout << A.back() << endl;

    cout << cnt << endl;
}


Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var SW = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var S = SW[0];
            var W = SW[1];
            Console.WriteLine(S<=W?"unsafe":"safe");

        }
    }
}

Measured memory_bytes: 18988
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	A := readInt()
	B := readInt()

	cur := 1

	var ans int
	for cur < B {
		ans++
		cur--
		cur += A
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
def na(): return map(int, input().split())
n, a = na()
x = list(na())
xa = list(map(lambda f: f-a, x))
'''
dp[i][点数] = パターン数
i番目まで使用したときの点数になるパターン数
'''
dp = [dict() for _ in range(n)]
if xa[0] == 0:
    dp[0][0] = 2
else:
    dp[0][0] = 1
    dp[0][xa[0]] = 1
for i in range(1, n):
    #xa[i]を採用する / 採用しないで2つに分岐
    #すべて採用しないと点数0になるので、最後に点数0になったパターン数から1引く
    for k, v in dp[i-1].items():#k:得点, v:パターン数
        score = xa[i] + k
        dp[i][score] = dp[i].get(score, 0) + v#xa[i]を採用
        dp[i][k] = dp[i].get(k, 0) + v#xa[i]を不採用
print(dp[n-1][0] - 1)

Measured memory_bytes: 4980
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            int X = int.Parse (Console.ReadLine ());

            int vhappy = X / 500;
            int happy = (X - 500 * vhappy) / 5;

            Console.WriteLine (1000 * vhappy + 5 * happy);

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

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

using namespace std;

int main() {
    int n, m, c;
    cin >> n >> m >> c;

    vector<int> b(m);
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int sum = c;
        for (int j = 0; j < m; j++) {
            int a;
            cin >> a;
            sum += a * b[j];
        }

        if (sum > 0) {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string a;
    int ans=0;
    cin>>a;
    REP(i,4){
        if(a[i]=='+')ans++;
        else ans--;
    }
    cout<<ans<<endl;
}

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

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

  int cnt = 0;
  while (H > 0) {
    cnt++;
    if (H == 1) {
      H = 0;
      continue;
    }
    H /= 2;
  }

  long long res = 0;
  long long num = 1;
  for (int i = 0; i < cnt; i++) {
    res += num;
    num *= 2;
  }

  cout << res;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [[0]*W for _ in range(H)]
h = 0
nums= []
for i,ai in enumerate(a):
    for _ in range(ai):
        nums.append(i+1)

for h in range(H):
    for w in range(W):              #一筆書きをリストに詰める
        if h % 2 == 0:
            ans[h][w] = nums.pop(0)
        else:
            ans[h][W-w-1] = nums.pop(0)

for a in ans:
    print(" ".join(map(str,a)))

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
N = int(input())
A, B = list(map(int, input().split()))
Pn = list(map(int, input().split()))

p1_cnt = sum([1 for p in Pn if p <= A])
p2_cnt = sum([1 for p in Pn if A+1 <= p <= B])
p3_cnt = sum([1 for p in Pn if B+1 <= p])

print(min([p1_cnt, p2_cnt, p3_cnt]))


Measured memory_bytes: 3060
N, M = [int(i) for i in input().split()]

def canMake(div):
    #return (M%div == 0) and (M//div) - (N-1) >= 1 
    return N * div <= M

ans = 1
for i in range(1, M):
    if i * i > M:
        break
    if M % i != 0:
        continue
    a, b = i, M//i
    if canMake(a):
        ans = max(ans, a)
    if canMake(b):
        ans = max(ans, b)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

bool no[100010];
bool f[100010];

vi es[100010];
ll d[100010];

int main(){
	int n, m, k, s;
	ll h, l;
	cin>>n>>m>>k>>s>>l>>h;
	queue<pii> q;
	rep(i, k){
		int t;
		cin>>t;
		q.push({t, 0LL});
		f[t] = true;
		no[t] = true;
	}
	rep(i, m){
		int a, b;
		cin>>a>>b;
		es[a].pb(b);
		es[b].pb(a);
	}

	pii p;
	while(!q.empty()){
		p = q.front(); q.pop();
		int from = p.fi, c = p.se;
		if(c == s) continue;
		for(auto to : es[from]){
			if(f[to]) continue;
			f[to] = true;
			q.push({to, c + 1});
		}
	}

	rep(i, n + 2) d[i] = LINF;
	d[1] = 0LL;

	auto dijkstra = [&]{
		typedef pair<ll, int> P;
		//P p;
		priority_queue<P, vector<P>, greater<P> > pq;
		pq.push({0LL, 1});
		while(!pq.empty()){
			p = pq.top(); pq.pop();
			int from = p.se;
			ll c = p.fi;
			for(int to : es[from]){
				if(no[to]) continue;
				if(d[to] > c + (from == 1 ? 0LL : (f[from] ? h : l))){
					d[to] = c + (from == 1 ? 0LL : (f[from] ? h : l));
					pq.push({d[to], to});
				}
			}
		}
	};
	dijkstra();
	cout<<d[n]<<endl;
}

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

#define ll long long

ll n, q;

vector<ll> adj[200005];
ll diff[200005];

ll dfs(ll node, ll par){
	for(auto child: adj[node]){
		if(child == par) continue;
		diff[child] += diff[node];
		dfs(child, node);
	}
}

int main(){
	cin >> n >> q;
	for(ll i=0;i<n-1;i++){
		ll u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	while(q--){
		ll p, x;
		cin >> p >> x;
		diff[p-1] += x;	
	}
	
	dfs(0, -1);
	
	for(ll i=0;i<n;i++) cout << diff[i] << " ";
}


Measured memory_bytes: 24320
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<queue>

using namespace std;

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

#define f first
#define s second

int main(){
	while(1){
		int n;
		cin>>n;
		
		if(n==0)break;
		
		vector<pair<int,int> > has;
		rep(i,n){
			int a,b;
			cin>>a>>b;
			has.push_back(make_pair(a,b));
		}
		
		sort(has.begin(),has.end());
		
		int ans=0;
		
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				rep(p,2){
					int dx=has[i].first-has[j].first;
					int dy=has[i].second-has[j].second;
					
					pair<int,int> nex1;
					pair<int,int> nex2;
					
					if(p==0){
						nex1.first = has[i].first-dy;
						nex1.second = has[i].second+dx;
						nex2.first = has[j].first-dy;
						nex2.second = has[j].second+dx;
					}else{
						nex1.first = has[i].first+dy;
						nex1.second = has[i].second-dx;
						nex2.first = has[j].first+dy;
						nex2.second = has[j].second-dx;
					}
					
					int a=binary_search(has.begin(),has.end(),nex1);
					if(a==0)continue;
					
					int b=binary_search(has.begin(),has.end(),nex2);
					if(b==0)continue;
					
					ans = max(ans, dx*dx+dy*dy);
					break;
				}
			}
		}
		
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 968
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q;
ll A[200001];
ll B[200001];
ll D[200001];
ll T[200001];
ll ans;
string S;
ll K;
map<ll, ll> m;
char ansmap[102][102];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin >> N;
	rep(i, 0, N) {
		cin >> D[i];
		m[D[i]]++;
	}
	cin >> M;
	rep(i, 0, M) {
		cin >> T[i];
		m[T[i]]--;
		if (m[T[i]] < 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  string s;
  cin>>s;

  bool ans=true;

  rep(i,s.size()){
    if(i%2==0){
      if(s[i]=='L') ans=false;
    }else{
      if(s[i]=='R') ans=false;
    }
    //if(!ans) cout<<i<<endl;
  }

  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

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

typedef long long ll;

int main()
{
  ll N;
  std::string S;
  std::cin >> N >> S;

  const ll z = 'Z' - 'A';
  std::string ans;
  for (auto& c : S) {
    if ((c - 'A') + N > z) {
      ans += ((c - 'A') + N - z - 1) + 'A';
    } else {
      ans += c + N;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> W(N);
    for (int n = 0; n < N; ++n) cin >> W[n];
    vector<int> S(N);
    S[0] = W[0];
    for (int n = 1; n < N; ++n) S[n] = S[n-1] + W[n];
    int Sum = S[N-1];
    int Res = INF;
    for (int n = 0; n < N-1; ++n) {
        int Tmp = abs(Sum-2*S[n]);
        if (Tmp < Res) Res = Tmp;
    }
    cout << Res << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextChar(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int {
	i, _ := strconv.Atoi(nextChar(sc))
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		h := nextInt(sc)
		w := nextInt(sc)

		if h == 0 && w == 0 {
			return
		}

		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if i == 0 || i == h-1 || j == 0 || j == w-1 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1096
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s[100];
	int L,N;
	cin>>N>>L;
	for(int i=0;i<N;i++)
		cin>>s[i];
	sort(s,s+N);
	for(int i=0;i<N;i++)
		cout<<s[i];
	return 0;
}

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

#define MAX_N 1355

int x[MAX_N][4], y[MAX_N][4];
int X[MAX_N][MAX_N], Y[MAX_N][MAX_N];
int n, m, M ,cnt;

int main() {
	while (true) {
		if (cnt >= 1) { cout << "+++++" << endl; }
		cnt++;
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		memset(X, 0, sizeof(X));
		memset(Y, 0, sizeof(Y));
		cin >> n;
		if (n == 0) { break; }
		cin >> M;
		for (int i = 0; i < M; i++) {
			cin >> x[i][0] >> y[i][0];
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < M; j++) {
				x[j][i + 1] = -y[j][i];
				y[j][i + 1] = x[j][i];
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> m;
			for (int j = 0; j < m; j++) {
				cin >> X[i][j] >> Y[i][j];
			}
			int same = 8;
			if (M != m) { same = 0; }
			else {
				for (int j = 0; j < 4; j++) {
					int X1 = x[0][j] - X[i][0], Y1 = y[0][j] - Y[i][0];
					for (int k = 1; k < M; k++) {
						if ((x[k][j] - X[i][k] != X1 || y[k][j] - Y[i][k] != Y1) && same == 8 - j) {
							same--;
						}
					}
				}
				for (int j = 0; j < 4; j++) {
					int X1 = x[0][j] - X[i][M - 1], Y1 = y[0][j] - Y[i][M - 1];
					for (int k = 1; k < M; k++) {
						if ((x[k][j] - X[i][M - 1 - k] != X1 || y[k][j] - Y[i][M - 1 - k] != Y1) && same == 4 - j) {
							same--;
						}
					}
				}
			}
			if (same >= 1) { cout << i << endl; }
		}
	}
	return 0;
}

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

const long long MOD = 1e9+7;

int main(){
  int H, W; cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> a[i][j];
    }
  }
  vector<vector<long long>> dp(H, vector<long long>(W,0));
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (a[i][j]=='#') continue;
      if (i==0&&j==0) dp[i][j] = 1;
      else if (i==0) dp[i][j] = dp[i][j-1];
      else if (j==0) dp[i][j] = dp[i-1][j];
      else dp[i][j] = dp[i-1][j] + dp[i][j-1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 9088
#include<iostream>
#include<math.h>

void swap( int *a, int *b )
{
	int t = *a;
	*a = *b;
	*b = t;
	
	return;
}

int main()
{
	int n;
	std::cin >> n;
	int a, b, c;
	while( n-- ){
		std::cin >> a >> b >> c;
		if( a < b ){
			swap( &a, &b );
		}
		if( a < c ){
		 	swap( &a, &c );
		}
		if( a*a == b*b + c*c ){
		 	std::cout << "YES" << std::endl;
		}
		else{
		 	std::cout << "NO" << std::endl;
		}
	}

 	return 0;
}

Measured memory_bytes: 0
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace<'a>) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: u64 = iter.read();
	let m: u64 = iter.read();

	use std::collections::HashMap;

	let mut cons: HashMap<u64, Vec<u64>> = HashMap::new();
	let mut vals: HashMap<u64, u32> = HashMap::new();

	for i in 1..(m + 1) {
		let k: u64 = iter.read();
		let mut v: Vec<u64> = vec![];
		for _ in 1..(k + 1) {
			let s: u64 = iter.read();
			v.push(s);
		}
		cons.insert(i, v);
	}
	for i in 1..(m + 1) {
		let p: u32 = iter.read();
		vals.insert(i, p);
	}

	let check = |sw: u64| -> bool {
		for (i, v) in cons.iter() {
			let mut c: u32 = 0;
			for &n in v.iter() {
				let on = sw & (1 << (n - 1));
				if 0 < on {
					c = c ^ 1;
				}
			}
			if let Some(&c2) = vals.get(i) {
				if c2 != c {
					return false;
				}
			}
		}
		true
	};

	let mut cnt: u64 = 0;
	for sw in 0..(1 << n) {
		if check(sw) {
			cnt += 1;
		}
	}

	println!("{}", cnt);
}


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

int main()
{
	string s;
	int n;
	bool flag = true;
	cin >> s;
	n = s.size();

	for(int i=1; i<=n; i++) {
		if(i&1 && (s[i-1] != 'R' && s[i-1] != 'U' && s[i-1] != 'D') )
			flag = false;
		if(!(i&1) && (s[i-1] != 'L' && s[i-1] != 'U' && s[i-1] != 'D') )
			flag = false;
	}

	if(flag) cout << "Yes\n";
	else cout << "No\n";
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll n , dp[N] , dp2[N] , mod = 998244353;
pair<ll,ll> seg[4*N];
vector< pair<ll,ll> > v;

void build(int node , int st , int en)
{
    if (st==en)
    {
        seg[node] = {v[st].f+v[st].s-1 , st};
        return;
    }
    int mid = (st+en)/2;
    build(2*node , st , mid);
    build(2*node+1 , mid+1 , en);
    seg[node] = max(seg[2*node] , seg[2*node+1]);
}

pair<ll,ll> query(int node , int st , int en , int l , int r)
{
    if (st > r || en < l) return {-2e9,-2e9};

    if (st >= l && en <= r)
        return seg[node];

    int mid = (st+en)/2;
    return max(query(2*node , st , mid , l , r) , query(2*node+1 , mid+1 , en , l , r));
}

ll solve(int i)
{
    if (i==n+1)
        return dp[i] = i;

    if (dp[i] != -1)
        return dp[i];

    ll ans = i+1 , up , idx , tmp , l , r;
    up = upper_bound(v.begin() , v.end() , make_pair(v[i].f+v[i].s-1 , (ll)3e9)) - v.begin();
    if (up == v.size() || up == i+1) ans = up;
    else
    {
        l = i+1 , r = up-1;
        idx = query(1,1,n,l,r).s;
        ans = max(ans , up);
        if (idx > i) ans = max(ans , solve(idx));
    }
    return dp[i] = ans;
}

ll solve2(int i)
{
    if (i > n)
        return 1;

    if (dp2[i] != -1)
        return dp2[i];

    ll ans = solve2(i+1);

    ans += solve2(dp[i]);
    ans %= mod;

    return dp2[i] = ans;
}

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

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        ll x,d;
        cin >> x >> d;
        v.push_back({x,d});
    }
    v.push_back({-3e9,-3e9});
    sort(v.begin() , v.end());
    build(1,1,n);

    memset(dp , -1 , sizeof(dp));
    memset(dp2 , -1 , sizeof(dp2));

    for(int i=1; i<=n; i++)
    {
        solve(i);
    }

    cout << solve2(1) << "\n";

    return 0;
}

Measured memory_bytes: 24044
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int A = a[0];
        int B = a[1];
        if((A * B) % 2 == 0)
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }
    }
}

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int N;
  cin >> N;
  bool x = false;
  for(int i = 0; 4*i<=N; i++){
    for(int j = 0; 7*j<=N; j++){
      if(4*i+7*j==N){
        x = true;
      }
    }
  }
  if(x) cout << "Yes" << endl;
  else cout << "No" << endl;
}      

Measured memory_bytes: 3644
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int m = scanner.nextInt();
            x -= m;
            min = Math.min(min, m);
        }
        System.out.println(n + x / min);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int main(){
	int N;
	scanf("%d",&N);
	printf("%d",N*(N+1)/2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<vector<int> > G(n);
    for(int i=0;i<m;i++){
      int x,y;
      cin>>x>>y;
      x--;y--;
      G[x].emplace_back(y);
      G[y].emplace_back(x);
    }
    int flg=0;
    for(int i=0;i<n;i++){
      if(G[i].size()>2u){
        cout<<"no"<<endl;
        flg=1;
        break;
      }
    }
    if(flg) continue;
    
    vector<int> used(n,0);
    function<void(int, int)> dfs=
      [&](int v,int p){
        for(int u:G[v]){
          if(u==p) continue;
          if(used[u]){
            flg=1;
            break;
          }
          used[u]=1;
          dfs(u,v);
        }
      };
    
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      used[i]=1;
      dfs(i,-1);
    }
    cout<<(flg?"no":"yes")<<endl;
  }
  return 0;
}



Measured memory_bytes: 6692
#再帰のlimitを解除
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())
#何と繋がっているか（隣接リスト）
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

#深さ優先探索 累積和
def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        #1つ先に情報を流す
        memo[nv] += memo[v]
        #dfsを更新
        dfs(nv, v)

dfs(0, -1)

print(*memo)

Measured memory_bytes: 230960
#include<bits/stdc++.h>
using namespace std;
int main(){
    const double pi = acos(-1);
    int a, b, c;
    cin >> a >>b >> c;//c=angle betwen a and b
    double S;//surface
    double L;//length
    float h;//height
    float d=sqrt(a*a+b*b-2*a*b*cos(c*M_PI/180));
    L=a+b+d;
    h=b*sin(c*M_PI/180);
    S=a*b*sin(c*pi/180)/2;
    cout <<fixed << setprecision(5)<< S << endl;
    cout <<fixed << setprecision(5)<< L << endl;
    cout <<fixed << setprecision(5)<< h << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int i,number;
  int y =100000000000;
  
  for(i=0;i<N;i++){
    cin >> number;
      int x =0;
      
      while(number%2 == 0){
      number /=2;
      x++;
    }
    
    if(x<y)
      y = x;
  }
  
  cout << y << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main() {
  ll n;
  cin>>n;
  ll d[100];
  clr(d,0);
  rep(i,0,n){
    ll a;
    cin>>a;
    d[a/400]++;
  }
  ll a = 0;
  rep(i,0,8){
    if(d[i]>0){
      a++;
    }
  }
  ll b = 0;
  rep(i,8,100){
    b += d[i];
  }
  cout << max(1LL,a) << " " << a+b << endl;
  return 0;
}

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

using namespace std;

const long long MOD = 1000000007;
int main() {
    long long X;
    cin>>X;
    int dp[1000000];
    for(int i=0;i<1000000;i++){
        dp[i]=0;
    }
    dp[0]=1;
    for(int i=0;i<100000;i++){
        if(dp[i]==1){
            dp[i+100]=1;
            dp[i+101]=1;
            dp[i+102]=1;
            dp[i+103]=1;
            dp[i+104]=1;
            dp[i+105]=1;
        }

    }
    cout<<dp[X]<<endl;





}













Measured memory_bytes: 4096
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define rall(v)     (v).rbegin(),(v).rend()
#define sort(v)     sort((v).begin(),(v).end())
#define rsort(v)    sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
#define sum(v)+x    accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;
//x.substr(start, length);
/*
// Create a vector containing n 
//vectors of size m.  
    vector<vector<int> > vec( n , vector<int> (m, 0));  
*/
struct type{
    int k, i, j;
};
//to check if a no is prime or not?
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k)
{
	int window_sum = 0;
	int min_window = INT_MAX;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		window_sum += arr[i];
		if (i + 1 >= k)
		{
			if (min_window > window_sum)
			{
				min_window = window_sum;
				last = i;
			}
			window_sum -= arr[i + 1 - k];
		}
	}
	int sum=0;
	for(int i=last-k+1;i<=last;i++)
	{
	    sum+=arr[i];
	}
	return sum;
}
//finds the next permutation to given sequence of nos
int nextpermutation(vi v)
{
    vi t=v;
    sort(t);
    int x=0;
    while(true)
    {
        x++;
        if(t==v)
        {
            return x;
        }
        next_permutation(all(t));
    }
}
vector<int>factors(int n) 
{ 
    // Note that this loop runs till square root 
    vi ans;
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i ) 
                ans.pb(i);
  
            else
         
                ans.pb(i);
                if (i!=n/i)
          
                ans.pb(n/i); 
        } 
    } 
    return ans;
}
int power(int x, int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y/2; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int a,b;
    cin>>a>>b;
    print((a*b)/gcd(a,b))
    
}
    
    


Measured memory_bytes: 3648
#include<iostream>
#include<string>
int main(){
  int H,W;
  std::cin>>H>>W;
  std::string str[H];
  for(int i=0;i<H;i++){
    std::cin>>str[i];
  }
  int cont,place=0;
  for(int i=0;i<H;i++){
    cont=0;
    for(int j=0;j<W;j++){
      if(str[i][j]=='#'&&cont!=-1){
        if(place>j){
          std::cout<<"Impossible"<<std::endl;
          return 0;
        }
        cont=1;
        place=j;
      }else if(cont==1&&str[i][j]=='.'){
        cont=-1;
      }else if(cont==-1&&str[i][j]=='#'){
        std::cout<<"Impossible"<<std::endl;
        return 0;
      }
    }
  }
  std::cout<<"Possible"<<std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
bool zs(int x){
	if(x<=1)return false;
	for(int i=2;i*i<=x;i++)
	 if(x%i==0)
	  return false;
	return true;
}
int n,t;
int main(){
	cin>>n;t=n;
	if(zs(n)){cout<<n<<endl;return 0;}
	while(!zs(t))t++;
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 3588
//
// Created by misclicked on 3/7/20.
//

#include <bits/stdc++.h>

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

#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    ios_base::sync_with_stdio(false);
    cin.tie();
#endif
    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll ans = 0;
    if (p == 2 || p == 5) {
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % p == 0)
                ans += i + 1;
        }
    } else {
        unordered_map<ll, ll> mape;
        mape[0]++;
        ll now = 0, p10 = 1;
        for (int i = n - 1; ~i; i--) {
            now = (now + (s[i] - '0') * p10) % p;
            ans += mape[now];
            mape[now]++;
            p10 = (p10 * 10) % p;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 916