akhauriyash/Code-Regression huggingface dataset:
# ABC152F

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



from collections import defaultdict
from queue import deque
import itertools
import functools
def find(start,goal):
    q = deque([start])
    seen = [None] * n
    seen[start] = -1
    while q:
        u = q.pop()
        d = seen[u]
        if u==goal:
            break
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    u = goal
    es = 0
    while True:
        t = (min(u, seen[u]), max(u, seen[u]))
        es |= 1<<uv2e[u,seen[u]]
        if seen[u]==start:
            break
        u = seen[u]
    return es

n = int(input())
ns = defaultdict(set)
uv2e = {}
for i in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1, u-1] = i
ans = 0
m = int(input())
paths = [None] * m
for i in range(m):
    u, v = map(int, input().split())
    paths[i] = find(u-1,v-1)

ans = 0

# def dfs(ind, s, ans):
#     if len(ind)==m:
#         if True in ind:
#             tmp = 0
#             for i in range(n-1):
#                 tmp += (s & 1<<i)>0
#             ans += 2**(n-1-tmp) * (-1)**((sum(ind)+1)%2)
#         return ans
#     ans = dfs(ind + [True], s | paths[len(ind)], ans)
#     ans = dfs(ind + [False], s, ans)
#     return ans
        
def bitlen(b):
    tmp = 0
    for i in range(n-1):
        tmp += (b&1<<i)>0
    return tmp
for ind in itertools.product(*[(False, True) for _ in range(m)]):
    num = sum(ind)+1
    if num==1:
        continue
    c = 2**(n - 1 - bitlen(functools.reduce(lambda x,y: x|y, (paths[i] for i in range(m) if ind[i]), 0)))
    ans += (-1)**num * c
# ans = dfs([], 0, 0)
print(2**(n-1) - ans)

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

int main(){
    int x, y;
    cin>>x>>y;
    while(x!=0 || y!=0){
        if(x>y){
            int t;
            t = x;
            x = y;
            y = t;
        }
        cout<<x<<" "<<y<<endl;
        cin>>x>>y;
    }
}


Measured memory_bytes: 3016
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
int A,B,C,X;
cin >> A >> B >> C >> X;
int counter = 0;
for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
        for(int k = 0; k <= C; k++){
            if(500*i + 100*j + 50*k == X)counter++;
        }
    }
}

cout << counter << endl;
}

Measured memory_bytes: 256
# = map(int, input().split())
# = int(input())
S = input()
T = input()
N = len(S)
M= len(T)
ans = N


for j in range(N- M+1):
  change = 0
  for l in range(M):
    if S[j+l] != T[l]:
      change += 1
  ans = min(ans, change)

print(ans)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main() {
	scanf("%d%d",&a,&b);
	k=a+b;
	if(k/2==k/2.0) printf("%d\n",k/2);
	else printf("IMPOSSIBLE\n"); 
	return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, H[MAXN], ans=0;


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> H[i];
    }
    int ct = 0;
    for(int i=N-2; i>=0; i--)
    {
        if(H[i] >=H[i+1])
        {
            ct++;
        }
        else
        {
            ans = max(ans, ct);
            ct=0;
        }
    }
    ans = max(ans, ct);
    cout << ans;
    return 0;
}


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

int n = 8;
int row[8] = {}, col[8] = {}, dpos[16] = {}, dneg[16] = {}; //0->free
int queen[8][8] = {}; //0->free

void printBoard(){
  
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(queen[i][j] && row[i] != j) return ;
    }
  }
  
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(row[i] == j) cout << 'Q';
      else cout << '.';
    }
    cout << endl;
  }
}

void putQueen(int i){
  
  if(i == n){
    printBoard();
    return ;
  }
  
  for(int j = 0;j < n;j++){
    if(col[j] || dpos[i + j] || dneg[i - j + n - 1]) continue;
    
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + n - 1] = 1; //not free
    
    putQueen(i + 1);
    
    col[j] = dpos[i + j] = dneg[i - j + n - 1] = 0; //free
  }
}

int main(){
  
  int k, r, c;
  
  cin >> k;
  for(int i = 0;i < k;i++){
    cin >> r >> c;
    queen[r][c] = 1;
  }
  
  putQueen(0);
  
  return 0;
}


Measured memory_bytes: 3128
#include<iostream>

using namespace std;

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

	string s;
    cin>>s;

    long long rez=0;
    for(int i=0; i<(1<<(s.size()-1)); i++)
    {
        long long cr=0;
        for(int j=0; j<=(int)s.size()-2; j++)
        {
            cr=cr*10+s[j]-'0';
            if((1<<j)&i)
            {
                rez=rez+cr;
                cr=0;
            }
        }

        cr=cr*10+s[s.size()-1]-'0';
        rez=rez+cr;
    }
    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPE(i,a,n) for(int i=a;i<=n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T,class U> void cinn(T& n,U a) {REP(i,0,n) cin >> a[i];}

int atcoder(){
    ll a,b,c;
    cin >> a >> b >> c;
    bool ans=false;

    if(max({a,b,c})==a+b+c-max({a,b,c})) ans=true;
    
    YesNo(ans);
    return 0;
    
    return 0;
}

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(),a = s.nextInt(),b=s.nextInt();

        System.out.println(Math.min(n*a,b));
    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25340
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
char s[100010];
int n;
bool qs(int l,int r)
{
	for(int i=l+1;i<=r;i++) if(s[i]!=s[i-1]) return false;
	return true;
}
bool check(int k)
{
	int l=n-k+1,r=k;
	//printf("%d %d %d %d\n",k,l,r,qs(l,r));
	if(l>=r) return true;
	return qs(l,r);
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int l=1,r=n,ans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
use strict;
use warnings;
use utf8;

# 11:13 - 11:17 wa
#       - 11:19 wa

my ($N) = split /\s/, <STDIN>;
my (@A) = split /\s/, <STDIN>;

@A = reverse sort {$a <=> $b} @A;
#@A = reverse sort @A;

#use Data::Dumper;
#print Dumper \@A;

my $alice = 0;
my $bob = 0;

for (my $i = 0; $i < scalar @A; $i += 2) {
    $alice += $A[$i];
}

for (my $i = 1; $i < scalar @A; $i += 2) {
    $bob += $A[$i];
}

printf "%s\n", $alice - $bob;


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

using namespace std; 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define forin(i, n) for ( int i = 0; i < (int)n; ++i )
typedef long long ll;

int main()
{
    //IOS
    
    int a, b; cin >> a >> b;
    cout << (a * b);

    return 0;
}

Measured memory_bytes: 3616
import kotlin.math.sqrt

//

fun main() {
    abc169d()
}

fun abc169d() {
    val n = readLine()!!.toLong()
    val primes = mutableMapOf<Long, Long>()
    var t = n
    var i = 2L
    while (i * i <= t) {
        if (t % i == 0L) {
            primes[i] = 0L
            while (t % i == 0L) {
                t /= i
                primes[i] = primes[i]!! + 1
            }
        }
        i++
    }
    if (t != 1L) primes[t] = 1L
    var count = 0
    for (l in primes.values) {
        t = l
        for (j in 1 .. l) {
            t -= j
            if (t >= 0) {
                count++
            } else {
                break
            }
        }
    }
    println(count)
}


Measured memory_bytes: 34636
#include<iostream>
using namespace std;
int main(){
  int n;
  char s[300005];
  int l[300005],r[300005];
  cin>>n;
  cin>>s;
  l[0]=0;
  r[n-1]=0;
  for(int i=1;i<n;i++){
    if(s[i-1]=='W')l[i]=l[i-1]+1;
    else l[i]=l[i-1];
  }
  for(int i=n-2;i>=0;i--){
    if(s[i+1]=='E')r[i]=r[i+1]+1;
    else r[i]=r[i+1];
  }
  int min=300000;
  for(int i=0;i<n;i++){
    if(r[i]+l[i]<min){
      min=r[i]+l[i];
    }
  }
  cout<<min<<"\n";
  return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>

int main(int argc, char *args[])
{
	int b,f,r,v;
	unsigned int person[4][3][10];
	int n;
	int i;

	for( b=0; b<4; b++ ) {
		for( f=0; f<3; f++ ) {
			for( r=0; r<10; r++ ) {
				person[b][f][r] = 0;
			}
		}
	}

	scanf("%d", &n);

	for( i=0; i<n; i++ ) {

		scanf("%d %d %d %d", &b, &f, &r, &v);

		person[b-1][f-1][r-1] += v;

	}

	for( b=0; b<4; b++ ) {

		for( f=0; f<3; f++ ) {

			for( r=0; r<10; r++ ) {
				printf(" %d", person[b][f][r]);
			}
			printf("\n");
		}
	
		if( b<3 ) {
			printf("####################\n");
		}
	}

	return 0;

}

Measured memory_bytes: 612
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
    string S;
	cin >> S;
	int min_diff = 1000;
	REP(i, SZ(S) - 2) {
		string s = S.substr(i, 3);
		int diff = abs(toInt(s) - 753);
		if (diff < min_diff) {
			min_diff = diff;
		}
	}

	cout << min_diff << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char x,y;
int main()
{
	cin>>x>>y;
		if(x>y)cout<<">"<<endl;
		else if(x<y)cout<<'<'<<endl;
		else cout<<"="<<endl;
	
	
	return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long int arr[n];
  for(long int i=0;i<n;i++)
   cin>>arr[i];

  long int largest=arr[0];
 long int sortest=arr[0];

  for(long int i=0;i<n;i++)
  {
     if(arr[i]>largest)
      largest=arr[i];

     if(arr[i]<sortest)
      sortest=arr[i];


  }
  cout<<largest-sortest<<endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def judge(info_list):
    result = 0
    info_list = info_list.split()
    for check in info_list:
        check = int(check)
        
        if check % 2 == 0:
            if (check % 3 != 0) and (check % 5 != 0) :
                result = 1
    
    return result

def main():
    info_num = int(input())
    info = input()
    answear = judge(info)
    
    if answear == 0:
        print("APPROVED")
    else:
        print("DENIED")
    

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 3060
w=input()
d={}
d["a"]=0
d["b"]=0
d["c"]=0
for i in w:
  d[i]+=1
l=[]
for i in d:
  l.append(d[i])
if max(l)>min(l)+1:
  print("NO")
else:
  print("YES")

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

int main() {
  // ここにプログラムを追記
  int A, B;
  cin >> A ;
  if( A < 1 ){ 
  	cout << "error: A under 1" << endl;
    return 1;
  }
  else if( B > 23 ){
  	cout << "error: B over 23" << endl;
    return 1;
  }
  cout << (24-A)+24 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x;
  cin >>n>>x;
  vector<int> l(n);
  for (int i=0; i<n; i++) {
    cin >> l.at(i);
  }
  vector<int> d(n+1);
  for (int j=0; j<n; j++) {
    d.at(j+1)=d.at(j)+l.at(j);
  }
  int y=0;
  for (int k=0; k<n+1; k++) {
    if (d.at(k) <= x) {
      y++;
    }    
  }
  cout <<y<<endl;
  }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    int ans = x;

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

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j += a[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a = list(map(int,input().split()))

s = max(a)
t = min(a)

if s == t:
    print(0)
elif abs(s) > abs(t):
    ss = a.index(s)
    print(2*n-2)
    for i in range(0,n):
        if i != ss:
            print(str(ss+1) + ' ' + str(i+1))
    for i in range(1,n):
        print(str(i) + ' '+str(i+1))
else:
    tt = a.index(t)
    print(2*n-2)
    for i in range(n):
        if i != tt:
            print(str(tt+1) + ' ' + str(i+1))
    for i in range(1,n):
        print(str(n-i+1) + ' ' + str(n-i))

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int32_t main() {

    int n; cin >> n;
    string s; cin >> s;

    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i; j < n; ++j) {
            if(s[i] == s[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
                if(i+dp[i+1][j+1] <= j) {
                    ans = max(ans, dp[i+1][j+1]);
                }
            } else {
                dp[i+1][j+1] = 0;
            }
        }
    }

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


Measured memory_bytes: 195840
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vector<pair<int, int> > ans[90001];

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int H, W, D; cin >> H >> W >> D;
	int vv[400][400];
	memr(ans, 0);
	map<int, pair<int, int> > mp;
	memr(vv, 0);
	rep(i, H){
		rep(j, W){
			cin >> vv[i][j];
			mp[vv[i][j]] =  {j, i};
		}
	}


	rep(i, D){
		int num = 1 + i;
		int origNum = num;
		pair<int, int> s = mp[num];
		int res = 0;
		ans[origNum].push_back({origNum, 0});
		while(num <= H * W){
			int n = num + D;
			pair<int, int> f = mp[n];
			int cnt = abs(f.first - s.first) + abs(f.second - s.second);
			s = {f.first, f.second};
			res += cnt;
			num = n;
			ans[origNum].push_back({num, res});
		}
		sort(ALL(ans[origNum]));
	}

	int Q; cin >> Q;
	rep(i, Q){
		int l, r; cin >>l >> r;
		int t = l % D;
		if(t == 0) t = D;
		pair<int, int> it = *lower_bound(ALL(ans[t]), make_pair(r, -INTINF));
		pair<int, int> it2 = *lower_bound(ALL(ans[t]), make_pair(l, -INTINF));

		cout << it.second - it2.second << endl;
	}


	return 0;
}


Measured memory_bytes: 17280
#include <stdio.h>
#include <math.h>
int p[100];
void reset(){
	int i;
	for(i=0;i<100;i++)p[i]=0;
}
int main(void){
	int i,j;
	reset();
	while(scanf("%d %d",&i,&j)!=EOF){
		if(i>0 && j>0){p[i-1]++;p[j-1]++;}
		else{
		j=1;
		for(j=2;j<100;j++){if(p[j]%2>0){j=0;break;}}
		if(j && p[0]%2==1 && p[1]%2==1)printf("OK\n"); else printf("NG\n");
		reset();
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int k; cin >> k;
    int cnt = 0;
    int num = 0;
    if(k%2==0){cout << -1 << endl; return 0;}
    while(1){
        cnt++;
        num = num + 7;
        num %= k;
        if(num==0){break;}
        num *= 10;
        if(cnt>10000000){cnt = -1; break;}
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int dx[4] = {0, 0, 1, -1}; //NSEW
int dy[4] = {-1, 1, 0, 0};
char color[7] = "rcgmby"; //tbnsew

struct die{
	int c[6];
	die(){
		for(int i=0; i<6; i++){
			c[i] = i;
		}
	}
	int top(){ return c[0]; }
	void rotate(int d){
		if(d==0){
			swap(c[0], c[3]);
			swap(c[3], c[1]);
			swap(c[1], c[2]);
		}else if(d==1){
			swap(c[0], c[2]);
			swap(c[2], c[1]);
			swap(c[1], c[3]);
		}else if(d==2){
			swap(c[0], c[5]);
			swap(c[5], c[1]);
			swap(c[1], c[4]);
		}else if(d==3){
			swap(c[0], c[4]);
			swap(c[4], c[1]);
			swap(c[1], c[5]);
		}
	}
};
struct info{
	die d;
	int step;
	int phase;
	int y,x;
	info(die d, int s, int p, int y, int x):
		d(d), step(s), phase(p), y(y), x(x){}
	bool operator<(const info &a) const{
		return step > a.step;
	}
	int hash(){
		return d.c[0] +(d.c[2]<<3) +(d.c[4]<<6) +(phase<<9) +(y<<12) +(x<<17);
	}
};

int main(){
	while(1){
		int w,h;
		cin >> w >> h;
		if(w==0) break;
		
		vector<vector<char> > c(h+2, vector<char>(w+2, 'k'));
		int sy, sx;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin >> c[i][j];
				if(c[i][j] == '#'){
					sy = i;
					sx = j;
					c[i][j] = 'w';
				}
			}
		}
		string v;
		cin >> v;
		
		info init(die(), 0, 0, sy, sx);
		priority_queue<info> wait;
		wait.push(init);
		vector<bool> used((int)1e7, false);
		used[init.hash()] = true;
		int ans = -1;
		while(!wait.empty()){
			info t = wait.top();
			wait.pop();
			if(t.phase == 6){
				ans = t.step;
				break;
			}
			for(int i=0; i<4; i++){
				die nd = t.d;
				nd.rotate(i);
				int ny = t.y +dy[i];
				int nx = t.x +dx[i];
				int np = t.phase;
				if(c[ny][nx] == 'k') continue;
				if(c[ny][nx] != 'w'){
					if(c[ny][nx] != v[t.phase] || c[ny][nx] != color[nd.top()]) continue;
					np++;
				}
				info next(nd, t.step+1, np, ny, nx);
				if(!used[next.hash()]){
					used[next.hash()] = true;
					wait.push(next);
				}
			}
		}
		if(ans == -1){
			cout << "unreachable" << endl;
		}else{
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
        cin >> p.at(i);
    }
    int count = 0, incount = 0;
    for (int i = 0; i < N; i++){
        if (i + 1 == p.at(i)){
            incount++;
            if (i == N - 1) count += (incount + 1) / 2;
        }
        else{
            count += (incount + 1) / 2;
            incount = 0;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	REP(i,n){
		if(a[i]%2==0){
			if(a[i]%3!=0 && a[i]%5!=0){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc073/tasks/abc073_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    unordered_set<int> st;
    REP(i, n) {
        int t;
        cin >> t;
        if (st.count(t) > 0) {
            st.erase(t);
        } else {
            st.insert(t);
        }
    }
    cout << st.size() << endl;
    return 0;
}


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

const int B = 131, P[] = {1000000007, 1000000009};
typedef long long ll;
int n;
ll ans;
pair<pair<int, int>, pair<int, int> > l[1 << 18];
char s[40];

int main()
{
	scanf("%d%s", &n, s);
	for (int i = 0; i < 1 << n; i++)
	{
		int h1[2] = {}, h2[2] = {};
		for (int k = 0; k < 2; k++)
			for (int j = 0; j < n; j++)
				if (i >> j & 1) h1[k] = (1ll * h1[k] * B + s[j]) % P[k];
				else h2[k] = (1ll * h2[k] * B + s[j]) % P[k];
		l[i] = make_pair(make_pair(h1[0], h2[0]), make_pair(h1[1], h2[1]));
	}
	sort(l, l + (1 << n));
	for (int i = 0; i < 1 << n; i++)
	{
		int h1[2] = {}, h2[2] = {};
		for (int k = 0; k < 2; k++)
			for (int j = n - 1; j >= 0; j--)
				if (i >> j & 1) h1[k] = (1ll * h1[k] * B + s[n + j]) % P[k];
				else h2[k] = (1ll * h2[k] * B + s[n + j]) % P[k];
		ans += upper_bound(l, l + (1 << n), make_pair(make_pair(h1[0], h2[0]), make_pair(h1[1], h2[1])))
			- lower_bound(l, l + (1 << n), make_pair(make_pair(h1[0], h2[0]), make_pair(h1[1], h2[1])));
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4352
from queue import Queue
N, M = map(int, input().split())
a, b = [0] * M, [0] * M
g = [[False] * N for _ in range(N)]
for i in range(M):
    a[i], b[i] = map(int, input().split())
    g[a[i]-1][b[i]-1] = True
    g[b[i]-1][a[i]-1] = True

ans = 0
for _a, _b in zip(a, b):
    g[_a-1][_b-1] = False
    g[_b-1][_a-1] = False
    visit = [False] * N
    q = Queue()
    q.put(0)
    while not q.empty():
        v = q.get()
        visit[v] = True
        for adj_v, adj in enumerate(g[v]):
            if not adj or visit[adj_v]:
                continue
            q.put(adj_v)
    if not all(visit):
        ans += 1
    g[_a-1][_b-1] = True
    g[_b-1][_a-1] = True
print(ans)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  print(min(a, b) + min(c, d));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define fi first
#define se second

const int maxn=1e5+10,mod=1e9+7;
int n;
int f[maxn][3];
vector<int> ad[maxn];
void add(int u,int v){
    ad[u].push_back(v);ad[v].push_back(u);
}
int DFS(int u,int co,int p){
    if(f[u][co]!=-1) return f[u][co];
    int ret=1;
    for(auto &v:ad[u]) if(v!=p)
    {
        if(co==0) ret=((DFS(v,1,u)+DFS(v,0,u))%mod)*ret%mod;
        else ret=ret*DFS(v,0,u)%mod;
    }
    return f[u][co]=ret;

}
main()
{
    //freopen("test.inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    forinc(i,1,n-1)
    {
        int x,y;
        cin>>x>>y;
        add(x,y);
    }
    memset(f,-1,sizeof f);
    cout<<(DFS(1,0,0)+DFS(1,1,0))%mod;
}


Measured memory_bytes: 14976
#59 D - Derangement
N = int(input())
P = list(map(int,input().split()))

cnt = 0
for i,j in enumerate(P):
    if (i+1) == j and i == N-1:
        P[i-1],P[i] = P[i],P[i-1]
        cnt += 1
        continue
    if (i+1) == j:
        P[i+1],P[i] = P[i],P[i+1]
        cnt += 1
print(cnt)

Measured memory_bytes: 20512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

ll N, A, B;
vector<ll> h;

// O(N)
bool can_kill(ll times) {
  ll cnt = 0;
  rep(i, N) {
    ll res = h[i] - times * B;
    if (res > 0)
      cnt += (res + (A - B - 1)) / (A - B);
  }
  if (cnt <= times)
    return true;
  else
    return false;
}

int main() {
  cin >> N >> A >> B;
  h = vector<ll>(N);
  rep(i, N) cin >> h[i];

  ll l = 0;
  ll r = 1.0e+10;

  while (r - l > 1) {
    ll c = (r + l) / 2;
    if (can_kill(c))
      r = c;
    else
      l = c;
  }

  cout << r << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int a,b;
  cin >> a >> b;
  if(a + b == 15)puts("+");
  else if(a * b == 15)puts("*");
  else puts("x");
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll current=100;
    ll target;
    cin>>target;
    for(int i=0;;i++)
    {
        if(current>=target)
        {
            cout<<i<<endl;
            break;
        }
        current=(current+current/100);
    }
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	string S; cin >> S;
	Cout(Yes(S[0] == S[2]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int ans=0;
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    for(int k=j+1;k<=n;k++)
    if(a[i]+a[j]<=a[k]||a[i]+a[k]<=a[j]||a[j]+a[k]<=a[i]);
    else if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])ans++;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int MAXM = 2e5 + 5;
const int inf = 0x3f3f3f3f;

struct Segment_Tree
{
	int mn[MAXM<<2], tag[MAXM<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	#define lson(u) ls(u),l,mid
	#define rson(u) rs(u),mid+1,r
	inline void push_up(int u){ mn[u] = min(mn[ls(u)], mn[rs(u)]);}
	inline void push_down(int u,int l,int r)
	{
		if(tag[u] != -inf)
		{
			int mid = (l+r)>>1;
			tag[ls(u)] = mn[ls(u)] = tag[u];
			tag[rs(u)] = mn[rs(u)] = tag[u] + (mid-l+1);
			tag[u] = -inf;
		}
	}
	void build(int u,int l,int r)
	{
		mn[u]=0; tag[u]=-inf;
		if(l==r) return;
		int mid = (l+r)>>1;
		build(lson(u)); build(rson(u));
	}
	void update(int u,int l,int r,int ql,int qr,int k)
	{
		if(ql<=l&&r<=qr){ tag[u] = mn[u] = k + (l-ql); return;}
		push_down(u,l,r);
		int mid = (l+r)>>1;
		if(ql<=mid) update(lson(u), ql,qr,k);
		if(mid<qr) update(rson(u), ql,qr,k);
		push_up(u);
	}
	int query(int u,int l,int r,int q)
	{
		if(l==r) return mn[u];
		push_down(u,l,r);
		int mid = (l+r)>>1, res;
		if(q<=mid) res = query(lson(u), q);
		else res = query(rson(u), q);
		push_up(u);
		return res;
	}
	int query(int u,int l,int r,int ql,int qr)
	{
		if(ql<=l && r<=qr) return mn[u];
		push_down(u,l,r);
		int mid = (l+r)>>1, res = inf;
		if(ql<=mid) res = min(res, query(lson(u),ql,qr));
		if(mid<qr) res = min(res, query(rson(u),ql,qr));
		push_up(u);
		return res;
	}
};

int a[MAXN], b[MAXN];

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%d%d",&a[i],&b[i]);
	
	static Segment_Tree tree;
	tree.build(1,1,m);
	
	int lef = 1;
	for(int i=1; i<=n; ++i)
	{
		if(a[i] <= lef) lef = max(lef, b[i]+1);
		else tree.update(1,1,m, a[i],b[i], tree.query(1,1,m,a[i]-1) + 1);
		
		if(lef > m){ printf("-1\n"); continue;}
		else printf("%d\n",tree.query(1,1,m, lef,m) + i);
	}
	return 0;
}


Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

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

	// 現時点での最大値を、その次の値に追いつくまで連続して減らす
	// 辞書順にするため、右のインデックスから減らしていく
	// そのため、左端のインデックスと、同一値の数が必要になる
	map<ll, ll> midx, count;
	for (ll i = 0; i < n; ++i) {
		++count[a[i]];
		if (midx.count(a[i]) == 0) midx[a[i]] = i;
		// midx.try_emplace(a[i] , i);
	}


	map<ll, ll> ans;
	ll sum = 0;
	for (auto it = count.rbegin(); it != count.rend(); ++it) {
		ll val = it->first;
		ll num = it->second;

		auto ne = it; ++ne;
		ll nval = 0;
		if (ne != count.rend()) nval = ne->first;

		ans[midx[val]] += (val - nval)*(sum + num);

		// 追いつくたびに、同一値の数は累積する
		sum += num;

		// 追いつくたびに、左端インデックスの更新を確認
		midx[nval] = min(midx[nval], midx[val]);
	}

	for (int i = 0; i < n; ++i) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

struct data{
	char c;
	int size;
};

std::vector<data> v;

int main(){
	std::string str;
	std::cin >> str;
	str += 'E';

	int s = 0;
	for (int i = 0; i < str.size() - 1; i++){
		if (str[i + 1] != str[i]){
			data d;
			d.c = str[i];
			d.size = i - s + 1;
			v.push_back(d);

			s = i + 1;
		}
	}

	int res = 0;
	for (int i = 1; i < v.size() - 1; i++){
		if (v[i - 1].c == 'J' && v[i].c == 'O' && v[i + 1].c == 'I'){
			int min = std::min(std::min(v[i - 1].size, v[i].size), v[i + 1].size);
			if (min == v[i].size)res = std::max(res, min);
		}
	}

	std::cout << res << std::endl;

	return 0;
}

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

int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    int x[N];
    for(int i=0;i<N;i++){
        cin>>x[i];
    }
    int y[M];
    for(int i=0;i<M;i++){
        cin>>y[i];
    }
    int line=200;
    for(int i=0;i<M;i++){
        if(y[i]<=line){
            line=y[i];
        }
    }
    if(X>=line or Y<line){
        cout<<"War"<<endl;
    }else{
        int mark=0;
        for(int i=0;i<N;i++){
            if(x[i]>=line){
                mark=-1;
            }
        }
        if(mark<0){
            cout<<"War"<<endl;
        }else{
            cout<<"No War"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int K;
    cin >>K;
    vector<vector<vector<long long>>> keta(12,vector<vector<long long>>(10));
    vector<long long> runrun;
    for (int i=0;i<10;i++)
    {
        keta[1][i].push_back(i);
        runrun.push_back(i);
    }
    for (int i=1;i<11;i++)
    {
        for (int j=0;j<10;j++)
        {
            if (j==0)
            {
                for (int k=0;k<keta[i][j].size();k++) keta[i+1][j].push_back(keta[i][j][k]);
                for (int k=0;k<keta[i][j+1].size();k++) keta[i+1][j].push_back(keta[i][j+1][k]);
            }
            if (j==9)
            {
                for (int k=0;k<keta[i][j].size();k++) 
                {
                    keta[i+1][j].push_back(j*pow(10,i)+keta[i][j][k]);
                    runrun.push_back(j*pow(10,i)+keta[i][j][k]);
                }
                for (int k=0;k<keta[i][j-1].size();k++) 
                {
                    keta[i+1][j].push_back(j*pow(10,i)+keta[i][j-1][k]);
                    runrun.push_back(j*pow(10,i)+keta[i][j-1][k]);
                }
            }
            if (j>=1 && j<=8)
            {
                for (int k=0;k<keta[i][j].size();k++) 
                {
                    keta[i+1][j].push_back(j*pow(10,i)+keta[i][j][k]);
                    runrun.push_back(j*pow(10,i)+keta[i][j][k]);
                }
                for (int k=0;k<keta[i][j-1].size();k++) 
                {
                    keta[i+1][j].push_back(j*pow(10,i)+keta[i][j-1][k]);
                    runrun.push_back(j*pow(10,i)+keta[i][j-1][k]);
                }
                for (int k=0;k<keta[i][j+1].size();k++) 
                {
                    keta[i+1][j].push_back(j*pow(10,i)+keta[i][j+1][k]);
                    runrun.push_back(j*pow(10,i)+keta[i][j+1][k]);
                }
            }
        }
    }
    sort(runrun.begin(),runrun.end());
    unique(runrun.begin(),runrun.end());
    cout <<runrun[K] << endl;
return 0;

}

Measured memory_bytes: 15468
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(ll, N);

    ll sum = 0;

    for (ll i = 1; i < sqrt(N); i++) {
        if ( N % i == 0 ) {
            ll a = i;
            ll b = N / i;

            if ( b < a - 1 ) {
                sum += (a-1);
            }
            if ( a < b - 1 ) {
                sum += (b-1);
            }
        }
    }

    cout << sum << "\n";
    return 0;
}

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

using namespace std;
int main(){
while(1){
	int a,b,n;
	int dp[20][20] = {0};
	int c[20][20] = {0};
	scanf("%d%d",&a,&b);
	if(a == 0 && b == 0)break;
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		c[x][y] = 1;
	}
	dp[1][1] = 1;

	for(int i = 1;i <= b;i++){
		for(int j = 1;j <= a;j++){
			if(c[j][i] == 1)continue;
			if(i == 1 && j == 1)continue;
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
		}
	}

	printf("%d\n",dp[b][a]);
}
	return 0;
}


Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Grid Compression
            var line = ReadLine();
            int h = line[0];

            var grid = GetGrid(h).ToList();

            //再帰処理
            Compress(grid);

            foreach(var g in grid)
            {
                string s = String.Join("", g);
                Console.WriteLine(s);
            }
        }

        static void Compress(List<List<char>> grid)
        {
            int h = grid.Count;
            int w = grid[0].Count;
            bool isTryAgain = false;

            //横方向のチェック
            for (int i = 0; i < h; i++)
            {
                bool isAllWhite = true;

                for(int j = 0; j < w; j++)
                {
                    if (grid[i][j] == '#')
                    {
                        isAllWhite = false;
                        break;
                    }
                }

                if (isAllWhite)
                {
                    grid.RemoveAt(i);
                    isTryAgain = true;
                    break;
                }
            }

            //すでに行削除された可能性もある
            h = grid.Count;

            //縦方向のチェック
            for (int j = 0; j < w; j++)
            {
                bool isAllWhite = true;

                for (int i = 0; i < h; i++)
                {
                    if (grid[i][j] == '#')
                    {
                        isAllWhite = false;
                        break;
                    }
                }

                if (isAllWhite)
                {
                    for(int i = 0; i < h; i++)
                    {
                        grid[i].RemoveAt(j);
                    }

                    isTryAgain = true;
                    break;
                }
            }

            if (isTryAgain)
            {
                Compress(grid);
            }
        }

        static IEnumerable<List<char>> GetGrid(int h)
        {
            for(int i = 0; i < h; i++)
            {
                string line = Console.ReadLine();
                var array = line.ToCharArray();
                yield return array.ToList();
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<int>();

            foreach (var s in array)
            {
                int num = int.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 11348
<?php

  $arr = explode(' ', fgets(STDIN));
  $five = 0;
  $seven = 0;
  foreach($arr as $key => $value) {
    $arr[$key] = intval($value);
    if ($arr[$key] === 5) {
      $five++;
      continue;
    }

    if ($arr[$key] === 7) {
      $seven++;
      continue;
    }
  }

  if  ($five === 2 && $seven === 1) {
    echo 'YES';
    return;
  }

  echo 'NO';
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 2;
const int INF = 2e18;

signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    cin >> S;
    int ans = INF;
    for (int i = 0; i < (1<<(H - 1)); i++) {
        vector<int> count(H, 0), cut(H, 0);
        int res = 0;
        {
            int temp = 0;
            for (int j = 0; j < H; j++) {
                cut[j] = temp;
                if ((i>>j)&1) temp++;
            }
            res += temp;
        }
        for (int j = 0; j < W; j++) {
            for (int k = 0; k < H; k++) {
                if (S[k][j] == '1') count[cut[k]]++;
            }
            {
                bool check = true;
                for (int k = 0; k < H; k++) {
                    if (count[cut[k]] > K) check = false;
                }
                if (!check) {
                    res++;
                    for (int k = 0; k < H; k++) count[cut[k]] = 0;
                    for (int k = 0; k < H; k++) count[cut[k]] += (S[k][j] == '1');
                    for (int k = 0; k < H; k++) {
                        if (count[cut[k]] > K) res = INF;
                    }
                }
            }
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    int a[n - 1], b[n - 1];
    rep(i, 0, n - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    set<int> usedcolor;
    map<pair<int, int>, int> mp;
    queue<pair<int, int>> que;
    que.push(make_pair(-1, 0));
    bool visited[n] = {};
    while (!que.empty()) {
        int p = que.front().first;
        int v = que.front().second;
        que.pop();
        visited[v] = true;
        int pc = 0;
        if (v != 0) pc = mp[make_pair(p, v)];
        int c = 0;
        for (auto nv : g[v]) {
            if (visited[nv]) continue;
            if (v == 0) {
                mp[make_pair(v, nv)] = c;
                usedcolor.insert(c);
                c++;
            } else {
                if (c == pc) {
                    c++;
                    mp[make_pair(v, nv)] = c;
                    usedcolor.insert(c);
                    c++;
                } else {
                    mp[make_pair(v, nv)] = c;
                    usedcolor.insert(c);
                    c++;
                }
            }
            que.push(make_pair(v, nv));
        }
    }

    cout << usedcolor.size() << endl;
    rep(i, 0, n - 1) {
        cout << mp[make_pair(a[i], b[i])] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;
static const int INF = 99999999;
struct Data
{
	int e, f, g, h;
};
int flag[301];

void solve()
{
	int a, b, c, N;
	while(cin >> a >> b >> c, a || b || c)
	{
		cin >> N;
		vector<Data> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i].e >> Vec[i].f >> Vec[i].g >> Vec[i].h;
		}
		int size = a + b + c;
		for(int i = 1; i <= size; ++i)
		{
			flag[i] = INF;
		}
		for(int i = 0; i < N; ++i)
		{
			if(Vec[i].h == 1)
			{
				flag[Vec[i].e] = flag[Vec[i].f] = flag[Vec[i].g] = 1;
			}
		}
		bool update = true;
		while(update)
		{
			update = false;
			for(int i = 0; i < N; ++i)
			{
				if(Vec[i].h == 0)
				{
					if((flag[Vec[i].e] + flag[Vec[i].f] + flag[Vec[i].g]) == (INF + 2))
					{
						if(flag[Vec[i].e] == INF)
						{
							flag[Vec[i].e] = 0;
						}
						else if(flag[Vec[i].f] == INF)
						{
							flag[Vec[i].f] = 0;
						}
						else if(flag[Vec[i].g] == INF)
						{
							flag[Vec[i].g] = 0;
						}
						update = true;
					}
				}
			}
		}
		for(int i = 1; i <= size; ++i)
		{
			if(flag[i] == INF)
			{
				cout << 2 << endl;
			}
			else
			{
				cout << flag[i] << endl;
			}
		}
	}
}

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

Measured memory_bytes: 0